Jamoma API  0.6.0.a19
TTFilter.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTFilter is a generalized filter wrapper object for Jamoma
6  *
7  * @details
8  *
9  * @authors Timothy Place, Trond Lossius
10  *
11  * @copyright Copyright © 2010, 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 
17 #ifndef __TT_FILTER_H__
18 #define __TT_FILTER_H__
19 
20 #include "TTDSP.h"
21 
22 
23 /** A Generalized filter wrapper object for Jamoma. */
26 
27 protected:
28 
29  TTAudioObjectBasePtr mActualFilterObject; ///< The actual filter object that this object is currently wrapping
30  TTFloat64 mFrequency; ///< The center or cutoff frequency of the filter
31  TTFloat64 mQ; ///< The width of the filter
32  TTSymbol mType; ///< The name of the current filter type
33 
34 public:
35 
36  TTErr setFrequency(const TTValue& newValue)
37  {
38  mFrequency = newValue;
39  return mActualFilterObject->setAttributeValue(TT("frequency"), mFrequency);
40  }
41 
42  TTErr setQ(const TTValue& newValue)
43  {
44  mQ = newValue;
45  return mActualFilterObject->setAttributeValue(TT("q"), mQ);
46  }
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 filter
54  if (newType == mType)
55  return kTTErrNone;
56 
57  mType = newType;
58  err = TTObjectBaseInstantiate(mType, &mActualFilterObject, mMaxNumChannels);
59  if (!err) {
60  // Now that we have our new filter, update it with the current state of the wrapper:
61  mActualFilterObject->setAttributeValue(TT("frequency"), mFrequency);
62  err = mActualFilterObject->setAttributeValue(TT("q"), mQ);
63  if (err == kTTErrInvalidAttribute)
64  err = mActualFilterObject->setAttributeValue(TT("resonance"), mQ);
65  mActualFilterObject->setAttributeValue(TT("bypass"), this->attrBypass);
66  mActualFilterObject->setAttributeValue(kTTSym_sampleRate, sr);
67  }
68  return err;
69  }
70 
71 
72  TTErr getTypes(const TTValue&, TTValue& listOfFilterTypesToReturn)
73  {
74  return TTObject::GetRegisteredClassNamesForTags(listOfFilterTypesToReturn, TT("filter"));
75  }
76 
77 
78  TTErr clear()
79  {
80  return mActualFilterObject->sendMessage(TT("clear"));
81  }
82 
83 
84  TTErr mode(const TTValue& newMode, TTValue&)
85  {
86  if (mActualFilterObject)
87  return mActualFilterObject->setAttributeValue(TT("mode"), const_cast<TTValue&>(newMode));
88  else
89  return kTTErrNone;
90  }
91 
92 
93  TTErr updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
94  {
95  if (mActualFilterObject)
96  return mActualFilterObject->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
97  else
98  return kTTErrNone;
99  }
100 
101 
102  TTErr updateSampleRate(const TTValue& oldSampleRate, TTValue&)
103  {
104  return mActualFilterObject->setAttributeValue(kTTSym_sampleRate, sr);
105  }
106 
107 
108  TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
109  {
110  return mActualFilterObject->process(inputs, outputs);
111  }
112 
113 
114  /** Unit Tests
115  @param returnedTestInfo Used to return test information
116  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
117  */
118  virtual TTErr test(TTValue& returnedTestInfo);
119 };
120 
121 
122 #endif // __TT_FILTER_H__
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
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
TTBoolean attrBypass
Are we bypassing the processMethod?
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
A Generalized filter wrapper object for Jamoma.
Definition: TTFilter.h:24
TTAudioObjectBasePtr mActualFilterObject
The actual filter object that this object is currently wrapping.
Definition: TTFilter.h:29
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
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.
TTFloat64 mQ
The width of the filter.
Definition: TTFilter.h:31
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
A simple container for an array of TTAudioSignal pointers.
TTFloat64 mFrequency
The center or cutoff frequency of the filter.
Definition: TTFilter.h:30
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
No Error.
Definition: TTBase.h:343
TTSymbol mType
The name of the current filter type.
Definition: TTFilter.h:32
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Bad Attribute specified.
Definition: TTBase.h:348
TTUInt32 sr
Current sample rate being used by this object.