37
40
/// Abstract base class for all DSPatch components
40
Classes derived from DspComponent can be added to an DspCircuit and routed to and from other
41
DspComponents. On construction, derived classes must configure the component's IO buses by calling
42
AddInput_() and AddOutput_() respectively. Derived classes must also implement the virtual method:
43
Process_(). The Process_() method is a callback from the DSPatch engine that occurs when a new set
44
of input signals is ready for processing. The Process_() method has 2 parameters: the input bus and
45
the output bus. This method's purpose is to pull its required inputs out of the input bus, process
46
these inputs, and populate the output bus with the results (see DspSignalBus).
43
Classes derived from DspComponent can be added to a DspCircuit and routed to and from other
46
On construction, derived classes must configure the component's IO buses by calling AddInput_() and
47
AddOutput_() respectively, as well as populate the component's parameter map via AddParameter_()
50
Derived classes must also implement the virtual method: Process_(). The Process_() method is a
51
callback from the DSPatch engine that occurs when a new set of input signals is ready for
52
processing. The Process_() method has 2 arguments: the input bus, and the output bus. This
53
method's purpose is to pull its required inputs out of the input bus, process these inputs, and
54
populate the output bus with the results (see DspSignalBus).
56
Derived classes that expose parameters will also need to implement the virtual ParameterUpdating_()
57
method. The ParameterUpdating_() method is a callback from the DSPatch engine that occurs when an
58
update to a component parameter has been requested via the public SetParameter() method.
59
ParameterUpdating_() has 2 arguments: the parameter name, and the new parameter value to be set.
60
This method's purpose is to: 1. validate that the new value is legal, 2. make the necessary
61
internal changes associated with that parameter change, and 3. update the target parameter itself
62
by calling the protected SetParameter_() method. If the new parameter value is legal and the update
63
was successful, ParameterUpdating_() should return true, otherwise, it should return false.
48
65
In order for a component to do any work it must be ticked over. This is performed by repeatedly
49
66
calling the Tick() and Reset() methods. The Tick() method is responsible for acquiring the next set
54
71
method. The Reset() method then informs the component that the last circuit traversal has completed
55
72
and hence can execute the next Tick() request. A component's Tick() and Reset() methods can be
56
73
called in a loop from the main application thread, or alternatively, by calling StartAutoTick(), a
57
seperate thread will spawn, automatically calling Tick() and Reset() methods continuously (This is
74
separate thread will spawn, automatically calling Tick() and Reset() methods continuously (This is
58
75
most commonly used to tick over an instance of DspCircuit).
61
78
class DLLEXPORT DspComponent
63
friend class DspCircuit;
64
friend class DspCircuitThread;
83
InputAdded, InputRemoved,
84
OutputAdded, OutputRemoved,
85
ParameterAdded, ParameterRemoved, ParameterUpdated
87
typedef void( *Callback_t )( DspComponent const* component, CallbackType const& callbackType, int index, void* userData );
68
90
virtual ~DspComponent();
70
void SetComponentName( std::string componentName );
92
void SetCallback( Callback_t const& callback, void* userData = NULL );
94
void SetComponentName( std::string const& componentName );
71
95
std::string GetComponentName() const;
73
template< class FromOutputType, class ToInputType >
74
bool ConnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput );
76
template< class FromOutputType, class ToInputType >
77
bool ConnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput );
79
template< class FromOutputType, class ToInputType >
80
void DisconnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput );
82
template< class FromOutputType, class ToInputType >
83
void DisconnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput );
97
template< class FromOutputId, class ToInputId >
98
bool ConnectInput( DspComponent* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
100
template< class FromOutputId, class ToInputId >
101
bool ConnectInput( DspComponent& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
103
template< class FromOutputId, class ToInputId >
104
void DisconnectInput( DspComponent const* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
106
template< class FromOutputId, class ToInputId >
107
void DisconnectInput( DspComponent const& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
85
109
void DisconnectInput( unsigned short inputIndex );
86
void DisconnectInput( std::string inputName );
87
void DisconnectInput( DspComponent* inputComponent );
88
void DisconnectInputs();
90
unsigned short GetInputCount() const;
91
unsigned short GetOutputCount() const;
110
void DisconnectInput( std::string const& inputName );
111
void DisconnectInput( DspComponent const* inputComponent );
112
void DisconnectAllInputs();
114
unsigned short GetInputCount();
115
unsigned short GetOutputCount();
116
unsigned short GetParameterCount();
118
std::string GetInputName( unsigned short index );
119
std::string GetOutputName( unsigned short index );
120
std::string GetParameterName( unsigned short index );
122
bool GetParameter( std::string const& paramName, DspParameter& param );
123
bool SetParameter( std::string const& paramName, DspParameter const& param );
99
131
virtual void ResumeAutoTick();
102
virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs ) {};
104
bool AddInput_( std::string inputName = "" );
105
bool AddOutput_( std::string outputName = "" );
107
void RemoveInputs_();
108
void RemoveOutputs_();
134
virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs ) {}
135
virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param ) { return false; }
137
bool AddInput_( std::string const& inputName = "" );
138
bool AddOutput_( std::string const& outputName = "" );
139
bool AddParameter_( std::string const& paramName, DspParameter const& param );
142
bool RemoveOutput_();
143
bool RemoveParameter_();
145
void RemoveAllInputs_();
146
void RemoveAllOutputs_();
147
void RemoveAllParameters_();
149
unsigned short GetInputCount_();
150
unsigned short GetOutputCount_();
151
unsigned short GetParameterCount_();
153
DspParameter const* GetParameter_( std::string const& paramName ) const;
154
bool SetParameter_( std::string const& paramName, DspParameter const& param );
111
157
void _SetParentCircuit( DspCircuit* parentCircuit );
112
158
DspCircuit* _GetParentCircuit();
114
bool _FindInput( std::string signalName, unsigned short& returnIndex ) const;
160
bool _FindInput( std::string const& signalName, unsigned short& returnIndex ) const;
115
161
bool _FindInput( unsigned short signalIndex, unsigned short& returnIndex ) const;
116
bool _FindOutput( std::string signalName, unsigned short& returnIndex ) const;
162
bool _FindOutput( std::string const& signalName, unsigned short& returnIndex ) const;
117
163
bool _FindOutput( unsigned short signalIndex, unsigned short& returnIndex ) const;
119
165
void _SetBufferCount( unsigned short bufferCount );
122
168
void _ThreadTick( unsigned short threadNo );
123
169
void _ThreadReset( unsigned short threadNo );
125
bool _SetInputSignal( unsigned short inputIndex, const DspSignal* newSignal );
126
bool _SetInputSignal( unsigned short inputIndex, unsigned short threadIndex, const DspSignal* newSignal );
171
bool _SetInputSignal( unsigned short inputIndex, DspSignal const* newSignal );
172
bool _SetInputSignal( unsigned short inputIndex, unsigned short threadIndex, DspSignal const* newSignal );
127
173
DspSignal* _GetOutputSignal( unsigned short outputIndex );
128
174
DspSignal* _GetOutputSignal( unsigned short outputIndex, unsigned short threadIndex );
155
206
std::vector< bool > _gotReleases; // bool pointers not used here as only 1 thread writes to this vector at a time
156
207
std::vector< DspMutex > _releaseMutexes;
157
208
std::vector< DspWaitCondition > _releaseCondts;
210
Callback_t _callback;
160
214
//=================================================================================================
162
template< class FromOutputType, class ToInputType >
163
bool DspComponent::ConnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput )
216
template< class FromOutputId, class ToInputId >
217
bool DspComponent::ConnectInput( DspComponent* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
165
219
unsigned short fromOutputIndex;
166
220
unsigned short toInputIndex;
181
235
//-------------------------------------------------------------------------------------------------
183
template< class FromOutputType, class ToInputType >
184
bool DspComponent::ConnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput )
237
template< class FromOutputId, class ToInputId >
238
bool DspComponent::ConnectInput( DspComponent& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
186
240
return ConnectInput( &fromComponent, fromOutput, toInput );
189
243
//-------------------------------------------------------------------------------------------------
191
template< class FromOutputType, class ToInputType >
192
void DspComponent::DisconnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput )
245
template< class FromOutputId, class ToInputId >
246
void DspComponent::DisconnectInput( DspComponent const* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
194
248
unsigned short fromOutputIndex;
195
249
unsigned short toInputIndex;