ofxPDSP
Engine.h
1 
2 // Engine.h
3 // ofxPDSP
4 // Nicola Pisanti, MIT License, 2016 - 2018
5 
6 #ifndef OFX_PDSP_ENGINE_H_INCLUDED
7 #define OFX_PDSP_ENGINE_H_INCLUDED
8 
9 #include "ofMain.h"
10 #include "../DSP/pdspCore.h"
11 #include "../sequencer/SequencerSection.h"
12 #include "../sequencer/SequencerProcessor.h"
13 #include "../DSP/utility/OneBarTimeMs.h"
14 #include "../modules/oscillators/FMOperator.h"
15 #include "../DSP/utility/DBtoLin.h"
16 
17 #include "SerialOut.h"
18 #include "OscInput.h"
19 
20 #ifndef __ANDROID__
21 #include "helper/Controller.h"
22 #include "MidiIn.h"
23 #include "MidiOut.h"
24 #endif
25 
26 #ifdef TARGET_OF_IOS
27  #include "ofxiOSSoundStream.h"
28 #endif
29 
34 namespace pdsp{
35 
36 class Engine : public ofBaseSoundInput, public ofBaseSoundOutput{
37 
38 public:
39  Engine();
40  ~Engine();
41 
48  void setup(int sampleRate, int bufferSize, int nBuffers);
49 
53  void start();
54 
58  void stop();
59 
63  void close();
64 
70  void setChannels( int inputChannels, int outputChannels );
71 
75  std::vector<ofSoundDevice> listDevices();
76 
81  void setApi( ofSoundDevice::Api api );
82 
87  void setDeviceID(int deviceID);
88 
93  void setInputDeviceID(int deviceID);
94 
99  void setOutputDeviceID(int deviceID);
100 
101  [[deprecated("deprecated, handled automatically between construction and destruction")]]
102  void addOscInput( pdsp::osc::Input & oscInput );
103 
104 #ifndef __ANDROID__
105 
111  void addMidiController( pdsp::Controller & controller, pdsp::midi::Input & midiIn );
112 
113  [[deprecated("deprecated, handled automatically between construction and destruction")]]
114  void addMidiOut( pdsp::midi::Output & midiOut );
115 
116 #ifndef TARGET_OF_IOS
117  [[deprecated("deprecated, handled automatically between construction and destruction")]]
118  void addSerialOut( pdsp::serial::Output & serialOut );
119 #endif // TARGET_OF_IOS
120 #endif // __ANDROID__
121 
122  [[deprecated("deprecated, handled automatically between construction and destruction")]]
123  void addExternalOut( pdsp::ExtSequencer & externalOut );
124 
129  pdsp::Patchable& audio_out( int channel );
130 
135  pdsp::Patchable& audio_in( int channel );
136 
141 
142 
147 
152 
158  void test( bool testingActive, float testingDB=-12.0f );
159 
164  void setBackgroundAudio( bool active );
165 
169  void audioOut(ofSoundBuffer &outBuffer);
170  void audioIn (ofSoundBuffer &outBuffer);
171 
172  pdsp::SequencerProcessor & score; // this is an alias for the sequencer, legacy reasons
173 
178 private:
179 
180  void handleDisconnectedDevices();
181 
182  ofSoundStream inputStream;
183  ofSoundStream outputStream;
184  ofSoundDevice::Api api;
185 
186  bool inStreamActive;
187  bool outStreamActive;
188 
189  int inputID;
190  int outputID;
191 
192  int outputChannels;
193  int inputChannels;
194 
195  pdsp::Processor processor;
196  std::vector<pdsp::ExternalInput> inputs;
197 
198 #ifndef __ANDROID__
199  std::vector<pdsp::midi::Input*> midiIns;
200  std::vector<pdsp::Controller*> controllers;
201  std::vector<pdsp::midi::Input*> controllerLinkedMidis;
202  bool hasMidiIn;
203 #endif
204 
205  int state;
206 
207  static const int closedState = 0;
208  static const int stoppedState = 1;
209  static const int startedState = 2;
210 
211 
212  void onExit( ofEventArgs &args);
213 
214  pdsp::FMOperator testOscillator;
215  pdsp::Amp testAmp;
216  pdsp::OneBarTimeMs barTime;
217 
218  bool bBackgroundAudio;
219 
220 };
221 
222 }
223 
224 #endif // OFX_PDSP_ENGINE_H_INCLUDED
void close()
close everything. This is called automatically on exit and probably you should never use it...
Definition: Engine.cpp:293
Constantly outputs a control rate value that rapresent the time in milliseconds for one bar...
Definition: OneBarTimeMs.h:17
Definition: Engine.h:36
Definition: MidiIn.h:22
void setBackgroundAudio(bool active)
activate/deactivate background audio on ios, this function has to be called before the setup...
Definition: Engine.cpp:432
pdsp::Patchable & out_bar_ms()
returns a module that outputs the time of a musical bar in milliseconds
Definition: Engine.cpp:428
void addMidiController(pdsp::Controller &controller, pdsp::midi::Input &midiIn)
adds a midi controller and a relative midi input to the engine, making them active.
Definition: Engine.cpp:378
FM operator based on a wavetable sine.
Definition: FMOperator.h:23
void stop()
stop the audio streams.
Definition: Engine.cpp:277
void setChannels(int inputChannels, int outputChannels)
sets the number of inputs and output channels. If not called, the standard is 0 input channels and 2 ...
Definition: Engine.cpp:111
pdsp::Patchable & audio_out(int channel)
returns a Patchable object that represent the audio out of the system. Patch your module to this for ...
Definition: Engine.cpp:71
pdsp::Patchable & blackhole()
returns a Patchable object that continously process all output patched to it without outputting nothi...
Definition: Engine.cpp:107
void start()
starts the audio streams again if they were stopped.
Definition: Engine.cpp:263
void setInputDeviceID(int deviceID)
sets the ID of the audio device to open for audio input.
Definition: Engine.cpp:67
void setOutputDeviceID(int deviceID)
sets the ID of the audio device to open for audio output.
Definition: Engine.cpp:63
Definition: SerialOut.h:29
Abstract class for implementing Units and Modules.
Definition: BasicNodes.h:82
Contains all the needed framework for generating and sequencing messages for the DSPs.
Definition: SequencerProcessor.h:22
Multiply in("signal") for in("mod").
Definition: Amp.h:23
void setDeviceID(int deviceID)
sets the ID of the audio device to open. You can get the available ID with listDevices(). Sometimes you have to use different ID for input and output devices, for that use setInputDeviceID() and setOutputDeviceID().
Definition: Engine.cpp:58
pdsp::Patchable & audio_in(int channel)
returns a Patchable object that represent the audio input of the system. Patch this to your modules f...
Definition: Engine.cpp:89
void setApi(ofSoundDevice::Api api)
sets the API to use for the engine soundstream, for the APIs see oF ofSoundBaseTypes.h file.
Definition: Engine.cpp:436
Definition: OscInput.h:41
void test(bool testingActive, float testingDB=-12.0f)
activate/deactivate a sine tone patched to the left output to testing that the engine is running...
Definition: Engine.cpp:420
Definition: Controller.h:11
std::vector< ofSoundDevice > listDevices()
calls ofSoundStreamListDevices() for listing the available audio devices.
Definition: Engine.cpp:54
Thread-safe value control with smoothing.
Definition: SequencerBridge.h:11
void setup(int sampleRate, int bufferSize, int nBuffers)
prepares all the module and units, initializing their internal buffers, then setup up the audioStream...
Definition: Engine.cpp:123
pdsp::SequencerProcessor sequencer
a SequencerProcessor class to manage the playhead and for sequencing. Look SequencerProcessor page fo...
Definition: Engine.h:146
Definition: MidiOut.h:28
The bridge between pdsp and the audio callback.
Definition: Processor.h:21