2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
26 |
|
|
27 |
#include <vector> |
#include <vector> |
28 |
#include <map> |
#include <map> |
29 |
|
#include "EventListeners.h" |
30 |
#include "common/global.h" |
#include "common/global.h" |
31 |
#include "common/LinuxSamplerException.h" |
#include "common/Exception.h" |
32 |
#include "engines/common/Engine.h" |
#include "engines/EngineChannel.h" |
33 |
#include "mididriver/MidiInputDevice.h" |
#include "drivers/midi/MidiInputDevice.h" |
34 |
#include "audiodriver/AudioOutputDevice.h" |
#include "drivers/audio/AudioOutputDevice.h" |
35 |
|
|
36 |
namespace LinuxSampler { |
namespace LinuxSampler { |
37 |
|
|
|
/** |
|
|
* Which sampler engine to be used. |
|
|
*/ |
|
|
enum engine_type_t { |
|
|
engine_type_gig |
|
|
}; |
|
|
|
|
|
/** |
|
|
* Which audio output system to be used. |
|
|
*/ |
|
|
enum audio_output_type_t { |
|
|
audio_output_type_alsa, |
|
|
audio_output_type_jack |
|
|
}; |
|
|
|
|
|
/** |
|
|
* Which MIDI input system to be used. |
|
|
*/ |
|
|
enum midi_input_type_t { |
|
|
midi_input_type_alsa |
|
|
}; |
|
|
|
|
38 |
// just symbol prototyping |
// just symbol prototyping |
39 |
class Sampler; |
class Sampler; |
40 |
|
|
41 |
/** LinuxSampler sampler channel |
/** @brief LinuxSampler sampler channel |
42 |
* |
* |
43 |
* Encapsulates one sampler engine, one connection to a MIDI input |
* Encapsulates a channel of a specific sampler engine type, one |
44 |
* device and one connection to an audio output device. You cannot |
* connection to a MIDI input device and one connection to an audio |
45 |
* create an instance of this class on you own, you have to use the |
* output device. You cannot create an instance of this class on your |
46 |
* AddSamplerChannel() method of the Sampler object to create a new |
* own, you have to use the AddSamplerChannel() method of the Sampler |
47 |
* sampler channel. |
* object to create a new sampler channel. |
48 |
*/ |
*/ |
49 |
class SamplerChannel { |
class SamplerChannel { |
50 |
public: |
public: |
51 |
/** |
/** |
52 |
* Deploy a sampler engine of the given type for this sampler |
* Assign a sampler engine type to this sampler channel. |
|
* channnel. If there was already a sampler engine deployed on |
|
|
* this sampler channel, then the old engine will automatically |
|
|
* be destroyed. |
|
53 |
* |
* |
54 |
* @param EngineType - type of the engine to deploy |
* @param EngineType - type of the engine to use |
55 |
|
* @throws Exception - if \a EngineType is invalid |
56 |
|
* @see Sampler::AvailableEngineTypes() |
57 |
*/ |
*/ |
58 |
void LoadEngine(engine_type_t EngineType); |
void SetEngineType(String EngineType) throw (Exception); |
59 |
|
|
60 |
/** |
/** |
61 |
* Connect this sampler channel to an audio output device (that |
* Connect this sampler channel to an audio output device, that |
62 |
* is audio output driver) of the given type. If the audio |
* is an instance of an audio output driver. If this sampler |
63 |
* output for the desired audio output system is not yet |
* channel was already connected to an audio output device, then |
64 |
* created, then it will be created automatically, but with |
* the old connection will automatically be removed before. |
|
* default settings though. If this sampler channel was already |
|
|
* connected to an audio output device, then the old connection |
|
|
* will automatically be removed before. |
|
65 |
* |
* |
66 |
* @param AudioType - audio output system to connect to |
* @param pDevice - audio output device to connect to |
67 |
*/ |
*/ |
68 |
void SetAudioOutputDevice(audio_output_type_t AudioType); |
void SetAudioOutputDevice(AudioOutputDevice* pDevice); |
69 |
|
|
70 |
/** |
/** |
71 |
* Connect this sampler channel to and MIDI input device (that |
* Connect this sampler channel to a MIDI input device. |
|
* is MIDI input driver) of the given type. If the MIDI input |
|
|
* driver for the desired MIDI input system is not yet created, |
|
|
* then it will be created automatically, but with default |
|
|
* settings though. If this sampler channel was already |
|
|
* connected to a MIDI input device, then the old connection |
|
|
* will automatically be removed before. |
|
72 |
* |
* |
73 |
* @param MidiType - MIDI input system to connect to |
* @param pDevice - MIDI input device to connect to |
74 |
|
*/ |
75 |
|
void SetMidiInputDevice(MidiInputDevice *pDevice); |
76 |
|
|
77 |
|
/** |
78 |
|
* Connect this sampler channel to a MIDI input port. |
79 |
|
* |
80 |
|
* @param MidiPort - MIDI port to connect to |
81 |
|
*/ |
82 |
|
void SetMidiInputPort(int MidiPort); |
83 |
|
|
84 |
|
/** |
85 |
|
* Define on which MIDI channel(s) this sampler channel should |
86 |
|
* listen to. By default, that is after creation of a new |
87 |
|
* sampler channel, the sampler channel will listen to all MIDI |
88 |
|
* channels. |
89 |
|
* |
90 |
|
* @param MidiChannel - MIDI channel to listen |
91 |
|
*/ |
92 |
|
void SetMidiInputChannel(midi_chan_t MidiChannel); |
93 |
|
|
94 |
|
/** |
95 |
|
* Connect this sampler channel to a MIDI input triplet. |
96 |
|
* |
97 |
|
* @param pDevice - MIDI input device to connect to |
98 |
|
* @param iMidiPort - MIDI port to connect to |
99 |
* @param MidiChannel - optional: MIDI channel on which the |
* @param MidiChannel - optional: MIDI channel on which the |
100 |
* sampler channel should listen to |
* sampler channel should listen to |
101 |
* (default: listen on all MIDI channels) |
* (default: listen on all MIDI channels) |
102 |
*/ |
*/ |
103 |
void SetMidiInputDevice(midi_input_type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel = MidiInputDevice::midi_chan_all); |
void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all); |
104 |
|
|
105 |
/** |
/** |
106 |
* Returns the engine that was deployed on this sampler channel. |
* Returns the EngineChannel object that was deployed on this |
107 |
|
* sampler channel appropriate to the given sampler engine type. |
108 |
* |
* |
109 |
* @returns pointer to engine or NULL if no engine deployed |
* @returns pointer to engine or NULL if no engine deployed |
110 |
*/ |
*/ |
111 |
Engine* GetEngine(); |
EngineChannel* GetEngineChannel(); |
112 |
|
|
113 |
/** |
/** |
114 |
* Returns the MIDI input device to which this sampler channel |
* Returns the MIDI input channel to which this sampler |
115 |
* is currently connected to. |
* channel is currently connected to. |
116 |
* |
* |
117 |
* @returns pointer to MIDI input device or NULL if not |
* @returns The MIDI input channel on which the sampler |
118 |
* connected |
* channel is listening to. |
119 |
*/ |
*/ |
120 |
MidiInputDevice* GetMidiInputDevice(); |
midi_chan_t GetMidiInputChannel(); |
121 |
|
|
122 |
|
/** |
123 |
|
* Returns the MIDI input port number to which this sampler |
124 |
|
* channel is currently connected to. |
125 |
|
* |
126 |
|
* @returns MIDI input port number or -1 if not connected |
127 |
|
*/ |
128 |
|
int GetMidiInputPort(); |
129 |
|
|
130 |
/** |
/** |
131 |
* Returns the audio output device to which this sampler channel |
* Returns the audio output device to which this sampler channel |
137 |
AudioOutputDevice* GetAudioOutputDevice(); |
AudioOutputDevice* GetAudioOutputDevice(); |
138 |
|
|
139 |
/** |
/** |
140 |
|
* Returns the MIDI input device to which this sampler channel |
141 |
|
* is currently connected to. |
142 |
|
* |
143 |
|
* @returns pointer to MIDI input device or NULL if not |
144 |
|
* connected |
145 |
|
*/ |
146 |
|
MidiInputDevice* GetMidiInputDevice(); |
147 |
|
|
148 |
|
/** |
149 |
* Returns the index number of this sampler channel within the |
* Returns the index number of this sampler channel within the |
150 |
* Sampler instance. |
* Sampler instance. |
151 |
*/ |
*/ |
152 |
uint Index(); |
uint Index(); |
153 |
|
|
154 |
|
/** Returns the sampler to which this channel belongs */ |
155 |
|
Sampler* GetSampler(); |
156 |
|
|
157 |
|
/////////////////////////////////////////////////////////////// |
158 |
|
// Event Listener methods |
159 |
|
|
160 |
|
/** |
161 |
|
* Registers the specified listener to be notified |
162 |
|
* when the engine type of this sampler channel is changed. |
163 |
|
*/ |
164 |
|
void AddEngineChangeListener(EngineChangeListener* l); |
165 |
|
|
166 |
|
/** |
167 |
|
* Removes the specified listener. |
168 |
|
*/ |
169 |
|
void RemoveEngineChangeListener(EngineChangeListener* l); |
170 |
|
|
171 |
|
/** |
172 |
|
* Removes the specified listener. |
173 |
|
*/ |
174 |
|
void RemoveAllEngineChangeListeners(); |
175 |
|
|
176 |
|
/** |
177 |
|
* Notifies listeners that the engine type of this sampler |
178 |
|
* channel is going to be changed soon. |
179 |
|
*/ |
180 |
|
void fireEngineToBeChanged(); |
181 |
|
|
182 |
|
/** |
183 |
|
* Notifies listeners that the engine |
184 |
|
* type of this sampler channel is changed. |
185 |
|
*/ |
186 |
|
void fireEngineChanged(); |
187 |
|
|
188 |
|
|
189 |
protected: |
protected: |
190 |
SamplerChannel(Sampler* pS); |
SamplerChannel(Sampler* pS); |
191 |
~SamplerChannel(); |
virtual ~SamplerChannel(); |
192 |
|
|
193 |
|
/** Getting MIDI input device port given its index number. */ |
194 |
|
MidiInputPort* __GetMidiInputDevicePort(int iMidiPort); |
195 |
|
|
196 |
Sampler* pSampler; |
Sampler* pSampler; |
197 |
Engine* pEngine; |
EngineChannel* pEngineChannel; |
|
MidiInputDevice* pMidiInputDevice; |
|
198 |
AudioOutputDevice* pAudioOutputDevice; |
AudioOutputDevice* pAudioOutputDevice; |
199 |
|
MidiInputDevice* pMidiInputDevice; |
200 |
int iIndex; |
int iIndex; |
201 |
|
|
202 |
friend class Sampler; |
friend class Sampler; |
203 |
|
private: |
204 |
|
int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! |
205 |
|
midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead ! |
206 |
|
ListenerList<EngineChangeListener*> llEngineChangeListeners; |
207 |
}; |
}; |
208 |
|
|
209 |
/** LinuxSampler main class |
/** @brief LinuxSampler main class |
210 |
* |
* |
211 |
* This is the toplevel class for a LinuxSampler instance. |
* This is the toplevel class for a LinuxSampler instance. |
212 |
* |
* |
214 |
* sampler channel can individually be deployed with it's own sampler |
* sampler channel can individually be deployed with it's own sampler |
215 |
* engine, connected to an arbitrary MIDI input device and connected to |
* engine, connected to an arbitrary MIDI input device and connected to |
216 |
* an arbitrary audio output device. Here an example setup: |
* an arbitrary audio output device. Here an example setup: |
217 |
|
* @code |
218 |
|
* S.Channel MIDI in S.Engine Audio out |
219 |
|
* ------------------------------------------------------------------- |
220 |
|
* 0 Alsa -> gig::Engine -> Jack |
221 |
|
* 1 VSTi -> Akai::Engine -> VSTi |
222 |
|
* 2 Jack -> DLS::Engine -> Jack |
223 |
|
* 3 Jack -> SF::Engine -> Alsa |
224 |
* |
* |
225 |
* S.Channel. MIDI in S.Engine Audio out |
* ... (and so on) ... |
226 |
* ------------------------------------------------------------------- |
* @endcode |
|
* 0 Alsa -> gig::Engine -> Jack |
|
|
* 1 VSTi -> Akai::Engine -> VSTi |
|
|
* 2 Jack -> DLS::Engine -> Jack |
|
|
* 3 Jack -> SF::Engine -> Alsa |
|
|
* |
|
|
* ... (and so on) ... |
|
227 |
* |
* |
228 |
* Note that not all audio and MIDI backends and sampler engines listed |
* Note that not all audio and MIDI backends and sampler engines listed |
229 |
* in the example above are already implemented! |
* in the example above might already been implemented! |
230 |
* |
* |
231 |
* As you can see in the example setup, LinuxSampler is capable to use |
* As you can see in the example setup, LinuxSampler is capable to use |
232 |
* several, different audio output and MIDI input systems |
* several, different audio output and MIDI input systems |
233 |
* simultaniously at the same time. Here the example setup shown in the |
* simultaniously at the same time. Here the example setup shown in the |
234 |
* ascpect of MIDI input and audio output devices / drivers: |
* aspect of MIDI input and audio output devices / drivers: |
235 |
* |
* @code |
236 |
* ######################### ######################### |
* ######################### ######################### |
237 |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
238 |
* ######################### ######################### |
* ######################### ######################### |
239 |
* ^ ^ ^ |
* ^ ^ ^ |
240 |
* /------------>|Sampler Channel 0|-----/ | | |
* /------------>|Sampler Channel 0|-----/ | | |
241 |
* | /--------->|Sampler Channel 1|---------------------/ |
* | /--------->|Sampler Channel 1|---------------------/ |
242 |
* | | /---->|Sampler Channel 2|---------/ |
* | | /------>|Sampler Channel 2|---------/ |
243 |
* | | | /->|Sampler Channel 3|------------>######################### |
* | | | /--->|Sampler Channel 3|------------>######################### |
244 |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
245 |
* | | | | ######################### |
* | | | | ######################### |
246 |
* | | | \----------------------------------------------------\ |
* | | | \-----------------------------------------------------\ |
247 |
* | | \-------------------------------------------\ | |
* | | \--------------------------------------------\ | |
248 |
* | \--------------------\ | | |
* | \--------------------\ | | |
249 |
* | | | | |
* | | | | |
250 |
* ####################### ####################### ####################### |
* ####################### ####################### ####################### |
251 |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
252 |
* ####################### ####################### ####################### |
* ####################### ####################### ####################### |
253 |
|
* @endcode |
254 |
* |
* |
255 |
* As you can see in this example setup, one device (that is midi input |
* As you can see in this example setup, one device (that is midi input |
256 |
* driver / audio output driver) can be connected multiple times to |
* driver / audio output driver) can be connected multiple times to |
257 |
* different sampler channels. |
* different sampler channels. |
258 |
|
* |
259 |
|
* It's even possible to create multiple instances of the same driver, for |
260 |
|
* example multiple instances of the Alsa output driver to use multiple |
261 |
|
* sound cards at the same time, or multiple instances of the JACK audio |
262 |
|
* output driver to leverage SMP systems or boxes with several hard discs. |
263 |
*/ |
*/ |
264 |
class Sampler { |
class Sampler { |
265 |
public: |
public: |
271 |
/** |
/** |
272 |
* Destructor. |
* Destructor. |
273 |
*/ |
*/ |
274 |
~Sampler(); |
virtual ~Sampler(); |
275 |
|
|
276 |
/** |
/** |
277 |
* Returns the number of sampler channels currently allocated. |
* Returns the number of sampler channels currently allocated. |
279 |
uint SamplerChannels(); |
uint SamplerChannels(); |
280 |
|
|
281 |
/** |
/** |
282 |
* Create and add a new sampler channel to this Sampler instance. |
* Create and add a new sampler channel to this Sampler |
283 |
|
* instance. For race condition reasons the new channel will use |
284 |
|
* an index past the last already existing sampler channel |
285 |
|
* index (in case the index limit was not reached yet, otherwise |
286 |
|
* a free index starting from 0 is searched). |
287 |
* |
* |
288 |
* @returns pointer to new sampler channel |
* @returns pointer to new sampler channel |
289 |
*/ |
*/ |
298 |
SamplerChannel* GetSamplerChannel(uint uiSamplerChannel); |
SamplerChannel* GetSamplerChannel(uint uiSamplerChannel); |
299 |
|
|
300 |
/** |
/** |
301 |
|
* Returns all created sampler channels. |
302 |
|
*/ |
303 |
|
std::map<uint, SamplerChannel*> GetSamplerChannels(); |
304 |
|
|
305 |
|
/** |
306 |
* Destroy and remove the given sampler channel from this |
* Destroy and remove the given sampler channel from this |
307 |
* Sampler instance. |
* Sampler instance. |
308 |
* |
* |
320 |
void RemoveSamplerChannel(uint uiSamplerChannel); |
void RemoveSamplerChannel(uint uiSamplerChannel); |
321 |
|
|
322 |
/** |
/** |
323 |
* Create an audio output device of the given type. |
* Destroy and remove all sampler channels from this |
324 |
|
* Sampler instance. |
325 |
|
*/ |
326 |
|
void RemoveAllSamplerChannels(); |
327 |
|
|
328 |
|
/** |
329 |
|
* Returns the names of all available audio output drivers. |
330 |
|
*/ |
331 |
|
std::vector<String> AvailableAudioOutputDrivers(); |
332 |
|
|
333 |
|
/** |
334 |
|
* Returns the names of all available MIDI input drivers. |
335 |
|
*/ |
336 |
|
std::vector<String> AvailableMidiInputDrivers(); |
337 |
|
|
338 |
|
/** |
339 |
|
* Returns the names of all available sampler engine types. |
340 |
|
* @see SamplerChannel::SetEngineType() |
341 |
|
*/ |
342 |
|
std::vector<String> AvailableEngineTypes(); |
343 |
|
|
344 |
|
/** |
345 |
|
* Create an audio output device. |
346 |
* |
* |
347 |
* @param AudioType - desired audio output system to use |
* @param AudioDriver - name of the audio driver |
348 |
|
* @param Parameters - eventually needed driver parameters to |
349 |
|
* create the device |
350 |
* @returns pointer to created audio output device |
* @returns pointer to created audio output device |
351 |
|
* @throws Exception if device could not be created |
352 |
|
*/ |
353 |
|
AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception); |
354 |
|
|
355 |
|
/** |
356 |
|
* Create a midi input device. |
357 |
|
* |
358 |
|
* @param MidiDriver - name of the midi driver |
359 |
|
* @param Parameters - eventually needed driver parameters to |
360 |
|
* create the device |
361 |
|
* @returns pointer to created midi input device |
362 |
|
* @throws Exception if device could not be created |
363 |
|
*/ |
364 |
|
MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception); |
365 |
|
|
366 |
|
/** |
367 |
|
* Returns the number of all created audio output devices. |
368 |
|
*/ |
369 |
|
uint AudioOutputDevices(); |
370 |
|
|
371 |
|
/** |
372 |
|
* Returns the number of all created MIDI input devices. |
373 |
|
*/ |
374 |
|
uint MidiInputDevices(); |
375 |
|
|
376 |
|
/** |
377 |
|
* Returns all created audio output devices. |
378 |
|
*/ |
379 |
|
std::map<uint, AudioOutputDevice*> GetAudioOutputDevices(); |
380 |
|
|
381 |
|
/** |
382 |
|
* Returns all created MIDI input devices. |
383 |
*/ |
*/ |
384 |
AudioOutputDevice* CreateAudioOutputDevice(audio_output_type_t AudioType); |
std::map<uint, MidiInputDevice*> GetMidiInputDevices(); |
385 |
|
|
386 |
/** |
/** |
387 |
* Returns the audio output device of the given type. |
* Destroy the given audio output device and takes care if there |
388 |
|
* are still sampler engines connected to this device, etc. |
389 |
* |
* |
390 |
* @param AudioType - desired audio output system to use |
* @throws Exception if sampler channels are still |
391 |
* @returns pointer to audio output device or NULL if device of |
* connected to the device |
|
* desired type is not yet created |
|
392 |
*/ |
*/ |
393 |
AudioOutputDevice* GetAudioOutputDevice(audio_output_type_t AudioType); |
void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception); |
394 |
|
|
395 |
/** |
/** |
396 |
* Create a MIDI input device of the given type. |
* Destroy all audio output devices and takes care if there |
397 |
|
* are still sampler engines connected to devices, etc. |
398 |
* |
* |
399 |
* @param MidiType - desired MIDI input system to use |
* Note: non-autonomous devices, that is devices associated with |
400 |
* @returns pointer to created MIDI input device |
* host plugin instances like VST, AU, DSSI, LV2 are not |
401 |
|
* destroyed by this method. |
402 |
|
* |
403 |
|
* @throws Exception if sampler channels are still |
404 |
|
* connected to device |
405 |
*/ |
*/ |
406 |
MidiInputDevice* CreateMidiInputDevice(midi_input_type_t MidiType); |
void DestroyAllAudioOutputDevices() throw (Exception); |
407 |
|
|
408 |
/** |
/** |
409 |
* Returns the MIDI input device of the given type. |
* Destroy the given MIDI input device and takes care if there |
410 |
|
* are still sampler engines connected to this device, etc. |
411 |
* |
* |
412 |
* @param MidiType - desired MIDI input system to use |
* @throws Exception if sampler channels are still |
413 |
* @returns pointer to MIDI input device or NULL if device of |
* connected to the device |
|
* desired type is not yet created |
|
414 |
*/ |
*/ |
415 |
MidiInputDevice* GetMidiInputDevice(midi_input_type_t MidiType); |
void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception); |
416 |
|
|
417 |
|
/** |
418 |
|
* Destroy all MIDI input devices and take care if there |
419 |
|
* are still sampler engines connected to device, etc. |
420 |
|
* |
421 |
|
* Note: non-autonomous devices, that is devices associated with |
422 |
|
* host plugin instances like VST, AU, DSSI, LV2 are not |
423 |
|
* destroyed by this method. |
424 |
|
* |
425 |
|
* @throws Exception if sampler channels are still |
426 |
|
* connected to device |
427 |
|
*/ |
428 |
|
void DestroyAllMidiInputDevices() throw (Exception); |
429 |
|
|
430 |
|
/** |
431 |
|
* Gets the current number of all active streams. |
432 |
|
* @returns The current number of all active streams. |
433 |
|
*/ |
434 |
|
int GetDiskStreamCount(); |
435 |
|
|
436 |
|
/** |
437 |
|
* Gets the current number of all active voices. |
438 |
|
* @returns The current number of all active voices. |
439 |
|
*/ |
440 |
|
int GetVoiceCount(); |
441 |
|
|
442 |
|
/** |
443 |
|
* Reset the whole sampler. Destroy all engines, sampler |
444 |
|
* channels, MIDI input devices and audio output devices. |
445 |
|
*/ |
446 |
|
void Reset(); |
447 |
|
|
448 |
|
/////////////////////////////////////////////////////////////// |
449 |
|
// Event Listener methods |
450 |
|
|
451 |
|
/** |
452 |
|
* Registers the specified listener to be notified |
453 |
|
* when the number of sampler chanels is changed. |
454 |
|
*/ |
455 |
|
void AddChannelCountListener(ChannelCountListener* l); |
456 |
|
|
457 |
|
/** |
458 |
|
* Removes the specified listener. |
459 |
|
*/ |
460 |
|
void RemoveChannelCountListener(ChannelCountListener* l); |
461 |
|
|
462 |
|
/** |
463 |
|
* Registers the specified listener to be notified |
464 |
|
* when the number of audio output devices is changed. |
465 |
|
*/ |
466 |
|
void AddAudioDeviceCountListener(AudioDeviceCountListener* l); |
467 |
|
|
468 |
|
/** |
469 |
|
* Removes the specified listener. |
470 |
|
*/ |
471 |
|
void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l); |
472 |
|
|
473 |
|
/** |
474 |
|
* Registers the specified listener to be notified |
475 |
|
* when the number of MIDI input devices is changed. |
476 |
|
*/ |
477 |
|
void AddMidiDeviceCountListener(MidiDeviceCountListener* l); |
478 |
|
|
479 |
|
/** |
480 |
|
* Removes the specified listener. |
481 |
|
*/ |
482 |
|
void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l); |
483 |
|
|
484 |
|
/** |
485 |
|
* Registers the specified listener to be notified when the number |
486 |
|
* of active voices in a particular sampler channel is changed. |
487 |
|
*/ |
488 |
|
void AddVoiceCountListener(VoiceCountListener* l); |
489 |
|
|
490 |
|
/** |
491 |
|
* Removes the specified listener. |
492 |
|
*/ |
493 |
|
void RemoveVoiceCountListener(VoiceCountListener* l); |
494 |
|
|
495 |
|
/** |
496 |
|
* Notifies listeners that the number of active voices |
497 |
|
* on the specified sampler channel is changed. |
498 |
|
* @param ChannelId The numerical ID of the sampler channel. |
499 |
|
* @param NewCount The new number of active voices. |
500 |
|
*/ |
501 |
|
void fireVoiceCountChanged(int ChannelId, int NewCount); |
502 |
|
|
503 |
|
/** |
504 |
|
* Registers the specified listener to be notified when the number |
505 |
|
* of active disk streams in a particular sampler channel is changed. |
506 |
|
*/ |
507 |
|
void AddStreamCountListener(StreamCountListener* l); |
508 |
|
|
509 |
|
/** |
510 |
|
* Removes the specified listener. |
511 |
|
*/ |
512 |
|
void RemoveStreamCountListener(StreamCountListener* l); |
513 |
|
|
514 |
|
/** |
515 |
|
* Notifies listeners that the number of active disk streams |
516 |
|
* on the specified sampler channel is changed. |
517 |
|
* @param ChannelId The numerical ID of the sampler channel. |
518 |
|
* @param NewCount The new number of active disk streams. |
519 |
|
*/ |
520 |
|
void fireStreamCountChanged(int ChannelId, int NewCount); |
521 |
|
|
522 |
|
/** |
523 |
|
* Registers the specified listener to be |
524 |
|
* notified when the fill state of the disk stream |
525 |
|
* buffers on a specific sampler channel is changed. |
526 |
|
*/ |
527 |
|
void AddBufferFillListener(BufferFillListener* l); |
528 |
|
|
529 |
|
/** |
530 |
|
* Removes the specified listener. |
531 |
|
*/ |
532 |
|
void RemoveBufferFillListener(BufferFillListener* l); |
533 |
|
|
534 |
|
/** |
535 |
|
* Notifies listeners that the fill state of the disk stream |
536 |
|
* buffers on the specified sampler channel is changed. |
537 |
|
* @param ChannelId The numerical ID of the sampler channel. |
538 |
|
* @param FillData The buffer fill data for the specified sampler channel. |
539 |
|
*/ |
540 |
|
void fireBufferFillChanged(int ChannelId, String FillData); |
541 |
|
|
542 |
|
/** |
543 |
|
* Registers the specified listener to be notified |
544 |
|
* when total number of active voices is changed. |
545 |
|
*/ |
546 |
|
void AddTotalVoiceCountListener(TotalVoiceCountListener* l); |
547 |
|
|
548 |
|
/** |
549 |
|
* Removes the specified listener. |
550 |
|
*/ |
551 |
|
void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l); |
552 |
|
|
553 |
|
/** |
554 |
|
* Notifies listeners that the total number of active voices is changed. |
555 |
|
* @param NewCount The new number of active voices. |
556 |
|
*/ |
557 |
|
void fireTotalVoiceCountChanged(int NewCount); |
558 |
|
|
559 |
|
/** |
560 |
|
* Registers the specified listener to be notified when the number |
561 |
|
* of total streams is changed. |
562 |
|
*/ |
563 |
|
void AddTotalStreamCountListener(TotalStreamCountListener* l); |
564 |
|
|
565 |
|
/** |
566 |
|
* Removes the specified listener. |
567 |
|
*/ |
568 |
|
void RemoveTotalStreamCountListener(TotalStreamCountListener* l); |
569 |
|
|
570 |
|
/** |
571 |
|
* Notifies listeners that the total number of total streams changed. |
572 |
|
* @param NewCount The new number of total streams. |
573 |
|
*/ |
574 |
|
void fireTotalStreamCountChanged(int NewCount); |
575 |
|
|
576 |
|
/** |
577 |
|
* Registers the specified listener to be notified when the number |
578 |
|
* of effect sends on a particular sampler channel is changed. |
579 |
|
*/ |
580 |
|
void AddFxSendCountListener(FxSendCountListener* l); |
581 |
|
|
582 |
|
/** |
583 |
|
* Removes the specified listener. |
584 |
|
*/ |
585 |
|
void RemoveFxSendCountListener(FxSendCountListener* l); |
586 |
|
|
587 |
|
/** |
588 |
|
* Notifies listeners about the current number of voices, |
589 |
|
* streams and total voices, and the current fill state of |
590 |
|
* the disk stream buffers. |
591 |
|
*/ |
592 |
|
void fireStatistics(); |
593 |
|
|
594 |
|
/////////////////////////////////////////////////////////////// |
595 |
|
// system specific methods |
596 |
|
|
597 |
|
/** |
598 |
|
* Advise the FPU to treat denormal floating point numbers as |
599 |
|
* zero, to avoid severe performance penalty when dealing with |
600 |
|
* such extreme floating point values. |
601 |
|
* |
602 |
|
* @returns @c true if FPU supports it, @c false otherwise |
603 |
|
*/ |
604 |
|
static bool EnableDenormalsAreZeroMode(); |
605 |
|
|
606 |
|
#if defined(WIN32) |
607 |
|
/** |
608 |
|
* Gets the directory where the liblinuxsampler dll is located. |
609 |
|
* Note: this method is currently only available for Windows. |
610 |
|
* @returns installation directory |
611 |
|
*/ |
612 |
|
static String GetInstallDir(); |
613 |
|
#endif |
614 |
protected: |
protected: |
615 |
typedef std::map<audio_output_type_t, AudioOutputDevice*> AudioOutputDeviceMap; |
/** |
616 |
typedef std::map<midi_input_type_t, MidiInputDevice*> MidiInputDeviceMap; |
* Notifies listeners that the number of sampler channels has been changed. |
617 |
|
* @param NewCount The new number of sampler channels. |
618 |
|
*/ |
619 |
|
void fireChannelCountChanged(int NewCount); |
620 |
|
|
621 |
|
/** |
622 |
|
* Notifies listeners that the specified sampler channel has just |
623 |
|
* been added. |
624 |
|
* @param pChannel The new sampler channel. |
625 |
|
*/ |
626 |
|
void fireChannelAdded(SamplerChannel* pChannel); |
627 |
|
|
628 |
|
/** |
629 |
|
* Notifies listeners that the specified sampler channel is |
630 |
|
* going to be removed soon. |
631 |
|
* @param pChannel sampler channel to be removed. |
632 |
|
*/ |
633 |
|
void fireChannelToBeRemoved(SamplerChannel* pChannel); |
634 |
|
|
635 |
|
/** |
636 |
|
* Notifies listeners that the number of audio output devices has been changed. |
637 |
|
* @param NewCount The new number of audio output devices. |
638 |
|
*/ |
639 |
|
void fireAudioDeviceCountChanged(int NewCount); |
640 |
|
|
641 |
|
/** |
642 |
|
* Notifies listeners that the number of MIDI input devices has been changed. |
643 |
|
* @param NewCount The new number of MIDI input devices. |
644 |
|
*/ |
645 |
|
void fireMidiDeviceCountChanged(int NewCount); |
646 |
|
|
647 |
std::vector<SamplerChannel*> vSamplerChannels; ///< contains all created sampler channels |
/** |
648 |
AudioOutputDeviceMap AudioOutputDevices; ///< contains all created audio output devices |
* Notifies listeners that the supplied MIDI input device is |
649 |
MidiInputDeviceMap MidiInputDevices; |
* going to be destroyed soon. |
650 |
|
* @param pDevice MIDI input device to be destroyed |
651 |
|
*/ |
652 |
|
void fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice); |
653 |
|
|
654 |
|
/** |
655 |
|
* Notifies listeners that the supplied MIDI input device was |
656 |
|
* just created. |
657 |
|
* @param pDevice new MIDI input device |
658 |
|
*/ |
659 |
|
void fireMidiDeviceCreated(MidiInputDevice* pDevice); |
660 |
|
|
661 |
|
/** |
662 |
|
* Notifies listeners that the number of effect sends |
663 |
|
* on a particular sampler channel is changed. |
664 |
|
* @param ChannelId The numerical ID of the sampler channel. |
665 |
|
* @param NewCount The new number of sampler channels. |
666 |
|
*/ |
667 |
|
void fireFxSendCountChanged(int ChannelId, int NewCount); |
668 |
|
|
669 |
|
typedef std::map<uint, SamplerChannel*> SamplerChannelMap; |
670 |
|
|
671 |
|
SamplerChannelMap mSamplerChannels; ///< contains all created sampler channels |
672 |
|
|
673 |
|
// statistics cache |
674 |
|
uint uiOldTotalVoiceCount; |
675 |
|
uint uiOldTotalStreamCount; |
676 |
|
std::map<uint, uint> mOldVoiceCounts; |
677 |
|
std::map<uint, uint> mOldStreamCounts; |
678 |
|
|
679 |
friend class SamplerChannel; |
friend class SamplerChannel; |
680 |
|
|
681 |
|
private: |
682 |
|
ListenerList<ChannelCountListener*> llChannelCountListeners; |
683 |
|
ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners; |
684 |
|
ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners; |
685 |
|
ListenerList<VoiceCountListener*> llVoiceCountListeners; |
686 |
|
ListenerList<StreamCountListener*> llStreamCountListeners; |
687 |
|
ListenerList<BufferFillListener*> llBufferFillListeners; |
688 |
|
ListenerList<TotalStreamCountListener*> llTotalStreamCountListeners; |
689 |
|
ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners; |
690 |
|
ListenerList<FxSendCountListener*> llFxSendCountListeners; |
691 |
|
|
692 |
|
class EventHandler : public EngineChangeListener, public FxSendCountListener { |
693 |
|
public: |
694 |
|
void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; } |
695 |
|
|
696 |
|
/** |
697 |
|
* Invoked when the engine type of the specified sampler |
698 |
|
* channel is going to be changed soon. |
699 |
|
* @param ChannelId The numerical ID of the sampler channel |
700 |
|
*/ |
701 |
|
virtual void EngineToBeChanged(int ChannelId); |
702 |
|
|
703 |
|
/** |
704 |
|
* Invoked when the engine type of the |
705 |
|
* specified sampler channel is changed. |
706 |
|
* @param ChannelId The numerical ID of the sampler |
707 |
|
* channel, which engine type has been changed. |
708 |
|
*/ |
709 |
|
virtual void EngineChanged(int ChannelId); |
710 |
|
|
711 |
|
/** |
712 |
|
* Invoked when the number of effect sends |
713 |
|
* on the specified sampler channel has changed. |
714 |
|
* @param ChannelId The numerical ID of the sampler channel. |
715 |
|
* @param NewCount The new number of effect sends. |
716 |
|
*/ |
717 |
|
virtual void FxSendCountChanged(int ChannelId, int NewCount); |
718 |
|
|
719 |
|
private: |
720 |
|
Sampler* pSampler; |
721 |
|
} eventHandler; |
722 |
}; |
}; |
723 |
} |
} |
724 |
|
|