Jamoma API  0.6.0.a19
TTDataObjectBase.h
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 #ifndef __TT_DATA_OBJECTBASE_H__
17 #define __TT_DATA_OBJECTBASE_H__
18 
19 #include "TTObjectBase.h"
20 #include "TTSymbol.h"
21 #include "TTValue.h"
22 
23 // Forward declaration of TTAudioObject for the typedef that follows...
24 class TTDataObjectBase;
25 class TTMatrixArray;
26 
27 /** A type that can be used to store a pointer to a calculate method (which calculates an array of matrices).
28  @ingroup typedefs
29  */
30 typedef TTErr (TTDataObjectBase::*TTMatrixCalculateMethod)(const TTMatrixArray* inputMatrices, TTMatrixArray* outputMatrices);
31 
32 #define setMatrixCalculateMethod(methodName) setMatrixCalculate((TTMatrixCalculateMethod)& thisTTClass ::methodName )
33 
34 
35 /****************************************************************************************************/
36 // Class Specification
37 
38 /** TTDataObjectBase is the base class for all data generating and processing objects.
39  It still has knowledge and support for sample-rates, but not channel counts or vector processing.
40  */
41 class TTFOUNDATION_EXPORT TTDataObjectBase : public TTObjectBase {
42 protected:
43  TTMatrixCalculateMethod mMatrixCalculateMethod; ///< This function pointer points to the active (non-bypass) calculate routine.
44  TTMatrixCalculateMethod mCurrentMatrixCalculateMethod; ///< This function pointer always points to the current calculate routine.
45  TTBoolean mBypass; ///< Are we bypassing the matrix calculation?
46  TTMatrixArray* mInputArray; ///< If the calculate method is passed a matrix, rather than an array of matrices, we wrap it in this array.
47  TTMatrixArray* mOutputArray; ///< If the calculate method is passed a matrix, rather than an array of matrices, we wrap it in this array.
48  TTFloat64 mStartProcessingTime; ///< The time at which this object's process method was last invoked (for benchmarking)
49  TTFloat64 mAccumulatedProcessingTime; ///< The amount of time spent in this object's process method (for benchmarking)
50  TTFloat64 mAccumulatedProcessingCalls; ///< The number of times the process method has been called (for benchmarking)
51  TTPtrSizedInt mReserved1; ///< Reserved -- May be used for something in the future without changing the size of the struct.
52  TTPtrSizedInt mReserved2; ///< Reserved -- May be used for something in the future without changing the size of the struct.
53 
54 protected:
55  /** Object constructor.
56  @param arguments Arguments to the constructor method.
57  */
58  TTDataObjectBase(const TTValue& arguments);
59 
60 
61  /** Object destructor. */
62  virtual ~TTDataObjectBase();
63 
64 
65  /** Set the sample calculate routine to point to a method that is defined as an arg to this function.
66  @param newMatrixCalculateMethod The new matrix calculation method to use.
67  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
68  */
69  TTErr setMatrixCalculate(TTMatrixCalculateMethod newMatrixCalculateMethod);
70 
71 
72  /** Bypass the audio processing routine and copy all input samples to the output unchanged.
73  @param value Set bypass property for the object, controling whether matrix calculation will be bypassed.
74  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
75  */
76  TTErr setBypass(const TTValue& value);
77 
78 
79  /** Built-in method to be used when calculation is to bypassed. It simply copied input to output.
80  @param input Input the calculation routine.
81  @param output Output from the calculation routine.
82  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
83  */
84  TTErr bypassMatrixCalculate(const TTMatrixArray* inputs, TTMatrixArray* outputs);
85 
86 
87  /** The default calculation method to use.
88  @param input Input the calculation routine.
89  @param output Output from the calculation routine.
90  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
91  */
92  TTErr defaultMatrixCalculateMethod(const TTMatrixArray* inputs, TTMatrixArray* outputs);
93 
94 
95  /** Reset internal values used when benchmarking performance.
96  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
97  */
98  TTErr resetBenchmarking();
99 
100 
101  /** Do performance benchmarking.
102  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
103  */
104  TTErr getProcessingBenchmark(TTValueRef v);
105 
106 
107 public:
108  /**
109  @param input Input the calculation routine.
110  @param output Output from the calculation routine.
111  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
112  */
113  TTErr calculate(const TTMatrixArray* inputs, TTMatrixArray* outputs);
114  TTErr calculate(const TTMatrixBase& x, TTMatrixBase& y);
115  TTErr calculate(const TTMatrixBase* x, TTMatrixBase* y)
116  {
117  return calculate(*x, *y);
118  }
119 
120  //! [doxygenChapter60_virtualMethod]
121  /** Default (empty) template for unit tests.
122  @param returnedTestInfo Returned information on the outcome of the unit test(s)
123  @return #kTTErrNone if tests exists and they all pass, else #TTErr error codes depending on the outcome of the test.
124  */
125  virtual TTErr test(TTValue& /*returnedTestInfo*/)
126  {
127  logMessage("No Tests have been written for this class -- please supply a test method.\n");
128  return kTTErrGeneric;
129  }
130  //! [doxygenChapter60_virtualMethod]
131 
132 };
133 
134 /** Pointer to a #TTDataObjectBase.
135  @ingroup typedefs
136  */
138 
139 #endif // __TT_DATA_OBJECTBASE_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
The Jamoma Object Base Class.
TTErr logMessage(TTImmutableCString fmtstring,...)
Log messages scoped to this object instance.
TTDataObjectBase is the base class for all data generating and processing objects.
TTPtrSizedInt mReserved2
Reserved – May be used for something in the future without changing the size of the struct...
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
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...
2-dimensional matrix of compound values with N elements each.
Definition: TTMatrixBase.h:41
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...
An array of TTMatrix instance pointers.
Definition: TTMatrixArray.h:25
TTDataObjectBase * TTDataObjectBasePtr
Pointer to a TTDataObjectBase.
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
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.
TTMatrixCalculateMethod mMatrixCalculateMethod
This function pointer points to the active (non-bypass) calculate routine.
virtual TTErr test(TTValue &)
[doxygenChapter60_virtualMethod]
Provides a common way of representing composite values.
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)
TTBoolean mBypass
Are we bypassing the matrix calculation?
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTPtrSizedInt mReserved1
Reserved – May be used for something in the future without changing the size of the struct...