Jamoma API  0.6.0.a19
TTSpat.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspSpatLib
4  *
5  * @brief Host a SpatLib object
6  *
7  * @details
8  *
9  * @authors Trond Lossius, Nils Peters, Timothy Place
10  *
11  * @copyright Copyright © 2011 by Trond Lossius, Nils Peters, and 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 "TTSpat.h"
17 
18 #define thisTTClass TTSpat
19 #define thisTTClassName "spat"
20 #define thisTTClassTags "audio, spatialization"
21 
22 
23 
24 TT_AUDIO_CONSTRUCTOR,
25 mSpatFunctionObject(NULL),
26 mSourceCount(0),
27 mSinkCount(0)
28 {
29  //TTValue v;
30 
31  addAttributeWithSetter(SpatFunction, kTypeSymbol);
32  addAttributeWithSetter(SourceCount, kTypeUInt16);
34 
35  addMessageWithArguments(getSourcePosition);
36  addMessageWithArguments(setSourcePosition);
37  addMessageWithArguments(getSinkPosition);
38  addMessageWithArguments(setSinkPosition);
39 
40  addMessageWithArguments(getSpatFunctions);
41 
42  //addUpdate(MaxNumChannels);
43 
44  setAttributeValue("spatFunction", "spat.snap");
45  setAttributeValue("sourceCount", 2);
46  setAttributeValue("sinkCount", 8);
47  setProcessMethod(process);
48 }
49 
50 
51 TTSpat::~TTSpat()
52 {
53  delete mSpatFunctionObject;
54 }
55 
56 
57 TTErr TTSpat::setSpatFunction(const TTValue& aSpatFunction)
58 {
59  TTErr err;
60  TTSymbol spatFunctionName;
61  TTAudioObjectBasePtr spatFunction = NULL;
62 
63  spatFunctionName = aSpatFunction[0];
64 
65  // if the function didn't change, then don't change the function
66  if (spatFunctionName == mSpatFunction)
67  return kTTErrNone;
68 
69  // TTObjectBaseInstantiate will automatically free the object passed into it
70  err = TTObjectBaseInstantiate(spatFunctionName, &spatFunction, kTTValNONE);
71  if (!err && spatFunction) {
72  // Now set the state of the object to the state we have stored
73  spatFunction->setAttributeValue(TT("sourceCount"), mSourceCount);
74  spatFunction->setAttributeValue(TT("sinkCount"), mSinkCount);
75 
76  mSpatFunction = spatFunctionName;
77  mSpatFunctionObject = spatFunction;
78 
79  // FIXME: This is not thread safe if the audio is running
80  // We need to queue this switch to occur at a time when it is safe
81  // (when audio is not processed by the old object any longer)
82  // Redmine #994
83  //
84  // ACTUALLY: it should be okay because of the locks in the TTObjectBaseInstantiate spinlocking to wait
85  // for any process calls.
86  // However, maybe those need some improvements like using volatile or atomic types
87  }
88  else {
89  // some problems have occurred, not yet sure how we should handle this...
90  }
91 
92 
93  return err;
94 }
95 
96 
97 
98 TTErr TTSpat::getSpatFunctions(const TTValue&, TTValue& listOfSpatFunctionsToReturn)
99 {
100  TTValue v;
101 
102  v.resize(2);
103  v[0] = TT("spatialization");
104  v[1] = TT("processing"); // more efficent than append
105  return TTObject::GetRegisteredClassNamesForTags(listOfSpatFunctionsToReturn, v);
106 
107 }
108 
109 /*
110 TTErr TTSpat::getFunctionParameters(const TTValue&, TTValue& aListOfParameterNamesToReturn)
111 {
112  mSpatFunctionObject->getAttributeNames(aListOfParameterNamesToReturn);
113  return kTTErrNone;
114 }
115 
116 
117 TTErr TTSpat::getFunctionParameter(const TTValue& aParameterNameIn, TTValue& aValueOut)
118 {
119  TTSymbol parameterName;
120 
121  aParameterNameIn.get(0, parameterName);
122  return mSpatFunctionObject->getAttributeValue(parameterName, aValueOut);
123 }
124 
125 
126 TTErr TTSpat::setFunctionParameter(const TTValue& aParameterNameAndValue, TTValue&)
127 {
128  TTSymbol parameterName;
129  TTValue parameterValue;
130 
131  aParameterNameAndValue.get(0, parameterName);
132  parameterValue.copyFrom(aParameterNameAndValue, 1); //TODO: maybe there are more arguments ?
133  //aParameterNameAndValue.clear(); // only needed so that we don't return a value
134  return mSpatFunctionObject->setAttributeValue(parameterName, parameterValue);
135 }
136 */
137 
138 
140 {
141  mSourceCount = aSourceCount;
142  return mSpatFunctionObject->setAttributeValue(TT("sourceCount"), (TTValue&)aSourceCount);
143 }
144 
145 
147 {
148  mSinkCount = aSinkCount;
149  return mSpatFunctionObject->setAttributeValue(TT("sinkCount"), (TTValue&)aSinkCount);
150 }
151 
152 
153 TTErr TTSpat::getSourcePosition(const TTValue& anIndex, TTValue& returnedPosition)
154 {
155 // return mSpatFunctionObject->getSourcePosition(aPosition);
156  return mSpatFunctionObject->sendMessage("getSourcePosition", anIndex, returnedPosition);
157 }
158 
159 
160 TTErr TTSpat::setSourcePosition(const TTValue& aPosition, TTValue& unused)
161 {
162 // return mSpatFunctionObject->setSourcePosition(aPosition);
163  return mSpatFunctionObject->sendMessage("setSourcePosition", aPosition, unused);
164 }
165 
166 
167 TTErr TTSpat::getSinkPosition(const TTValue& anIndex, TTValue& returnedPosition)
168 {
169 // return mSpatFunctionObject->getSinkPosition(aPosition);
170  return mSpatFunctionObject->sendMessage("getSinkPosition", anIndex, returnedPosition);
171 }
172 
173 
174 TTErr TTSpat::setSinkPosition(const TTValue& aPosition, TTValue& unused)
175 {
176 // return mSpatFunctionObject->setSinkPosition(aPosition);
177  return mSpatFunctionObject->sendMessage("setSinkPosition", aPosition, unused);
178 }
179 
180 
181 #if 0
182 #pragma mark -
183 #pragma mark Process Routines
184 #endif
185 
186 
188 {
189  return mSpatFunctionObject->process(inputs, outputs);
190 }
191 
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTErr setSpatFunction(const TTValue &aSpatFunction)
Set what spatialisation function to use.
Definition: TTSpat.cpp:57
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
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTChannelCount mSourceCount
The number of sources.
Definition: TTSpat.h:31
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
TTErr getSpatFunctions(const TTValue &, TTValue &listOfSpatFunctionsToReturn)
Return a list of all the available spatialisation methods.
Definition: TTSpat.cpp:98
Symbol type.
Definition: TTBase.h:282
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTErr process(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Return a list of all the available parameters that are specific to the current spatialisation method...
Definition: TTSpat.cpp:187
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
A simple container for an array of TTAudioSignal pointers.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
Host a SpatLib object.
No Error.
Definition: TTBase.h:343
void resize(size_type n)
Change the number of elements.
TTChannelCount mSinkCount
The number of destinations.
Definition: TTSpat.h:32
TTErr setSinkCount(const TTValue &aSink)
Set number of destinations.
Definition: TTSpat.cpp:146
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTErr setSourceCount(const TTValue &aSource)
Set the number of sources.
Definition: TTSpat.cpp:139