DSPatch  v.3.00
C++ Cross-Platform, Object-Oriented, Flow-Based Programming Library
Public Types | Public Member Functions | Protected Member Functions | List of all members
DspComponent Class Reference

Abstract base class for all DSPatch components. More...

#include <DspComponent.h>

Inheritance diagram for DspComponent:
DspCircuit

Public Types

enum  CallbackType {
  InputAdded, InputRemoved, OutputAdded, OutputRemoved,
  ParameterAdded, ParameterRemoved, ParameterUpdated
}
 
typedef void(* Callback_t) (DspComponent *component, CallbackType const &callbackType, int index, void *userData)
 

Public Member Functions

void SetCallback (Callback_t const &callback, void *userData=NULL)
 
void SetComponentName (std::string const &componentName)
 
std::string GetComponentName () const
 
template<class FromOutputId , class ToInputId >
bool ConnectInput (DspComponent *fromComponent, FromOutputId const &fromOutput, ToInputId const &toInput)
 
template<class FromOutputId , class ToInputId >
bool ConnectInput (DspComponent &fromComponent, FromOutputId const &fromOutput, ToInputId const &toInput)
 
template<class FromOutputId , class ToInputId >
void DisconnectInput (DspComponent const *fromComponent, FromOutputId const &fromOutput, ToInputId const &toInput)
 
template<class FromOutputId , class ToInputId >
void DisconnectInput (DspComponent const &fromComponent, FromOutputId const &fromOutput, ToInputId const &toInput)
 
void DisconnectInput (int inputIndex)
 
void DisconnectInput (std::string const &inputName)
 
void DisconnectInput (DspComponent const *inputComponent)
 
void DisconnectAllInputs ()
 
int GetInputCount ()
 
int GetOutputCount ()
 
int GetParameterCount ()
 
std::string GetInputName (int index)
 
std::string GetOutputName (int index)
 
std::string GetParameterName (int index)
 
bool GetParameter (int index, DspParameter &param)
 
DspParameter const * GetParameter (int index)
 
bool SetParameter (int index, DspParameter const &param)
 
void Tick ()
 
void Reset ()
 
void StartAutoTick ()
 
void StopAutoTick ()
 
void PauseAutoTick ()
 
void ResumeAutoTick ()
 

Protected Member Functions

virtual void Process_ (DspSignalBus &, DspSignalBus &)
 
virtual bool ParameterUpdating_ (int, DspParameter const &)
 
bool AddInput_ (std::string const &inputName="")
 
bool AddOutput_ (std::string const &outputName="")
 
int AddParameter_ (std::string const &paramName, DspParameter const &param)
 
bool RemoveInput_ ()
 
bool RemoveOutput_ ()
 
bool RemoveParameter_ ()
 
void RemoveAllInputs_ ()
 
void RemoveAllOutputs_ ()
 
void RemoveAllParameters_ ()
 
int GetInputCount_ ()
 
int GetOutputCount_ ()
 
int GetParameterCount_ ()
 
DspParameter const * GetParameter_ (int index) const
 
bool SetParameter_ (int index, DspParameter const &param)
 

Detailed Description

Abstract base class for all DSPatch components.

Classes derived from DspComponent can be added to a DspCircuit and routed to and from other DspComponents.

On construction, derived classes must configure the component's IO buses by calling AddInput_() and AddOutput_() respectively, as well as populate the component's parameter map via AddParameter_() (see DspParameter).

Derived classes must also implement the virtual method: Process_(). The Process_() method is a callback from the DSPatch engine that occurs when a new set of input signals is ready for processing. The Process_() method has 2 arguments: the input bus, and the output bus. This method's purpose is to pull its required inputs out of the input bus, process these inputs, and populate the output bus with the results (see DspSignalBus).

Derived classes that expose parameters will also need to implement the virtual ParameterUpdating_() method. The ParameterUpdating_() method is a callback from the DSPatch engine that occurs when an update to a component parameter has been requested via the public SetParameter() method. ParameterUpdating_() has 2 arguments: the parameter name, and the new parameter value to be set. This method's purpose is to: 1. validate that the new value is legal, 2. make the necessary internal changes associated with that parameter change, and 3. update the target parameter itself by calling the protected SetParameter_() method. If the new parameter value is legal and the update was successful, ParameterUpdating_() should return true, otherwise, it should return false.

In order for a component to do any work it must be ticked over. This is performed by repeatedly calling the Tick() and Reset() methods. The Tick() method is responsible for acquiring the next set of input signals from component input wires and populating the component's input bus. To insure that these inputs are up-to-date, the dependent component first calls all of its input components' Tick() methods -hence recursively called in all components going backward through the circuit (This is what's classified as a "pull system"). The acquired input bus is then passed to the Process_() method. The Reset() method then informs the component that the last circuit traversal has completed and hence can execute the next Tick() request. A component's Tick() and Reset() methods can be called in a loop from the main application thread, or alternatively, by calling StartAutoTick(), a separate thread will spawn, automatically calling Tick() and Reset() methods continuously (This is most commonly used to tick over an instance of DspCircuit).

Definition at line 76 of file DspComponent.h.


The documentation for this class was generated from the following files: