Jamoma API  0.6.0.a19
TTDataObjectBase.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief TTDataObjectBase is the base class for all data generating and processing objects.
6  *
7  * @details It still has knowledge and support for sample-rates, but not channel counts or vector processing.
8  *
9  * @author Timothy Place, 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 "TTDataObjectBase.h"
17 #include "TTEnvironment.h"
18 #include "TTMatrixArray.h"
19 
20 
21 /****************************************************************************************************/
22 
24  TTObjectBase(arguments),
25  mMatrixCalculateMethod(NULL),
26  mCurrentMatrixCalculateMethod(NULL),
27  mBypass(NO),
28  mInputArray(NULL),
29  mOutputArray(NULL),
30  mStartProcessingTime(0.0),
31  mAccumulatedProcessingTime(0.0),
32  mAccumulatedProcessingCalls(0.0),
33  mReserved1(0),
34  mReserved2(0)
35 {
37 
41 
42  ttEnvironment->createInstance(kTTSym_matrixarray, (TTObjectBasePtr*)&mInputArray, 2);
43  ttEnvironment->createInstance(kTTSym_matrixarray, (TTObjectBasePtr*)&mOutputArray, 2);
44 
45  // Set Defaults...
47  setAttributeValue("bypass", NO);
48 }
49 
50 
52 {
55 }
56 
57 
59 {
60  mMatrixCalculateMethod = newMatrixCalculateMethod;
61  if (!mBypass)
63  return kTTErrNone;
64 }
65 
66 
68 {
69  mBypass = value;
70  if (mBypass) {
72  }
73 // else if (attrMute) {
74 // currentProcessMethod = &TTAudioObject::muteProcess;
75 // }
76  else {
79  else
81  }
82  return kTTErrNone;
83 }
84 
85 
87 {
88  for (TTUInt16 i=0; i < outputs->getMatrixCount(); i++) {
89  TTMatrixBasePtr out = outputs->getMatrix(i);
90 
91  if (i < inputs->getMatrixCount()) {
92  TTMatrixBasePtr in = inputs->getMatrix(i);
93  TTMatrixBase::copy(in, out);
94  }
95  else
96  out->clear();
97  }
98  return kTTErrNone;
99 }
100 
101 
103 {
104  return bypassMatrixCalculate(inputs, outputs);
105 }
106 
107 
109 {
110  TTErr err = kTTErrGeneric;
111 
112  if (valid) {
114  lock();
115  err = (this->*mCurrentMatrixCalculateMethod)(inputs, outputs);
116  unlock();
117  }else {
118  lock();
120  err = (this->*mCurrentMatrixCalculateMethod)(inputs, outputs);
123  unlock();
124  }
125 
126  }
127  return err;
128 }
129 
130 
132 {
133  TTErr err = kTTErrGeneric;
134 
135  if (valid) {
136  lock();
137  mInputArray->setMatrixCount(1);
138  mInputArray->setMatrix(0, (TTMatrixBase&)x);
139  mOutputArray->setMatrixCount(1);
140  mOutputArray->setMatrix(0, y);
143  else{
148  unlock();
149  }
150  }
151  return err;
152 }
153 
154 
156 {
158  mStartProcessingTime = 0.0;
160  return kTTErrNone;
161 }
162 
163 
165 {
167  return kTTErrNone;
168 }
169 
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
TTErr getProcessingBenchmark(TTValueRef v)
Do performance benchmarking.
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr unlock()
Unlock the object when thread-safe processing is no longer required.
Definition: TTObjectBase.h:530
TTErr bypassMatrixCalculate(const TTMatrixArray *inputs, TTMatrixArray *outputs)
Built-in method to be used when calculation is to bypassed.
TTErr clear()
Set every element in the matrix to zero.
TTErr setMatrixCalculate(TTMatrixCalculateMethod newMatrixCalculateMethod)
Set the sample calculate routine to point to a method that is defined as an arg to this function...
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
TTErr resetBenchmarking()
Reset internal values used when benchmarking performance.
TTDataObjectBase is the base class for all data generating and processing objects.
static TTErr copy(const TTMatrixBase &source, TTMatrixBase &dest)
Copy the data from one matrix into another.
TTBoolean mBenchmarking
Attribute: Enable benchmarking in TTAudioObject and TTDataObject ?
Definition: TTEnvironment.h:56
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTErr(TTObjectBase::* TTMethod)(const TTSymbol methodName, const TTValue &anInputValue, TTValue &anOutputValue)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:46
TTErr registerAttribute(const TTSymbol name, const TTDataType type, void *address)
Register an attribute.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
TTBoolean valid
If the object isn't completely built, or is in the process of freeing, this will be false...
Definition: TTObjectBase.h:124
virtual ~TTDataObjectBase()
Object destructor.
TTErr registerMessage(const TTSymbol name, TTMethod method)
Register a message with this object.
TTErr(TTDataObjectBase::* TTMatrixCalculateMethod)(const TTMatrixArray *inputMatrices, TTMatrixArray *outputMatrices)
A type that can be used to store a pointer to a calculate method (which calculates an array of matric...
TTFloat64 TTGetTimeInMicroseconds()
Return the current system time in microseconds.
Definition: TTBase.h:445
TTErr createInstance(const TTSymbol className, TTObjectBasePtr *anObject, const TTValue &anArgument)
Create a new instance of a registered TTObjectBase class.
2-dimensional matrix of compound values with N elements each.
Definition: TTMatrixBase.h:41
TTErr setBypass(const TTValue &value)
Bypass the audio processing routine and copy all input samples to the output unchanged.
TTErr releaseInstance(TTObjectBasePtr *anObject)
Release an instance of a TTObjectBase class.
TTMatrixArray * mInputArray
If the calculate method is passed a matrix, rather than an array of matrices, we wrap it in this arra...
TTMatrixArray * mOutputArray
If the calculate method is passed a matrix, rather than an array of matrices, we wrap it in this arra...
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
TTDataObjectBase(const TTValue &arguments)
Object constructor.
An array of TTMatrix instance pointers.
Definition: TTMatrixArray.h:25
TTErr defaultMatrixCalculateMethod(const TTMatrixArray *inputs, TTMatrixArray *outputs)
The default calculation method to use.
TTEnvironment is a global object providing information on the environemt.
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 mAccumulatedProcessingTime
The amount of time spent in this object's process method (for benchmarking)
TTMatrixCalculateMethod mCurrentMatrixCalculateMethod
This function pointer always points to the current calculate routine.
TTErr calculate(const TTMatrixArray *inputs, TTMatrixArray *outputs)
TTMatrixCalculateMethod mMatrixCalculateMethod
This function pointer points to the active (non-bypass) calculate routine.
No Error.
Definition: TTBase.h:343
Set this flag if the method you are binding to this message is prototyped to accept no arguments...
Definition: TTObjectBase.h:86
virtual TTErr test(TTValue &)
[doxygenChapter60_virtualMethod]
TTFloat64 mStartProcessingTime
The time at which this object's process method was last invoked (for benchmarking) ...
TTFloat64 mAccumulatedProcessingCalls
The number of times the process method has been called (for benchmarking)
TTErr lock()
Lock the object in order to ensure thread-safe processing.
Definition: TTObjectBase.h:520
TTBoolean mBypass
Are we bypassing the matrix calculation?
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34