Jamoma API  0.6.0.a19
TTClock.cpp
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 #include "TTClock.h"
18 
19 #define thisTTClass TTClock
20 
21 /****************************************************************************************************/
22 
23 TTClock::TTClock(const TTValue& arguments) :
24 TTObjectBase(arguments),
25 mDuration(0.),
26 mOffset(0.),
27 mSpeed(1.),
28 mExternalTick(NO),
29 mInfinite(NO),
30 mRunning(NO),
31 mPaused(NO),
32 mPosition(0.),
33 mDate(0.),
34 mCallback(NULL),
35 mBaton(NULL)
36 {
37  mCallback = TTClockPositionCallback((TTPtr)arguments[0]);
38  mBaton = arguments[1];
39 
41  addAttributeProperty(Name, readOnly, YES);
42 
43  addAttribute(Version, kTypeSymbol);
44  addAttributeProperty(Version, readOnly, YES);
45 
46  addAttribute(Author, kTypeSymbol);
47  addAttributeProperty(Author, readOnly, YES);
48 
52  addAttribute(ExternalTick, kTypeBoolean);
53  addAttribute(Infinite, kTypeBoolean);
54 
55  addAttribute(Stretchable, kTypeBoolean);
56  addAttributeProperty(Stretchable, readOnly, YES);
57 
58  addAttribute(Running, kTypeBoolean);
59  addAttributeProperty(Running, readOnly, YES);
60 
61  addAttribute(Paused, kTypeBoolean);
62  addAttributeProperty(Paused, readOnly, YES);
63 
64  addAttribute(Position, kTypeFloat64);
65  addAttributeProperty(Position, readOnly, YES);
66 
68  addAttributeProperty(Date, readOnly, YES);
69 
70  addMessage(Go);
71  addMessage(Stop);
72  addMessage(Pause);
73  addMessage(Resume);
74  addMessage(Tick);
75 }
76 
78 {
79  ;
80 }
81 
83 {
84  if (value.size() == 1) {
85 
86  if (value[0].type() == kTypeFloat64) {
87 
88  mDuration = value[0];
89 
90  // update offset
91  if (mDuration < mOffset) {
92 
94 
95  sendNotification(TTSymbol("ClockOffsetChanged"), mOffset);
96  }
97 
99  mDate = mOffset;
100 
101  sendNotification(TTSymbol("ClockDurationChanged"), mDuration);
102 
103  return kTTErrNone;
104  }
105  }
106 
107  return kTTErrGeneric;
108 }
109 
111 {
112  if (value.size() == 1) {
113 
114  if (value[0].type() == kTypeFloat64) {
115 
116  mOffset = value[0];
118  mDate = mOffset;
119 
120  sendNotification(TTSymbol("ClockOffsetChanged"), mOffset);
121 
122  return kTTErrNone;
123  }
124  }
125 
126  return kTTErrGeneric;
127 }
128 
130 {
131  if (value.size() == 1) {
132 
133  if (value[0].type() == kTypeFloat64) {
134 
135  TTFloat64 newSpeed = value[0];
136 
137  if (newSpeed != mSpeed) {
138 
139  mSpeed = value[0];
140 
141  sendNotification(TTSymbol("ClockSpeedChanged"), mSpeed);
142  }
143 
144  return kTTErrNone;
145  }
146  }
147 
148  return kTTErrGeneric;
149 }
150 
151 /***************************************************************************
152 
153  ClockLib
154 
155  ***************************************************************************/
156 
157 void TTClockLib::getClockNames(TTValue& ClockNames)
158 {
159  ClockNames.clear();
160  ClockNames.append(TTSymbol("max"));
161  ClockNames.append(TTSymbol("system"));
162 }
163 
164 TTErr TTClockLib::isClockNameAvailable(TTSymbol aClockName)
165 {
166  if (aClockName == TTSymbol("max") || aClockName == TTSymbol("system"))
167  return kTTErrNone;
168  else
169  return kTTErrValueNotFound;
170 }
171 
TTErr setSpeed(const TTValue &value)
set the speed factor attribute new speed factor
Definition: TTClock.cpp:129
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
size_type size() const noexcept
Return the number of elements.
TTErr sendNotification(const TTSymbol name, const TTValue &arguments)
Send a notification.
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
Symbol type.
Definition: TTBase.h:282
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
Definition: TTValue.h:243
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
64-bit floating point
Definition: TTBase.h:272
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
A value was not found when doing a look up for it (in a TTHash, TTList, or other class).
Definition: TTBase.h:352
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTFloat64 mSpeed
ATTRIBUTE : the speed factor of the clock.
Definition: TTClock.h:59
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
A Clock interface.
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
No Error.
Definition: TTBase.h:343
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
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34