Jamoma API  0.6.0.a19
TTAttribute.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief The TTAttribute class represents a single attribute, as used by the TTObjectBase class.
6  *
7  * @details
8  *
9  * @author Timothy Place, Theo de la Hogue, Nils Peters, Trond Lossius
10  *
11  * @copyright Copyright © 2008, Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTObject.h"
17 #include "TTMatrix.h"
18 #include "TTEnvironment.h"
19 #include "TTCallback.h"
20 
21 
22 TTAttribute::TTAttribute(const TTSymbol newName, TTDataType newType, void* newAddress) :
24  name(newName),
25  type(newType),
26  address(newAddress),
27  getterObject(NULL),
28  setterObject(NULL),
29  getterFlags(kTTAttrDefaultFlags),
30  setterFlags(kTTAttrDefaultFlags),
31  readOnly(NO),
32  rangeLowBound(0.0),
33  rangeHighBound(1.0),
34  rangeChecking(kTTSym_none),
35  hidden(NO),
36  description(kTTSymEmpty),
37  mDefaultValue(0)
38 {
41 }
42 
43 TTAttribute::TTAttribute(const TTSymbol newName, TTDataType newType, void* newAddress, TTGetterMethod newGetter)
44 : TTObjectBase(TTValue()), name(newName), type(newType), address(newAddress), getter(newGetter), getterObject(NULL), setterObject(NULL), getterFlags(kTTAttrDefaultFlags), setterFlags(kTTAttrDefaultFlags),
45  readOnly(NO), rangeLowBound(0.0), rangeHighBound(1.0), rangeChecking(kTTSym_none), hidden(NO), description(kTTSymEmpty), mDefaultValue(0)
46 {
48 }
49 
50 TTAttribute::TTAttribute(const TTSymbol newName, TTDataType newType, void* newAddress, TTSetterMethod newSetter)
51 : TTObjectBase(TTValue()), name(newName), type(newType), address(newAddress), setter(newSetter), getterObject(NULL), setterObject(NULL), getterFlags(kTTAttrDefaultFlags), setterFlags(kTTAttrDefaultFlags),
52  readOnly(NO), rangeLowBound(0.0), rangeHighBound(1.0), rangeChecking(kTTSym_none), hidden(NO), description(kTTSymEmpty), mDefaultValue(0)
53 {
55 }
56 
57 TTAttribute::TTAttribute(const TTSymbol newName, TTDataType newType, void* newAddress, TTGetterMethod newGetter, TTSetterMethod newSetter)
58 : TTObjectBase(TTValue()), name(newName), type(newType), address(newAddress), getter(newGetter), setter(newSetter), getterObject(NULL), setterObject(NULL), getterFlags(kTTAttrDefaultFlags), setterFlags(kTTAttrDefaultFlags),
59  readOnly(NO), rangeLowBound(0.0), rangeHighBound(1.0), rangeChecking(kTTSym_none), hidden(NO), description(kTTSymEmpty), mDefaultValue(0)
60 {
61  ;
62 }
63 
64 TTAttribute::TTAttribute(const TTSymbol newName, const TTObjectBasePtr newGetterObject, const TTObjectBasePtr newSetterObject)
65 : TTObjectBase(TTValue()), name(newName), type(kTypeNone), getterObject(newGetterObject), setterObject(newSetterObject), getterFlags(kTTAttrPassObject), setterFlags(kTTAttrPassObject),
66  readOnly(NO), rangeLowBound(0.0), rangeHighBound(1.0), rangeChecking(kTTSym_none), hidden(NO), description(kTTSymEmpty), mDefaultValue(0)
67 {
70 }
71 
72 TTAttribute::TTAttribute(TTAttributePtr extendedAttribute, const TTObjectBasePtr extendedObject)
73 : TTObjectBase(TTValue()), name(extendedAttribute->name), type(extendedAttribute->type), getterObject(extendedObject), setterObject(extendedObject), getterFlags(kTTAttrPassObject), setterFlags(kTTAttrPassObject),
74 readOnly(extendedAttribute->readOnly), rangeLowBound(extendedAttribute->rangeLowBound), rangeHighBound(extendedAttribute->rangeHighBound), rangeChecking(extendedAttribute->rangeChecking), description(kTTSymEmpty), mDefaultValue(0)
75 {
78 }
79 
81 {
82  ;
83 }
84 
85 
87 {
88  getterFlags = newFlags;
89 }
90 
92 {
93  currentFlags = getterFlags;
94 }
95 
97 {
98  setterFlags = newFlags;
99 }
100 
102 {
103  currentFlags = setterFlags;
104 }
105 
106 
108 {
109  switch(attribute.type) {
110  case kTypeFloat32:
111  value = *((TTFloat32*)attribute.address);
112  return kTTErrNone;
113  case kTypeFloat64:
114  value = *((TTFloat64*)attribute.address);
115  return kTTErrNone;
116  case kTypeInt8:
117  value = *((TTInt8*)attribute.address);
118  return kTTErrNone;
119  case kTypeUInt8:
120  value = *((TTUInt8*)attribute.address);
121  return kTTErrNone;
122  case kTypeInt16:
123  value = *((TTInt16*)attribute.address);
124  return kTTErrNone;
125  case kTypeUInt16:
126  value = *((TTUInt16*)attribute.address);
127  return kTTErrNone;
128  case kTypeInt32:
129  value = (int)*((TTInt32*)attribute.address);
130  return kTTErrNone;
131  case kTypeUInt32:
132  value = *((TTUInt32*)attribute.address);
133  return kTTErrNone;
134  case kTypeInt64:
135  value = *((TTInt64*)attribute.address);
136  return kTTErrNone;
137  case kTypeUInt64:
138  value = *((TTUInt64*)attribute.address);
139  return kTTErrNone;
140  case kTypeBoolean:
141  value = *((TTBoolean*)attribute.address);
142  return kTTErrNone;
143  case kTypeSymbol:
144  value = *((TTSymbol*)attribute.address);
145  return kTTErrNone;
146  case kTypeObject:
147  value = *((TTObject*)attribute.address);
148  return kTTErrNone;
149 // case kTypeMatrix:
150 // value = *((TTMatrix*)attribute.address);
151 // return kTTErrNone;
152  case kTypePointer:
153  value = *((TTPtr*)attribute.address);
154  return kTTErrNone;
155  case kTypeNone:
156  return kTTErrNone;
157  case kTypeLocalValue:
158  value = *((TTValue*)attribute.address);
159  return kTTErrNone;
160 
161  case kTypeString:
162 
163  case kNumTTDataTypes:
164  default:
165  return kTTErrInvalidType;
166  }
167  return kTTErrInvalidType;
168 }
169 
170 
171 TTErr TTAttribute::defaultSetter(const TTAttribute& attribute, const TTValue& value)
172 {
173  switch (attribute.type) {
174  case kTypeFloat32:
175  *((TTFloat32*)attribute.address) = value;
176  return kTTErrNone;
177  case kTypeFloat64:
178  *((TTFloat64*)attribute.address) = value;
179  return kTTErrNone;
180  case kTypeInt8:
181  *((TTInt8*)attribute.address) = value;
182  return kTTErrNone;
183  case kTypeUInt8:
184  *((TTUInt8*)attribute.address) = value;
185  return kTTErrNone;
186  case kTypeInt16:
187  *((TTInt16*)attribute.address) = value;
188  return kTTErrNone;
189  case kTypeUInt16:
190  *((TTUInt16*)attribute.address) = value;
191  return kTTErrNone;
192  case kTypeInt32:
193  *((TTInt32*)attribute.address) = value;
194  return kTTErrNone;
195  case kTypeUInt32:
196  *((TTUInt32*)attribute.address) = value;
197  return kTTErrNone;
198  case kTypeInt64:
199  *((TTInt64*)attribute.address) = value;
200  return kTTErrNone;
201  case kTypeUInt64:
202  *((TTUInt64*)attribute.address) = value;
203  return kTTErrNone;
204  case kTypeBoolean:
205  *((TTBoolean*)attribute.address) = value;
206  return kTTErrNone;
207  case kTypeSymbol:
208  *((TTSymbol*)attribute.address) = value;
209  return kTTErrNone;
210  case kTypeObject:
211  *((TTObject*)attribute.address) = value;
212  return kTTErrNone;
213 // case kTypeMatrix:
214 // *((TTMatrix*)attribute.address) = value;
215 // return kTTErrNone;
216  case kTypePointer:
217  *((TTPtr*)attribute.address) = (TTPtr)value;
218  return kTTErrNone;
219  case kTypeNone:
220  return kTTErrNone;
221 
222  case kTypeString:
223  case kTypeLocalValue:
224  case kNumTTDataTypes:
225  default:
226  return kTTErrInvalidType;
227  }
228  return kTTErrInvalidType;
229 }
230 
232 {
233  TTCallbackPtr aGetter = (TTCallbackPtr)attribute.getterObject;
234 
235  return aGetter->notify(value, value);
236 }
237 
239 {
240  TTCallbackPtr aSetter = (TTCallbackPtr)attribute.setterObject;
241 
242  return aSetter->notify(value, value);
243 }
244 
246 {
247  TTObjectBasePtr anExtendedObject = (TTObjectBasePtr)attribute.getterObject;
248 
249  return anExtendedObject->getAttributeValue(attribute.name, value);
250 }
251 
253 {
254  TTObjectBasePtr anExtendedObject = (TTObjectBasePtr)attribute.setterObject;
255 
256  return anExtendedObject->setAttributeValue(attribute.name, value);
257 }
258 
259 TTErr TTAttribute::setreadOnly(const TTValue& newReadOnlyValue)
260 {
261  readOnly = newReadOnlyValue;
262  return kTTErrNone;
263 }
264 
265 TTErr TTAttribute::getreadOnly(TTValue& currentReadOnlyValue)
266 {
267  currentReadOnlyValue = readOnly;
268  return kTTErrNone;
269 }
270 
271 
273 {
274  if (newRange.size() == 2) {
275  rangeLowBound = newRange[0];
276  rangeHighBound = newRange[1];
277  return kTTErrNone;
278  }
279  else
280  return kTTErrWrongNumValues;
281 }
282 
284 {
285  currentRange.clear();
286  currentRange.push_back(rangeLowBound);
287  currentRange.append(rangeHighBound);
288  return kTTErrNone;
289 }
290 
291 
292 TTErr TTAttribute::setrangeChecking(const TTValue& newRangeCheckingMode)
293 {
294  rangeChecking = newRangeCheckingMode;
295  return kTTErrNone;
296 }
297 
298 TTErr TTAttribute::getrangeChecking(TTValue& currentRangeCheckingMode)
299 {
300  currentRangeCheckingMode = rangeChecking;
301  return kTTErrNone;
302 }
303 
304 
305 TTErr TTAttribute::sethidden(const TTValue& newHiddenFlag)
306 {
307  hidden = newHiddenFlag;
308  return kTTErrNone;
309 }
310 
312 {
313  currentHiddenFlag = hidden;
314  return kTTErrNone;
315 }
316 
317 
319 {
320  description = newDescription[0];
321  return kTTErrNone;
322 }
323 
325 {
326  returnedDescription = description;
327  return kTTErrNone;
328 }
329 
330 
331 TTErr TTAttribute::setdefaultValue(const TTValue& aDefaultValue)
332 {
333  mDefaultValue = aDefaultValue;
334  return kTTErrNone;
335 }
336 
337 TTErr TTAttribute::getdefaultValue(TTValue& aReturnedDefaultValue)
338 {
339  aReturnedDefaultValue = mDefaultValue;
340  return kTTErrNone;
341 }
342 
const TTObjectBasePtr getterObject
TTObjectBasePtr to fetch the attribute value.
Definition: TTAttribute.h:88
TTErr(TTObjectBase::* TTSetterMethod)(const TTAttribute &attribute, const TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:78
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr setrangeChecking(const TTValue &newRangeCheckingMode)
Set the range boundary checking mode property for the attribute.
void getSetterFlags(TTAttributeFlags &currentFlags)
Get the current setterFlag property of the attribute, describing the behavior of the attribute setter...
This class is used to be sensitive to any TTObject notifications and report them using a function wit...
Definition: TTCallback.h:28
Create Jamoma object instances.
TTErr getrange(TTValue &currentRange)
Get the range of possible values for the attribute.
TTSymbol description
Property: description of this attribute.
Definition: TTAttribute.h:99
TTErr getdescription(TTValue &returnedDescription)
Get the description property of the attribute, used for documentation purposes.
std::uint64_t TTUInt64
64 bit unsigned integer
Definition: TTBase.h:180
TTDataType type
The data type of the attribute value.
Definition: TTAttribute.h:84
void * address
Pointer to the memory holding the attribute value.
Definition: TTAttribute.h:85
8-bit unsigned integer, range is 0 through 255.
Definition: TTBase.h:274
Object type.
Definition: TTBase.h:283
TTErr setreadOnly(const TTValue &newReadOnlyValue)
Set the readOnly property of the attribute, controlling if the attribute value can be changed or not...
Create and use Jamoma object instances.
Definition: TTObject.h:29
64-bit unsigned integer, range is 0 through 18,446,744,073,709,551,615.
Definition: TTBase.h:280
TTAttribute(const TTSymbol newName, TTDataType newType, void *newAddress)
Object constructor.
Definition: TTAttribute.cpp:22
size_type size() const noexcept
Return the number of elements.
TTErr extendedGetter(const TTAttribute &attribute, TTValue &value)
TODO: This needs to be documented.
TTDataType
TTBlue Data Types Enumeration of data types used through out TTBlue, including the TTValue class and ...
Definition: TTBase.h:269
TTErr getreadOnly(TTValue &currentReadOnlyValue)
Get the readOnly property of the attribute, controlling if the attribute value can be changed or not...
Bad DataType for the context.
Definition: TTBase.h:347
The wrong number of values were passed to a method or attribute.
Definition: TTBase.h:350
TTErr getAttributeValue(const TTSymbol name, TTValue &value)
Get an attribute value for an object.
This class represents a single attribute, as used by the TTObjectBase class.
Definition: TTAttribute.h:79
TTValue mDefaultValue
Property: the default value for this attribute.
Definition: TTAttribute.h:100
TTSetterMethod setter
Method to set the attribute value.
Definition: TTAttribute.h:87
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTErr gethidden(TTValue &currentHiddenFlag)
Get the hidden flag for the attribute, indicating if this attribute is private/invisible to the outsi...
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
Symbol type.
Definition: TTBase.h:282
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
This is a special type used by TTAttribute to indicate that a value is a TTValue and is locally maint...
Definition: TTBase.h:286
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
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
std::int64_t TTInt64
64 bit signed integer
Definition: TTBase.h:179
std::int16_t TTInt16
16 bit signed integer
Definition: TTBase.h:175
TTErr getrangeChecking(TTValue &currentRangeCheckingMode)
Get the range boundary checking mode property for the attribute.
TTBoolean hidden
Property: this attribute is private/invisible to the outside world.
Definition: TTAttribute.h:98
TTErr defaultGetter(const TTAttribute &attribute, TTValue &value)
The default method for getting the current attribute value.
This class is used to create a backward communication channel to notify a client that something chang...
16-bit signed integer, range is −32,768 through 32,767.
Definition: TTBase.h:275
void setGetterFlags(TTAttributeFlags newFlags)
Set the getterFlag property of the attribute, defining the behavior of the attribute getter method...
Definition: TTAttribute.cpp:86
Attribute accessors will first be passed a reference to the TTAttribute object, then it will be passe...
Definition: TTObjectBase.h:97
64-bit floating point
Definition: TTBase.h:272
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr defaultSetter(const TTAttribute &attribute, const TTValue &value)
The default method for setting the attribute value.
const TTObjectBasePtr setterObject
TTObjectBasePtr to set the attribute value.
Definition: TTAttribute.h:89
TTErr setrange(const TTValue &newRange)
Set the range of possible values for the attribute.
float TTFloat32
32 bit floating point number
Definition: TTBase.h:187
The default set of flags will be used if this is specified. At this time the default is kTTAttrPassVa...
Definition: TTObjectBase.h:95
TTAttributeFlags setterFlags
Define the behavior of the attribute setter method.
Definition: TTAttribute.h:91
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
TTErr extendedSetter(const TTAttribute &attribute, TTValue &value)
TODO: This needs to be documented.
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTErr callbackSetter(const TTAttribute &attribute, TTValue &value)
TODO: This needs to be documented.
64-bit signed integer, ragne is −9,223,372,036,854,775,808 through 9,223,372,036,854,775,807
Definition: TTBase.h:279
virtual ~TTAttribute()
Object destructor.
Definition: TTAttribute.cpp:80
32-bit floating point
Definition: TTBase.h:271
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
TTFloat64 rangeLowBound
If the range property is defined, this is the bottom of a value's range.
Definition: TTAttribute.h:95
TTMatrix wraps a TTMatrixBase for use.
TTEnvironment is a global object providing information on the environemt.
TTCallback * TTCallbackPtr
Pointer to a TTCallback object.
Definition: TTCallback.h:75
const TTSymbol name
The name of the attribute.
Definition: TTAttribute.h:83
TTErr setdescription(const TTValue &newDescription)
Set the description property of the attribute, used for documentation purposes.
32-bit signed integer, range is -2,147,483,648 through 2,147,483,647.
Definition: TTBase.h:277
void getGetterFlags(TTAttributeFlags &currentFlags)
Get the current getterFlag property of the attribute, describing the behavior of the attribute getter...
Definition: TTAttribute.cpp:91
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
signed char TTInt8
8 bit signed integer (char)
Definition: TTBase.h:173
void setSetterFlags(TTAttributeFlags newFlags)
Set the setterFlag property of the attribute, defining the behavior of the attribute setter method...
Definition: TTAttribute.cpp:96
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
Pointer type.
Definition: TTBase.h:284
TTErr sethidden(const TTValue &newHiddenFlag)
Set the hidden flag for the attribute, determining if this attribute is private/invisible to the outs...
TTFloat64 rangeHighBound
If the range property is defined, this is the top of a value's range.
Definition: TTAttribute.h:96
TTAttributeFlags getterFlags
Define the behavior of the attribute getter method.
Definition: TTAttribute.h:90
TTErr callbackGetter(const TTAttribute &attribute, TTValue &value)
TODO: This needs to be documented.
TTAttributeFlags
Flags that determine the behavior of messages.
Definition: TTObjectBase.h:94
32-bit unsigned integer, range is 0 through 4,294,967,295.
Definition: TTBase.h:278
8-bit signed integer, range is -128 through 127.
Definition: TTBase.h:273
No Error.
Definition: TTBase.h:343
TTErr notify(const TTValue &anInputValue, TTValue &anUnusedOutputValue)
Message called because we are registered as an observer to some other object, and then calls our exte...
Definition: TTCallback.cpp:69
TTGetterMethod getter
Method to fetch the attribute value.
Definition: TTAttribute.h:86
String type.
Definition: TTBase.h:285
TTSymbol rangeChecking
If the rangeChecking property is defined, the value should be checked for range and modified accordin...
Definition: TTAttribute.h:97
TTErr(TTObjectBase::* TTGetterMethod)(const TTAttribute &attribute, TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:73
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTBoolean readOnly
The readonly property, if defined, means an attribute cannot be set.
Definition: TTAttribute.h:94
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174