Merge lp:~marcustomlinson/dspatch/component_params into lp:dspatch

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 59
Merged at revision: 21
Proposed branch: lp:~marcustomlinson/dspatch/component_params
Merge into: lp:dspatch
Diff against target: 4019 lines (+1738/-656)
35 files modified
doc/Doxyfile (+1/-1)
example/CMakeLists.txt (+1/-1)
example/DspAdder.h (+3/-3)
example/DspAudioDevice.cpp (+101/-67)
example/DspAudioDevice.h (+20/-20)
example/DspGain.h (+20/-13)
example/DspOscillator.cpp (+89/-28)
example/DspOscillator.h (+13/-28)
example/DspWaveStreamer.cpp (+55/-12)
example/DspWaveStreamer.h (+10/-4)
example/main.cpp (+22/-10)
include/DSPatch.h (+171/-164)
include/dspatch/DspCircuit.h (+46/-43)
include/dspatch/DspCircuitThread.h (+1/-1)
include/dspatch/DspComponent.h (+103/-49)
include/dspatch/DspComponentThread.h (+1/-1)
include/dspatch/DspParameter.h (+111/-0)
include/dspatch/DspRunType.h (+11/-11)
include/dspatch/DspSignal.h (+6/-6)
include/dspatch/DspSignalBus.h (+24/-21)
include/dspatch/DspThread.h (+1/-1)
include/dspatch/DspThreadNull.h (+1/-1)
include/dspatch/DspThreadUnix.h (+3/-3)
include/dspatch/DspThreadWin.h (+4/-4)
include/dspatch/DspWire.h (+1/-1)
include/dspatch/DspWireBus.h (+2/-2)
src/DSPatch.cpp (+3/-3)
src/DspCircuit.cpp (+52/-35)
src/DspCircuitThread.cpp (+2/-2)
src/DspComponent.cpp (+341/-77)
src/DspComponentThread.cpp (+1/-1)
src/DspParameter.cpp (+462/-0)
src/DspSignal.cpp (+3/-3)
src/DspSignalBus.cpp (+50/-33)
src/DspWireBus.cpp (+3/-7)
To merge this branch: bzr merge lp:~marcustomlinson/dspatch/component_params
Reviewer Review Type Date Requested Status
Marcus Tomlinson Approve
Review via email: mp+222453@code.launchpad.net
To post a comment you must log in.
41. By Marcus Tomlinson

Allow DspParameter to be default constructed (SetParam then used to specify type, value etc.)

42. By Marcus Tomlinson

DspParameter constructible with initial values.

43. By Marcus Tomlinson

Added protected methods for IO and param count, and get/setting params, to be used from DspComponent child implementations.

44. By Marcus Tomlinson

Return pointers from DspParameter get methods to be compared with NULL.
ParameterUpdated_() replaced with ParameterUpdating_() for components to first validate the new value.

45. By Marcus Tomlinson

Allow list parameters to be set as an int parameter (to select a list index)

46. By Marcus Tomlinson

ParameterUpdating_() to simply redirect to the target class method

47. By Marcus Tomlinson

Parameter introduction to DspAudioDevice complete

48. By Marcus Tomlinson

Updated DspComponent to describe the Process_() correctly

49. By Marcus Tomlinson

Updated DspGain to use a gain parameter

50. By Marcus Tomlinson

Updated DspOscillator to use parameters

51. By Marcus Tomlinson

Store int and float ranges as pairs in DspParameter

52. By Marcus Tomlinson

Updated DspWaveStreamer to use parameters

53. By Marcus Tomlinson

Updated demo main.cpp to demonstrate parameter usage

54. By Marcus Tomlinson

Updated doxygen

55. By Marcus Tomlinson

Added userData parameter to callback

56. By Marcus Tomlinson

Updated documentation

57. By Marcus Tomlinson

Renamed "Release Notes" to "Changelog"

58. By Marcus Tomlinson

Fixed build errors on Windows

59. By Marcus Tomlinson

Removed unused PI variable

Revision history for this message
Marcus Tomlinson (marcustomlinson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/Doxyfile'
2--- doc/Doxyfile 2014-02-27 14:01:09 +0000
3+++ doc/Doxyfile 2014-06-16 15:43:30 +0000
4@@ -32,7 +32,7 @@
5 # This could be handy for archiving the generated documentation or
6 # if some version control system is used.
7
8-PROJECT_NUMBER = v.2.60
9+PROJECT_NUMBER = v.2.61
10
11 # Using the PROJECT_BRIEF tag one can provide an optional one line description
12 # for a project that appears at the top of each page and should give viewer
13
14=== modified file 'example/CMakeLists.txt'
15--- example/CMakeLists.txt 2014-04-12 15:48:46 +0000
16+++ example/CMakeLists.txt 2014-06-16 15:43:30 +0000
17@@ -35,7 +35,7 @@
18 )
19 endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
20
21-# Definition for RtAudio Linux, using ASLA
22+# Definition for RtAudio Linux, using ALSA
23 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
24 add_definitions(-D__LINUX_ALSA__)
25
26
27=== modified file 'example/DspAdder.h'
28--- example/DspAdder.h 2014-01-19 09:07:19 +0000
29+++ example/DspAdder.h 2014-06-16 15:43:30 +0000
30@@ -1,6 +1,6 @@
31 /************************************************************************
32 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
33-Copyright (c) 2012-2013 Marcus Tomlinson
34+Copyright (c) 2012-2014 Marcus Tomlinson
35
36 This file is part of DSPatch.
37
38@@ -43,7 +43,7 @@
39 achieved by making calls to the base class protected methods: "AddInput_()" and "AddOutput_().
40 These methods must be called once per input / output required. IO signal names are optional
41 (Component IO can be referenced by either string ID or index) and can be assigned to each
42- input / output by supplying the desired string ID as a parameter to the respective AddInput_()
43+ input / output by supplying the desired string ID as an argument to the respective AddInput_()
44 / AddOutput_() method call.*/
45
46 DspAdder()
47@@ -61,7 +61,7 @@
48 protected:
49 //! Virtual process method inherited from DspComponent
50 /*! The Process_() method is called from the DSPatch engine when a new set of component input
51- signals are ready for processing. The Process() method has 2 parameters: the input bus and the
52+ signals are ready for processing. The Process() method has 2 arguments: the input bus and the
53 output bus. This method's purpose is to pull its required inputs out of the input bus, process
54 these inputs, and populate the output bus with the results (see DspSignalBus). */
55
56
57=== modified file 'example/DspAudioDevice.cpp'
58--- example/DspAudioDevice.cpp 2014-04-12 23:16:46 +0000
59+++ example/DspAudioDevice.cpp 2014-06-16 15:43:30 +0000
60@@ -1,6 +1,6 @@
61 /************************************************************************
62 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
63-Copyright (c) 2012-2013 Marcus Tomlinson
64+Copyright (c) 2012-2014 Marcus Tomlinson
65
66 This file is part of DSPatch.
67
68@@ -32,6 +32,13 @@
69
70 //=================================================================================================
71
72+std::string const DspAudioDevice::pDeviceList = "deviceList";
73+std::string const DspAudioDevice::pIsStreaming = "isStreaming";
74+std::string const DspAudioDevice::pBufferSize = "bufferSize";
75+std::string const DspAudioDevice::pSampleRate = "sampleRate";
76+
77+//=================================================================================================
78+
79 struct RtAudioMembers
80 {
81 std::vector< RtAudio::DeviceInfo > deviceList;
82@@ -45,18 +52,8 @@
83
84 DspAudioDevice::DspAudioDevice()
85 : _rtAudio( new RtAudioMembers() ),
86-
87- _bufferSize( 256 ),
88- _sampleRate( 44100 ),
89-
90- _deviceCount( 0 ),
91-
92 _gotWaitReady( false ),
93- _gotSyncReady( true ),
94-
95- _streamStop( false ),
96-
97- _currentDevice( 0 )
98+ _gotSyncReady( true )
99 {
100 _outputChannels.resize( 20 );
101 for( unsigned short i = 0; i < 20; i++ )
102@@ -72,18 +69,22 @@
103 AddOutput_();
104 }
105
106- _deviceCount = _rtAudio->audioStream.getDeviceCount();
107- _rtAudio->deviceList.resize( _deviceCount );
108+ std::vector< std::string > deviceNameList;
109
110- for( short i = 0; i < _deviceCount; i++ )
111+ for( unsigned int i = 0; i < _rtAudio->audioStream.getDeviceCount(); i++ )
112 {
113- _rtAudio->deviceList[i] = _rtAudio->audioStream.getDeviceInfo( i );
114+ _rtAudio->deviceList.push_back( _rtAudio->audioStream.getDeviceInfo( i ) );
115+ deviceNameList.push_back( _rtAudio->audioStream.getDeviceInfo( i ).name );
116 }
117
118+ AddParameter_( pDeviceList, DspParameter( DspParameter::List, deviceNameList ) );
119+ AddParameter_( pIsStreaming, DspParameter( DspParameter::Bool, false ) );
120+ AddParameter_( pBufferSize, DspParameter( DspParameter::Int, 256 ) );
121+ AddParameter_( pSampleRate, DspParameter( DspParameter::Int, 44100 ) );
122+
123 SetDevice( _rtAudio->audioStream.getDefaultOutputDevice() );
124-
125- SetBufferSize( _bufferSize );
126- SetSampleRate( _sampleRate );
127+ SetBufferSize( GetBufferSize() );
128+ SetSampleRate( GetSampleRate() );
129 }
130
131 //-------------------------------------------------------------------------------------------------
132@@ -99,12 +100,12 @@
133
134 bool DspAudioDevice::SetDevice( short deviceIndex )
135 {
136- if( deviceIndex >= 0 && deviceIndex < ( _deviceCount ) )
137+ if( deviceIndex >= 0 && deviceIndex < GetDeviceCount() )
138 {
139- _currentDevice = deviceIndex;
140-
141 _StopStream();
142
143+ SetParameter_( pDeviceList, DspParameter( DspParameter::Int, deviceIndex ) );
144+
145 _rtAudio->inputParams.nChannels = _rtAudio->deviceList[deviceIndex].inputChannels;
146 _rtAudio->inputParams.deviceId = deviceIndex;
147
148@@ -121,9 +122,9 @@
149
150 //-------------------------------------------------------------------------------------------------
151
152-std::string DspAudioDevice::GetDeviceName( short deviceIndex )
153+std::string DspAudioDevice::GetDeviceName( short deviceIndex ) const
154 {
155- if( deviceIndex >= 0 && deviceIndex < ( _deviceCount ) )
156+ if( deviceIndex >= 0 && deviceIndex < GetDeviceCount() )
157 {
158 return _rtAudio->deviceList[deviceIndex].name;
159 }
160@@ -133,50 +134,42 @@
161
162 //-------------------------------------------------------------------------------------------------
163
164-unsigned short DspAudioDevice::GetDeviceInputCount( short deviceIndex )
165+unsigned short DspAudioDevice::GetDeviceInputCount( short deviceIndex ) const
166 {
167 return _rtAudio->deviceList[deviceIndex].inputChannels;
168 }
169
170 //-------------------------------------------------------------------------------------------------
171
172-unsigned short DspAudioDevice::GetDeviceOutputCount( short deviceIndex )
173+unsigned short DspAudioDevice::GetDeviceOutputCount( short deviceIndex ) const
174 {
175 return _rtAudio->deviceList[deviceIndex].outputChannels;
176 }
177
178 //-------------------------------------------------------------------------------------------------
179
180-unsigned short DspAudioDevice::GetCurrentDevice()
181-{
182- return _currentDevice;
183-}
184-
185-//-------------------------------------------------------------------------------------------------
186-
187-unsigned short DspAudioDevice::GetDeviceCount()
188-{
189- return _deviceCount;
190-}
191-
192-//-------------------------------------------------------------------------------------------------
193-
194-bool DspAudioDevice::IsStreaming()
195-{
196- return !_streamStop;
197-}
198-
199-//-------------------------------------------------------------------------------------------------
200-
201-void DspAudioDevice::SetBufferSize( unsigned long bufferSize )
202+unsigned short DspAudioDevice::GetCurrentDevice() const
203+{
204+ return *GetParameter_( pDeviceList )->GetInt();
205+}
206+
207+//-------------------------------------------------------------------------------------------------
208+
209+unsigned short DspAudioDevice::GetDeviceCount() const
210+{
211+ return GetParameter_( pDeviceList )->GetList()->size();
212+}
213+
214+//-------------------------------------------------------------------------------------------------
215+
216+void DspAudioDevice::SetBufferSize( int bufferSize )
217 {
218 _StopStream();
219
220- _bufferSize = bufferSize;
221-
222+ SetParameter_( pBufferSize, DspParameter( DspParameter::Int, bufferSize ) );
223 for( unsigned short i = 0; i < _inputChannels.size(); i++ )
224 {
225- _inputChannels[i].resize( _bufferSize );
226+ _inputChannels[i].resize( bufferSize );
227 }
228
229 _StartStream();
230@@ -184,20 +177,32 @@
231
232 //-------------------------------------------------------------------------------------------------
233
234-void DspAudioDevice::SetSampleRate( unsigned long sampleRate )
235+void DspAudioDevice::SetSampleRate( int sampleRate )
236 {
237 _StopStream();
238-
239- _sampleRate = sampleRate;
240-
241+ SetParameter_( pSampleRate, DspParameter( DspParameter::Int, sampleRate ) );
242 _StartStream();
243 }
244
245 //-------------------------------------------------------------------------------------------------
246
247-unsigned long DspAudioDevice::GetSampleRate()
248-{
249- return _sampleRate;
250+bool DspAudioDevice::IsStreaming() const
251+{
252+ return *GetParameter_( pIsStreaming )->GetBool();
253+}
254+
255+//-------------------------------------------------------------------------------------------------
256+
257+int DspAudioDevice::GetBufferSize() const
258+{
259+ return *GetParameter_( pBufferSize )->GetInt();
260+}
261+
262+//-------------------------------------------------------------------------------------------------
263+
264+int DspAudioDevice::GetSampleRate() const
265+{
266+ return *GetParameter_( pSampleRate )->GetInt();
267 }
268
269 //=================================================================================================
270@@ -227,7 +232,7 @@
271 // =========================================================
272 if( inputs.GetValue( 0, _outputChannels[0] ) )
273 {
274- if( _bufferSize != _outputChannels[0].size() &&
275+ if( GetBufferSize() != _outputChannels[0].size() &&
276 _outputChannels[0].size() != 0 )
277 {
278 SetBufferSize( _outputChannels[0].size() );
279@@ -259,8 +264,37 @@
280 _buffersMutex.Unlock();
281 }
282
283+//-------------------------------------------------------------------------------------------------
284+
285+bool DspAudioDevice::ParameterUpdating_( std::string const& name, DspParameter const& param )
286+{
287+ if( name == pDeviceList )
288+ {
289+ return SetDevice( *param.GetInt() );
290+ }
291+ else if( name == pBufferSize )
292+ {
293+ SetBufferSize( *param.GetInt() );
294+ return true;
295+ }
296+ else if( name == pSampleRate )
297+ {
298+ SetSampleRate( *param.GetInt() );
299+ return true;
300+ }
301+
302+ return false;
303+}
304+
305 //=================================================================================================
306
307+void DspAudioDevice::_SetIsStreaming( bool isStreaming )
308+{
309+ SetParameter_( pIsStreaming, DspParameter( DspParameter::Bool, isStreaming ) );
310+}
311+
312+//-------------------------------------------------------------------------------------------------
313+
314 void DspAudioDevice::_WaitForBuffer()
315 {
316 _buffersMutex.Lock();
317@@ -284,7 +318,7 @@
318
319 void DspAudioDevice::_StopStream()
320 {
321- _streamStop = true;
322+ _SetIsStreaming( false );
323
324 _buffersMutex.Lock();
325 _gotWaitReady = true; // set release flag
326@@ -321,15 +355,15 @@
327 _rtAudio->audioStream.openStream( outputParams,
328 inputParams,
329 RTAUDIO_FLOAT32,
330- _sampleRate,
331- ( unsigned int* ) &_bufferSize,
332+ GetSampleRate(),
333+ ( unsigned int* ) GetParameter_( pBufferSize )->GetInt(),
334 &_StaticCallback,
335 this,
336 &options );
337
338 _rtAudio->audioStream.startStream();
339
340- _streamStop = false;
341+ _SetIsStreaming( true );
342 }
343
344 //-------------------------------------------------------------------------------------------------
345@@ -341,7 +375,7 @@
346 unsigned int status,
347 void* userData )
348 {
349- return ( ( DspAudioDevice* ) userData )->_DynamicCallback( inputBuffer, outputBuffer );
350+ return ( reinterpret_cast<DspAudioDevice*>( userData ) )->_DynamicCallback( inputBuffer, outputBuffer );
351 }
352
353 //-------------------------------------------------------------------------------------------------
354@@ -350,7 +384,7 @@
355 {
356 _WaitForBuffer();
357
358- if( !_streamStop )
359+ if( IsStreaming() )
360 {
361 float* floatOutput = ( float* ) outputBuffer;
362 float* floatInput = ( float* ) inputBuffer;
363@@ -359,7 +393,7 @@
364 {
365 for( unsigned long i = 0; i < _outputChannels.size(); i++ )
366 {
367- if( _rtAudio->deviceList[_currentDevice].outputChannels >= ( i + 1 ) )
368+ if( _rtAudio->deviceList[GetCurrentDevice()].outputChannels >= ( i + 1 ) )
369 {
370 for( unsigned long j = 0; j < _outputChannels[i].size(); j++ )
371 {
372@@ -373,7 +407,7 @@
373 {
374 for( unsigned long i = 0; i < _inputChannels.size(); i++ )
375 {
376- if( _rtAudio->deviceList[_currentDevice].inputChannels >= ( i + 1 ) )
377+ if( _rtAudio->deviceList[GetCurrentDevice()].inputChannels >= ( i + 1 ) )
378 {
379 for( unsigned long j = 0; j < _inputChannels[i].size(); j++ )
380 {
381
382=== modified file 'example/DspAudioDevice.h'
383--- example/DspAudioDevice.h 2014-04-12 23:16:46 +0000
384+++ example/DspAudioDevice.h 2014-06-16 15:43:30 +0000
385@@ -1,6 +1,6 @@
386 /************************************************************************
387 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
388-Copyright (c) 2012-2013 Marcus Tomlinson
389+Copyright (c) 2012-2014 Marcus Tomlinson
390
391 This file is part of DSPatch.
392
393@@ -34,25 +34,32 @@
394 class DspAudioDevice : public DspComponent
395 {
396 public:
397+ static std::string const pDeviceList; // List
398+ static std::string const pIsStreaming; // Bool
399+ static std::string const pBufferSize; // Int
400+ static std::string const pSampleRate; // Int
401+
402 DspAudioDevice();
403 ~DspAudioDevice();
404
405 bool SetDevice( short deviceIndex );
406
407- std::string GetDeviceName( short deviceIndex );
408- unsigned short GetDeviceInputCount( short deviceIndex );
409- unsigned short GetDeviceOutputCount( short deviceIndex );
410- unsigned short GetCurrentDevice();
411- unsigned short GetDeviceCount();
412-
413- bool IsStreaming();
414-
415- void SetBufferSize( unsigned long bufferSize );
416- void SetSampleRate( unsigned long sampleRate );
417- unsigned long GetSampleRate();
418+ std::string GetDeviceName( short deviceIndex ) const;
419+ unsigned short GetDeviceInputCount( short deviceIndex ) const;
420+ unsigned short GetDeviceOutputCount( short deviceIndex ) const;
421+ unsigned short GetCurrentDevice() const;
422+ unsigned short GetDeviceCount() const;
423+
424+ void SetBufferSize( int bufferSize );
425+ void SetSampleRate( int sampleRate );
426+
427+ bool IsStreaming() const;
428+ int GetBufferSize() const;
429+ int GetSampleRate() const;
430
431 protected:
432 virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs );
433+ virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param );
434
435 private:
436 std::vector< std::vector< float > > _outputChannels;
437@@ -60,11 +67,6 @@
438
439 RtAudioMembers* _rtAudio;
440
441- unsigned long _bufferSize;
442- unsigned long _sampleRate;
443-
444- unsigned short _deviceCount;
445-
446 DspMutex _buffersMutex;
447 DspMutex _syncMutex;
448 DspWaitCondition _waitCondt;
449@@ -72,9 +74,7 @@
450 bool _gotWaitReady;
451 bool _gotSyncReady;
452
453- bool _streamStop;
454-
455- unsigned short _currentDevice;
456+ void _SetIsStreaming( bool isStreaming );
457
458 void _WaitForBuffer();
459 void _SyncBuffer();
460
461=== modified file 'example/DspGain.h'
462--- example/DspGain.h 2014-01-19 09:07:19 +0000
463+++ example/DspGain.h 2014-06-16 15:43:30 +0000
464@@ -1,6 +1,6 @@
465 /************************************************************************
466 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
467-Copyright (c) 2012-2013 Marcus Tomlinson
468+Copyright (c) 2012-2014 Marcus Tomlinson
469
470 This file is part of DSPatch.
471
472@@ -32,29 +32,25 @@
473 class DspGain : public DspComponent
474 {
475 public:
476+ static std::string const pGain; // Float
477+
478 DspGain()
479- : _gain( 1.0 )
480 {
481 AddInput_();
482 AddOutput_();
483+
484+ AddParameter_( pGain, DspParameter( DspParameter::Float, 1, std::make_pair( 0, 2 ) ) );
485 }
486 ~DspGain() {}
487
488 void SetGain( float gain )
489 {
490- if( gain < 0.0 )
491- {
492- _gain = 0;
493- }
494- else
495- {
496- _gain = gain;
497- }
498+ SetParameter_( pGain, DspParameter( DspParameter::Float, gain ) );
499 }
500
501 float GetGain() const
502 {
503- return _gain;
504+ return *GetParameter_( pGain )->GetFloat();
505 }
506
507 protected:
508@@ -67,17 +63,28 @@
509
510 for( unsigned long i = 0; i < _stream.size(); i++ )
511 {
512- _stream[i] *= _gain;
513+ _stream[i] *= GetGain();
514 }
515
516 outputs.SetValue( 0, _stream );
517 }
518
519+ virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param )
520+ {
521+ if( name == pGain )
522+ {
523+ SetGain( *param.GetFloat() );
524+ return true;
525+ }
526+ return false;
527+ }
528+
529 private:
530 std::vector< float > _stream;
531- float _gain;
532 };
533
534+std::string const DspGain::pGain = "gain";
535+
536 //=================================================================================================
537
538 #endif // DSPGAIN_H
539
540=== modified file 'example/DspOscillator.cpp'
541--- example/DspOscillator.cpp 2014-04-12 23:16:46 +0000
542+++ example/DspOscillator.cpp 2014-06-16 15:43:30 +0000
543@@ -1,6 +1,6 @@
544 /************************************************************************
545 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
546-Copyright (c) 2012-2013 Marcus Tomlinson
547+Copyright (c) 2012-2014 Marcus Tomlinson
548
549 This file is part of DSPatch.
550
551@@ -26,25 +26,32 @@
552
553 #include <math.h>
554
555-static const float PI = 3.1415926535897932384626433832795f;
556+//=================================================================================================
557+
558 static const float TWOPI = 6.283185307179586476925286766559f;
559
560+std::string const DspOscillator::pBufferSize = "bufferSize";
561+std::string const DspOscillator::pSampleRate = "sampleRate";
562+std::string const DspOscillator::pAmplitude = "amplitude";
563+std::string const DspOscillator::pFrequency = "frequency";
564+
565 //=================================================================================================
566
567 DspOscillator::DspOscillator( float startFreq, float startAmpl )
568-: _freq( startFreq ),
569- _ampl( startAmpl ),
570- _lastPos( 0 ),
571- _lookupLength( 0 ),
572- _bufferSize( 256 ),
573- _sampleRate( 44100 )
574+: _lastPos( 0 ),
575+ _lookupLength( 0 )
576 {
577- _BuildLookup();
578-
579 AddInput_( "Sample Rate" );
580 AddInput_( "Buffer Size" );
581
582 AddOutput_();
583+
584+ AddParameter_( pBufferSize, DspParameter( DspParameter::Int, 256 ) );
585+ AddParameter_( pSampleRate, DspParameter( DspParameter::Int, 44100 ) );
586+ AddParameter_( pAmplitude, DspParameter( DspParameter::Float, startAmpl ) );
587+ AddParameter_( pFrequency, DspParameter( DspParameter::Float, startFreq ) );
588+
589+ _BuildLookup();
590 }
591
592 //-------------------------------------------------------------------------------------------------
593@@ -53,9 +60,9 @@
594
595 //=================================================================================================
596
597-void DspOscillator::SetBufferSize( unsigned long bufferSize )
598+void DspOscillator::SetBufferSize( int bufferSize )
599 {
600- _bufferSize = bufferSize;
601+ SetParameter_( pBufferSize, DspParameter( DspParameter::Int, bufferSize ) );
602
603 _processMutex.Lock();
604 _BuildLookup();
605@@ -64,9 +71,9 @@
606
607 //-------------------------------------------------------------------------------------------------
608
609-void DspOscillator::SetSampleRate( unsigned long sampleRate )
610+void DspOscillator::SetSampleRate( int sampleRate )
611 {
612- _sampleRate = sampleRate;
613+ SetParameter_( pSampleRate, DspParameter( DspParameter::Int, sampleRate ) );
614
615 _processMutex.Lock();
616 _BuildLookup();
617@@ -77,7 +84,7 @@
618
619 void DspOscillator::SetAmpl( float ampl )
620 {
621- _ampl = ampl;
622+ SetParameter_( pAmplitude, DspParameter( DspParameter::Float, ampl ) );
623
624 _processMutex.Lock();
625 _BuildLookup();
626@@ -88,13 +95,41 @@
627
628 void DspOscillator::SetFreq( float freq )
629 {
630- _freq = freq;
631+ SetParameter_( pFrequency, DspParameter( DspParameter::Float, freq ) );
632
633 _processMutex.Lock();
634 _BuildLookup();
635 _processMutex.Unlock();
636 }
637
638+//-------------------------------------------------------------------------------------------------
639+
640+int DspOscillator::GetBufferSize() const
641+{
642+ return *GetParameter_( pBufferSize )->GetInt();
643+}
644+
645+//-------------------------------------------------------------------------------------------------
646+
647+int DspOscillator::GetSampleRate() const
648+{
649+ return *GetParameter_( pSampleRate )->GetInt();
650+}
651+
652+//-------------------------------------------------------------------------------------------------
653+
654+float DspOscillator::GetAmpl() const
655+{
656+ return *GetParameter_( pAmplitude )->GetFloat();
657+}
658+
659+//-------------------------------------------------------------------------------------------------
660+
661+float DspOscillator::GetFreq() const
662+{
663+ return *GetParameter_( pFrequency )->GetFloat();
664+}
665+
666 //=================================================================================================
667
668 void DspOscillator::Process_( DspSignalBus& inputs, DspSignalBus& outputs )
669@@ -104,10 +139,9 @@
670 unsigned long sampleRate;
671 if( inputs.GetValue( "Sample Rate", sampleRate ) )
672 {
673- if( sampleRate != _sampleRate )
674+ if( sampleRate != GetSampleRate() )
675 {
676- _sampleRate = sampleRate;
677- _BuildLookup();
678+ SetSampleRate( sampleRate );
679 }
680 }
681
682@@ -115,10 +149,9 @@
683 // =========================================================
684 if( inputs.GetValue( "Buffer Size", _signal ) )
685 {
686- if( _bufferSize != _signal.size() )
687+ if( GetBufferSize() != _signal.size() )
688 {
689- _bufferSize = _signal.size();
690- _BuildLookup();
691+ SetBufferSize( _signal.size() );
692 }
693 }
694
695@@ -139,21 +172,49 @@
696 _processMutex.Unlock();
697 }
698
699+//-------------------------------------------------------------------------------------------------
700+
701+bool DspOscillator::ParameterUpdating_( std::string const& name, DspParameter const& param )
702+{
703+ if( name == pBufferSize )
704+ {
705+ SetBufferSize( *param.GetInt() );
706+ return true;
707+ }
708+ else if( name == pSampleRate )
709+ {
710+ SetSampleRate( *param.GetInt() );
711+ return true;
712+ }
713+ else if( name == pAmplitude )
714+ {
715+ SetAmpl( *param.GetFloat() );
716+ return true;
717+ }
718+ else if( name == pFrequency )
719+ {
720+ SetFreq( *param.GetFloat() );
721+ return true;
722+ }
723+
724+ return false;
725+}
726+
727 //=================================================================================================
728
729 void DspOscillator::_BuildLookup()
730 {
731 float posFrac = ( float ) _lastPos / ( float ) _lookupLength;
732- float angleInc = TWOPI * _freq / _sampleRate;
733-
734- _lookupLength = ( unsigned long ) ( ( float ) _sampleRate / _freq );
735-
736- _signal.resize( _bufferSize );
737+ float angleInc = TWOPI * GetFreq() / GetSampleRate();
738+
739+ _lookupLength = ( unsigned long ) ( ( float ) GetSampleRate() / GetFreq() );
740+
741+ _signal.resize( GetBufferSize() );
742 _signalLookup.resize( _lookupLength );
743
744 for( unsigned long i = 0; i < _lookupLength; i++ )
745 {
746- _signalLookup[i] = sin( angleInc * i ) * _ampl;
747+ _signalLookup[i] = sin( angleInc * i ) * GetAmpl();
748 }
749
750 _lastPos = ( unsigned long ) ( posFrac * ( float ) _lookupLength + 0.5f ); //calculate new position (round up)
751
752=== modified file 'example/DspOscillator.h'
753--- example/DspOscillator.h 2014-01-19 09:07:19 +0000
754+++ example/DspOscillator.h 2014-06-16 15:43:30 +0000
755@@ -1,6 +1,6 @@
756 /************************************************************************
757 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
758-Copyright (c) 2012-2013 Marcus Tomlinson
759+Copyright (c) 2012-2014 Marcus Tomlinson
760
761 This file is part of DSPatch.
762
763@@ -32,49 +32,34 @@
764 class DspOscillator : public DspComponent
765 {
766 public:
767+ static std::string const pBufferSize; // Int
768+ static std::string const pSampleRate; // Int
769+ static std::string const pAmplitude; // Float
770+ static std::string const pFrequency; // Float
771+
772 DspOscillator( float startFreq = 1000.0, float startAmpl = 1.0 );
773 ~DspOscillator();
774
775- void SetBufferSize( unsigned long bufferSize );
776- void SetSampleRate( unsigned long sampleRate );
777-
778+ void SetBufferSize( int bufferSize );
779+ void SetSampleRate( int sampleRate );
780 void SetAmpl( float ampl );
781 void SetFreq( float freq );
782
783- unsigned long GetBufferSize() const
784- {
785- return _bufferSize;
786- }
787-
788- unsigned long GetSampleRate() const
789- {
790- return _sampleRate;
791- }
792-
793- float GetAmpl() const
794- {
795- return _ampl;
796- }
797-
798- float GetFreq() const
799- {
800- return _freq;
801- }
802+ int GetBufferSize() const;
803+ int GetSampleRate() const;
804+ float GetAmpl() const;
805+ float GetFreq() const;
806
807 protected:
808 virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs );
809+ virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param );
810
811 private:
812- float _freq;
813- float _ampl;
814-
815 std::vector< float > _signalLookup;
816 std::vector< float > _signal;
817
818 unsigned long _lastPos;
819 unsigned long _lookupLength;
820- unsigned long _bufferSize;
821- unsigned long _sampleRate;
822
823 DspMutex _processMutex;
824
825
826=== modified file 'example/DspWaveStreamer.cpp'
827--- example/DspWaveStreamer.cpp 2014-04-12 23:16:46 +0000
828+++ example/DspWaveStreamer.cpp 2014-06-16 15:43:30 +0000
829@@ -1,6 +1,6 @@
830 /************************************************************************
831 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
832-Copyright (c) 2012-2013 Marcus Tomlinson
833+Copyright (c) 2012-2014 Marcus Tomlinson
834
835 This file is part of DSPatch.
836
837@@ -30,19 +30,34 @@
838
839 //=================================================================================================
840
841+std::string const DspWaveStreamer::pFilePath = "filePath";
842+std::string const DspWaveStreamer::pPlay = "play";
843+std::string const DspWaveStreamer::pPause = "pause";
844+std::string const DspWaveStreamer::pStop = "stop";
845+std::string const DspWaveStreamer::pIsPlaying = "isPlaying";
846+
847+//=================================================================================================
848+
849 DspWaveStreamer::DspWaveStreamer()
850 : _waveData( 0 ),
851- _isPlaying( false ),
852 _bufferSize( 256 ),
853 _sampleIndex( 0 ),
854 _shortToFloatCoeff( 1.0f / 32767.0f )
855 {
856+ _waveFormat.Clear();
857+
858 _leftChannel.resize( _bufferSize );
859 _rightChannel.resize( _bufferSize );
860
861 AddOutput_();
862 AddOutput_();
863 AddOutput_( "Sample Rate" );
864+
865+ AddParameter_( pFilePath, DspParameter( DspParameter::FilePath, "" ) );
866+ AddParameter_( pPlay, DspParameter( DspParameter::Trigger ) );
867+ AddParameter_( pPause, DspParameter( DspParameter::Trigger ) );
868+ AddParameter_( pStop, DspParameter( DspParameter::Trigger ) );
869+ AddParameter_( pIsPlaying, DspParameter( DspParameter::Bool, false ) );
870 }
871
872 //-------------------------------------------------------------------------------------------------
873@@ -51,9 +66,9 @@
874
875 //=================================================================================================
876
877-bool DspWaveStreamer::LoadFile( const char* filePath )
878+bool DspWaveStreamer::LoadFile( char const* filePath )
879 {
880- bool wasPlaying = _isPlaying;
881+ bool wasPlaying = IsPlaying();
882 Stop();
883
884 if( filePath == NULL )
885@@ -64,8 +79,8 @@
886 return false;
887
888 unsigned long dwFileSize = 0, dwChunkSize = 0;
889- char* dwChunkId = new char[5];
890- char* dwExtra = new char[5];
891+ char dwChunkId[5];
892+ char dwExtra[5];
893
894 dwChunkId[4] = 0;
895 dwExtra[4] = 0;
896@@ -163,6 +178,7 @@
897 Play();
898 }
899
900+ SetParameter_( pFilePath, DspParameter( DspParameter::FilePath, filePath ) );
901 return true;
902 }
903
904@@ -170,14 +186,14 @@
905
906 void DspWaveStreamer::Play()
907 {
908- _isPlaying = true;
909+ SetParameter_( pIsPlaying, DspParameter( DspParameter::Bool, true ) );
910 }
911
912 //-------------------------------------------------------------------------------------------------
913
914 void DspWaveStreamer::Pause()
915 {
916- _isPlaying = false;
917+ SetParameter_( pIsPlaying, DspParameter( DspParameter::Bool, false ) );
918 }
919
920 //-------------------------------------------------------------------------------------------------
921@@ -187,23 +203,23 @@
922 _busyMutex.Lock();
923
924 _sampleIndex = 0;
925- _isPlaying = false;
926+ SetParameter_( pIsPlaying, DspParameter( DspParameter::Bool, false ) );
927
928 _busyMutex.Unlock();
929 }
930
931 //-------------------------------------------------------------------------------------------------
932
933-bool DspWaveStreamer::IsPlaying()
934+bool DspWaveStreamer::IsPlaying() const
935 {
936- return _isPlaying;
937+ return *GetParameter_( pIsPlaying )->GetBool();
938 }
939
940 //=================================================================================================
941
942 void DspWaveStreamer::Process_( DspSignalBus& inputs, DspSignalBus& outputs )
943 {
944- if( _isPlaying && _waveData.size() > 0 )
945+ if( IsPlaying() && _waveData.size() > 0 )
946 {
947 _busyMutex.Lock();
948
949@@ -235,4 +251,31 @@
950 }
951 }
952
953+//-------------------------------------------------------------------------------------------------
954+
955+bool DspWaveStreamer::ParameterUpdating_( std::string const& name, DspParameter const& param )
956+{
957+ if( name == pFilePath )
958+ {
959+ return LoadFile( param.GetString()->c_str() );
960+ }
961+ else if( name == pPlay )
962+ {
963+ Play();
964+ return true;
965+ }
966+ else if( name == pPause )
967+ {
968+ Pause();
969+ return true;
970+ }
971+ else if( name == pStop )
972+ {
973+ Stop();
974+ return true;
975+ }
976+
977+ return false;
978+}
979+
980 //=================================================================================================
981
982=== modified file 'example/DspWaveStreamer.h'
983--- example/DspWaveStreamer.h 2014-01-19 09:07:19 +0000
984+++ example/DspWaveStreamer.h 2014-06-16 15:43:30 +0000
985@@ -1,6 +1,6 @@
986 /************************************************************************
987 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
988-Copyright (c) 2012-2013 Marcus Tomlinson
989+Copyright (c) 2012-2014 Marcus Tomlinson
990
991 This file is part of DSPatch.
992
993@@ -32,18 +32,25 @@
994 class DspWaveStreamer : public DspComponent
995 {
996 public:
997+ static std::string const pFilePath; // FilePath
998+ static std::string const pPlay; // Trigger
999+ static std::string const pPause; // Trigger
1000+ static std::string const pStop; // Trigger
1001+ static std::string const pIsPlaying; // Bool
1002+
1003 DspWaveStreamer();
1004 ~DspWaveStreamer();
1005
1006- bool LoadFile( const char* filePath );
1007+ bool LoadFile( char const* filePath );
1008 void Play();
1009 void Pause();
1010 void Stop();
1011
1012- bool IsPlaying();
1013+ bool IsPlaying() const;
1014
1015 protected:
1016 virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs );
1017+ virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param );
1018
1019 private:
1020 struct WaveFormat
1021@@ -70,7 +77,6 @@
1022
1023 WaveFormat _waveFormat;
1024 std::vector< short > _waveData;
1025- bool _isPlaying;
1026 unsigned long _bufferSize;
1027 unsigned long _sampleIndex;
1028 float _shortToFloatCoeff;
1029
1030=== modified file 'example/main.cpp'
1031--- example/main.cpp 2014-01-19 09:07:19 +0000
1032+++ example/main.cpp 2014-06-16 15:43:30 +0000
1033@@ -1,6 +1,6 @@
1034 /************************************************************************
1035 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
1036-Copyright (c) 2012-2013 Marcus Tomlinson
1037+Copyright (c) 2012-2014 Marcus Tomlinson
1038
1039 This file is part of DSPatch.
1040
1041@@ -38,10 +38,10 @@
1042
1043 int main()
1044 {
1045- // 1. Stream Wave
1046+ // 1. Stream wave
1047 // ==============
1048
1049- // create a circuit
1050+ // create a circuit
1051 DspCircuit circuit;
1052
1053 // declare components to be added to the circuit
1054@@ -53,7 +53,7 @@
1055 // set circuit thread count to 2
1056 circuit.SetThreadCount( 2 );
1057
1058- //// start separate thread to tick the circuit continuously ("auto-tick")
1059+ // start separate thread to tick the circuit continuously ("auto-tick")
1060 circuit.StartAutoTick();
1061
1062 // add new components to the circuit (these methods return pointers to the new components)
1063@@ -63,7 +63,7 @@
1064 circuit.AddComponent( gainRight );
1065
1066 // DspWaveStreamer has an output signal named "Sample Rate" that streams the current wave's sample rate
1067- // DspAudioDevice's "Sample Rate" input receives a sample rate value and updates the audio stream accordingly
1068+ // DspAudioDevice's "Sample Rate" input receives a sample rate value and updates the audio stream accordingly
1069 circuit.ConnectOutToIn( waveStreamer, "Sample Rate", audioDevice, "Sample Rate" ); // sample rate sync
1070
1071 // connect component output signals to respective component input signals
1072@@ -74,17 +74,20 @@
1073
1074 // set the gain of components gainLeft and gainRight (wave left and right channels)
1075 gainLeft.SetGain( 0.75 );
1076- gainRight.SetGain( 0.75 );
1077+ gainRight.SetParameter( DspGain::pGain, DspParameter( DspParameter::Float, 0.75f ) ); // OR: gainRight.SetGain( 0.75 );
1078
1079 // load a wave into the wave streamer and start playing the track
1080- waveStreamer.LoadFile(EXAMPLE_WAV_FILE);
1081- waveStreamer.Play();
1082+ waveStreamer.SetParameter( DspWaveStreamer::pFilePath, DspParameter( DspParameter::FilePath, EXAMPLE_WAV_FILE ) );
1083+ waveStreamer.SetParameter( DspWaveStreamer::pPlay, DspParameter( DspParameter::Trigger ) );
1084
1085 // wait for key press
1086 getchar();
1087
1088- // 2. Overlay oscillator
1089- // =====================
1090+ // 2. Stream oscillator
1091+ // ====================
1092+
1093+ // pause the track
1094+ waveStreamer.Pause();
1095
1096 // A component input pin can only receive one signal at a time so an adders are required to combine the signals
1097
1098@@ -114,6 +117,15 @@
1099 // wait for key press
1100 getchar();
1101
1102+ // 3. Overlay both streams
1103+ // =======================
1104+
1105+ // resume the track (via parameter)
1106+ waveStreamer.Play();
1107+
1108+ // wait for key press
1109+ getchar();
1110+
1111 // clean up DSPatch
1112 DSPatch::Finalize();
1113
1114
1115=== modified file 'include/DSPatch.h'
1116--- include/DSPatch.h 2014-01-25 09:05:16 +0000
1117+++ include/DSPatch.h 2014-06-16 15:43:30 +0000
1118@@ -1,6 +1,6 @@
1119 /************************************************************************
1120 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
1121-Copyright (c) 2012-2013 Marcus Tomlinson
1122+Copyright (c) 2012-2014 Marcus Tomlinson
1123
1124 This file is part of DSPatch.
1125
1126@@ -49,17 +49,17 @@
1127
1128 class DLLEXPORT DSPatch
1129 {
1130- friend class DspComponent;
1131-
1132 public:
1133 static void SetGlobalThreadCount( unsigned short threadCount );
1134 static void Finalize();
1135
1136 private:
1137- static bool _IsThisGlobalCircuit( DspComponent* thisComponent );
1138+ friend class DspComponent;
1139+
1140+ static bool _IsThisGlobalCircuit( DspComponent const* thisComponent );
1141
1142 static bool _AddGlobalComponent( DspComponent* component );
1143- static void _RemoveGlobalComponent( DspComponent* component );
1144+ static void _RemoveGlobalComponent( DspComponent const* component );
1145
1146 static unsigned short _GetGlobalComponentCount();
1147
1148@@ -81,113 +81,114 @@
1149 \mainpage Welcome!
1150
1151 \section intro_sec Introduction
1152- DSPatch, pronounced "dispatch", is a powerful C++ flow-based programming library that allows
1153- you to create and route (or "patch") high performance data processing circuits. DSPatch is not
1154- limited to any particular type of circuit or signal, its generic object-oriented API allows you
1155- to create almost any system imaginable, from simple logic circuits to high performance audio
1156- process chains and electronics simulation. DSPatch's simple framework makes development quick
1157- and easy, allowing you to hit the ground running on every project.
1158-
1159- DSPatch is designed around the concept of a "circuit" containing "components", interconnected
1160- via "wires" that transfer "signals" to and from input and output "buses". For more detail on
1161- how DSPatch works, check out the <a href="spec_page.html"><b>DSPatch Design Specification</b></a>.
1162-
1163- The two most important classes to consider are DspComponent and DspCircuit. In order to route
1164- data to and from DspComponents they can either be added to an DspCircuit, where they can be
1165- wired together (recommended), or they can be wired directly via public DspComponent methods.
1166- The DSPatch engine takes care of data transfer between interconnected components, when data is
1167- ready for a component to process, a callback: "Process_()" is executed in that component. For a
1168- component to form part of the DSPatch framework, designers simply have to derive their
1169- component from the DspComponent base class, configure the component's IO buses, and implement
1170- the virtual Process_() callback method.
1171+ DSPatch, pronounced "dispatch", is a powerful C++ flow-based programming library that allows
1172+ you to create and route (or "patch") high performance data processing circuits. DSPatch is not
1173+ limited to any particular type of circuit or signal, its generic object-oriented API allows you
1174+ to create almost any system imaginable, from simple logic circuits to high performance audio
1175+ process chains and electronics simulation. DSPatch's simple framework makes development quick
1176+ and easy, allowing you to hit the ground running on every project.
1177+
1178+ DSPatch is designed around the concept of a "circuit" containing "components", interconnected
1179+ via "wires" that transfer "signals" to and from input and output "buses". For more detail on
1180+ how DSPatch works, check out the <a href="spec_page.html"><b>DSPatch Design Specification</b></a>.
1181+
1182+ The two most important classes to consider are DspComponent and DspCircuit. In order to route
1183+ data to and from DspComponents they can either be added to an DspCircuit, where they can be
1184+ wired together (recommended), or they can be wired directly via public DspComponent methods.
1185+
1186+ The DSPatch engine takes care of data transfer between interconnected components, when data is
1187+ ready for a component to process, a callback: "Process_()" is executed in that component. For a
1188+ component to form part of the DSPatch framework, designers simply have to derive their
1189+ component from the DspComponent base class, configure the component's IO buses, and implement
1190+ the virtual Process_() callback method.
1191
1192 \n
1193
1194 \section features_sec Features
1195- - <b>Automatic branch synchronization</b> - The result of data diverging across parallel branches is guaranteed to arrive synchronized at a converging point.
1196- - <b>Dynamic thread count adjustment</b> - Specify at run-time, the number of threads in which you require a circuit to process.
1197- - <b>Easy-to-use object-oriented API</b> - DSPatch is modeled around real-world circuit entities and concepts, making code more readable and easy to understand.
1198- - <b>Feedback loops</b> - Create true closed-circuit systems by feeding resultant signals back into previous component inputs.
1199- - <b>High performance parallel processing</b> - Circuits use advanced multi-threaded scheduling to maximize data flow efficiency.
1200- - <b>Integrated circuits</b> - Build circuits within circuits to encapsulate complex component networks into single circuit components.
1201- - <b>Non-threaded platform support</b> - Develop for (or port to) platforms without multi-threading support and process complex circuit systems in a single thread.
1202- - <b>Run-time circuit wiring</b> - Connect and disconnect wires on the fly whilst maintaining steady data flow through the system.
1203- - <b>Run-time adaptive signal types</b> - Component inputs can accept values of run-time varying types allowing you to create more flexible, multi-purpose component processes.
1204+ - <b>Automatic branch synchronization</b> - The result of data diverging across parallel branches is guaranteed to arrive synchronized at a converging point.
1205+ - <b>Dynamic thread count adjustment</b> - Specify at run-time, the number of threads in which you require a circuit to process.
1206+ - <b>Easy-to-use object-oriented API</b> - DSPatch is modeled around real-world circuit entities and concepts, making code more readable and easy to understand.
1207+ - <b>Feedback loops</b> - Create true closed-circuit systems by feeding resultant signals back into previous component inputs.
1208+ - <b>High performance parallel processing</b> - Circuits use advanced multi-threaded scheduling to maximize data flow efficiency.
1209+ - <b>Integrated circuits</b> - Build circuits within circuits to encapsulate complex component networks into single circuit components.
1210+ - <b>Non-threaded platform support</b> - Develop for (or port to) platforms without multi-threading support and process complex circuit systems in a single thread.
1211+ - <b>Run-time circuit wiring</b> - Connect and disconnect wires on the fly whilst maintaining steady data flow through the system.
1212+ - <b>Run-time adaptive signal types</b> - Component inputs can accept values of run-time varying types allowing you to create more flexible, multi-purpose component processes.
1213
1214 \n
1215
1216 \section install_sec Getting Started
1217
1218 \subsection step1 Step 1: Download DSPatch
1219- The DSPatch library can be downloaded from the
1220- <a href="https://sourceforge.net/projects/dspatch/"><b>SourceForge project page</b></a>.
1221- Download the project archive and extract the contents anywhere you like.
1222+ The DSPatch library can be downloaded from the
1223+ <a href="https://sourceforge.net/projects/dspatch/"><b>SourceForge project page</b></a>.
1224+ Download the project archive and extract the contents anywhere you like.
1225
1226 \subsection step2 Step 2: Read the Tutorials
1227- The "Tutorials" section below covers 2 vital aspects to developing with DSPatch:
1228- 1. Creating a DspComponent - This tutorial is a start to finish demonstration of how to
1229- create a DSPatch component.
1230- 2. Building a DspCircuit - In this tutorial you will learn how to use the DSPatch framework
1231- to interconnect and process DspComponent networks using the DspCircuit interface.
1232+ The "Tutorials" section below covers 2 vital aspects to developing with DSPatch:
1233+ 1. Creating a DspComponent - This tutorial is a start to finish demonstration of how to
1234+ create a DSPatch component.
1235+ 2. Building a DspCircuit - In this tutorial you will learn how to use the DSPatch framework
1236+ to interconnect and process DspComponent networks using the DspCircuit interface.
1237
1238 \subsection step3 Step 3: Check out the example project
1239- In the "example" folder (in the DSPatch root directory) you will find a DSPatch demo project,
1240- written to assist developers in understanding the DSPatch API as well as to demonstrate how it
1241- could be used to build audio process chains. This project uses the open-source library RtAudio
1242- in order to stream sound to your computer's audio device -Linux users will need to install
1243- "libasound2-dev" (ALSA) before attempting to build.
1244-
1245+ In the "example" folder (in the DSPatch root directory) you will find a DSPatch demo project,
1246+ written to assist developers in understanding the DSPatch API as well as to demonstrate how it
1247+ could be used to build audio process chains. This project uses the open-source library RtAudio
1248+ in order to stream sound to your computer's audio device -Linux users will need to install
1249+ "libasound2-dev" (ALSA) before attempting to build.
1250+
1251 \subsection step4 Step 4: Make your own DspComponents
1252- A fast way to create your own DspComponent could be to copy an existing component to another
1253- destination, rename it, and edit the contents to satisfy your component's required behavior.
1254- In the "example" folder (from Step 3) you will find 2 source files: "DspAdder.h" and
1255- "DspAdder.cpp". These files make up a very simple DspComponent that receives 2 floating-point
1256- buffers into it's 2 inputs, adds each buffer element of the 1st buffer to the corresponding
1257- element of the 2nd buffer, then passes the resultant buffer to the output. Alternatively, you
1258- could just copy / reference the source code from the "Creating a DspComponent" tutorial
1259- (found under the "tutorial" folder in the root directory).
1260+ A fast way to create your own DspComponent could be to copy an existing component to another
1261+ destination, rename it, and edit the contents to satisfy your component's required behavior.
1262+ In the "example" folder (from Step 3) you will find 2 source files: "DspAdder.h" and
1263+ "DspAdder.cpp". These files make up a very simple DspComponent that receives 2 floating-point
1264+ buffers into it's 2 inputs, adds each buffer element of the 1st buffer to the corresponding
1265+ element of the 2nd buffer, then passes the resultant buffer to the output. Alternatively, you
1266+ could just copy / reference the source code from the "Creating a DspComponent" tutorial
1267+ (found under the "tutorial" folder in the root directory).
1268
1269 \subsection step5 Step 5: Roll your own DSPatch projects
1270- As DSPatch is not reliant on any non-standard 3rd party sources, getting a DSPatch project to
1271- compile and run is relatively painless. All you need to do from your project is #include
1272- "DSPatch.h" from the "include" folder (in the DSPatch root directory), and link to the
1273- DSPatch library (either by including all DSPatch source or by linking to a compiled library
1274- file). To speed things up you may want to copy, rename, and edit the example project from
1275- step 3 to get up and running faster.
1276+ As DSPatch is not reliant on any non-standard 3rd party sources, getting a DSPatch project to
1277+ compile and run is relatively painless. All you need to do from your project is include
1278+ "DSPatch.h" from the "include" folder (in the DSPatch root directory), and link to the
1279+ DSPatch library (either by including all DSPatch source or by linking to a compiled library
1280+ file). To speed things up you may want to copy, rename, and edit the example project from
1281+ step 3 to get up and running faster.
1282
1283 \subsection step6 Step 6: Refer to the documentation
1284- Between the example project, the DspAdder component template, and the documentation found
1285- here, you should have enough resources to get started with DSPatch straight away. If you have
1286- any questions or wish to report a bug, feel free to email me at marcus@adaptaudio.com.
1287+ Between the example project, the DspAdder component template, and the documentation found
1288+ here, you should have enough resources to get started with DSPatch straight away. If you have
1289+ any questions or wish to report a bug, feel free to email me at marcus@adaptaudio.com.
1290
1291 \n
1292
1293 \section tutorial_sec Tutorials
1294
1295 \subsection create_component 1. Creating a DspComponent
1296- In order to create a new DspComponent, we must derive our component class from the
1297- DspComponent base class, configure component IO, and implement the inherited virtual
1298- "Process_()" method.
1299-
1300- Lets take a look at how we would go about creating a boolean logic "AND" component. This
1301- component will accept 2 boolean input values and output the result of: input 1 && input 2.
1302-
1303- We begin by deriving our new "DspAnd" component from DspComponent:
1304-
1305- \code
1306+ In order to create a new DspComponent, we must derive our component class from the
1307+ DspComponent base class, configure component IO, and implement the inherited virtual
1308+ "Process_()" method.
1309+
1310+ Lets take a look at how we would go about creating a boolean logic "AND" component. This
1311+ component will accept 2 boolean input values and output the result of: input 1 && input 2.
1312+
1313+ We begin by deriving our new "DspAnd" component from DspComponent:
1314+
1315+ \code
1316 // 1. Derive component class from DspComponent
1317 // ===========================================
1318 class DspAnd : public DspComponent
1319 {
1320- \endcode
1321-
1322- The next step is to configure our component's input and output buses. This is achieved by
1323- calling the base protected methods AddInput_() and AddOutput_() respectively from our
1324- component's constructor. Each method must be called once per input / output required. In our
1325- component's case, we require 2 inputs and 1 output, therefore our constructor code will look
1326- like this:
1327-
1328- \code
1329+ \endcode
1330+
1331+ The next step is to configure our component's input and output buses. This is achieved by
1332+ calling the base protected methods AddInput_() and AddOutput_() respectively from our
1333+ component's constructor. Each method must be called once per input / output required. In our
1334+ component's case, we require 2 inputs and 1 output, therefore our constructor code will look
1335+ like this:
1336+
1337+ \code
1338 public:
1339 // 2. Configure component IO buses
1340 // ===============================
1341@@ -200,20 +201,20 @@
1342 // add 1 output
1343 AddOutput_( "output" );
1344 }
1345- \endcode
1346-
1347- The string values passed into the AddInput_() and AddOutput_() method calls are signal names
1348- / IDs. As component IO can be referenced by either string ID or index, IO signal names are
1349- optional. If we do not require a signal to have a string ID associated with it, we can simply
1350- leave the parenthesis empty.
1351-
1352- Lastly, our component must implement the DspComponent virtual Process_() method. This is
1353- where our component does it's work. The Process_() method provides us with 2 parameters: the
1354- input bus and the output bus. It is our duty as the component designer to pull the inputs we
1355- require out of the input bus, process them accordingly, and populate the output bus with the
1356- results. Our component's process method will look something like this:
1357-
1358- \code
1359+ \endcode
1360+
1361+ The string values passed into the AddInput_() and AddOutput_() method calls are signal names
1362+ / IDs. As component IO can be referenced by either string ID or index, IO signal names are
1363+ optional. If we do not require a signal to have a string ID associated with it, we can simply
1364+ leave the parenthesis empty.
1365+
1366+ Lastly, our component must implement the DspComponent virtual Process_() method. This is
1367+ where our component does it's work. The Process_() method provides us with 2 arguments: the
1368+ input bus and the output bus. It is our duty as the component designer to pull the inputs we
1369+ require out of the input bus, process them accordingly, and populate the output bus with the
1370+ results. Our component's process method will look something like this:
1371+
1372+ \code
1373 protected:
1374 // 3. Implement virtual Process_() method
1375 // ======================================
1376@@ -232,35 +233,35 @@
1377 }
1378 }
1379 };
1380- \endcode
1381+ \endcode
1382
1383- And that's it! Our component is now ready to form part of the DSPatch framework. Next we'll
1384- look at how we can add our component to a DspCircuit and route it to and from other
1385- DspComponents.
1386+ And that's it! Our component is now ready to form part of the DSPatch framework. Next we'll
1387+ look at how we can add our component to a DspCircuit and route it to and from other
1388+ DspComponents.
1389
1390 \n
1391
1392 \subsection use_component 2. Building a DspCircuit
1393- In order for us to get any real use out of our DspComponents, we need them to interact with
1394- each other. This is where the DspCircuit class comes in. A DspCircuit is a workspace for
1395- adding and routing DspComponents. In this section we will have a look at how to create a
1396- simple DSPatch application that generates random boolean pairs, performs a logic AND on each
1397- pair, then prints the result to screen.
1398-
1399- First we must include the DSPatch header and any other headers that contain DspComponents we
1400- wish to use in our application:
1401-
1402- \code
1403+ In order for us to get any real use out of our DspComponents, we need them to interact with
1404+ each other. This is where the DspCircuit class comes in. A DspCircuit is a workspace for
1405+ adding and routing DspComponents. In this section we will have a look at how to create a
1406+ simple DSPatch application that generates random boolean pairs, performs a logic AND on each
1407+ pair, then prints the result to screen.
1408+
1409+ First we must include the DSPatch header and any other headers that contain DspComponents we
1410+ wish to use in our application:
1411+
1412+ \code
1413 #include <DSPatch.h>
1414 #include <components.h>
1415- \endcode
1416-
1417- Next, we must instantiate our DspCircuit object and all DspComponent objects needed for our
1418- circuit. Lets say we had 2 other components included with "DspAnd" (from the first tutorial):
1419- "DspRandBool" (generates a random boolean value then outputs the result) and "DspPrintBool"
1420- (receives a boolean value and outputs it to the console):
1421-
1422- \code
1423+ \endcode
1424+
1425+ Next, we must instantiate our DspCircuit object and all DspComponent objects needed for our
1426+ circuit. Lets say we had 2 other components included with "DspAnd" (from the first tutorial):
1427+ "DspRandBool" (generates a random boolean value then outputs the result) and "DspPrintBool"
1428+ (receives a boolean value and outputs it to the console):
1429+
1430+ \code
1431 void main()
1432 {
1433 // 1. Create a DspCircuit where we can route our components
1434@@ -273,29 +274,29 @@
1435 DspRandBool randBoolGen2;
1436 DspAnd logicAnd;
1437 DspPrintBool boolPrinter;
1438- \endcode
1439-
1440- Now that we have a circuit and some components, lets add all of our components to the circuit:
1441-
1442- \code
1443+ \endcode
1444+
1445+ Now that we have a circuit and some components, lets add all of our components to the circuit:
1446+
1447+ \code
1448 // 3. Add component instances to circuit
1449 // =====================================
1450 circuit.AddComponent( randBoolGen1, "Bool Generator 1" );
1451 circuit.AddComponent( randBoolGen2, "Bool Generator 2" );
1452 circuit.AddComponent( logicAnd, "Logic AND" );
1453 circuit.AddComponent( boolPrinter, "Bool Printer" );
1454- \endcode
1455-
1456- The string values passed into the AddComponent() method calls are component names / IDs.
1457- Although we still have the option of referencing a component via it's pointer in a circuit,
1458- component string IDs can allow circuit objects to be entirely self-contained. This could give
1459- us the ability to pass circuits around by reference, allowing the receiver access to all
1460- circuit components via their string IDs, without having to manage both component and circuit
1461- references everywhere.
1462-
1463- We are now ready to begin wiring the circuit:
1464-
1465- \code
1466+ \endcode
1467+
1468+ The string values passed into the AddComponent() method calls are component names / IDs.
1469+ Although we still have the option of referencing a component via it's pointer in a circuit,
1470+ component string IDs can allow circuit objects to be entirely self-contained. This could give
1471+ us the ability to pass circuits around by reference, allowing the receiver access to all
1472+ circuit components via their string IDs, without having to manage both component and circuit
1473+ references everywhere.
1474+
1475+ We are now ready to begin wiring the circuit:
1476+
1477+ \code
1478 // 4. Wire up the components inside the circuit
1479 // ============================================
1480
1481@@ -310,28 +311,28 @@
1482 circuit.ConnectOutToIn( logicAnd, 0, boolPrinter, 0 );
1483 //OR circuit.ConnectOutToIn( "Logic AND", 0, "Bool Printer", 0 );
1484 //OR circuit.ConnectOutToIn( "Logic AND", "output", "Bool Printer", 0 );
1485- \endcode
1486+ \endcode
1487
1488- The code above results in the following wiring configuration:
1489- \code
1490+ The code above results in the following wiring configuration:
1491+ \code
1492 ___________
1493 ["Bool Generator 1"] 0 ---> 0 | |
1494 |"Logic AND"| 0 ---> 0 ["Bool Printer"]
1495 ["Bool Generator 2"] 0 ---> 1 |___________|
1496- \endcode
1497-
1498- *N.B. Each component input can only accept one wire at a time. When another wire is connected
1499- to an input that already has a connected wire, that wire is replaced with the new one. One
1500- output, on the other hand, can be distributed to multiple inputs.
1501-
1502- Lastly, in order for our circuit to do any work it must be ticked over. This is performed by
1503- repeatedly calling the circuit's Tick() and Reset() methods. These methods can be called
1504- manually in a loop from the main application thread, or alternatively, by calling
1505- StartAutoTick(), a seperate thread will spawn, automatically calling Tick() and Reset()
1506- continuously. A circuit's thread count can be adjusted at runtime, allowing us to increase /
1507- decrease the number of threads use by the circuit as required during execution:
1508-
1509- \code
1510+ \endcode
1511+
1512+ *N.B. Each component input can only accept one wire at a time. When another wire is connected
1513+ to an input that already has a connected wire, that wire is replaced with the new one. One
1514+ output, on the other hand, can be distributed to multiple inputs.
1515+
1516+ Lastly, in order for our circuit to do any work it must be ticked over. This is performed by
1517+ repeatedly calling the circuit's Tick() and Reset() methods. These methods can be called
1518+ manually in a loop from the main application thread, or alternatively, by calling
1519+ StartAutoTick(), a seperate thread will spawn, automatically calling Tick() and Reset()
1520+ continuously. A circuit's thread count can be adjusted at runtime, allowing us to increase /
1521+ decrease the number of threads use by the circuit as required during execution:
1522+
1523+ \code
1524 // 5. Tick the circuit
1525 // ===================
1526
1527@@ -353,23 +354,29 @@
1528
1529 // Press any key to quit
1530 getchar();
1531- \endcode
1532-
1533- Lastly, the DSPatch::Finalize() method must be called on application exit in order for DSPatch
1534- to perform its own internal memory cleanup.
1535-
1536- \code
1537+ \endcode
1538+
1539+ Lastly, the DSPatch::Finalize() method must be called on application exit in order for DSPatch
1540+ to perform its own internal memory cleanup.
1541+
1542+ \code
1543 // 6. Clean up
1544 // ===========
1545 DSPatch::Finalize();
1546 }
1547- \endcode
1548+ \endcode
1549
1550- (All the source code from these tutorials can be found under the "tutorial" folder in the DSPatch root directory).
1551+ (All the source code from these tutorials can be found under the "tutorial" folder in the DSPatch root directory).
1552
1553 \n
1554
1555-\section release_notes Release Notes
1556+\section changelog Changelog
1557+
1558+\subsection v261 v.2.61 (16 June 2014)
1559+ - Introduced component parameters (DspParameter).
1560+ - Added DspComponent user callback mechanism.
1561+ - Improved const-correctness and code style.
1562+ - Added ability to remove single IO pins.
1563
1564 \subsection v260 v.2.60 (19 January 2014)
1565 - Replaced project files with more flexible CMakeLists.
1566@@ -486,10 +493,10 @@
1567 next set of inputs from its input wires and populating the component's input
1568 bus. To insure that these inputs are up-to-date, the dependent component
1569 first calls all of its input components' Tick() methods -hence recursively
1570-called in all components going backward through the circuit. The acquired
1571+called in all components going backward through the circuit. The acquired
1572 input bus is then passed into a virtual method: Process() -it is the
1573 responsibility of the (derived) component creator to implement this virtual
1574-function. The Process() method has 2 input parameters: the input bus and the
1575+function. The Process() method has 2 input arguments: the input bus and the
1576 output bus. This method's purpose is to pull its required inputs out of the
1577 input bus, process these inputs, and populate the output bus with the results.
1578 These resultant outputs in the output bus are then acquired by dependent
1579
1580=== modified file 'include/dspatch/DspCircuit.h'
1581--- include/dspatch/DspCircuit.h 2014-01-25 09:05:16 +0000
1582+++ include/dspatch/DspCircuit.h 2014-06-16 15:43:30 +0000
1583@@ -1,6 +1,6 @@
1584 /************************************************************************
1585 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
1586-Copyright (c) 2012-2013 Marcus Tomlinson
1587+Copyright (c) 2012-2014 Marcus Tomlinson
1588
1589 This file is part of DSPatch.
1590
1591@@ -70,51 +70,54 @@
1592 void SetThreadCount( unsigned short threadCount );
1593 unsigned short GetThreadCount() const;
1594
1595- bool AddComponent( DspComponent* component, std::string componentName = "" );
1596- bool AddComponent( DspComponent& component, std::string componentName = "" );
1597+ bool AddComponent( DspComponent* component, std::string const& componentName = "" );
1598+ bool AddComponent( DspComponent& component, std::string const& componentName = "" );
1599
1600- void RemoveComponent( DspComponent* component );
1601- void RemoveComponent( DspComponent& component );
1602- void RemoveComponent( std::string componentName );
1603+ void RemoveComponent( DspComponent const* component );
1604+ void RemoveComponent( DspComponent const& component );
1605+ void RemoveComponent( std::string const& componentName );
1606
1607 void RemoveAllComponents();
1608
1609 template< class ComponentType >
1610- ComponentType* GetComponent( std::string componentName );
1611+ ComponentType* GetComponent( std::string const& componentName );
1612
1613 unsigned short GetComponentCount() const;
1614
1615 // component output to component input
1616- template< class FromComponentType, class FromOutputType, class ToComponentType, class ToInputType >
1617- bool ConnectOutToIn( FromComponentType& fromComponent, FromOutputType fromOutput, ToComponentType& toComponent, ToInputType toInput );
1618+ template< class FromComponentType, class FromOutputId, class ToComponentType, class ToInputId >
1619+ bool ConnectOutToIn( FromComponentType& fromComponent, FromOutputId const& fromOutput, ToComponentType& toComponent, ToInputId const& toInput );
1620
1621 // circuit input to component input
1622- template< class FromInputType, class ToComponentType, class ToInputType >
1623- bool ConnectInToIn( FromInputType fromInput, ToComponentType& toComponent, ToInputType toInput );
1624+ template< class FromInputId, class ToComponentType, class ToInputId >
1625+ bool ConnectInToIn( FromInputId const& fromInput, ToComponentType& toComponent, ToInputId const& toInput );
1626
1627 // component output to circuit output
1628- template< class FromComponentType, class FromOutputType, class ToOutputType >
1629- bool ConnectOutToOut( FromComponentType& fromComponent, FromOutputType fromOutput, ToOutputType toOutput );
1630+ template< class FromComponentType, class FromOutputId, class ToOutputId >
1631+ bool ConnectOutToOut( FromComponentType& fromComponent, FromOutputId const& fromOutput, ToOutputId const& toOutput );
1632
1633 // component output to component input
1634- template< class FromComponentType, class FromOutputType, class ToComponentType, class ToInputType >
1635- void DisconnectOutToIn( FromComponentType& fromComponent, FromOutputType fromOutput, ToComponentType& toComponent, ToInputType toInput );
1636+ template< class FromComponentType, class FromOutputId, class ToComponentType, class ToInputId >
1637+ void DisconnectOutToIn( FromComponentType const& fromComponent, FromOutputId const& fromOutput, ToComponentType const& toComponent, ToInputId const& toInput );
1638
1639 // circuit input to component input
1640- template< class FromInputType, class ToComponentType, class ToInputType >
1641- bool DisconnectInToIn( FromInputType fromInput, ToComponentType& toComponent, ToInputType toInput );
1642+ template< class FromInputId, class ToComponentType, class ToInputId >
1643+ bool DisconnectInToIn( FromInputId const& fromInput, ToComponentType const& toComponent, ToInputId const& toInput );
1644
1645 // component output to circuit output
1646- template< class FromComponentType, class FromOutputType, class ToOutputType >
1647- bool DisconnectOutToOut( FromComponentType& fromComponent, FromOutputType fromOutput, ToOutputType toOutput );
1648-
1649- void DisconnectComponent( std::string component );
1650-
1651- bool AddInput( std::string inputName = "" );
1652- bool AddOutput( std::string outputName = "" );
1653-
1654- void RemoveInputs();
1655- void RemoveOutputs();
1656+ template< class FromComponentType, class FromOutputId, class ToOutputId >
1657+ bool DisconnectOutToOut( FromComponentType const& fromComponent, FromOutputId const& fromOutput, ToOutputId const& toOutput );
1658+
1659+ void DisconnectComponent( std::string const& component );
1660+
1661+ bool AddInput( std::string const& inputName = "" );
1662+ bool AddOutput( std::string const& outputName = "" );
1663+
1664+ void RemoveInput();
1665+ void RemoveOutput();
1666+
1667+ void RemoveAllInputs();
1668+ void RemoveAllOutputs();
1669
1670 protected:
1671 virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs );
1672@@ -128,9 +131,9 @@
1673 DspWireBus _inToInWires;
1674 DspWireBus _outToOutWires;
1675
1676- bool _FindComponent( DspComponent* component, unsigned short& returnIndex ) const;
1677- bool _FindComponent( DspComponent& component, unsigned short& returnIndex ) const;
1678- bool _FindComponent( std::string componentName, unsigned short& returnIndex ) const;
1679+ bool _FindComponent( DspComponent const* component, unsigned short& returnIndex ) const;
1680+ bool _FindComponent( DspComponent const& component, unsigned short& returnIndex ) const;
1681+ bool _FindComponent( std::string const& componentName, unsigned short& returnIndex ) const;
1682 bool _FindComponent( unsigned short componentIndex, unsigned short& returnIndex ) const;
1683
1684 void _DisconnectComponent( unsigned short componentIndex );
1685@@ -140,7 +143,7 @@
1686 //=================================================================================================
1687
1688 template< class ComponentType >
1689-ComponentType* DspCircuit::GetComponent( std::string componentName )
1690+ComponentType* DspCircuit::GetComponent( std::string const& componentName )
1691 {
1692 unsigned short componentIndex;
1693
1694@@ -156,8 +159,8 @@
1695
1696 //-------------------------------------------------------------------------------------------------
1697
1698-template< class FromComponentType, class FromOutputType, class ToComponentType, class ToInputType >
1699-bool DspCircuit::ConnectOutToIn( FromComponentType& fromComponent, FromOutputType fromOutput, ToComponentType& toComponent, ToInputType toInput )
1700+template< class FromComponentType, class FromOutputId, class ToComponentType, class ToInputId >
1701+bool DspCircuit::ConnectOutToIn( FromComponentType& fromComponent, FromOutputId const& fromOutput, ToComponentType& toComponent, ToInputId const& toInput )
1702 {
1703 unsigned short fromComponentIndex;
1704 unsigned short toComponentIndex;
1705@@ -180,8 +183,8 @@
1706
1707 //-------------------------------------------------------------------------------------------------
1708
1709-template< class FromInputType, class ToComponentType, class ToInputType >
1710-bool DspCircuit::ConnectInToIn( FromInputType fromInput, ToComponentType& toComponent, ToInputType toInput )
1711+template< class FromInputId, class ToComponentType, class ToInputId >
1712+bool DspCircuit::ConnectInToIn( FromInputId const& fromInput, ToComponentType& toComponent, ToInputId const& toInput )
1713 {
1714 unsigned short fromInputIndex;
1715 unsigned short toComponentIndex;
1716@@ -206,8 +209,8 @@
1717
1718 //-------------------------------------------------------------------------------------------------
1719
1720-template< class FromComponentType, class FromOutputType, class ToOutputType >
1721-bool DspCircuit::ConnectOutToOut( FromComponentType& fromComponent, FromOutputType fromOutput, ToOutputType toOutput )
1722+template< class FromComponentType, class FromOutputId, class ToOutputId >
1723+bool DspCircuit::ConnectOutToOut( FromComponentType& fromComponent, FromOutputId const& fromOutput, ToOutputId const& toOutput )
1724 {
1725 unsigned short fromComponentIndex;
1726 unsigned short fromOutputIndex;
1727@@ -232,8 +235,8 @@
1728
1729 //-------------------------------------------------------------------------------------------------
1730
1731-template< class FromComponentType, class FromOutputType, class ToComponentType, class ToInputType >
1732-void DspCircuit::DisconnectOutToIn( FromComponentType& fromComponent, FromOutputType fromOutput, ToComponentType& toComponent, ToInputType toInput )
1733+template< class FromComponentType, class FromOutputId, class ToComponentType, class ToInputId >
1734+void DspCircuit::DisconnectOutToIn( FromComponentType const& fromComponent, FromOutputId const& fromOutput, ToComponentType const& toComponent, ToInputId const& toInput )
1735 {
1736 unsigned short fromComponentIndex;
1737 unsigned short toComponentIndex;
1738@@ -254,8 +257,8 @@
1739
1740 //-------------------------------------------------------------------------------------------------
1741
1742-template< class FromInputType, class ToComponentType, class ToInputType >
1743-bool DspCircuit::DisconnectInToIn( FromInputType fromInput, ToComponentType& toComponent, ToInputType toInput )
1744+template< class FromInputId, class ToComponentType, class ToInputId >
1745+bool DspCircuit::DisconnectInToIn( FromInputId const& fromInput, ToComponentType const& toComponent, ToInputId const& toInput )
1746 {
1747 unsigned short fromInputIndex;
1748 unsigned short toComponentIndex;
1749@@ -280,8 +283,8 @@
1750
1751 //-------------------------------------------------------------------------------------------------
1752
1753-template< class FromComponentType, class FromOutputType, class ToOutputType >
1754-bool DspCircuit::DisconnectOutToOut( FromComponentType& fromComponent, FromOutputType fromOutput, ToOutputType toOutput )
1755+template< class FromComponentType, class FromOutputId, class ToOutputId >
1756+bool DspCircuit::DisconnectOutToOut( FromComponentType const& fromComponent, FromOutputId const& fromOutput, ToOutputId const& toOutput )
1757 {
1758 unsigned short fromComponentIndex;
1759 unsigned short fromOutputIndex;
1760
1761=== modified file 'include/dspatch/DspCircuitThread.h'
1762--- include/dspatch/DspCircuitThread.h 2014-01-25 09:05:16 +0000
1763+++ include/dspatch/DspCircuitThread.h 2014-06-16 15:43:30 +0000
1764@@ -1,6 +1,6 @@
1765 /************************************************************************
1766 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
1767-Copyright (c) 2012-2013 Marcus Tomlinson
1768+Copyright (c) 2012-2014 Marcus Tomlinson
1769
1770 This file is part of DSPatch.
1771
1772
1773=== modified file 'include/dspatch/DspComponent.h'
1774--- include/dspatch/DspComponent.h 2014-01-25 09:05:16 +0000
1775+++ include/dspatch/DspComponent.h 2014-06-16 15:43:30 +0000
1776@@ -1,6 +1,6 @@
1777 /************************************************************************
1778 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
1779-Copyright (c) 2012-2013 Marcus Tomlinson
1780+Copyright (c) 2012-2014 Marcus Tomlinson
1781
1782 This file is part of DSPatch.
1783
1784@@ -30,6 +30,9 @@
1785 #include <dspatch/DspSignalBus.h>
1786 #include <dspatch/DspWireBus.h>
1787 #include <dspatch/DspComponentThread.h>
1788+#include <dspatch/DspParameter.h>
1789+
1790+#include <map>
1791
1792 class DspCircuit;
1793
1794@@ -37,13 +40,27 @@
1795 /// Abstract base class for all DSPatch components
1796
1797 /**
1798-Classes derived from DspComponent can be added to an DspCircuit and routed to and from other
1799-DspComponents. On construction, derived classes must configure the component's IO buses by calling
1800-AddInput_() and AddOutput_() respectively. Derived classes must also implement the virtual method:
1801-Process_(). The Process_() method is a callback from the DSPatch engine that occurs when a new set
1802-of input signals is ready for processing. The Process_() method has 2 parameters: the input bus and
1803-the output bus. This method's purpose is to pull its required inputs out of the input bus, process
1804-these inputs, and populate the output bus with the results (see DspSignalBus).
1805+Classes derived from DspComponent can be added to a DspCircuit and routed to and from other
1806+DspComponents.
1807+
1808+On construction, derived classes must configure the component's IO buses by calling AddInput_() and
1809+AddOutput_() respectively, as well as populate the component's parameter map via AddParameter_()
1810+(see DspParameter).
1811+
1812+Derived classes must also implement the virtual method: Process_(). The Process_() method is a
1813+callback from the DSPatch engine that occurs when a new set of input signals is ready for
1814+processing. The Process_() method has 2 arguments: the input bus, and the output bus. This
1815+method's purpose is to pull its required inputs out of the input bus, process these inputs, and
1816+populate the output bus with the results (see DspSignalBus).
1817+
1818+Derived classes that expose parameters will also need to implement the virtual ParameterUpdating_()
1819+method. The ParameterUpdating_() method is a callback from the DSPatch engine that occurs when an
1820+update to a component parameter has been requested via the public SetParameter() method.
1821+ParameterUpdating_() has 2 arguments: the parameter name, and the new parameter value to be set.
1822+This method's purpose is to: 1. validate that the new value is legal, 2. make the necessary
1823+internal changes associated with that parameter change, and 3. update the target parameter itself
1824+by calling the protected SetParameter_() method. If the new parameter value is legal and the update
1825+was successful, ParameterUpdating_() should return true, otherwise, it should return false.
1826
1827 In order for a component to do any work it must be ticked over. This is performed by repeatedly
1828 calling the Tick() and Reset() methods. The Tick() method is responsible for acquiring the next set
1829@@ -54,41 +71,56 @@
1830 method. The Reset() method then informs the component that the last circuit traversal has completed
1831 and hence can execute the next Tick() request. A component's Tick() and Reset() methods can be
1832 called in a loop from the main application thread, or alternatively, by calling StartAutoTick(), a
1833-seperate thread will spawn, automatically calling Tick() and Reset() methods continuously (This is
1834+separate thread will spawn, automatically calling Tick() and Reset() methods continuously (This is
1835 most commonly used to tick over an instance of DspCircuit).
1836 */
1837
1838 class DLLEXPORT DspComponent
1839 {
1840- friend class DspCircuit;
1841- friend class DspCircuitThread;
1842-
1843 public:
1844+ enum CallbackType
1845+ {
1846+ InputAdded, InputRemoved,
1847+ OutputAdded, OutputRemoved,
1848+ ParameterAdded, ParameterRemoved, ParameterUpdated
1849+ };
1850+ typedef void( *Callback_t )( DspComponent const* component, CallbackType const& callbackType, int index, void* userData );
1851+
1852 DspComponent();
1853 virtual ~DspComponent();
1854
1855- void SetComponentName( std::string componentName );
1856+ void SetCallback( Callback_t const& callback, void* userData = NULL );
1857+
1858+ void SetComponentName( std::string const& componentName );
1859 std::string GetComponentName() const;
1860
1861- template< class FromOutputType, class ToInputType >
1862- bool ConnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput );
1863-
1864- template< class FromOutputType, class ToInputType >
1865- bool ConnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput );
1866-
1867- template< class FromOutputType, class ToInputType >
1868- void DisconnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput );
1869-
1870- template< class FromOutputType, class ToInputType >
1871- void DisconnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput );
1872+ template< class FromOutputId, class ToInputId >
1873+ bool ConnectInput( DspComponent* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
1874+
1875+ template< class FromOutputId, class ToInputId >
1876+ bool ConnectInput( DspComponent& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
1877+
1878+ template< class FromOutputId, class ToInputId >
1879+ void DisconnectInput( DspComponent const* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
1880+
1881+ template< class FromOutputId, class ToInputId >
1882+ void DisconnectInput( DspComponent const& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput );
1883
1884 void DisconnectInput( unsigned short inputIndex );
1885- void DisconnectInput( std::string inputName );
1886- void DisconnectInput( DspComponent* inputComponent );
1887- void DisconnectInputs();
1888-
1889- unsigned short GetInputCount() const;
1890- unsigned short GetOutputCount() const;
1891+ void DisconnectInput( std::string const& inputName );
1892+ void DisconnectInput( DspComponent const* inputComponent );
1893+ void DisconnectAllInputs();
1894+
1895+ unsigned short GetInputCount();
1896+ unsigned short GetOutputCount();
1897+ unsigned short GetParameterCount();
1898+
1899+ std::string GetInputName( unsigned short index );
1900+ std::string GetOutputName( unsigned short index );
1901+ std::string GetParameterName( unsigned short index );
1902+
1903+ bool GetParameter( std::string const& paramName, DspParameter& param );
1904+ bool SetParameter( std::string const& paramName, DspParameter const& param );
1905
1906 void Tick();
1907 void Reset();
1908@@ -99,21 +131,35 @@
1909 virtual void ResumeAutoTick();
1910
1911 protected:
1912- virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs ) {};
1913-
1914- bool AddInput_( std::string inputName = "" );
1915- bool AddOutput_( std::string outputName = "" );
1916-
1917- void RemoveInputs_();
1918- void RemoveOutputs_();
1919+ virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs ) {}
1920+ virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param ) { return false; }
1921+
1922+ bool AddInput_( std::string const& inputName = "" );
1923+ bool AddOutput_( std::string const& outputName = "" );
1924+ bool AddParameter_( std::string const& paramName, DspParameter const& param );
1925+
1926+ bool RemoveInput_();
1927+ bool RemoveOutput_();
1928+ bool RemoveParameter_();
1929+
1930+ void RemoveAllInputs_();
1931+ void RemoveAllOutputs_();
1932+ void RemoveAllParameters_();
1933+
1934+ unsigned short GetInputCount_();
1935+ unsigned short GetOutputCount_();
1936+ unsigned short GetParameterCount_();
1937+
1938+ DspParameter const* GetParameter_( std::string const& paramName ) const;
1939+ bool SetParameter_( std::string const& paramName, DspParameter const& param );
1940
1941 private:
1942 void _SetParentCircuit( DspCircuit* parentCircuit );
1943 DspCircuit* _GetParentCircuit();
1944
1945- bool _FindInput( std::string signalName, unsigned short& returnIndex ) const;
1946+ bool _FindInput( std::string const& signalName, unsigned short& returnIndex ) const;
1947 bool _FindInput( unsigned short signalIndex, unsigned short& returnIndex ) const;
1948- bool _FindOutput( std::string signalName, unsigned short& returnIndex ) const;
1949+ bool _FindOutput( std::string const& signalName, unsigned short& returnIndex ) const;
1950 bool _FindOutput( unsigned short signalIndex, unsigned short& returnIndex ) const;
1951
1952 void _SetBufferCount( unsigned short bufferCount );
1953@@ -122,8 +168,8 @@
1954 void _ThreadTick( unsigned short threadNo );
1955 void _ThreadReset( unsigned short threadNo );
1956
1957- bool _SetInputSignal( unsigned short inputIndex, const DspSignal* newSignal );
1958- bool _SetInputSignal( unsigned short inputIndex, unsigned short threadIndex, const DspSignal* newSignal );
1959+ bool _SetInputSignal( unsigned short inputIndex, DspSignal const* newSignal );
1960+ bool _SetInputSignal( unsigned short inputIndex, unsigned short threadIndex, DspSignal const* newSignal );
1961 DspSignal* _GetOutputSignal( unsigned short outputIndex );
1962 DspSignal* _GetOutputSignal( unsigned short outputIndex, unsigned short threadIndex );
1963
1964@@ -131,6 +177,9 @@
1965 void _ReleaseThread( unsigned short threadNo );
1966
1967 private:
1968+ friend class DspCircuit;
1969+ friend class DspCircuitThread;
1970+
1971 DspCircuit* _parentCircuit;
1972
1973 unsigned short _bufferCount;
1974@@ -141,6 +190,8 @@
1975 std::vector< DspSignalBus > _inputBuses;
1976 std::vector< DspSignalBus > _outputBuses;
1977
1978+ std::map< std::string, DspParameter > _parameters;
1979+
1980 std::string _componentName;
1981 bool _isAutoTickRunning;
1982 bool _isAutoTickPaused;
1983@@ -155,12 +206,15 @@
1984 std::vector< bool > _gotReleases; // bool pointers not used here as only 1 thread writes to this vector at a time
1985 std::vector< DspMutex > _releaseMutexes;
1986 std::vector< DspWaitCondition > _releaseCondts;
1987+
1988+ Callback_t _callback;
1989+ void* _userData;
1990 };
1991
1992 //=================================================================================================
1993
1994-template< class FromOutputType, class ToInputType >
1995-bool DspComponent::ConnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput )
1996+template< class FromOutputId, class ToInputId >
1997+bool DspComponent::ConnectInput( DspComponent* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
1998 {
1999 unsigned short fromOutputIndex;
2000 unsigned short toInputIndex;
2001@@ -180,16 +234,16 @@
2002
2003 //-------------------------------------------------------------------------------------------------
2004
2005-template< class FromOutputType, class ToInputType >
2006-bool DspComponent::ConnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput )
2007+template< class FromOutputId, class ToInputId >
2008+bool DspComponent::ConnectInput( DspComponent& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
2009 {
2010 return ConnectInput( &fromComponent, fromOutput, toInput );
2011 }
2012
2013 //-------------------------------------------------------------------------------------------------
2014
2015-template< class FromOutputType, class ToInputType >
2016-void DspComponent::DisconnectInput( DspComponent* fromComponent, FromOutputType fromOutput, ToInputType toInput )
2017+template< class FromOutputId, class ToInputId >
2018+void DspComponent::DisconnectInput( DspComponent const* fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
2019 {
2020 unsigned short fromOutputIndex;
2021 unsigned short toInputIndex;
2022@@ -207,8 +261,8 @@
2023
2024 //-------------------------------------------------------------------------------------------------
2025
2026-template< class FromOutputType, class ToInputType >
2027-void DspComponent::DisconnectInput( DspComponent& fromComponent, FromOutputType fromOutput, ToInputType toInput )
2028+template< class FromOutputId, class ToInputId >
2029+void DspComponent::DisconnectInput( DspComponent const& fromComponent, FromOutputId const& fromOutput, ToInputId const& toInput )
2030 {
2031 DisconnectInput( &fromComponent, fromOutput, toInput );
2032 }
2033
2034=== modified file 'include/dspatch/DspComponentThread.h'
2035--- include/dspatch/DspComponentThread.h 2014-01-25 09:05:16 +0000
2036+++ include/dspatch/DspComponentThread.h 2014-06-16 15:43:30 +0000
2037@@ -1,6 +1,6 @@
2038 /************************************************************************
2039 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2040-Copyright (c) 2012-2013 Marcus Tomlinson
2041+Copyright (c) 2012-2014 Marcus Tomlinson
2042
2043 This file is part of DSPatch.
2044
2045
2046=== added file 'include/dspatch/DspParameter.h'
2047--- include/dspatch/DspParameter.h 1970-01-01 00:00:00 +0000
2048+++ include/dspatch/DspParameter.h 2014-06-16 15:43:30 +0000
2049@@ -0,0 +1,111 @@
2050+/************************************************************************
2051+DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2052+Copyright (c) 2012-2014 Marcus Tomlinson
2053+
2054+This file is part of DSPatch.
2055+
2056+GNU Lesser General Public License Usage
2057+This file may be used under the terms of the GNU Lesser General Public
2058+License version 3.0 as published by the Free Software Foundation and
2059+appearing in the file LGPLv3.txt included in the packaging of this
2060+file. Please review the following information to ensure the GNU Lesser
2061+General Public License version 3.0 requirements will be met:
2062+http://www.gnu.org/copyleft/lgpl.html.
2063+
2064+Other Usage
2065+Alternatively, this file may be used in accordance with the terms and
2066+conditions contained in a signed written agreement between you and
2067+Marcus Tomlinson.
2068+
2069+DSPatch is distributed in the hope that it will be useful,
2070+but WITHOUT ANY WARRANTY; without even the implied warranty of
2071+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2072+************************************************************************/
2073+
2074+#ifndef DSPPARAMETER_H
2075+#define DSPPARAMETER_H
2076+
2077+//-------------------------------------------------------------------------------------------------
2078+
2079+#include <dspatch/DspThread.h>
2080+#include <string>
2081+#include <vector>
2082+
2083+//=================================================================================================
2084+/// Value container used to hold non-transient component IO
2085+
2086+/**
2087+DspParameters are similar to DspSignals in that they provide a generic means of inputting and
2088+outputting data to and from DspComponents. However, unlike signals, parameters are non-transient
2089+inputs and outputs (such as enable / disable, bias, offset, etc.) that allow for a component's
2090+behaviour to be manipulated via direct set / get methods. The parameter type (ParamType) must be
2091+specified on construction of a DspParameter. Any type mismatches on subsequent set / get calls will
2092+immediatly return false.
2093+
2094+NOTE: Abstracting component parameters behind the generic DspParameter container allows a
2095+component to be entirely controllable via the DspComponent base class.
2096+*/
2097+
2098+class DLLEXPORT DspParameter
2099+{
2100+public:
2101+ enum ParamType
2102+ {
2103+ Null,
2104+ Bool,
2105+ Int,
2106+ Float,
2107+ String,
2108+ FilePath, // this is essentially just a string, but helps when determining an appropriate user input method
2109+ List, // this type acts as a vector (available items), an int (index selected), and a string (item selected)
2110+ Trigger // this type has no value, SetParam(triggerParam) simply represents a trigger. E.g. a button press
2111+ };
2112+
2113+ DspParameter();
2114+ DspParameter( ParamType const& type );
2115+ DspParameter( ParamType const& type, int const& initValue, std::pair<int, int> const& valueRange = std::make_pair( -1, -1 ) );
2116+ DspParameter( ParamType const& type, float const& initValue, std::pair<float, float> const& valueRange = std::make_pair( -1.0f, -1.0f ) );
2117+ DspParameter( ParamType const& type, std::string const& initValue );
2118+ DspParameter( ParamType const& type, std::vector< std::string > const& initValue );
2119+
2120+ ParamType Type() const;
2121+ bool IsSet() const;
2122+
2123+ bool const* GetBool() const;
2124+ int const* GetInt() const;
2125+ std::pair<int, int> const* GetIntRange() const;
2126+ float const* GetFloat() const;
2127+ std::pair<float, float> const* GetFloatRange() const;
2128+ std::string const* GetString() const;
2129+ std::vector< std::string > const* GetList() const;
2130+
2131+ bool SetBool( bool const& value );
2132+ bool SetInt( int const& value );
2133+ bool SetIntRange( std::pair<int, int> const& intRange );
2134+ bool SetFloat( float const& value );
2135+ bool SetFloatRange( std::pair<float, float> const& floatRange );
2136+ bool SetString( std::string const& value );
2137+ bool SetList( std::vector< std::string > const& value );
2138+
2139+ bool SetParam( DspParameter const& param );
2140+
2141+private:
2142+ ParamType _type;
2143+ bool _isSet;
2144+ bool _isRangeSet;
2145+
2146+ bool _boolValue;
2147+
2148+ std::pair<int, int> _intRange;
2149+ int _intValue;
2150+
2151+ std::pair<float, float> _floatRange;
2152+ float _floatValue;
2153+
2154+ std::string _stringValue;
2155+ std::vector< std::string > _listValue;
2156+};
2157+
2158+//=================================================================================================
2159+
2160+#endif // DSPPARAMETER_H
2161
2162=== modified file 'include/dspatch/DspRunType.h'
2163--- include/dspatch/DspRunType.h 2014-01-25 09:05:16 +0000
2164+++ include/dspatch/DspRunType.h 2014-06-16 15:43:30 +0000
2165@@ -1,6 +1,6 @@
2166 /************************************************************************
2167 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2168-Copyright (c) 2012-2013 Marcus Tomlinson
2169+Copyright (c) 2012-2014 Marcus Tomlinson
2170
2171 This file is part of DSPatch.
2172
2173@@ -49,12 +49,12 @@
2174 : _valueHolder( NULL ) {}
2175
2176 template< typename ValueType >
2177- DspRunType( const ValueType& value )
2178+ DspRunType( ValueType const& value )
2179 {
2180 _valueHolder = new _DspRtValue< ValueType >( value );
2181 }
2182
2183- DspRunType( const DspRunType& other )
2184+ DspRunType( DspRunType const& other )
2185 {
2186 if( other._valueHolder != NULL )
2187 {
2188@@ -78,7 +78,7 @@
2189 return *this;
2190 }
2191
2192- void CopyFrom( const DspRunType& rhs )
2193+ void CopyFrom( DspRunType const& rhs )
2194 {
2195 if( _valueHolder != NULL && rhs._valueHolder != NULL &&
2196 _valueHolder->GetType() == rhs._valueHolder->GetType() )
2197@@ -92,7 +92,7 @@
2198 }
2199
2200 template< typename ValueType >
2201- DspRunType& operator=( const ValueType& rhs )
2202+ DspRunType& operator=( ValueType const& rhs )
2203 {
2204 if( typeid( rhs ) == GetType() )
2205 {
2206@@ -117,7 +117,7 @@
2207 return !_valueHolder;
2208 }
2209
2210- const std::type_info& GetType() const
2211+ std::type_info const& GetType() const
2212 {
2213 if( _valueHolder != NULL )
2214 {
2215@@ -143,7 +143,7 @@
2216 }
2217
2218 template< typename ValueType >
2219- static inline const ValueType* RunTypeCast( const DspRunType* operand )
2220+ static inline ValueType const* RunTypeCast( DspRunType const* operand )
2221 {
2222 return RunTypeCast< ValueType >( const_cast< DspRunType* >( operand ) );
2223 }
2224@@ -155,7 +155,7 @@
2225 virtual ~_DspRtValueHolder() {}
2226
2227 public:
2228- virtual const std::type_info& GetType() const = 0;
2229+ virtual std::type_info const& GetType() const = 0;
2230 virtual _DspRtValueHolder* GetCopy() const = 0;
2231 virtual void SetValue( _DspRtValueHolder* valueHolder ) = 0;
2232 };
2233@@ -164,11 +164,11 @@
2234 class _DspRtValue : public _DspRtValueHolder
2235 {
2236 public:
2237- _DspRtValue( const ValueType& value )
2238+ _DspRtValue( ValueType const& value )
2239 : value( value ) {}
2240
2241 public:
2242- virtual const std::type_info& GetType() const
2243+ virtual std::type_info const& GetType() const
2244 {
2245 return typeid( ValueType );
2246 }
2247@@ -187,7 +187,7 @@
2248 ValueType value;
2249
2250 private:
2251- _DspRtValue& operator=( const _DspRtValue& ); // disable copy-assignment
2252+ _DspRtValue& operator=( _DspRtValue const& ); // disable copy-assignment
2253 };
2254
2255 private:
2256
2257=== modified file 'include/dspatch/DspSignal.h'
2258--- include/dspatch/DspSignal.h 2014-01-25 09:05:16 +0000
2259+++ include/dspatch/DspSignal.h 2014-06-16 15:43:30 +0000
2260@@ -1,6 +1,6 @@
2261 /************************************************************************
2262 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2263-Copyright (c) 2012-2013 Marcus Tomlinson
2264+Copyright (c) 2012-2014 Marcus Tomlinson
2265
2266 This file is part of DSPatch.
2267
2268@@ -54,16 +54,16 @@
2269 virtual ~DspSignal();
2270
2271 template< class ValueType >
2272- bool SetValue( const ValueType& newValue );
2273+ bool SetValue( ValueType const& newValue );
2274
2275 template< class ValueType >
2276 bool GetValue( ValueType& returnValue ) const;
2277
2278- bool SetSignal( const DspSignal* newSignal );
2279+ bool SetSignal( DspSignal const* newSignal );
2280
2281 void ClearValue();
2282
2283- const std::type_info& GetSignalType() const;
2284+ std::type_info const& GetSignalType() const;
2285
2286 std::string GetSignalName() const;
2287
2288@@ -76,7 +76,7 @@
2289 //=================================================================================================
2290
2291 template< class ValueType >
2292-bool DspSignal::SetValue( const ValueType& newValue )
2293+bool DspSignal::SetValue( ValueType const& newValue )
2294 {
2295 _signalValue = newValue;
2296 _valueAvailable = true;
2297@@ -90,7 +90,7 @@
2298 {
2299 if( _valueAvailable )
2300 {
2301- const ValueType* returnValuePtr = DspRunType::RunTypeCast< ValueType >( &_signalValue );
2302+ ValueType const* returnValuePtr = DspRunType::RunTypeCast< ValueType >( &_signalValue );
2303 if( returnValuePtr != NULL )
2304 {
2305 returnValue = *returnValuePtr;
2306
2307=== modified file 'include/dspatch/DspSignalBus.h'
2308--- include/dspatch/DspSignalBus.h 2014-01-25 09:05:16 +0000
2309+++ include/dspatch/DspSignalBus.h 2014-06-16 15:43:30 +0000
2310@@ -1,6 +1,6 @@
2311 /************************************************************************
2312 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2313-Copyright (c) 2012-2013 Marcus Tomlinson
2314+Copyright (c) 2012-2014 Marcus Tomlinson
2315
2316 This file is part of DSPatch.
2317
2318@@ -37,8 +37,7 @@
2319 receives signals into it's "inputs" DspSignalBus and provides signals to it's "outputs"
2320 DspSignalBus. Although DspSignals can be acquired from a DspSignalBus, the DspSignalBus class
2321 provides public getters and setters for manipulating it's internal DspSignal values directly,
2322-abstracting the need to retrieve and interface with the contained DspSignal objects. Likewise,
2323-signals can be added and removed from a DspSignalBus via public methods.
2324+abstracting the need to retrieve and interface with the contained DspSignals themself.
2325 */
2326
2327 class DLLEXPORT DspSignalBus
2328@@ -46,46 +45,50 @@
2329 public:
2330 virtual ~DspSignalBus();
2331
2332- bool AddSignal( std::string signalName = "" );
2333-
2334- bool SetSignal( unsigned short signalIndex, const DspSignal* newSignal );
2335- bool SetSignal( std::string signalName, const DspSignal* newSignal );
2336+ bool SetSignal( unsigned short signalIndex, DspSignal const* newSignal );
2337+ bool SetSignal( std::string const& signalName, DspSignal const* newSignal );
2338
2339 DspSignal* GetSignal( unsigned short signalIndex );
2340- DspSignal* GetSignal( std::string signalName );
2341+ DspSignal* GetSignal( std::string const& signalName );
2342
2343- bool FindSignal( std::string signalName, unsigned short& returnIndex ) const;
2344+ bool FindSignal( std::string const& signalName, unsigned short& returnIndex ) const;
2345 bool FindSignal( unsigned short signalIndex, unsigned short& returnIndex ) const;
2346
2347 unsigned short GetSignalCount() const;
2348
2349- void RemoveAllSignals();
2350-
2351- template< class ValueType >
2352- bool SetValue( unsigned short signalIndex, const ValueType& newValue );
2353-
2354- template< class ValueType >
2355- bool SetValue( std::string signalName, const ValueType& newValue );
2356+ template< class ValueType >
2357+ bool SetValue( unsigned short signalIndex, ValueType const& newValue );
2358+
2359+ template< class ValueType >
2360+ bool SetValue( std::string const& signalName, ValueType const& newValue );
2361
2362 template< class ValueType >
2363 bool GetValue( unsigned short signalIndex, ValueType& returnValue ) const;
2364
2365 template< class ValueType >
2366- bool GetValue( std::string signalName, ValueType& returnValue ) const;
2367+ bool GetValue( std::string const& signalName, ValueType& returnValue ) const;
2368
2369 void ClearValue( unsigned short signalIndex );
2370- void ClearValue( std::string signalName );
2371+ void ClearValue( std::string const& signalName );
2372
2373 void ClearAllValues();
2374
2375 private:
2376+ friend class DspComponent;
2377+
2378+ bool _AddSignal( std::string const& signalName = "" );
2379+
2380+ bool _RemoveSignal();
2381+ void _RemoveAllSignals();
2382+
2383+private:
2384 std::vector< DspSignal > _signals;
2385 };
2386
2387 //=================================================================================================
2388
2389 template< class ValueType >
2390-bool DspSignalBus::SetValue( unsigned short signalIndex, const ValueType& newValue )
2391+bool DspSignalBus::SetValue( unsigned short signalIndex, ValueType const& newValue )
2392 {
2393 if( signalIndex < _signals.size() )
2394 {
2395@@ -100,7 +103,7 @@
2396 //-------------------------------------------------------------------------------------------------
2397
2398 template< class ValueType >
2399-bool DspSignalBus::SetValue( std::string signalName, const ValueType& newValue )
2400+bool DspSignalBus::SetValue( std::string const& signalName, ValueType const& newValue )
2401 {
2402 unsigned short signalIndex;
2403
2404@@ -132,7 +135,7 @@
2405 //-------------------------------------------------------------------------------------------------
2406
2407 template< class ValueType >
2408-bool DspSignalBus::GetValue( std::string signalName, ValueType& returnValue ) const
2409+bool DspSignalBus::GetValue( std::string const& signalName, ValueType& returnValue ) const
2410 {
2411 unsigned short signalIndex;
2412
2413
2414=== modified file 'include/dspatch/DspThread.h'
2415--- include/dspatch/DspThread.h 2014-01-25 09:05:16 +0000
2416+++ include/dspatch/DspThread.h 2014-06-16 15:43:30 +0000
2417@@ -1,6 +1,6 @@
2418 /************************************************************************
2419 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2420-Copyright (c) 2012-2013 Marcus Tomlinson
2421+Copyright (c) 2012-2014 Marcus Tomlinson
2422
2423 This file is part of DSPatch.
2424
2425
2426=== modified file 'include/dspatch/DspThreadNull.h'
2427--- include/dspatch/DspThreadNull.h 2014-01-25 09:05:16 +0000
2428+++ include/dspatch/DspThreadNull.h 2014-06-16 15:43:30 +0000
2429@@ -1,6 +1,6 @@
2430 /************************************************************************
2431 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2432-Copyright (c) 2012-2013 Marcus Tomlinson
2433+Copyright (c) 2012-2014 Marcus Tomlinson
2434
2435 This file is part of DSPatch.
2436
2437
2438=== modified file 'include/dspatch/DspThreadUnix.h'
2439--- include/dspatch/DspThreadUnix.h 2014-01-25 09:05:16 +0000
2440+++ include/dspatch/DspThreadUnix.h 2014-06-16 15:43:30 +0000
2441@@ -1,6 +1,6 @@
2442 /************************************************************************
2443 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2444-Copyright (c) 2012-2013 Marcus Tomlinson
2445+Copyright (c) 2012-2014 Marcus Tomlinson
2446
2447 This file is part of DSPatch.
2448
2449@@ -114,8 +114,6 @@
2450
2451 class DspMutex
2452 {
2453- friend class DspWaitCondition;
2454-
2455 public:
2456 DspMutex()
2457 {
2458@@ -138,6 +136,8 @@
2459 }
2460
2461 private:
2462+ friend class DspWaitCondition;
2463+
2464 pthread_mutex_t _mutex;
2465 };
2466
2467
2468=== modified file 'include/dspatch/DspThreadWin.h'
2469--- include/dspatch/DspThreadWin.h 2014-01-25 09:05:16 +0000
2470+++ include/dspatch/DspThreadWin.h 2014-06-16 15:43:30 +0000
2471@@ -1,6 +1,6 @@
2472 /************************************************************************
2473 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2474-Copyright (c) 2012-2013 Marcus Tomlinson
2475+Copyright (c) 2012-2014 Marcus Tomlinson
2476
2477 This file is part of DSPatch.
2478
2479@@ -37,7 +37,7 @@
2480 DspThread()
2481 : _threadHandle( NULL ) {}
2482
2483- DspThread( const DspThread& )
2484+ DspThread( DspThread const& )
2485 : _threadHandle( NULL ) {}
2486
2487 virtual ~DspThread()
2488@@ -105,7 +105,7 @@
2489 InitializeCriticalSection( &_cs );
2490 }
2491
2492- DspMutex( const DspMutex& )
2493+ DspMutex( DspMutex const& )
2494 {
2495 InitializeCriticalSection( &_cs );
2496 }
2497@@ -139,7 +139,7 @@
2498 _hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
2499 }
2500
2501- DspWaitCondition( const DspWaitCondition& )
2502+ DspWaitCondition( DspWaitCondition const& )
2503 {
2504 _hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
2505 }
2506
2507=== modified file 'include/dspatch/DspWire.h'
2508--- include/dspatch/DspWire.h 2014-01-25 09:05:16 +0000
2509+++ include/dspatch/DspWire.h 2014-06-16 15:43:30 +0000
2510@@ -1,6 +1,6 @@
2511 /************************************************************************
2512 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2513-Copyright (c) 2012-2013 Marcus Tomlinson
2514+Copyright (c) 2012-2014 Marcus Tomlinson
2515
2516 This file is part of DSPatch.
2517
2518
2519=== modified file 'include/dspatch/DspWireBus.h'
2520--- include/dspatch/DspWireBus.h 2014-01-25 09:05:16 +0000
2521+++ include/dspatch/DspWireBus.h 2014-06-16 15:43:30 +0000
2522@@ -1,6 +1,6 @@
2523 /************************************************************************
2524 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2525-Copyright (c) 2012-2013 Marcus Tomlinson
2526+Copyright (c) 2012-2014 Marcus Tomlinson
2527
2528 This file is part of DSPatch.
2529
2530@@ -53,7 +53,7 @@
2531 bool AddWire( DspComponent* linkedComponent, unsigned short fromSignalIndex, unsigned short toSignalIndex );
2532
2533 bool RemoveWire( unsigned short wireIndex );
2534- bool RemoveWire( DspComponent* linkedComponent, unsigned short fromSignalIndex, unsigned short toSignalIndex );
2535+ bool RemoveWire( DspComponent const* linkedComponent, unsigned short fromSignalIndex, unsigned short toSignalIndex );
2536
2537 void RemoveAllWires();
2538
2539
2540=== modified file 'src/DSPatch.cpp'
2541--- src/DSPatch.cpp 2014-01-19 09:07:19 +0000
2542+++ src/DSPatch.cpp 2014-06-16 15:43:30 +0000
2543@@ -1,6 +1,6 @@
2544 /************************************************************************
2545 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2546-Copyright (c) 2012-2013 Marcus Tomlinson
2547+Copyright (c) 2012-2014 Marcus Tomlinson
2548
2549 This file is part of DSPatch.
2550
2551@@ -48,7 +48,7 @@
2552
2553 //=================================================================================================
2554
2555-bool DSPatch::_IsThisGlobalCircuit( DspComponent* thisComponent )
2556+bool DSPatch::_IsThisGlobalCircuit( DspComponent const* thisComponent )
2557 {
2558 if( _globalCircuit != NULL )
2559 {
2560@@ -72,7 +72,7 @@
2561
2562 //-------------------------------------------------------------------------------------------------
2563
2564-void DSPatch::_RemoveGlobalComponent( DspComponent* component )
2565+void DSPatch::_RemoveGlobalComponent( DspComponent const* component )
2566 {
2567 if( _globalCircuit != NULL )
2568 {
2569
2570=== modified file 'src/DspCircuit.cpp'
2571--- src/DspCircuit.cpp 2014-01-25 09:05:16 +0000
2572+++ src/DspCircuit.cpp 2014-06-16 15:43:30 +0000
2573@@ -1,6 +1,6 @@
2574 /************************************************************************
2575 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2576-Copyright (c) 2012-2013 Marcus Tomlinson
2577+Copyright (c) 2012-2014 Marcus Tomlinson
2578
2579 This file is part of DSPatch.
2580
2581@@ -109,14 +109,16 @@
2582
2583 //-------------------------------------------------------------------------------------------------
2584
2585-bool DspCircuit::AddComponent( DspComponent* component, std::string componentName )
2586+bool DspCircuit::AddComponent( DspComponent* component, std::string const& componentName )
2587 {
2588 if( component != this )
2589 {
2590+ std::string compName = componentName;
2591+
2592 // if the component has a name already
2593- if( component->GetComponentName() != "" && componentName == "" )
2594+ if( component->GetComponentName() != "" && compName == "" )
2595 {
2596- componentName = component->GetComponentName();
2597+ compName = component->GetComponentName();
2598 }
2599
2600 unsigned short componentIndex;
2601@@ -129,7 +131,7 @@
2602 {
2603 return false; // if the component is already in the array
2604 }
2605- if( _FindComponent( componentName, componentIndex ) )
2606+ if( _FindComponent( compName, componentIndex ) )
2607 {
2608 return false; // if the component name is already in the array
2609 }
2610@@ -137,7 +139,7 @@
2611 // components within the circuit need to have as many buffers as there are threads in the circuit
2612 component->_SetParentCircuit( this );
2613 component->_SetBufferCount( _circuitThreads.size() );
2614- component->SetComponentName( componentName );
2615+ component->SetComponentName( compName );
2616
2617 PauseAutoTick();
2618 _components.push_back( component );
2619@@ -151,14 +153,14 @@
2620
2621 //-------------------------------------------------------------------------------------------------
2622
2623-bool DspCircuit::AddComponent( DspComponent& component, std::string componentName )
2624+bool DspCircuit::AddComponent( DspComponent& component, std::string const& componentName )
2625 {
2626 return AddComponent( &component, componentName );
2627 }
2628
2629 //-------------------------------------------------------------------------------------------------
2630
2631-void DspCircuit::RemoveComponent( DspComponent* component )
2632+void DspCircuit::RemoveComponent( DspComponent const* component )
2633 {
2634 unsigned short componentIndex;
2635
2636@@ -172,14 +174,14 @@
2637
2638 //-------------------------------------------------------------------------------------------------
2639
2640-void DspCircuit::RemoveComponent( DspComponent& component )
2641+void DspCircuit::RemoveComponent( DspComponent const& component )
2642 {
2643 RemoveComponent( &component );
2644 }
2645
2646 //-------------------------------------------------------------------------------------------------
2647
2648-void DspCircuit::RemoveComponent( std::string componentName )
2649+void DspCircuit::RemoveComponent( std::string const& componentName )
2650 {
2651 unsigned short componentIndex;
2652
2653@@ -212,7 +214,7 @@
2654
2655 //-------------------------------------------------------------------------------------------------
2656
2657-void DspCircuit::DisconnectComponent( std::string component )
2658+void DspCircuit::DisconnectComponent( std::string const& component )
2659 {
2660 unsigned short componentIndex;
2661
2662@@ -228,38 +230,58 @@
2663
2664 //-------------------------------------------------------------------------------------------------
2665
2666-bool DspCircuit::AddInput( std::string inputName )
2667+bool DspCircuit::AddInput( std::string const& inputName )
2668 {
2669 PauseAutoTick();
2670 bool result = AddInput_( inputName );
2671 ResumeAutoTick();
2672-
2673 return result;
2674 }
2675
2676 //-------------------------------------------------------------------------------------------------
2677
2678-bool DspCircuit::AddOutput( std::string outputName )
2679+bool DspCircuit::AddOutput( std::string const& outputName )
2680 {
2681 PauseAutoTick();
2682 bool result = AddOutput_( outputName );
2683 ResumeAutoTick();
2684-
2685 return result;
2686 }
2687
2688 //-------------------------------------------------------------------------------------------------
2689
2690-void DspCircuit::RemoveInputs()
2691-{
2692- RemoveInputs_();
2693-}
2694-
2695-//-------------------------------------------------------------------------------------------------
2696-
2697-void DspCircuit::RemoveOutputs()
2698-{
2699- RemoveOutputs_();
2700+void DspCircuit::RemoveInput()
2701+{
2702+ PauseAutoTick();
2703+ RemoveInput_();
2704+ ResumeAutoTick();
2705+}
2706+
2707+//-------------------------------------------------------------------------------------------------
2708+
2709+void DspCircuit::RemoveOutput()
2710+{
2711+ PauseAutoTick();
2712+ RemoveOutput_();
2713+ ResumeAutoTick();
2714+}
2715+
2716+//-------------------------------------------------------------------------------------------------
2717+
2718+void DspCircuit::RemoveAllInputs()
2719+{
2720+ PauseAutoTick();
2721+ RemoveAllInputs_();
2722+ ResumeAutoTick();
2723+}
2724+
2725+//-------------------------------------------------------------------------------------------------
2726+
2727+void DspCircuit::RemoveAllOutputs()
2728+{
2729+ PauseAutoTick();
2730+ RemoveAllOutputs_();
2731+ ResumeAutoTick();
2732 }
2733
2734 //=================================================================================================
2735@@ -334,7 +356,7 @@
2736
2737 //=================================================================================================
2738
2739-bool DspCircuit::_FindComponent( DspComponent* component, unsigned short& returnIndex ) const
2740+bool DspCircuit::_FindComponent( DspComponent const* component, unsigned short& returnIndex ) const
2741 {
2742 for( unsigned short i = 0; i < _components.size(); i++ )
2743 {
2744@@ -350,14 +372,14 @@
2745
2746 //-------------------------------------------------------------------------------------------------
2747
2748-bool DspCircuit::_FindComponent( DspComponent& component, unsigned short& returnIndex ) const
2749+bool DspCircuit::_FindComponent( DspComponent const& component, unsigned short& returnIndex ) const
2750 {
2751 return _FindComponent( &component, returnIndex );
2752 }
2753
2754 //-------------------------------------------------------------------------------------------------
2755
2756-bool DspCircuit::_FindComponent( std::string componentName, unsigned short& returnIndex ) const
2757+bool DspCircuit::_FindComponent( std::string const& componentName, unsigned short& returnIndex ) const
2758 {
2759 for( unsigned short i = 0; i < _components.size(); i++ )
2760 {
2761@@ -389,7 +411,7 @@
2762 void DspCircuit::_DisconnectComponent( unsigned short componentIndex )
2763 {
2764 // remove component from _inputComponents and _inputWires
2765- _components[ componentIndex ]->DisconnectInputs();
2766+ _components[ componentIndex ]->DisconnectAllInputs();
2767
2768 // remove component from _inToInWires
2769 DspWire* wire;
2770@@ -427,12 +449,7 @@
2771 // setting a component's parent to NULL (above) calls _RemoveComponent (hence the following code will run)
2772 else if( _components.size() != 0 )
2773 {
2774- for( unsigned short i = componentIndex; i < _components.size() - 1; i++ )
2775- {
2776- _components[i] = _components[i + 1]; // shift all lower elements up
2777- }
2778-
2779- _components.pop_back(); // remove end item
2780+ _components.erase( _components.begin() + componentIndex );
2781 }
2782 }
2783
2784
2785=== modified file 'src/DspCircuitThread.cpp'
2786--- src/DspCircuitThread.cpp 2014-01-25 09:05:16 +0000
2787+++ src/DspCircuitThread.cpp 2014-06-16 15:43:30 +0000
2788@@ -1,6 +1,6 @@
2789 /************************************************************************
2790 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2791-Copyright (c) 2012-2013 Marcus Tomlinson
2792+Copyright (c) 2012-2014 Marcus Tomlinson
2793
2794 This file is part of DSPatch.
2795
2796@@ -44,7 +44,7 @@
2797
2798 //=================================================================================================
2799
2800-void DspCircuitThread::Initialise( std::vector< DspComponent* >* components, unsigned short threadNo )
2801+void DspCircuitThread::Initialise( std::vector< DspComponent* >* components, unsigned short threadNo )
2802 {
2803 _components = components;
2804 _threadNo = threadNo;
2805
2806=== modified file 'src/DspComponent.cpp'
2807--- src/DspComponent.cpp 2014-01-25 09:05:16 +0000
2808+++ src/DspComponent.cpp 2014-06-16 15:43:30 +0000
2809@@ -1,6 +1,6 @@
2810 /************************************************************************
2811 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
2812-Copyright (c) 2012-2013 Marcus Tomlinson
2813+Copyright (c) 2012-2014 Marcus Tomlinson
2814
2815 This file is part of DSPatch.
2816
2817@@ -37,7 +37,9 @@
2818 _componentName( "" ),
2819 _isAutoTickRunning( false ),
2820 _isAutoTickPaused( false ),
2821- _hasTicked( false )
2822+ _hasTicked( false ),
2823+ _callback( NULL ),
2824+ _userData( NULL )
2825 {
2826 _componentThread.Initialise( this );
2827 }
2828@@ -53,12 +55,22 @@
2829
2830 StopAutoTick();
2831 _SetBufferCount( 0 );
2832- DisconnectInputs();
2833+ DisconnectAllInputs();
2834 }
2835
2836 //=================================================================================================
2837
2838-void DspComponent::SetComponentName( std::string componentName )
2839+void DspComponent::SetCallback( Callback_t const& callback, void* userData )
2840+{
2841+ PauseAutoTick();
2842+ _callback = callback;
2843+ _userData = userData;
2844+ ResumeAutoTick();
2845+}
2846+
2847+//-------------------------------------------------------------------------------------------------
2848+
2849+void DspComponent::SetComponentName( std::string const& componentName )
2850 {
2851 _componentName = componentName;
2852 }
2853@@ -92,19 +104,23 @@
2854
2855 //-------------------------------------------------------------------------------------------------
2856
2857-void DspComponent::DisconnectInput( std::string inputName )
2858+void DspComponent::DisconnectInput( std::string const& inputName )
2859 {
2860 unsigned short inputIndex;
2861
2862+ PauseAutoTick();
2863+
2864 if( _FindInput( inputName, inputIndex ) )
2865 {
2866 DisconnectInput( inputIndex );
2867 }
2868+
2869+ ResumeAutoTick();
2870 }
2871
2872 //-------------------------------------------------------------------------------------------------
2873
2874-void DspComponent::DisconnectInput( DspComponent* inputComponent )
2875+void DspComponent::DisconnectInput( DspComponent const* inputComponent )
2876 {
2877 PauseAutoTick();
2878
2879@@ -123,7 +139,7 @@
2880
2881 //-------------------------------------------------------------------------------------------------
2882
2883-void DspComponent::DisconnectInputs()
2884+void DspComponent::DisconnectAllInputs()
2885 {
2886 PauseAutoTick();
2887 _inputWires.RemoveAllWires();
2888@@ -132,16 +148,115 @@
2889
2890 //-------------------------------------------------------------------------------------------------
2891
2892-unsigned short DspComponent::GetInputCount() const
2893-{
2894- return _inputBus.GetSignalCount();
2895-}
2896-
2897-//-------------------------------------------------------------------------------------------------
2898-
2899-unsigned short DspComponent::GetOutputCount() const
2900-{
2901- return _outputBus.GetSignalCount();
2902+unsigned short DspComponent::GetInputCount()
2903+{
2904+ PauseAutoTick();
2905+ unsigned short inputCount = GetInputCount_();
2906+ ResumeAutoTick();
2907+ return inputCount;
2908+}
2909+
2910+//-------------------------------------------------------------------------------------------------
2911+
2912+unsigned short DspComponent::GetOutputCount()
2913+{
2914+ PauseAutoTick();
2915+ unsigned short outputCount = GetOutputCount_();
2916+ ResumeAutoTick();
2917+ return outputCount;
2918+}
2919+
2920+//-------------------------------------------------------------------------------------------------
2921+
2922+unsigned short DspComponent::GetParameterCount()
2923+{
2924+ PauseAutoTick();
2925+ unsigned short parameterCount = GetParameterCount_();
2926+ ResumeAutoTick();
2927+ return parameterCount;
2928+}
2929+
2930+//-------------------------------------------------------------------------------------------------
2931+
2932+std::string DspComponent::GetInputName( unsigned short index )
2933+{
2934+ std::string inputName;
2935+
2936+ PauseAutoTick();
2937+
2938+ if( index < _inputBus.GetSignalCount() )
2939+ {
2940+ inputName = _inputBus.GetSignal( index )->GetSignalName();
2941+ }
2942+ inputName = "";
2943+
2944+ ResumeAutoTick();
2945+ return inputName;
2946+}
2947+
2948+//-------------------------------------------------------------------------------------------------
2949+
2950+std::string DspComponent::GetOutputName( unsigned short index )
2951+{
2952+ std::string outputName;
2953+
2954+ PauseAutoTick();
2955+
2956+ if( index < _outputBus.GetSignalCount() )
2957+ {
2958+ outputName = _outputBus.GetSignal( index )->GetSignalName();
2959+ }
2960+ outputName = "";
2961+
2962+ ResumeAutoTick();
2963+ return outputName;
2964+}
2965+
2966+//-------------------------------------------------------------------------------------------------
2967+
2968+std::string DspComponent::GetParameterName( unsigned short index )
2969+{
2970+ std::string parameterName;
2971+
2972+ PauseAutoTick();
2973+
2974+ if( index < _parameters.size() )
2975+ {
2976+ std::map< std::string, DspParameter >::const_iterator it = _parameters.begin();
2977+ std::advance( it, index );
2978+ parameterName = it->first;
2979+ }
2980+ parameterName = "";
2981+
2982+ ResumeAutoTick();
2983+ return parameterName;
2984+}
2985+
2986+//-------------------------------------------------------------------------------------------------
2987+
2988+bool DspComponent::GetParameter( std::string const& paramName, DspParameter& param )
2989+{
2990+ bool result = false;
2991+ PauseAutoTick();
2992+
2993+ DspParameter const* paramPtr = GetParameter_( paramName );
2994+ if( paramPtr )
2995+ {
2996+ result = param.SetParam( *paramPtr );
2997+ }
2998+
2999+ ResumeAutoTick();
3000+ return result;
3001+}
3002+
3003+//-------------------------------------------------------------------------------------------------
3004+
3005+bool DspComponent::SetParameter( std::string const& paramName, DspParameter const& param )
3006+{
3007+ PauseAutoTick();
3008+ bool result = ParameterUpdating_( paramName, param );
3009+ ResumeAutoTick();
3010+ return result;
3011 }
3012
3013 //-------------------------------------------------------------------------------------------------
3014@@ -285,62 +400,197 @@
3015 }
3016 }
3017
3018-//-------------------------------------------------------------------------------------------------
3019-
3020-DspSignal* DspComponent::_GetOutputSignal( unsigned short outputIndex )
3021-{
3022- return _outputBus.GetSignal( outputIndex );
3023-}
3024-
3025-//-------------------------------------------------------------------------------------------------
3026-
3027-DspSignal* DspComponent::_GetOutputSignal( unsigned short outputIndex, unsigned short threadIndex )
3028-{
3029- return _outputBuses[threadIndex].GetSignal( outputIndex );
3030-}
3031-
3032 //=================================================================================================
3033
3034-bool DspComponent::AddInput_( std::string inputName )
3035-{
3036- for( unsigned short i = 0; i < _inputBuses.size(); i++ )
3037- {
3038- _inputBuses[i].AddSignal( inputName );
3039- }
3040- return _inputBus.AddSignal( inputName );
3041-}
3042-
3043-//-------------------------------------------------------------------------------------------------
3044-
3045-bool DspComponent::AddOutput_( std::string outputName )
3046-{
3047- for( unsigned short i = 0; i < _outputBuses.size(); i++ )
3048- {
3049- _outputBuses[i].AddSignal( outputName );
3050- }
3051- return _outputBus.AddSignal( outputName );
3052-}
3053-
3054-//-------------------------------------------------------------------------------------------------
3055-
3056-void DspComponent::RemoveInputs_()
3057-{
3058- for( unsigned short i = 0; i < _inputBuses.size(); i++ )
3059- {
3060- _inputBuses[i].RemoveAllSignals();
3061- }
3062- return _inputBus.RemoveAllSignals();
3063-}
3064-
3065-//-------------------------------------------------------------------------------------------------
3066-
3067-void DspComponent::RemoveOutputs_()
3068-{
3069- for( unsigned short i = 0; i < _outputBuses.size(); i++ )
3070- {
3071- _outputBuses[i].RemoveAllSignals();
3072- }
3073- return _outputBus.RemoveAllSignals();
3074+bool DspComponent::AddInput_( std::string const& inputName )
3075+{
3076+ for( unsigned short i = 0; i < _inputBuses.size(); i++ )
3077+ {
3078+ _inputBuses[i]._AddSignal( inputName );
3079+ }
3080+ if( _inputBus._AddSignal( inputName ) )
3081+ {
3082+ if( _callback )
3083+ {
3084+ _callback( this, InputAdded, _inputBus.GetSignalCount() - 1, _userData );
3085+ }
3086+ return true;
3087+ }
3088+ return false;
3089+}
3090+
3091+//-------------------------------------------------------------------------------------------------
3092+
3093+bool DspComponent::AddOutput_( std::string const& outputName )
3094+{
3095+ for( unsigned short i = 0; i < _outputBuses.size(); i++ )
3096+ {
3097+ _outputBuses[i]._AddSignal( outputName );
3098+ }
3099+ if( _outputBus._AddSignal( outputName ) )
3100+ {
3101+ if( _callback )
3102+ {
3103+ _callback( this, OutputAdded, _outputBus.GetSignalCount() - 1, _userData );
3104+ }
3105+ return true;
3106+ }
3107+ return false;
3108+}
3109+
3110+//-------------------------------------------------------------------------------------------------
3111+
3112+bool DspComponent::AddParameter_( std::string const& paramName, DspParameter const& param )
3113+{
3114+ if( _parameters.find( paramName ) == _parameters.end() )
3115+ {
3116+ _parameters.insert( std::make_pair( paramName, param ) );
3117+ if( _callback )
3118+ {
3119+ _callback( this, ParameterAdded, _parameters.size() - 1, _userData );
3120+ }
3121+ return true;
3122+ }
3123+ return false;
3124+}
3125+
3126+//-------------------------------------------------------------------------------------------------
3127+
3128+bool DspComponent::RemoveInput_()
3129+{
3130+ if( _inputBus._RemoveSignal() )
3131+ {
3132+ if( _callback )
3133+ {
3134+ _callback( this, InputRemoved, _inputBus.GetSignalCount(), _userData );
3135+ }
3136+ return true;
3137+ }
3138+ return false;
3139+}
3140+
3141+//-------------------------------------------------------------------------------------------------
3142+
3143+bool DspComponent::RemoveOutput_()
3144+{
3145+ if( _outputBus._RemoveSignal() )
3146+ {
3147+ if( _callback )
3148+ {
3149+ _callback( this, OutputRemoved, _outputBus.GetSignalCount(), _userData );
3150+ }
3151+ return true;
3152+ }
3153+ return false;
3154+}
3155+
3156+//-------------------------------------------------------------------------------------------------
3157+
3158+bool DspComponent::RemoveParameter_()
3159+{
3160+ if( !_parameters.empty() )
3161+ {
3162+ _parameters.erase( _parameters.rbegin()->first );
3163+ if( _callback )
3164+ {
3165+ _callback( this, ParameterRemoved, _parameters.size(), _userData );
3166+ }
3167+ return true;
3168+ }
3169+ return false;
3170+}
3171+
3172+//-------------------------------------------------------------------------------------------------
3173+
3174+void DspComponent::RemoveAllInputs_()
3175+{
3176+ for( unsigned short i = 0; i < _inputBuses.size(); i++ )
3177+ {
3178+ _inputBuses[i]._RemoveAllSignals();
3179+ }
3180+ _inputBus._RemoveAllSignals();
3181+ if( _callback )
3182+ {
3183+ _callback( this, InputRemoved, -1, _userData );
3184+ }
3185+}
3186+
3187+//-------------------------------------------------------------------------------------------------
3188+
3189+void DspComponent::RemoveAllOutputs_()
3190+{
3191+ for( unsigned short i = 0; i < _outputBuses.size(); i++ )
3192+ {
3193+ _outputBuses[i]._RemoveAllSignals();
3194+ }
3195+ _outputBus._RemoveAllSignals();
3196+ if( _callback )
3197+ {
3198+ _callback( this, OutputRemoved, -1, _userData );
3199+ }
3200+}
3201+
3202+//-------------------------------------------------------------------------------------------------
3203+
3204+void DspComponent::RemoveAllParameters_()
3205+{
3206+ _parameters.clear();
3207+ if( _callback )
3208+ {
3209+ _callback( this, ParameterRemoved, -1, _userData );
3210+ }
3211+}
3212+
3213+//-------------------------------------------------------------------------------------------------
3214+
3215+unsigned short DspComponent::GetInputCount_()
3216+{
3217+ return _inputBus.GetSignalCount();
3218+}
3219+
3220+//-------------------------------------------------------------------------------------------------
3221+
3222+unsigned short DspComponent::GetOutputCount_()
3223+{
3224+ return _outputBus.GetSignalCount();
3225+}
3226+
3227+//-------------------------------------------------------------------------------------------------
3228+
3229+unsigned short DspComponent::GetParameterCount_()
3230+{
3231+ return _parameters.size();
3232+}
3233+
3234+//-------------------------------------------------------------------------------------------------
3235+
3236+DspParameter const* DspComponent::GetParameter_( std::string const& paramName ) const
3237+{
3238+ std::map< std::string, DspParameter >::const_iterator it = _parameters.find( paramName );
3239+ if( it != _parameters.end() )
3240+ {
3241+ return &it->second;
3242+ }
3243+ return NULL;
3244+}
3245+
3246+//-------------------------------------------------------------------------------------------------
3247+
3248+bool DspComponent::SetParameter_( std::string const& paramName, DspParameter const& param )
3249+{
3250+ std::map< std::string, DspParameter >::iterator it = _parameters.find( paramName );
3251+ if( it != _parameters.end() )
3252+ {
3253+ if( it->second.SetParam( param ) )
3254+ {
3255+ if( _callback )
3256+ {
3257+ _callback( this, ParameterUpdated, std::distance( _parameters.begin(), _parameters.find( paramName ) ), _userData );
3258+ }
3259+ return true;
3260+ }
3261+ }
3262+ return false;
3263 }
3264
3265 //=================================================================================================
3266@@ -373,7 +623,7 @@
3267
3268 //-------------------------------------------------------------------------------------------------
3269
3270-bool DspComponent::_FindInput( std::string signalName, unsigned short& returnIndex ) const
3271+bool DspComponent::_FindInput( std::string const& signalName, unsigned short& returnIndex ) const
3272 {
3273 return _inputBus.FindSignal( signalName, returnIndex );
3274 }
3275@@ -393,7 +643,7 @@
3276
3277 //-------------------------------------------------------------------------------------------------
3278
3279-bool DspComponent::_FindOutput( std::string signalName, unsigned short& returnIndex ) const
3280+bool DspComponent::_FindOutput( std::string const& signalName, unsigned short& returnIndex ) const
3281 {
3282 return _outputBus.FindSignal( signalName, returnIndex );
3283 }
3284@@ -446,12 +696,12 @@
3285
3286 for( unsigned short j = 0; j < _inputBus.GetSignalCount(); j++ )
3287 {
3288- _inputBuses[i].AddSignal( _inputBus.GetSignal( j )->GetSignalName() );
3289+ _inputBuses[i]._AddSignal( _inputBus.GetSignal( j )->GetSignalName() );
3290 }
3291
3292 for( unsigned short j = 0; j < _outputBus.GetSignalCount(); j++ )
3293 {
3294- _outputBuses[i].AddSignal( _outputBus.GetSignal( j )->GetSignalName() );
3295+ _outputBuses[i]._AddSignal( _outputBus.GetSignal( j )->GetSignalName() );
3296 }
3297 }
3298
3299@@ -517,20 +767,34 @@
3300
3301 //-------------------------------------------------------------------------------------------------
3302
3303-bool DspComponent::_SetInputSignal( unsigned short inputIndex, const DspSignal* newSignal )
3304+bool DspComponent::_SetInputSignal( unsigned short inputIndex, DspSignal const* newSignal )
3305 {
3306 return _inputBus.SetSignal( inputIndex, newSignal );
3307 }
3308
3309 //-------------------------------------------------------------------------------------------------
3310
3311-bool DspComponent::_SetInputSignal( unsigned short inputIndex, unsigned short threadIndex, const DspSignal* newSignal )
3312+bool DspComponent::_SetInputSignal( unsigned short inputIndex, unsigned short threadIndex, DspSignal const* newSignal )
3313 {
3314 return _inputBuses[threadIndex].SetSignal( inputIndex, newSignal );
3315 }
3316
3317 //-------------------------------------------------------------------------------------------------
3318
3319+DspSignal* DspComponent::_GetOutputSignal( unsigned short outputIndex )
3320+{
3321+ return _outputBus.GetSignal( outputIndex );
3322+}
3323+
3324+//-------------------------------------------------------------------------------------------------
3325+
3326+DspSignal* DspComponent::_GetOutputSignal( unsigned short outputIndex, unsigned short threadIndex )
3327+{
3328+ return _outputBuses[threadIndex].GetSignal( outputIndex );
3329+}
3330+
3331+//-------------------------------------------------------------------------------------------------
3332+
3333 void DspComponent::_WaitForRelease( unsigned short threadNo )
3334 {
3335 _releaseMutexes[threadNo].Lock();
3336
3337=== modified file 'src/DspComponentThread.cpp'
3338--- src/DspComponentThread.cpp 2014-01-25 09:05:16 +0000
3339+++ src/DspComponentThread.cpp 2014-06-16 15:43:30 +0000
3340@@ -1,6 +1,6 @@
3341 /************************************************************************
3342 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3343-Copyright (c) 2012-2013 Marcus Tomlinson
3344+Copyright (c) 2012-2014 Marcus Tomlinson
3345
3346 This file is part of DSPatch.
3347
3348
3349=== added file 'src/DspParameter.cpp'
3350--- src/DspParameter.cpp 1970-01-01 00:00:00 +0000
3351+++ src/DspParameter.cpp 2014-06-16 15:43:30 +0000
3352@@ -0,0 +1,462 @@
3353+/************************************************************************
3354+DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3355+Copyright (c) 2012-2014 Marcus Tomlinson
3356+
3357+This file is part of DSPatch.
3358+
3359+GNU Lesser General Public License Usage
3360+This file may be used under the terms of the GNU Lesser General Public
3361+License version 3.0 as published by the Free Software Foundation and
3362+appearing in the file LGPLv3.txt included in the packaging of this
3363+file. Please review the following information to ensure the GNU Lesser
3364+General Public License version 3.0 requirements will be met:
3365+http://www.gnu.org/copyleft/lgpl.html.
3366+
3367+Other Usage
3368+Alternatively, this file may be used in accordance with the terms and
3369+conditions contained in a signed written agreement between you and
3370+Marcus Tomlinson.
3371+
3372+DSPatch is distributed in the hope that it will be useful,
3373+but WITHOUT ANY WARRANTY; without even the implied warranty of
3374+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
3375+************************************************************************/
3376+
3377+#include <dspatch/DspParameter.h>
3378+
3379+//=================================================================================================
3380+
3381+DspParameter::DspParameter()
3382+ : _type( Null ),
3383+ _isSet( false ),
3384+ _isRangeSet( false ) {}
3385+
3386+//-------------------------------------------------------------------------------------------------
3387+
3388+DspParameter::DspParameter( ParamType const& type )
3389+ : _type( type ),
3390+ _isSet( false ),
3391+ _isRangeSet( false ) {}
3392+
3393+//-------------------------------------------------------------------------------------------------
3394+
3395+DspParameter::DspParameter( ParamType const& type, int const& initValue, std::pair<int, int> const& valueRange )
3396+: _type( type ),
3397+ _isSet( false ),
3398+ _isRangeSet( false )
3399+{
3400+ if( type == Bool )
3401+ {
3402+ if( !SetBool( initValue != 0 ) )
3403+ {
3404+ _type = Null;
3405+ }
3406+ }
3407+ else if( type == Float )
3408+ {
3409+ if( !SetFloatRange( std::make_pair( ( float ) valueRange.first, ( float ) valueRange.second ) ) || !SetFloat( ( float ) initValue ) )
3410+ {
3411+ _type = Null;
3412+ }
3413+ }
3414+ else
3415+ {
3416+ if( !SetIntRange( valueRange ) || !SetInt( initValue ) )
3417+ {
3418+ _type = Null;
3419+ }
3420+ }
3421+}
3422+
3423+//-------------------------------------------------------------------------------------------------
3424+
3425+DspParameter::DspParameter( ParamType const& type, float const& initValue, std::pair<float, float> const& valueRange )
3426+ : _type( type ),
3427+ _isSet( false ),
3428+ _isRangeSet( false )
3429+{
3430+ if( !SetFloatRange( valueRange ) || !SetFloat( initValue ) )
3431+ {
3432+ _type = Null;
3433+ }
3434+}
3435+
3436+//-------------------------------------------------------------------------------------------------
3437+
3438+DspParameter::DspParameter( ParamType const& type, std::string const& initValue )
3439+ : _type( type ),
3440+ _isSet( false ),
3441+ _isRangeSet( false )
3442+{
3443+ if( !SetString( initValue ) )
3444+ {
3445+ _type = Null;
3446+ }
3447+}
3448+
3449+//-------------------------------------------------------------------------------------------------
3450+
3451+DspParameter::DspParameter( ParamType const& type, std::vector< std::string > const& initValue )
3452+ : _type( type ),
3453+ _isSet( false ),
3454+ _isRangeSet( false )
3455+{
3456+ if( !SetList( initValue ) )
3457+ {
3458+ _type = Null;
3459+ }
3460+}
3461+
3462+//=================================================================================================
3463+
3464+DspParameter::ParamType DspParameter::Type() const
3465+{
3466+ return _type;
3467+}
3468+
3469+//-------------------------------------------------------------------------------------------------
3470+
3471+bool DspParameter::IsSet() const
3472+{
3473+ return _isSet;
3474+}
3475+
3476+//-------------------------------------------------------------------------------------------------
3477+
3478+bool const* DspParameter::GetBool() const
3479+{
3480+ if( !_isSet )
3481+ {
3482+ return NULL;
3483+ }
3484+
3485+ if( _type == Bool )
3486+ {
3487+ return &_boolValue;
3488+ }
3489+
3490+ return NULL;
3491+}
3492+
3493+//-------------------------------------------------------------------------------------------------
3494+
3495+int const* DspParameter::GetInt() const
3496+{
3497+ if( !_isSet )
3498+ {
3499+ return NULL;
3500+ }
3501+
3502+ if( _type == Int || _type == List )
3503+ {
3504+ return &_intValue;
3505+ }
3506+
3507+ return NULL;
3508+}
3509+
3510+//-------------------------------------------------------------------------------------------------
3511+
3512+std::pair<int, int> const* DspParameter::GetIntRange() const
3513+{
3514+ if( !_isRangeSet )
3515+ {
3516+ return NULL;
3517+ }
3518+
3519+ if( _type == Int || _type == List )
3520+ {
3521+ return &_intRange;
3522+ }
3523+
3524+ return NULL;
3525+}
3526+
3527+//-------------------------------------------------------------------------------------------------
3528+
3529+float const* DspParameter::GetFloat() const
3530+{
3531+ if( !_isSet )
3532+ {
3533+ return NULL;
3534+ }
3535+
3536+ if( _type == Float )
3537+ {
3538+ return &_floatValue;
3539+ }
3540+
3541+ return NULL;
3542+}
3543+
3544+//-------------------------------------------------------------------------------------------------
3545+
3546+std::pair<float, float> const* DspParameter::GetFloatRange() const
3547+{
3548+ if( !_isRangeSet )
3549+ {
3550+ return NULL;
3551+ }
3552+
3553+ if( _type == Float )
3554+ {
3555+ return &_floatRange;
3556+ }
3557+
3558+ return NULL;
3559+}
3560+
3561+//-------------------------------------------------------------------------------------------------
3562+
3563+std::string const* DspParameter::GetString() const
3564+{
3565+ if( !_isSet )
3566+ {
3567+ return NULL;
3568+ }
3569+
3570+ if( _type == String || _type == FilePath )
3571+ {
3572+ return &_stringValue;
3573+ }
3574+ else if( _type == List )
3575+ {
3576+ return &_listValue[_intValue];
3577+ }
3578+
3579+ return NULL;
3580+}
3581+
3582+//-------------------------------------------------------------------------------------------------
3583+
3584+std::vector< std::string > const* DspParameter::GetList() const
3585+{
3586+ if( !_isSet )
3587+ {
3588+ return NULL;
3589+ }
3590+
3591+ if( _type == List )
3592+ {
3593+ return &_listValue;
3594+ }
3595+
3596+ return NULL;
3597+}
3598+
3599+//-------------------------------------------------------------------------------------------------
3600+
3601+bool DspParameter::SetBool( bool const& value )
3602+{
3603+ if( _type == Bool )
3604+ {
3605+ _boolValue = value;
3606+ _isSet = true;
3607+ return true;
3608+ }
3609+
3610+ return false;
3611+}
3612+
3613+//-------------------------------------------------------------------------------------------------
3614+
3615+bool DspParameter::SetInt( int const& value )
3616+{
3617+ if( _type == Int || _type == List )
3618+ {
3619+ if( _isRangeSet )
3620+ {
3621+ _intValue = value < _intRange.first ? _intRange.first : value;
3622+ _intValue = value > _intRange.second ? _intRange.second : value;
3623+ }
3624+ else
3625+ {
3626+ _intValue = value;
3627+ }
3628+ _isSet = true;
3629+ return true;
3630+ }
3631+
3632+ return false;
3633+}
3634+
3635+//-------------------------------------------------------------------------------------------------
3636+
3637+bool DspParameter::SetIntRange( std::pair<int, int> const& intRange )
3638+{
3639+ if( _type == Int )
3640+ {
3641+ _intRange = intRange;
3642+
3643+ if( intRange.first == intRange.second && intRange.first == -1 )
3644+ {
3645+ _isRangeSet = false;
3646+ }
3647+ else
3648+ {
3649+ _intValue = _intValue < intRange.first ? intRange.first : _intValue;
3650+ _intValue = _intValue > intRange.second ? intRange.second : _intValue;
3651+ _isRangeSet = true;
3652+ }
3653+ return true;
3654+ }
3655+
3656+ return false;
3657+}
3658+
3659+//-------------------------------------------------------------------------------------------------
3660+
3661+bool DspParameter::SetFloat( float const& value )
3662+{
3663+ if( _type == Float )
3664+ {
3665+ if( _isRangeSet )
3666+ {
3667+ _floatValue = value < _floatRange.first ? _floatRange.first : value;
3668+ _floatValue = value > _floatRange.second ? _floatRange.second : value;
3669+ }
3670+ else
3671+ {
3672+ _floatValue = value;
3673+ }
3674+ _isSet = true;
3675+ return true;
3676+ }
3677+
3678+ return false;
3679+}
3680+
3681+//-------------------------------------------------------------------------------------------------
3682+
3683+bool DspParameter::SetFloatRange( std::pair<float, float> const& floatRange )
3684+{
3685+ if( _type == Float )
3686+ {
3687+ _floatRange = floatRange;
3688+
3689+ if( floatRange.first == floatRange.second && floatRange.first == -1 )
3690+ {
3691+ _isRangeSet = false;
3692+ }
3693+ else
3694+ {
3695+ _floatValue = _floatValue < floatRange.first ? floatRange.first : _floatValue;
3696+ _floatValue = _floatValue > floatRange.second ? floatRange.second : _floatValue;
3697+ _isRangeSet = true;
3698+ }
3699+ return true;
3700+ }
3701+
3702+ return false;
3703+}
3704+
3705+//-------------------------------------------------------------------------------------------------
3706+
3707+bool DspParameter::SetString( std::string const& value )
3708+{
3709+ if( _type == String || _type == FilePath )
3710+ {
3711+ _stringValue = value;
3712+ _isSet = true;
3713+ return true;
3714+ }
3715+ else if( _type == List )
3716+ {
3717+ for( unsigned short i = 0; i < _listValue.size(); ++i )
3718+ {
3719+ if( _listValue[i] == value )
3720+ {
3721+ _intValue = i;
3722+ _isSet = true;
3723+ return true;
3724+ }
3725+ }
3726+ }
3727+
3728+ return false;
3729+}
3730+
3731+//-------------------------------------------------------------------------------------------------
3732+
3733+bool DspParameter::SetList( std::vector< std::string > const& value )
3734+{
3735+ if( _type == List )
3736+ {
3737+ _listValue = value;
3738+
3739+ _intRange.first = 0;
3740+ _intRange.second = value.size() - 1;
3741+ _isRangeSet = true;
3742+
3743+ _intValue = 0;
3744+ _isSet = true;
3745+ return true;
3746+ }
3747+
3748+ return false;
3749+}
3750+
3751+//-------------------------------------------------------------------------------------------------
3752+
3753+bool DspParameter::SetParam( DspParameter const& param )
3754+{
3755+ if( _type == Null )
3756+ {
3757+ _type = param.Type();
3758+ }
3759+
3760+ if( param.Type() == Bool )
3761+ {
3762+ if( param.GetBool() )
3763+ {
3764+ return SetBool( *param.GetBool() );
3765+ }
3766+ }
3767+ else if( param.Type() == Int )
3768+ {
3769+ if( param.GetIntRange() && param.GetInt() )
3770+ {
3771+ return SetIntRange( *param.GetIntRange() ) && SetInt( *param.GetInt() );
3772+ }
3773+ else if( param.GetInt() )
3774+ {
3775+ return SetInt( *param.GetInt() );
3776+ }
3777+ }
3778+ else if( param.Type() == Float )
3779+ {
3780+ if( param.GetFloatRange() && param.GetFloat() )
3781+ {
3782+ return SetFloatRange( *param.GetFloatRange() ) && SetFloat( *param.GetFloat() );
3783+ }
3784+ if( param.GetFloat() )
3785+ {
3786+ return SetFloat( *param.GetFloat() );
3787+ }
3788+ }
3789+ else if( param.Type() == String || param.Type() == FilePath )
3790+ {
3791+ if( param.GetString() )
3792+ {
3793+ return SetString( *param.GetString() );
3794+ }
3795+ }
3796+ else if( param.Type() == Trigger )
3797+ {
3798+ if( _type == Trigger )
3799+ {
3800+ return true;
3801+ }
3802+ }
3803+ else if( param.Type() == List )
3804+ {
3805+ if( param.GetList() )
3806+ {
3807+ return SetList( *param.GetList() );
3808+ }
3809+ }
3810+
3811+ return false;
3812+}
3813+
3814+//=================================================================================================
3815
3816=== modified file 'src/DspSignal.cpp'
3817--- src/DspSignal.cpp 2014-01-25 09:05:16 +0000
3818+++ src/DspSignal.cpp 2014-06-16 15:43:30 +0000
3819@@ -1,6 +1,6 @@
3820 /************************************************************************
3821 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3822-Copyright (c) 2012-2013 Marcus Tomlinson
3823+Copyright (c) 2012-2014 Marcus Tomlinson
3824
3825 This file is part of DSPatch.
3826
3827@@ -32,11 +32,11 @@
3828
3829 //-------------------------------------------------------------------------------------------------
3830
3831-DspSignal::~DspSignal() {};
3832+DspSignal::~DspSignal() {}
3833
3834 //=================================================================================================
3835
3836-bool DspSignal::SetSignal( const DspSignal* newSignal )
3837+bool DspSignal::SetSignal( DspSignal const* newSignal )
3838 {
3839 if( newSignal != NULL )
3840 {
3841
3842=== modified file 'src/DspSignalBus.cpp'
3843--- src/DspSignalBus.cpp 2014-01-25 09:05:16 +0000
3844+++ src/DspSignalBus.cpp 2014-06-16 15:43:30 +0000
3845@@ -1,6 +1,6 @@
3846 /************************************************************************
3847 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3848-Copyright (c) 2012-2013 Marcus Tomlinson
3849+Copyright (c) 2012-2014 Marcus Tomlinson
3850
3851 This file is part of DSPatch.
3852
3853@@ -26,29 +26,11 @@
3854
3855 //=================================================================================================
3856
3857-DspSignalBus::~DspSignalBus() {};
3858+DspSignalBus::~DspSignalBus() {}
3859
3860 //=================================================================================================
3861
3862-bool DspSignalBus::AddSignal( std::string signalName )
3863-{
3864- if( signalName != "" )
3865- {
3866- unsigned short signalIndex;
3867- if( FindSignal( signalName, signalIndex ) ) // if the name already exists
3868- {
3869- return false;
3870- }
3871- }
3872-
3873- _signals.push_back( DspSignal( signalName ) );
3874-
3875- return true;
3876-}
3877-
3878-//-------------------------------------------------------------------------------------------------
3879-
3880-bool DspSignalBus::SetSignal( unsigned short signalIndex, const DspSignal* newSignal )
3881+bool DspSignalBus::SetSignal( unsigned short signalIndex, DspSignal const* newSignal )
3882 {
3883 if( signalIndex < _signals.size() && newSignal != NULL )
3884 {
3885@@ -62,7 +44,7 @@
3886
3887 //-------------------------------------------------------------------------------------------------
3888
3889-bool DspSignalBus::SetSignal( std::string signalName, const DspSignal* newSignal )
3890+bool DspSignalBus::SetSignal( std::string const& signalName, DspSignal const* newSignal )
3891 {
3892 unsigned short signalIndex;
3893
3894@@ -92,7 +74,7 @@
3895
3896 //-------------------------------------------------------------------------------------------------
3897
3898-DspSignal* DspSignalBus::GetSignal( std::string signalName )
3899+DspSignal* DspSignalBus::GetSignal( std::string const& signalName )
3900 {
3901 unsigned short signalIndex;
3902
3903@@ -108,11 +90,16 @@
3904
3905 //-------------------------------------------------------------------------------------------------
3906
3907-bool DspSignalBus::FindSignal( std::string signalName, unsigned short& returnIndex ) const
3908+bool DspSignalBus::FindSignal( std::string const& signalName, unsigned short& returnIndex ) const
3909 {
3910+ if( signalName == "" )
3911+ {
3912+ return false;
3913+ }
3914+
3915 for( unsigned short i = 0; i < _signals.size(); i++ )
3916 {
3917- if( signalName != "" && _signals[i].GetSignalName() == signalName )
3918+ if( _signals[i].GetSignalName() == signalName )
3919 {
3920 returnIndex = i;
3921 return true;
3922@@ -144,13 +131,6 @@
3923
3924 //-------------------------------------------------------------------------------------------------
3925
3926-void DspSignalBus::RemoveAllSignals()
3927-{
3928- _signals.clear();
3929-}
3930-
3931-//-------------------------------------------------------------------------------------------------
3932-
3933 void DspSignalBus::ClearValue( unsigned short signalIndex )
3934 {
3935 if( signalIndex < _signals.size() )
3936@@ -161,7 +141,7 @@
3937
3938 //-------------------------------------------------------------------------------------------------
3939
3940-void DspSignalBus::ClearValue( std::string signalName )
3941+void DspSignalBus::ClearValue( std::string const& signalName )
3942 {
3943 unsigned short signalIndex;
3944
3945@@ -182,3 +162,40 @@
3946 }
3947
3948 //=================================================================================================
3949+
3950+bool DspSignalBus::_AddSignal( std::string const& signalName )
3951+{
3952+ if( signalName != "" )
3953+ {
3954+ unsigned short signalIndex;
3955+ if( FindSignal( signalName, signalIndex ) ) // if the name already exists
3956+ {
3957+ return false;
3958+ }
3959+ }
3960+
3961+ _signals.push_back( DspSignal( signalName ) );
3962+
3963+ return true;
3964+}
3965+
3966+//-------------------------------------------------------------------------------------------------
3967+
3968+bool DspSignalBus::_RemoveSignal()
3969+{
3970+ if( _signals.size() > 0 )
3971+ {
3972+ _signals.pop_back();
3973+ return true;
3974+ }
3975+ return false;
3976+}
3977+
3978+//-------------------------------------------------------------------------------------------------
3979+
3980+void DspSignalBus::_RemoveAllSignals()
3981+{
3982+ _signals.clear();
3983+}
3984+
3985+//=================================================================================================
3986
3987=== modified file 'src/DspWireBus.cpp'
3988--- src/DspWireBus.cpp 2014-01-25 09:05:16 +0000
3989+++ src/DspWireBus.cpp 2014-06-16 15:43:30 +0000
3990@@ -1,6 +1,6 @@
3991 /************************************************************************
3992 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3993-Copyright (c) 2012-2013 Marcus Tomlinson
3994+Copyright (c) 2012-2014 Marcus Tomlinson
3995
3996 This file is part of DSPatch.
3997
3998@@ -76,7 +76,7 @@
3999
4000 //-------------------------------------------------------------------------------------------------
4001
4002-bool DspWireBus::RemoveWire( DspComponent* linkedComponent, unsigned short fromSignalIndex, unsigned short toSignalIndex )
4003+bool DspWireBus::RemoveWire( DspComponent const* linkedComponent, unsigned short fromSignalIndex, unsigned short toSignalIndex )
4004 {
4005 for( unsigned short i = 0; i < _wires.size(); i++ )
4006 {
4007@@ -101,11 +101,7 @@
4008 return false;
4009 }
4010
4011- for( unsigned short j = wireIndex; j < ( _wires.size() - 1 ); j++ )
4012- {
4013- _wires[j] = _wires[j + 1]; // shift all other elements up
4014- }
4015- _wires.pop_back(); // remove end item
4016+ _wires.erase( _wires.begin() + wireIndex );
4017
4018 return true;
4019 }

Subscribers

People subscribed via source and target branches

to all changes: