Jamoma API  0.6.0.a19
TTAudioObjectArray.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspLibrary
4  *
5  * @brief Wrapper for an array of audio objects
6  *
7  * @details
8  *
9  * @see TTAudioObjectBase
10  *
11  * @authors Tim Place, Nils Peters, Trond Lossius
12  *
13  * @copyright Copyright © 2011 by Timothy Place and Nils Peters @n
14  * This code is licensed under the terms of the "New BSD License" @n
15  * http://creativecommons.org/licenses/BSD/
16  */
17 
18 
19 #include "TTDSP.h"
20 #include "TTAudioObjectArray.h"
21 
22 
23 #define thisTTClass TTAudioObjectBaseArray
24 #define thisTTClassName "array"
25 #define thisTTClassTags "dspLibrary, audio, array"
26 
27 
28 TT_AUDIO_CONSTRUCTOR,
29  mSize(0),
30  mInputChannelSignal(NULL),
31  mOutputChannelSignal(NULL)
32 {
33  TTChannelCount initialMaxNumChannels = arguments;
34 
35  TTObjectBaseInstantiate(kTTSym_audiosignal, &mInputChannelSignal, 1);
36  TTObjectBaseInstantiate(kTTSym_audiosignal, &mOutputChannelSignal, 1);
37 
40  addUpdates(MaxNumChannels);
41 
43 
44  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
45  setAttributeValue("class", "gain");
46  setProcessMethod(processAudio);
47 }
48 
49 
50 TTAudioObjectBaseArray::~TTAudioObjectBaseArray()
51 {
54 }
55 
56 
58 {
59  return setAttributeValue("size", mMaxNumChannels);
60 }
61 
62 
64 {
65  // TODO: lock so that audio is not processed when we are resizing!
66 
67  mSize = newSize;
68 
69  // 1. free the old instances
70  for (TTAudioObjectBaseIter obj = mInstances.begin(); obj != mInstances.end(); ++obj)
71  TTObjectBaseRelease(&(*obj));
72 
73  // 2. resize the vector of pointers and set to NULL
74  mInstances.resize(mSize);
75  mInstances.assign(sizeof(TTPtr), 0);
76 
77  // 3. create the new instances (if the class has been defined)
78  if (mClass) {
79  for (TTAudioObjectBaseIter obj = mInstances.begin(); obj != mInstances.end(); ++obj)
80  TTObjectBaseInstantiate(mClass, &(*obj), 1);
81  }
82 
83  return kTTErrNone;
84 }
85 
86 
88 {
89  TTSymbol theClassName = newClass;
90  int err = 0;
91 
92  // TODO: find out if the specified class name is a legitimate class before proceeding
93 
94  for (int i=0; i<mSize; i++)
95  err |= TTObjectBaseInstantiate(newClass, &mInstances[i], 1);
96 
97  if (!err)
98  mClass = theClassName;
99  return (TTErr)err;
100 }
101 
102 
104 {
105  // There may be two or more arguments
106  // if the first argument is a number, it specifies which instance in the array to address
107  // if the first argument is a symbol, then the attribute will be set for all instances
108  // the first or second arg (the first which is a symbol) is the name of the attribute
109  // the args past that are the value
110 
111  TTInt32 target = -1; // -1 means all voices
112  TTSymbol attrName(kTTSymEmpty);
113  TTValue attrValue;
114  int err = kTTErrNone;
115 
116  if (ttDataTypeInfo[arguments[0].type()]->isNumerical)
117  target = arguments;
118 
119  if (target >= 0) {
120  if (target < mSize){
121  if (arguments.size() < 3)
122  return kTTErrWrongNumValues;
123  else
124  attrName = arguments[1];
125 
126  if (!attrName)
127  return kTTErrInvalidAttribute;
128 
129  attrValue.copyFrom(arguments, 2);
130 
131  err = mInstances[target]->setAttributeValue(attrName, attrValue);
132  }
133 
134  }
135  else {
136  if (arguments.size() < 2)
137  return kTTErrWrongNumValues;
138  else
139  attrName = arguments[0];
140 
141  if (!attrName)
142  return kTTErrInvalidAttribute;
143 
144  attrValue.copyFrom(arguments, 1);
145 
146  for (int i=0; i<mSize; i++)
147  err |= mInstances[i]->setAttributeValue(attrName, attrValue);
148 
149  }
150 
151  arguments.clear();
152  return (TTErr)err;
153 }
154 
155 
157 {
158  TTAudioSignal& in = inputs->getSignal(0);
159  TTAudioSignal& out = outputs->getSignal(0);
160  TTChannelCount channelCount = TTAudioSignal::getMinChannelCount(in, out);
161  TTUInt16 vs = in.getVectorSizeAsInt();
162 
163  for (TTChannelCount channel=0; channel<channelCount; channel++) {
164  mInputChannelSignal->setVector(0, vs, in.mSampleVectors[channel]);
165  mOutputChannelSignal->setVector(0, vs, out.mSampleVectors[channel]);
167  }
168  return kTTErrNone;
169 }
170 
171 
172 
TTFOUNDATION_EXPORT TTDataInfoPtr ttDataTypeInfo[kNumTTDataTypes]
An array, indexed by values from TTDataType, containing information about those data types...
Definition: TTBase.cpp:424
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
void copyFrom(const TTValue &obj, TTUInt16 index)
Copy a value starting from an index until the last element.
Definition: TTValue.h:147
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTUInt16 mSize
The number of instances in the array.
TTSymbol mClass
The name of the object we will instantiate in the array.
size_type size() const noexcept
Return the number of elements.
The wrong number of values were passed to a method or attribute.
Definition: TTBase.h:350
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTAudioSignalPtr mInputChannelSignal
Signal used within the process method for passing to individual instances.
Jamoma DSP Library.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
Symbol type.
Definition: TTBase.h:282
Wrapper for an array of audio objects.
TTErr setSize(const TTValueRef newSize)
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr setVector(const TTChannelCount channel, const TTUInt16 vectorSize, const TTSampleValuePtr newVector)
[doxygenAppendixC_methodExample]
TTAudioObjectBaseVector mInstances
The actual vector containing object instance pointers.
TTErr set(TTValue &arguments, TTValue &)
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Process audio.
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 updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Update the maximum number of channels that the array will be able to process.
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTErr setClass(const TTValueRef newClass)
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
TTAudioSignalPtr mOutputChannelSignal
Signal used within the process method for passing to individual instances.
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
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Bad Attribute specified.
Definition: TTBase.h:348
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44