Jamoma API  0.6.0.a19
TTClock.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief A Clock interface
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright © 2013, Théo de la Hogue @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #ifndef __TT_CLOCK_H__
18 #define __TT_CLOCK_H__
19 
20 #include "TTFoundationAPI.h"
21 #include <atomic>
22 
23 #define TT_CLOCK_CONSTRUCTOR \
24 TTObjectBasePtr thisTTClass :: instantiate (TTSymbol name, TTValue arguments) {return new thisTTClass (arguments);} \
25 \
26 extern "C" void thisTTClass :: registerClass () {TTClassRegister( TTSymbol(thisTTClassName), thisTTClassTags, thisTTClass :: instantiate );} \
27 \
28 thisTTClass :: thisTTClass (const TTValue& arguments) : TTClock(arguments)
29 
30 #define TT_CLOCK_INITIALIZE \
31 mName = TTSymbol(thisTTClassName); \
32 mVersion = TTSymbol(thisClockVersion); \
33 mAuthor = TTSymbol(thisClockAuthor); \
34 mStretchable = TTSymbol(thisClockStretchable); \
35 registerAttribute(TTSymbol("parameterNames"), kTypeLocalValue, NULL, (TTGetterMethod)& thisTTClass::getParameterNames); \
36 /*addAttributeProperty(ParameterNames, readOnly, YES); \ */
37 
38 typedef void (*TTClockPositionCallback)(TTPtr, TTFloat64, TTFloat64);
39 
40 /****************************************************************************************************/
41 // Class Specification
42 
43 /** TTClock is the base class for all Clock Unit.
44  It still has knowledge and support for ...
45  */
46 class TTClock : public TTObjectBase {
47 
48 public:
49 
50  TTSymbol mName; ///< ATTRIBUTE : the name of the clock
51  TTSymbol mVersion; ///< ATTRIBUTE : the version of the clock
52  TTSymbol mAuthor; ///< ATTRIBUTE : the author of the clock
53  TTBoolean mStretchable; ///< ATTRIBUTE : is the clock provide stretch feature ?
54 
55 protected:
56 
57  TTFloat64 mDuration; ///< ATTRIBUTE : the time (in ms) the clock will run at normal speed factor
58  TTFloat64 mOffset; ///< ATTRIBUTE : the date (in ms) the sheduler will run from
59  TTFloat64 mSpeed; ///< ATTRIBUTE : the speed factor of the clock
60  TTBoolean mExternalTick; ///< ATTRIBUTE : if true the Tick message comes from an external source
61  TTBoolean mInfinite; ///< ATTRIBUTE : if true the clock will run until Stop (this attribute overrides mDuration)
62 
63  bool mRunning; ///< ATTRIBUTE : is the clock running right now ?
64  TTBoolean mPaused; ///< ATTRIBUTE : is the clock paused right now ?
65  TTFloat64 mPosition; ///< ATTRIBUTE : the progression of the clock between the beginning and the end [0. :: 1.]
66  TTFloat64 mDate; ///< ATTRIBUTE : how many time the clock is running (without no speed factor consideration)
67 
68  TTClockPositionCallback mCallback; ///< the callback to use for each step
69  TTPtr mBaton; ///< the baton to use for each step
70 
71 public:
72 
73  //** Constructor. */
74  TTClock(const TTValue& arguments);
75 
76  /** Destructor. */
77  virtual ~TTClock();
78 
79  /** Get specific parameters names needed by this clock
80  @return an error code if the clock fails to give his specific parameters */
81  virtual TTErr getParameterNames(TTValue& value) = 0;
82 
83  /** Start the clock
84  @return an error code if the clock fails to start */
85  virtual TTErr Go() = 0;
86 
87  /** Halt the sheduler
88  @return an error code if the clock fails to stop */
89  virtual TTErr Stop() = 0;
90 
91  /** Pause the sheduler progression
92  @return an error code if the clock fails to pause */
93  virtual TTErr Pause() = 0;
94 
95  /** Resume the sheduler progression
96  @return an error code if the clock fails to resume */
97  virtual TTErr Resume() = 0;
98 
99  /** Called every time a new step should be processed
100  @return an error code if the clock step fails */
101  virtual TTErr Tick() = 0;
102 
103  /** set the duration attribute
104  @value new duration
105  @return kTTErrGeneric if the value is not a single TTFloat64 >= 0. */
106  TTErr setDuration(const TTValue& value);
107 
108  /** set the offset attribute
109  @value new offset
110  @return kTTErrGeneric if the value is not a single TTFloat64 */
111  TTErr setOffset(const TTValue& value);
112 
113  /** set the speed factor attribute
114  @value new speed factor
115  @return kTTErrGeneric if the value is not a single TTFloat64 */
116  TTErr setSpeed(const TTValue& value);
117 
118 };
119 typedef TTClock* TTClockPtr;
120 
121 #endif //__TT_CLOCK_H__
122 
123 
124 
125 #ifndef __TT_CLOCKLIB_H__
126 #define __TT_CLOCKLIB_H__
127 
128 class TT_EXTENSION_EXPORT TTClockLib {
129 public:
130 
131  /** Return a list of all available Clocks. */
132  static void getClockNames(TTValue& ClockNames);
133 
134  /** Return if a clock name is available */
135  static TTErr isClockNameAvailable(TTSymbol aClockName);
136 };
137 
138 #endif //__TT_CLOCKLIB_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr setSpeed(const TTValue &value)
set the speed factor attribute new speed factor
Definition: TTClock.cpp:129
virtual TTErr Resume()=0
Resume the sheduler progression.
bool mRunning
ATTRIBUTE : is the clock running right now ?
Definition: TTClock.h:63
TTSymbol mName
ATTRIBUTE : the name of the clock.
Definition: TTClock.h:50
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTFloat64 mDate
ATTRIBUTE : how many time the clock is running (without no speed factor consideration) ...
Definition: TTClock.h:66
TTErr setDuration(const TTValue &value)
set the duration attribute new duration
Definition: TTClock.cpp:82
TTClockPositionCallback mCallback
the callback to use for each step
Definition: TTClock.h:68
virtual TTErr Go()=0
Start the clock.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTBoolean mStretchable
ATTRIBUTE : is the clock provide stretch feature ?
Definition: TTClock.h:53
virtual TTErr Stop()=0
Halt the sheduler.
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
virtual TTErr Tick()=0
Called every time a new step should be processed.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTBoolean mInfinite
ATTRIBUTE : if true the clock will run until Stop (this attribute overrides mDuration) ...
Definition: TTClock.h:61
TTBoolean mExternalTick
ATTRIBUTE : if true the Tick message comes from an external source.
Definition: TTClock.h:60
TTSymbol mVersion
ATTRIBUTE : the version of the clock.
Definition: TTClock.h:51
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTBoolean mPaused
ATTRIBUTE : is the clock paused right now ?
Definition: TTClock.h:64
TTFloat64 mSpeed
ATTRIBUTE : the speed factor of the clock.
Definition: TTClock.h:59
TTClock is the base class for all Clock Unit.
Definition: TTClock.h:46
virtual TTErr Pause()=0
Pause the sheduler progression.
virtual TTErr getParameterNames(TTValue &value)=0
Get specific parameters names needed by this clock.
virtual ~TTClock()
Destructor.
Definition: TTClock.cpp:77
TTFloat64 mPosition
ATTRIBUTE : the progression of the clock between the beginning and the end [0. :: 1...
Definition: TTClock.h:65
TTErr setOffset(const TTValue &value)
set the offset attribute new offset
Definition: TTClock.cpp:110
TTFloat64 mOffset
ATTRIBUTE : the date (in ms) the sheduler will run from.
Definition: TTClock.h:58
TTFloat64 mDuration
ATTRIBUTE : the time (in ms) the clock will run at normal speed factor.
Definition: TTClock.h:57
TTSymbol mAuthor
ATTRIBUTE : the author of the clock.
Definition: TTClock.h:52
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTPtr mBaton
the baton to use for each step
Definition: TTClock.h:69