Jamoma API  0.6.0.a19
TTTrajectory.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspTrajectoryLib
4  *
5  * @brief A generalized Trajectory generator wrapper object for Jamoma DSP
6  *
7  * @details This file wraps TrajectoyLib for Max.
8  *
9  * @authors Nils Peters, Tim Place
10  *
11  * @copyright Copyright © 2009 by Nils Peters @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #ifndef __TT_TRAJECTORY_H__
17 #define __TT_TRAJECTORY_H__
18 
19 #include "TTDSP.h"
20 
21 /** Generalized Trajectory Function Wrapper
22 */
25 
26 protected:
27  TTAudioObjectBasePtr mActualTrajectoryObject; ///< The actual trajectory object that this object is currently wrapping
28  TTFloat64 mA; ///< Trajectory Parameter, usage depend on the actual trajectory
29  TTFloat64 mB; ///< Trajectory Parameter, usage depend on the actual trajectory
30  TTFloat64 mC; ///< Trajectory Parameter, usage depend on the actual trajectory
31  TTFloat64 mDeltaX; ///< Trajectory Parameter, usage depend on the actual trajectory
32  TTFloat64 mDeltaY; ///< Trajectory Parameter, usage depend on the actual trajectory
33  TTFloat64 mDeltaZ; ///< Trajectory Parameter, usage depend on the actual trajectory function
34  TTSymbol mType; ///< The name of the current trajectory type
35  TTSymbol mMode; ///< the underlying signal generator, can be "phasor" or "ramp"
36  //TTList mAnchorPoints;
37  TTAudioObject mPhasor; ///< The internal phasor generator
38  TTAudio mPhasorOutputSignal; ///< The output vector of the phasor generator
39  TTAudioObject mRamp; ///< The internal ramp generator
40  TTAudio mRampOutputSignal; ///< The output vector of the ramp generator
41 
42 public:
43 
44  /** Setting the trajectory type
45  @param newValue
46  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
47  */
48  TTErr setType(const TTValue& newValue)
49  {
50  TTSymbol newType = newValue;
51  TTErr err = kTTErrNone;
52 
53  // if the type didn't change, then don't change the trajectory
54  if (newType == mType)
55  return kTTErrNone;
56 
57  mType = newType;
58  err = TTObjectBaseInstantiate(mType, &mActualTrajectoryObject, 2);
59  if (!err) {
60  // Now that we have our new trajectory type, update it with the current state of the wrapper:
61  mActualTrajectoryObject->setAttributeValue(TT("a"), mA);
62  mActualTrajectoryObject->setAttributeValue(TT("b"), mB);
63  mActualTrajectoryObject->setAttributeValue(TT("c"), mC);
64  mActualTrajectoryObject->setAttributeValue(TT("deltaX"), mDeltaX);
65  mActualTrajectoryObject->setAttributeValue(TT("deltaY"), mDeltaY);
66  mActualTrajectoryObject->setAttributeValue(TT("deltaZ"), mDeltaZ);
67 
68  //TODO: I currently update ALL Attributes, regardless whether the types support it or not
69 
70  //mActualTrajectoryObject->setAttributeValue(kTTSym_sampleRate, sr);
71  //mActualFilterObject->setAttributeValue(TT("frequency"), mFrequency);
72  //err = mActualFilterObject->setAttributeValue(TT("q"), mQ);
73  //if (err == kTTErrInvalidAttribute)
74  // err = mActualFilterObject->setAttributeValue(TT("resonance"), mQ);
75  //mActualFilterObject->setAttributeValue(TT("bypass"), this->attrBypass);
76  //mActualFilterObject->setAttributeValue(kTTSym_sampleRate, sr);
77  }
78  return err;
79  }
80 
81 
82  /** Return a list of all the available trajectory types.
83  @param listOfTrajectoryTypesToReturn Pointer to an array that will be filled with a list of all available trajectory types.
84  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
85  */
86  TTErr getTypes(const TTValue&, TTValue& listOfTrajectoryTypesToReturn)
87  {
88  TTValue v;
89  v.resize(2);
90  v[0] = TT("trajectory");
91  v[1] = TT("audio");
92  return TTObject::GetRegisteredClassNamesForTags(listOfTrajectoryTypesToReturn, v);
93  }
94 
95  /** Return the current trajectory type.
96  @param CurrentTypeToReturn Pointer to an array that will be filled the current trajectory type.
97  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
98  */
99  TTErr getCurrentType(const TTValue&, TTValue& CurrentTypeToReturn)
100 
101  {
102  CurrentTypeToReturn = mType;
103  return kTTErrNone;
104  }
105 
106 
107  /** Return a list of the attribute names used in the selected trajectory type.
108  @param listOfCurrentAttributesToReturn Pointer to an array that will be filled all attributes used in the current trajectory type.
109  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
110  */
111  TTErr getCurrentAttributeNames(const TTValue&, TTValue& listOfCurrentAttributesToReturn)
112  {
113  long n;
114  TTValue names;
115  TTSymbol aName;
116 
117  listOfCurrentAttributesToReturn.clear();
118  mActualTrajectoryObject->getAttributeNames(names);
119  n = names.size();
120  for (int i=0; i<n; i++) {
121  aName = names[i];
122 
123  if (aName == TT("bypass") || aName == TT("mute") || aName == TT("maxNumChannels") || aName == TT("sampleRate"))
124  continue;
125  listOfCurrentAttributesToReturn.append(aName);
126  }
127  if (listOfCurrentAttributesToReturn.size()==0)
128  listOfCurrentAttributesToReturn.append(TT("NULL")); // in case there is no attribute, send a NULL value out
129 
130  return kTTErrNone;
131  }
132 
133  /** Function to trigger the trajectory generation when ramp mode is selected
134  @param arguments additional arguments will determine ramping:
135  ramp <startValue|double> <stopValue|double> <time|double> <type|string>
136  ramp <stopValue|double> <time|double> <type|string>
137  ramp <startValue|double> <stopValue|double> <time|double>
138  ramp <stopValue|double> <time|double> @n
139  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
140  */
141  TTErr ramp(const TTValue& arguments, TTValue&)
142  {
143  /*
144  ramp <startValue|double> <stopValue|double> <time|double> <type|string>
145  ramp <stopValue|double> <time|double> <type|string>
146  ramp <startValue|double> <stopValue|double> <time|double>
147  ramp <stopValue|double> <time|double>
148  */
149  long n;
150  TTSymbol attrType;
151  TTFloat64 x;
152  TTErr err = kTTErrNone;
153 
154  if (mMode == TT("ramp")){
155  if (ttDataTypeInfo[arguments[0].type()]->isNumerical && ttDataTypeInfo[arguments[1].type()]->isNumerical) {
156  n = arguments.size();
157  switch(n)
158  {
159  case 4:
160  if (ttDataTypeInfo[arguments[2].type()]->isNumerical && ttDataTypeInfo[arguments[3].type()]->isNumerical == false) {
161  attrType = arguments[3];
162  setType(attrType);
163  x = arguments[0];
164  x = x * 2.0; // scaling
165  mRamp.set("startValue", x);
166  x = arguments[1];
167  x = x * 2.0; // scaling
168  mRamp.set("destinationValue", x);
169  x = arguments[2];
170  mRamp.set("rampTime", x);
171  }
172  break;
173  case 3:
174  if (ttDataTypeInfo[arguments[2].type()]->isNumerical) {
175  // start stop time
176  x = arguments[0];
177  x = arguments[0];
178  x = x * 2.0; // scaling
179  mRamp.set("startValue", x);
180  x = arguments[1];
181  x = x * 2.0; // scaling
182  mRamp.set("destinationValue", x);
183  x = arguments[2];
184  mRamp.set("rampTime", x);
185  }
186  else {// stop time type
187  attrType = arguments[2];
188  setType(attrType);
189  x = arguments[0];
190  x = x * 2.0; // scaling
191  mRamp.set("destinationValue", x);
192  x = arguments[1];
193  mRamp.set("rampTime", x);
194  }
195  break;
196  case 2: // stop time
197  x = arguments[0];
198  x = x * 2.0; // scaling
199  mRamp.set("destinationValue", x);
200  x = arguments[1];
201  mRamp.set("rampTime", x);
202  break;
203  default:
204  err = kTTErrWrongNumValues;
205  }
206  }
207  }
208  return err;
209  }
210 
211  /** reset the phasor and ramp generators
212  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
213  */
215  {
216  TTValue v;
217  v[0] = 0.0;
218  //for (int i=0; i<1; i++) {
219  mPhasor.set("phase",v);
220  mRamp.set("startValue",v);
221  //}
222  return kTTErrNone;
223  }
224 
225  /*TTErr setAnchorPoints(const TTValue& newValue)
226  {
227  mAnchorPoints = newValue;
228  return mActualTrajectoryObject->setAttributeValue(TT("anchorPoints"), mAnchorPoints);
229  }*/
230 
231  /** Set parameter A, actual usage depends on selected trajectory type
232  @param newValue new value
233  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
234  */
235  TTErr setA(const TTValue& newValue)
236  {
237  mA = newValue;
238  return mActualTrajectoryObject->setAttributeValue(TT("a"), mA);
239  }
240 
241  /** Set parameter B, actual usage depends on selected trajectory type
242  @param newValue new value
243  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
244  */
245  TTErr setB(const TTValue& newValue)
246  {
247  mB = newValue;
248  return mActualTrajectoryObject->setAttributeValue(TT("b"), mB);
249  }
250 
251  /** Set parameter C, actual usage depends on selected trajectory type
252  @param newValue new value
253  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
254  */
255  TTErr setC(const TTValue& newValue)
256  {
257  mC = newValue;
258  return mActualTrajectoryObject->setAttributeValue(TT("c"), mC);
259  }
260 
261  /** Set parameter DeltaX, actual usage depends on selected trajectory type
262  @param newValue new value
263  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
264  */
265  TTErr setDeltaX(const TTValue& newValue)
266  {
267  mDeltaX = newValue;
268  return mActualTrajectoryObject->setAttributeValue(TT("deltaX"), mDeltaX);
269  }
270 
271  /** Set parameter DeltaY, actual usage depends on selected trajectory type
272  @param newValue new value
273  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
274  */
275  TTErr setDeltaY(const TTValue& newValue)
276  {
277  mDeltaY = newValue;
278  return mActualTrajectoryObject->setAttributeValue(TT("deltaY"), mDeltaY);
279  }
280 
281  /** Set parameter DeltaZ, actual usage depends on selected trajectory type
282  @param newValue new value
283  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
284  */
285  TTErr setDeltaZ(const TTValue& newValue)
286  {
287  mDeltaZ = newValue;
288  return mActualTrajectoryObject->setAttributeValue(TT("deltaZ"), mDeltaZ);
289  }
290 
291 
292  TTErr updateSampleRate(const TTValue& oldSampleRate, TTValue&)
293  {
294  //for (int i=0; i<3; i++) {
295  mPhasor.set(kTTSym_sampleRate, sr);
296  mRamp.set(kTTSym_sampleRate, sr);
297  //}
298  return mActualTrajectoryObject->setAttributeValue(kTTSym_sampleRate, sr);
299  }
300 
301  /** Set mode to "ramp" or "phasor"
302  @param newValue new value
303  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
304  */
305  TTErr setMode(const TTValue& newValue)
306  {
307  mMode = newValue;
308  return setProcessPointers();
309  }
310 
311  /** Internal function to set the process pointers to the ramp o phasor generator according to the setMode function
312  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
313  */
315  {
316  TTErr err = kTTErrNone;
317 
318  if (mMode == TT("phasor")) {
320  }
321  else { //TT("ramp")
323  }
324  return err;
325  }
326 
327  /** Internal Computing the phasor signal to drive the trajectory functions
328  @param newValue new value
329  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
330  */
332  {
333  mPhasorOutputSignal.allocWithVectorSize(outputs->getVectorSize());
334  mPhasor.process(mPhasorOutputSignal);
335 
336  return mActualTrajectoryObject->process(*mPhasorOutputSignal.instance(), outputs->getSignal(0));
337  }
338 
339  /** Internal Computing the ramp signal to drive the trajectory functions
340  @param newValue new value
341  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
342  */
344  {
345  mRampOutputSignal.allocWithVectorSize(outputs->getVectorSize());
346 
347  mRamp.process(mRampOutputSignal);
348 
349  return mActualTrajectoryObject->process(*mRampOutputSignal.instance(), outputs->getSignal(0));
350  }
351 };
352 
353 
354 #endif // __TT_TRAJECTORY_H__
TTFOUNDATION_EXPORT TTDataInfoPtr ttDataTypeInfo[kNumTTDataTypes]
An array, indexed by values from TTDataType, containing information about those data types...
Definition: TTBase.cpp:424
TTSymbol mType
The name of the current trajectory type.
Definition: TTTrajectory.h:34
TTFloat64 mC
Trajectory Parameter, usage depend on the actual trajectory.
Definition: TTTrajectory.h:30
TTAudioObjectBasePtr mActualTrajectoryObject
The actual trajectory object that this object is currently wrapping.
Definition: TTTrajectory.h:27
TTFloat64 mDeltaZ
Trajectory Parameter, usage depend on the actual trajectory function.
Definition: TTTrajectory.h:33
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTErr setC(const TTValue &newValue)
Set parameter C, actual usage depends on selected trajectory type.
Definition: TTTrajectory.h:255
TTErr setDeltaZ(const TTValue &newValue)
Set parameter DeltaZ, actual usage depends on selected trajectory type.
Definition: TTTrajectory.h:285
TTAudioObject mPhasor
The internal phasor generator.
Definition: TTTrajectory.h:37
size_type size() const noexcept
Return the number of elements.
TTAudio mPhasorOutputSignal
The output vector of the phasor generator.
Definition: TTTrajectory.h:38
static TTErr GetRegisteredClassNamesForTags(TTValue &classNames, const TTValue &searchTags)
Query TTEnvironment for names of all registered TTObjectBase classes that share specific tags...
Definition: TTObject.cpp:78
The wrong number of values were passed to a method or attribute.
Definition: TTBase.h:350
TTErr getTypes(const TTValue &, TTValue &listOfTrajectoryTypesToReturn)
Return a list of all the available trajectory types.
Definition: TTTrajectory.h:86
Wrap audio objects for convenience.
TTErr getCurrentAttributeNames(const TTValue &, TTValue &listOfCurrentAttributesToReturn)
Return a list of the attribute names used in the selected trajectory type.
Definition: TTTrajectory.h:111
Jamoma DSP Library.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr processAudioRampInternal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Internal Computing the ramp signal to drive the trajectory functions.
Definition: TTTrajectory.h:343
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
Definition: TTValue.h:243
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
TTErr setMode(const TTValue &newValue)
Set mode to "ramp" or "phasor".
Definition: TTTrajectory.h:305
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr(TTAudioObjectBase::* TTProcessMethod)(TTAudioSignalArrayPtr in, TTAudioSignalArrayPtr out)
A type that can be used to store a pointer to a process method (which calculates a vector of samples)...
TTFloat64 mDeltaY
Trajectory Parameter, usage depend on the actual trajectory.
Definition: TTTrajectory.h:32
TTFloat64 mB
Trajectory Parameter, usage depend on the actual trajectory.
Definition: TTTrajectory.h:29
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTAudio mRampOutputSignal
The output vector of the ramp generator.
Definition: TTTrajectory.h:40
TTFloat64 mDeltaX
Trajectory Parameter, usage depend on the actual trajectory.
Definition: TTTrajectory.h:31
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
TTErr setProcess(TTProcessMethod processMethod)
Set the audio processing routine to point to a method that is defined as an arg to this function...
TTErr setType(const TTValue &newValue)
Setting the trajectory type.
Definition: TTTrajectory.h:48
TTAudioObject mRamp
The internal ramp generator.
Definition: TTTrajectory.h:39
TTErr setProcessPointers()
Internal function to set the process pointers to the ramp o phasor generator according to the setMode...
Definition: TTTrajectory.h:314
A simple container for an array of TTAudioSignal pointers.
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
Generalized Trajectory Function Wrapper.
Definition: TTTrajectory.h:23
TTSymbol mMode
the underlying signal generator, can be "phasor" or "ramp"
Definition: TTTrajectory.h:35
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr getCurrentType(const TTValue &, TTValue &CurrentTypeToReturn)
Return the current trajectory type.
Definition: TTTrajectory.h:99
TTFloat64 mA
Trajectory Parameter, usage depend on the actual trajectory.
Definition: TTTrajectory.h:28
TTErr reset()
reset the phasor and ramp generators
Definition: TTTrajectory.h:214
TTErr setDeltaY(const TTValue &newValue)
Set parameter DeltaY, actual usage depends on selected trajectory type.
Definition: TTTrajectory.h:275
No Error.
Definition: TTBase.h:343
TTErr setDeltaX(const TTValue &newValue)
Set parameter DeltaX, actual usage depends on selected trajectory type.
Definition: TTTrajectory.h:265
TTErr processAudioPhasorInternal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Internal Computing the phasor signal to drive the trajectory functions.
Definition: TTTrajectory.h:331
TTErr setB(const TTValue &newValue)
Set parameter B, actual usage depends on selected trajectory type.
Definition: TTTrajectory.h:245
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
void getAttributeNames(TTValue &attributeNameList)
Return a list of names of the available attributes.
Wrap TTAudioSignal instances for convenience.
Definition: TTAudioObject.h:25
TTErr setA(const TTValue &newValue)
Set parameter A, actual usage depends on selected trajectory type.
Definition: TTTrajectory.h:235
TTErr ramp(const TTValue &arguments, TTValue &)
Function to trigger the trajectory generation when ramp mode is selected.
Definition: TTTrajectory.h:141
TTUInt32 sr
Current sample rate being used by this object.