#include <gapeunit.h>
Inheritance diagram for GapeUnit::
Public Slots | |
virtual void | receiveTick (const GapeFloat *values, int numValues)=0 |
Pure virtual function that all subclasses of GapeUnit must define. More... | |
virtual void | setFreq (double f) |
Sets the frequency (in hertz) for this unit. More... | |
virtual void | setGain (double g) |
Sets the gain (as a floating point coefficient) of this unit. More... | |
virtual void | setGainDb (double g) |
Sets the gain (as a decibel coefficient) of this unit. More... | |
virtual GapeFloat | getFreq () const |
Gets the frequency of this unit. More... | |
virtual GapeFloat | getGain () const |
Gets the gain of this unit. More... | |
virtual GapeFloat | getGainDb () const |
Gets the gain of this unit. More... | |
virtual void | setMute (bool b) |
Mutes the unit. More... | |
virtual void | setSolo (bool b) |
Sets the unit to solo. More... | |
virtual bool | getMute () const |
Gets the current muting status of the unit. More... | |
virtual bool | getSolo () const |
Gets the current solo status of the unit. More... | |
virtual GapeUnitGroup* | getParent () const |
Gets the group which this unit belongs to. More... | |
virtual void | setParent (GapeUnitGroup *p) |
Notifes the unit that it has a new parent. More... | |
virtual GapeController** | getControllers () const |
Gets the controllers for this unit. More... | |
virtual void | addController (GapeController *c) |
Adds a controller for this unit. More... | |
virtual void | removeController (GapeController *c) |
Removes a controller for this unit. More... | |
virtual void | setNumChannels (int n) |
Sets the number of channels for this unit. More... | |
virtual int | getNumChannels () const |
Gets the number of channels for this unit. More... | |
virtual int | getNumControllers () const |
Gets the number of controllers for this unit. More... | |
virtual bool | isGraphical () |
Determines if the unit has a graphical controller or not. More... | |
Signals | |
void | emitTick (const GapeFloat *values, int numValues) |
Emits a new sample(s). More... | |
void | emitFreq (double f) |
void | emitGain (double g) |
void | emitGainDb (double g) |
void | emitMute (bool b) |
void | emitSolo (bool b) |
void | emitNumChannels (int n) |
Public Methods | |
GapeUnit (GapeController *c=NULL, int nChannels=1) | |
The constructor, which allows the graphical controller for this unit to be set if so desired. More... | |
virtual | ~GapeUnit () |
The destructor. More... | |
Protected Methods | |
virtual void | setupControls (GapeController *c) |
Setups up the graphical controller for this unit. More... | |
virtual void | disconnectControls (GapeController *c) |
Disconnects the current graphical controller. More... | |
Protected Attributes | |
GapeController** | controllers |
GapeUnitGroup* | parent |
bool | muted |
bool | solo |
GapeFloat | gain |
GapeFloat | frequency |
int | numChannels |
int | numControllers |
int | controllerCapacity |
QMutex | updateMutex |
All sources, filters, outputs, etc must subclass off of this class. The important function to implement is receiveTick(), which recieves a sample (can be any number of channels, depending on the numValues parameter). The function should do its work and then emit a new sample, letting the Qt connection methods take care of routing the new sample somewhere useful. For example, a simple unit that just amplified a signals amplitude might do the following:
someclass::receiveTick(const GapeFloat* values, int numValues) {
GapeFloat[10] sample;
if (muted) {
emitTick(sample,numValues);
} else {
for (int i = 0;i<numvalues;i++) {
sample[i] = values[i]*gain;
}
emitTick(sample,numValues);
}
}
Obviously, this is a preety simple class, and would run into trouble with > 10 channel audio, but you get the point. Remember to account for muting in your classes. Any subclass of GapeUnit may be simply plugged together using Qt's connect method. For example, where BlackBox is a subclass of GapeUnit:
BlackBox *box1 = new BlackBox;
BlackBox *box2 = new BlackBox;
double someSignal[4] = {1.0, 0, -1.0, 0};
connect(box1, SIGNAL(emitTick(const GapeFloat*, int)), box2, SLOT(receiveTick(const GapeFloat*, int)));
emit box1->emitTick(someSignal, 4); //this will cause box2->receiveTick(someSignal,4) to happen
The GapeUnit class has built in functions for adjusting frequency, gain, muting, solo mode, and setting up the graphical controller (which can be any subclass of GapeController). Subclasses with complex controls will have to re-implement setupControls(), although disconnectControls(), setController() and getController() should work as is, unless you want more than one controller for the unit. Some units (ie file readers, reverbs) may not have a use for frequency, gain, etc controls - in this case they can be safely ignored. They should, however, at least use "setNumChannels" to set a reasonable value. GapeUnits can also have a "parent" GapeUnitGroup - however, this is not necesary, and units can stand alone. See the GapeUnitGroup class for more info on this.
This class also has a mutex built in to it, since most units may be affected by both the GUI thread as well as whatever thread the audio is running on. Functions which change control values like setFreq or setGain are synchronized in this manner. If your subclasses monitor things like
Definition at line 62 of file gapeunit.h.
|
The constructor, which allows the graphical controller for this unit to be set if so desired.
Definition at line 9 of file gapeunit.cpp. |
|
The destructor. Doesn't actually destroy anything, but it does disconnect the controls Definition at line 31 of file gapeunit.cpp. |
|
Pure virtual function that all subclasses of GapeUnit must define. This function is the primary function in the GapeUnit environment. See class documentation for more info.
Reimplemented in GapeAccumulator, GapeAudioDriver, GapeAudioInput, GapeAudioOutput, GapeCosWindow, GapeFileReader, GapeFunctionUnit, GapeFileSampleUnit, GapePowerSpectrum, GapeSignalDisplay, GapeTimeDomainDisplay, GapeFreqDomainDisplay, and GapeUnitGroup. Referenced by GapeUnitGroup::receiveTick().
|
|
Sets the frequency (in hertz) for this unit.
Definition at line 34 of file gapeunit.cpp. Referenced by setupControls().
|
|
Sets the gain (as a floating point coefficient) of this unit.
Definition at line 49 of file gapeunit.cpp. Referenced by setGainDb(), and setupControls().
|
|
Sets the gain (as a decibel coefficient) of this unit.
Definition at line 60 of file gapeunit.cpp. Referenced by setupControls().
|
|
Gets the frequency of this unit.
Definition at line 70 of file gapeunit.cpp. |
|
Gets the gain of this unit.
Definition at line 75 of file gapeunit.cpp. |
|
Gets the gain of this unit.
Definition at line 80 of file gapeunit.cpp. |
|
Mutes the unit.
Reimplemented in GapeAudioInput, and GapeAudioOutput. Definition at line 86 of file gapeunit.cpp. Referenced by GapeUnitGroup::endSolo(), GapeUnitGroup::requestSolo(), and setupControls().
|
|
Sets the unit to solo.
Definition at line 100 of file gapeunit.cpp. Referenced by setParent(), and setupControls().
|
|
Gets the current muting status of the unit.
Definition at line 118 of file gapeunit.cpp. |
|
Gets the current solo status of the unit.
Definition at line 123 of file gapeunit.cpp. |
|
Gets the group which this unit belongs to.
Definition at line 128 of file gapeunit.cpp. |
|
Notifes the unit that it has a new parent. If the unit is in "solo" mode, it will notify its current parent to end the mode before changing to the new parent. Generally, users don't have to explicitly call this function, as a GapeUnitGroup will call setParent when it recieves an "addUnit()" message.
Definition at line 133 of file gapeunit.cpp. |
|
Gets the controllers for this unit.
Definition at line 152 of file gapeunit.cpp. |
|
Adds a controller for this unit. Previously attached controllers remain attached.
Reimplemented in GapeUnitGroup. Definition at line 157 of file gapeunit.cpp. Referenced by GapeUnit(), GapeUnitGroup::addController(), and GapeUnitGroup::addUnit().
|
|
Removes a controller for this unit.
Reimplemented in GapeUnitGroup. Definition at line 168 of file gapeunit.cpp. Referenced by GapeUnitGroup::removeController(), and GapeUnitGroup::removeUnit().
|
|
Sets the number of channels for this unit.
Reimplemented in GapeAudioInput, and GapeAudioOutput. Definition at line 186 of file gapeunit.cpp. Referenced by GapeFileReader::GapeFileReader(), and GapeFileSampleUnit::fillBuffer().
|
|
Gets the number of channels for this unit.
Definition at line 194 of file gapeunit.cpp. |
|
Gets the number of controllers for this unit.
Definition at line 147 of file gapeunit.cpp. |
|
Determines if the unit has a graphical controller or not.
Definition at line 199 of file gapeunit.cpp. |
|
Emits a new sample(s). Generally, its hooked up with connect() to a receiveSlot() of some other unit.
Referenced by GapeUnitGroup::addUnit(), GapeUnitGroup::receiveTick(), GapeFreqDomainDisplay::receiveTick(), GapeTimeDomainDisplay::receiveTick(), GapePowerSpectrum::receiveTick(), GapeFileSampleUnit::receiveTick(), GapeFunctionUnit::receiveTick(), GapeFileReader::receiveTick(), GapeCosWindow::receiveTick(), GapeAudioOutput::receiveTick(), GapeAudioInput::receiveTick(), GapeAudioDriver::receiveTick(), GapeAccumulator::receiveTick(), and GapeUnitGroup::removeUnit().
|
|
Setups up the graphical controller for this unit. Subclasses should redefine this function if they have complex controls. The default version just connects signals and slots for freq, gain, muting and soloing. Definition at line 204 of file gapeunit.cpp. Referenced by addController().
|
|
Disconnects the current graphical controller. This breaks all signal/slot connections between the controller and the unit. Generally units will not have to redefine this function. Does not actually destroy anything, and it does not set the controller pointer to NULL. Simply removes connections. Definition at line 222 of file gapeunit.cpp. Referenced by removeController().
|