Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

GapeUnit Class Reference

The fundamental GAPE class. More...

#include <gapeunit.h>

Inheritance diagram for GapeUnit::

GapeAccumulator GapeAudioDriver GapeAudioInput GapeAudioOutput GapeCosWindow GapeFileReader GapeFunctionUnit GapePowerSpectrum GapeSignalDisplay GapeUnitGroup List of all members.

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 GapeUnitGroupgetParent () 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
GapeUnitGroupparent
bool muted
bool solo
GapeFloat gain
GapeFloat frequency
int numChannels
int numControllers
int controllerCapacity
QMutex updateMutex

Detailed Description

The fundamental GAPE class.

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

Author:
Dave Chisholm
Since:
Beta 1.0
Version:
Last Modified Beta 1.0

Definition at line 62 of file gapeunit.h.


Constructor & Destructor Documentation

GapeUnit::GapeUnit ( GapeController * c = NULL,
int nChannels = 1 )
 

The constructor, which allows the graphical controller for this unit to be set if so desired.

Parameters:
c   A pointer to a gapeController to be used with this unit.
nChannels   how many channels of audio this gapeunit will be using

Definition at line 9 of file gapeunit.cpp.

GapeUnit::~GapeUnit ( ) [virtual]
 

The destructor.

Doesn't actually destroy anything, but it does disconnect the controls

Definition at line 31 of file gapeunit.cpp.


Member Function Documentation

void GapeUnit::receiveTick ( const GapeFloat * values,
int numValues ) [pure virtual, slot]
 

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.

Parameters:
values   pointer to samples data being sent to the function
numValues   number of floating point values pointed to by "values" (ie number of channels of audio)

Reimplemented in GapeAccumulator, GapeAudioDriver, GapeAudioInput, GapeAudioOutput, GapeCosWindow, GapeFileReader, GapeFunctionUnit, GapeFileSampleUnit, GapePowerSpectrum, GapeSignalDisplay, GapeTimeDomainDisplay, GapeFreqDomainDisplay, and GapeUnitGroup.

Referenced by GapeUnitGroup::receiveTick().

void GapeUnit::setFreq ( double f ) [virtual, slot]
 

Sets the frequency (in hertz) for this unit.

Parameters:
f   the frequency in hertz

Definition at line 34 of file gapeunit.cpp.

Referenced by setupControls().

void GapeUnit::setGain ( double g ) [virtual, slot]
 

Sets the gain (as a floating point coefficient) of this unit.

Parameters:
g   the gain, from 0.0 to 1.0 (higher values are allowed, but you risk clipping)

Definition at line 49 of file gapeunit.cpp.

Referenced by setGainDb(), and setupControls().

void GapeUnit::setGainDb ( double g ) [virtual, slot]
 

Sets the gain (as a decibel coefficient) of this unit.

Parameters:
g   the gain, in decibels

Definition at line 60 of file gapeunit.cpp.

Referenced by setupControls().

GapeFloat GapeUnit::getFreq ( ) const [virtual, slot]
 

Gets the frequency of this unit.

Returns:
the frequency in hertz

Definition at line 70 of file gapeunit.cpp.

GapeFloat GapeUnit::getGain ( ) const [virtual, slot]
 

Gets the gain of this unit.

Returns:
the gain in Db

Definition at line 75 of file gapeunit.cpp.

GapeFloat GapeUnit::getGainDb ( ) const [virtual, slot]
 

Gets the gain of this unit.

Parameters:
g   new gain in Db

Definition at line 80 of file gapeunit.cpp.

void GapeUnit::setMute ( bool b ) [virtual, slot]
 

Mutes the unit.

Parameters:
b   true to mute, false to unmute

Reimplemented in GapeAudioInput, and GapeAudioOutput.

Definition at line 86 of file gapeunit.cpp.

Referenced by GapeUnitGroup::endSolo(), GapeUnitGroup::requestSolo(), and setupControls().

void GapeUnit::setSolo ( bool b ) [virtual, slot]
 

Sets the unit to solo.

Parameters:
b   true to set solo, false to stop solo

Definition at line 100 of file gapeunit.cpp.

Referenced by setParent(), and setupControls().

bool GapeUnit::getMute ( ) const [virtual, slot]
 

Gets the current muting status of the unit.

Returns:
true if muted, false otherwise

Definition at line 118 of file gapeunit.cpp.

bool GapeUnit::getSolo ( ) const [virtual, slot]
 

Gets the current solo status of the unit.

Returns:
true if solo, false otherwise

Definition at line 123 of file gapeunit.cpp.

GapeUnitGroup * GapeUnit::getParent ( ) const [virtual, slot]
 

Gets the group which this unit belongs to.

Returns:
the GapeUnitGroup which contains this unit, or NULL if none.

Definition at line 128 of file gapeunit.cpp.

void GapeUnit::setParent ( GapeUnitGroup * p ) [virtual, slot]
 

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.

Parameters:
p   a pointer to the new group

Definition at line 133 of file gapeunit.cpp.

GapeController ** GapeUnit::getControllers ( ) const [virtual, slot]
 

Gets the controllers for this unit.

Returns:
the current controller unit, or NULL if none

Definition at line 152 of file gapeunit.cpp.

void GapeUnit::addController ( GapeController * c ) [virtual, slot]
 

Adds a controller for this unit.

Previously attached controllers remain attached.

Parameters:
c   a pointer to the new controller

Reimplemented in GapeUnitGroup.

Definition at line 157 of file gapeunit.cpp.

Referenced by GapeUnit(), GapeUnitGroup::addController(), and GapeUnitGroup::addUnit().

void GapeUnit::removeController ( GapeController * c ) [virtual, slot]
 

Removes a controller for this unit.

Parameters:
c   a pointer to the new controller
Returns:
true if the controller was removed, false if the controller was not already attached

Reimplemented in GapeUnitGroup.

Definition at line 168 of file gapeunit.cpp.

Referenced by GapeUnitGroup::removeController(), and GapeUnitGroup::removeUnit().

void GapeUnit::setNumChannels ( int nc ) [virtual, slot]
 

Sets the number of channels for this unit.

Parameters:
n   the number of channels

Reimplemented in GapeAudioInput, and GapeAudioOutput.

Definition at line 186 of file gapeunit.cpp.

Referenced by GapeFileReader::GapeFileReader(), and GapeFileSampleUnit::fillBuffer().

int GapeUnit::getNumChannels ( ) const [virtual, slot]
 

Gets the number of channels for this unit.

Returns:
the number of channels this unit outputs

Definition at line 194 of file gapeunit.cpp.

int GapeUnit::getNumControllers ( ) const [virtual, slot]
 

Gets the number of controllers for this unit.

Returns:
the number of controllers this unit currently has

Definition at line 147 of file gapeunit.cpp.

bool GapeUnit::isGraphical ( ) [virtual, slot]
 

Determines if the unit has a graphical controller or not.

Returns:
True is this unit has a graphical controller.

Definition at line 199 of file gapeunit.cpp.

void GapeUnit::emitTick ( const GapeFloat * values,
int numValues ) [signal]
 

Emits a new sample(s).

Generally, its hooked up with connect() to a receiveSlot() of some other unit.

Parameters:
values   a (const) pointer to the sample data.
numValues   the number of samples emitted.

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().

void GapeUnit::setupControls ( GapeController * controller ) [protected, virtual]
 

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().

void GapeUnit::disconnectControls ( GapeController * controller ) [protected, virtual]
 

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().


The documentation for this class was generated from the following files:
Generated at Thu Jun 21 13:28:53 2001 for GAPE by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001