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/Exception.h" |
#include "common/Exception.h" |
32 |
#include "engines/common/EngineChannel.h" |
#include "engines/EngineChannel.h" |
33 |
#include "drivers/midi/MidiInputDevice.h" |
#include "drivers/midi/MidiInputDevice.h" |
34 |
#include "drivers/audio/AudioOutputDevice.h" |
#include "drivers/audio/AudioOutputDevice.h" |
35 |
|
|
53 |
* |
* |
54 |
* @param EngineType - type of the engine to use |
* @param EngineType - type of the engine to use |
55 |
* @throws Exception - if \a EngineType is invalid |
* @throws Exception - if \a EngineType is invalid |
56 |
|
* @see Sampler::AvailableEngineTypes() |
57 |
*/ |
*/ |
58 |
void SetEngineType(String EngineType) throw (Exception); |
void SetEngineType(String EngineType) throw (Exception); |
59 |
|
|
150 |
* Sampler instance. |
* Sampler instance. |
151 |
*/ |
*/ |
152 |
uint Index(); |
uint Index(); |
153 |
|
|
154 |
|
/** |
155 |
|
* Registers the specified listener to be notified |
156 |
|
* when the engine type of this sampler channel is changed. |
157 |
|
*/ |
158 |
|
void AddEngineChangeListener(EngineChangeListener* l); |
159 |
|
|
160 |
|
/** |
161 |
|
* Removes the specified listener. |
162 |
|
*/ |
163 |
|
void RemoveEngineChangeListener(EngineChangeListener* l); |
164 |
|
|
165 |
|
/** |
166 |
|
* Removes the specified listener. |
167 |
|
*/ |
168 |
|
void RemoveAllEngineChangeListeners(); |
169 |
|
|
170 |
|
/** |
171 |
|
* Notifies listeners that the engine |
172 |
|
* type of this sampler channel is changed. |
173 |
|
*/ |
174 |
|
void fireEngineChanged(); |
175 |
|
|
176 |
|
|
177 |
protected: |
protected: |
178 |
SamplerChannel(Sampler* pS); |
SamplerChannel(Sampler* pS); |
191 |
private: |
private: |
192 |
int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! |
int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! |
193 |
midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead ! |
midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead ! |
194 |
|
ListenerList<EngineChangeListener*> llEngineChangeListeners; |
195 |
}; |
}; |
196 |
|
|
197 |
/** @brief LinuxSampler main class |
/** @brief LinuxSampler main class |
203 |
* engine, connected to an arbitrary MIDI input device and connected to |
* engine, connected to an arbitrary MIDI input device and connected to |
204 |
* an arbitrary audio output device. Here an example setup: |
* an arbitrary audio output device. Here an example setup: |
205 |
* @code |
* @code |
206 |
* S.Channel. MIDI in S.Engine Audio out |
* S.Channel MIDI in S.Engine Audio out |
207 |
* ------------------------------------------------------------------- |
* ------------------------------------------------------------------- |
208 |
* 0 Alsa -> gig::Engine -> Jack |
* 0 Alsa -> gig::Engine -> Jack |
209 |
* 1 VSTi -> Akai::Engine -> VSTi |
* 1 VSTi -> Akai::Engine -> VSTi |
210 |
* 2 Jack -> DLS::Engine -> Jack |
* 2 Jack -> DLS::Engine -> Jack |
211 |
* 3 Jack -> SF::Engine -> Alsa |
* 3 Jack -> SF::Engine -> Alsa |
212 |
* |
* |
213 |
* ... (and so on) ... |
* ... (and so on) ... |
214 |
* @endcode |
* @endcode |
215 |
* |
* |
216 |
* Note that not all audio and MIDI backends and sampler engines listed |
* Note that not all audio and MIDI backends and sampler engines listed |
217 |
* in the example above are already implemented! |
* in the example above might already been implemented! |
218 |
* |
* |
219 |
* 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 |
220 |
* several, different audio output and MIDI input systems |
* several, different audio output and MIDI input systems |
221 |
* simultaniously at the same time. Here the example setup shown in the |
* simultaniously at the same time. Here the example setup shown in the |
222 |
* ascpect of MIDI input and audio output devices / drivers: |
* aspect of MIDI input and audio output devices / drivers: |
223 |
* @code |
* @code |
224 |
* ######################### ######################### |
* ######################### ######################### |
225 |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
226 |
* ######################### ######################### |
* ######################### ######################### |
227 |
* ^ ^ ^ |
* ^ ^ ^ |
228 |
* /------------>|Sampler Channel 0|-----/ | | |
* /------------>|Sampler Channel 0|-----/ | | |
229 |
* | /--------->|Sampler Channel 1|---------------------/ |
* | /--------->|Sampler Channel 1|---------------------/ |
230 |
* | | /------>|Sampler Channel 2|---------/ |
* | | /------>|Sampler Channel 2|---------/ |
231 |
* | | | /--->|Sampler Channel 3|------------>######################### |
* | | | /--->|Sampler Channel 3|------------>######################### |
232 |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
233 |
* | | | | ######################### |
* | | | | ######################### |
234 |
* | | | \-----------------------------------------------------\ |
* | | | \-----------------------------------------------------\ |
235 |
* | | \--------------------------------------------\ | |
* | | \--------------------------------------------\ | |
236 |
* | \--------------------\ | | |
* | \--------------------\ | | |
237 |
* | | | | |
* | | | | |
238 |
* ####################### ####################### ####################### |
* ####################### ####################### ####################### |
239 |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
240 |
* ####################### ####################### ####################### |
* ####################### ####################### ####################### |
243 |
* 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 |
244 |
* driver / audio output driver) can be connected multiple times to |
* driver / audio output driver) can be connected multiple times to |
245 |
* different sampler channels. |
* different sampler channels. |
246 |
|
* |
247 |
|
* It's even possible to create multiple instances of the same driver, for |
248 |
|
* example multiple instances of the Alsa output driver to use multiple |
249 |
|
* sound cards at the same time, or multiple instances of the JACK audio |
250 |
|
* output driver to leverage SMP systems or boxes with several hard discs. |
251 |
*/ |
*/ |
252 |
class Sampler { |
class Sampler { |
253 |
public: |
public: |
308 |
void RemoveSamplerChannel(uint uiSamplerChannel); |
void RemoveSamplerChannel(uint uiSamplerChannel); |
309 |
|
|
310 |
/** |
/** |
311 |
|
* Registers the specified listener to be notified |
312 |
|
* when the number of sampler chanels is changed. |
313 |
|
*/ |
314 |
|
void AddChannelCountListener(ChannelCountListener* l); |
315 |
|
|
316 |
|
/** |
317 |
|
* Removes the specified listener. |
318 |
|
*/ |
319 |
|
void RemoveChannelCountListener(ChannelCountListener* l); |
320 |
|
|
321 |
|
/** |
322 |
|
* Registers the specified listener to be notified |
323 |
|
* when the number of audio output devices is changed. |
324 |
|
*/ |
325 |
|
void AddAudioDeviceCountListener(AudioDeviceCountListener* l); |
326 |
|
|
327 |
|
/** |
328 |
|
* Removes the specified listener. |
329 |
|
*/ |
330 |
|
void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l); |
331 |
|
|
332 |
|
|
333 |
|
/** |
334 |
|
* Registers the specified listener to be notified |
335 |
|
* when the number of MIDI input devices is changed. |
336 |
|
*/ |
337 |
|
void AddMidiDeviceCountListener(MidiDeviceCountListener* l); |
338 |
|
|
339 |
|
/** |
340 |
|
* Removes the specified listener. |
341 |
|
*/ |
342 |
|
void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l); |
343 |
|
|
344 |
|
/** |
345 |
|
* Registers the specified listener to be notified when the number |
346 |
|
* of active voices in a particular sampler channel is changed. |
347 |
|
*/ |
348 |
|
void AddVoiceCountListener(VoiceCountListener* l); |
349 |
|
|
350 |
|
/** |
351 |
|
* Removes the specified listener. |
352 |
|
*/ |
353 |
|
void RemoveVoiceCountListener(VoiceCountListener* l); |
354 |
|
|
355 |
|
/** |
356 |
|
* Notifies listeners that the number of active voices |
357 |
|
* on the specified sampler channel is changed. |
358 |
|
* @param ChannelId The numerical ID of the sampler channel. |
359 |
|
* @param NewCount The new number of active voices. |
360 |
|
*/ |
361 |
|
void fireVoiceCountChanged(int ChannelId, int NewCount); |
362 |
|
|
363 |
|
/** |
364 |
|
* Registers the specified listener to be notified when the number |
365 |
|
* of active disk streams in a particular sampler channel is changed. |
366 |
|
*/ |
367 |
|
void AddStreamCountListener(StreamCountListener* l); |
368 |
|
|
369 |
|
/** |
370 |
|
* Removes the specified listener. |
371 |
|
*/ |
372 |
|
void RemoveStreamCountListener(StreamCountListener* l); |
373 |
|
|
374 |
|
/** |
375 |
|
* Notifies listeners that the number of active disk streams |
376 |
|
* on the specified sampler channel is changed. |
377 |
|
* @param ChannelId The numerical ID of the sampler channel. |
378 |
|
* @param NewCount The new number of active disk streams. |
379 |
|
*/ |
380 |
|
void fireStreamCountChanged(int ChannelId, int NewCount); |
381 |
|
|
382 |
|
/** |
383 |
|
* Registers the specified listener to be |
384 |
|
* notified when the fill state of the disk stream |
385 |
|
* buffers on a specific sampler channel is changed. |
386 |
|
*/ |
387 |
|
void AddBufferFillListener(BufferFillListener* l); |
388 |
|
|
389 |
|
/** |
390 |
|
* Removes the specified listener. |
391 |
|
*/ |
392 |
|
void RemoveBufferFillListener(BufferFillListener* l); |
393 |
|
|
394 |
|
/** |
395 |
|
* Notifies listeners that the fill state of the disk stream |
396 |
|
* buffers on the specified sampler channel is changed. |
397 |
|
* @param ChannelId The numerical ID of the sampler channel. |
398 |
|
* @param FillData The buffer fill data for the specified sampler channel. |
399 |
|
*/ |
400 |
|
void fireBufferFillChanged(int ChannelId, String FillData); |
401 |
|
|
402 |
|
/** |
403 |
|
* Registers the specified listener to be notified |
404 |
|
* when total number of active voices is changed. |
405 |
|
*/ |
406 |
|
void AddTotalVoiceCountListener(TotalVoiceCountListener* l); |
407 |
|
|
408 |
|
/** |
409 |
|
* Removes the specified listener. |
410 |
|
*/ |
411 |
|
void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l); |
412 |
|
|
413 |
|
/** |
414 |
|
* Notifies listeners that the total number of active voices is changed. |
415 |
|
* @param NewCount The new number of active voices. |
416 |
|
*/ |
417 |
|
void fireTotalVoiceCountChanged(int NewCount); |
418 |
|
|
419 |
|
/** |
420 |
|
* Registers the specified listener to be notified when the number |
421 |
|
* of effect sends on a particular sampler channel is changed. |
422 |
|
*/ |
423 |
|
void AddFxSendCountListener(FxSendCountListener* l); |
424 |
|
|
425 |
|
/** |
426 |
|
* Removes the specified listener. |
427 |
|
*/ |
428 |
|
void RemoveFxSendCountListener(FxSendCountListener* l); |
429 |
|
|
430 |
|
/** |
431 |
* Returns the names of all available audio output drivers. |
* Returns the names of all available audio output drivers. |
432 |
*/ |
*/ |
433 |
std::vector<String> AvailableAudioOutputDrivers(); |
std::vector<String> AvailableAudioOutputDrivers(); |
434 |
|
|
435 |
/** |
/** |
436 |
|
* Returns the names of all available MIDI input drivers. |
437 |
|
*/ |
438 |
|
std::vector<String> AvailableMidiInputDrivers(); |
439 |
|
|
440 |
|
/** |
441 |
|
* Returns the names of all available sampler engine types. |
442 |
|
* @see SamplerChannel::SetEngineType() |
443 |
|
*/ |
444 |
|
std::vector<String> AvailableEngineTypes(); |
445 |
|
|
446 |
|
/** |
447 |
* Create an audio output device. |
* Create an audio output device. |
448 |
* |
* |
449 |
* @param AudioDriver - name of the audio driver |
* @param AudioDriver - name of the audio driver |
516 |
void Reset(); |
void Reset(); |
517 |
|
|
518 |
protected: |
protected: |
519 |
|
/** |
520 |
|
* Notifies listeners that the number of sampler channels has been changed. |
521 |
|
* @param NewCount The new number of sampler channels. |
522 |
|
*/ |
523 |
|
void fireChannelCountChanged(int NewCount); |
524 |
|
|
525 |
|
/** |
526 |
|
* Notifies listeners that the number of audio output devices has been changed. |
527 |
|
* @param NewCount The new number of audio output devices. |
528 |
|
*/ |
529 |
|
void fireAudioDeviceCountChanged(int NewCount); |
530 |
|
|
531 |
|
/** |
532 |
|
* Notifies listeners that the number of MIDI input devices has been changed. |
533 |
|
* @param NewCount The new number of MIDI input devices. |
534 |
|
*/ |
535 |
|
void fireMidiDeviceCountChanged(int NewCount); |
536 |
|
|
537 |
|
/** |
538 |
|
* Notifies listeners that the number of effect sends |
539 |
|
* on a particular sampler channel is changed. |
540 |
|
* @param ChannelId The numerical ID of the sampler channel. |
541 |
|
* @param NewCount The new number of sampler channels. |
542 |
|
*/ |
543 |
|
void fireFxSendCountChanged(int ChannelId, int NewCount); |
544 |
|
|
545 |
typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap; |
typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap; |
546 |
typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap; |
typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap; |
547 |
typedef std::map<uint, SamplerChannel*> SamplerChannelMap; |
typedef std::map<uint, SamplerChannel*> SamplerChannelMap; |
551 |
MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices |
MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices |
552 |
|
|
553 |
friend class SamplerChannel; |
friend class SamplerChannel; |
554 |
|
|
555 |
|
private: |
556 |
|
ListenerList<ChannelCountListener*> llChannelCountListeners; |
557 |
|
ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners; |
558 |
|
ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners; |
559 |
|
ListenerList<VoiceCountListener*> llVoiceCountListeners; |
560 |
|
ListenerList<StreamCountListener*> llStreamCountListeners; |
561 |
|
ListenerList<BufferFillListener*> llBufferFillListeners; |
562 |
|
ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners; |
563 |
|
ListenerList<FxSendCountListener*> llFxSendCountListeners; |
564 |
|
|
565 |
|
class EventHandler : public EngineChangeListener, public FxSendCountListener { |
566 |
|
public: |
567 |
|
void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; } |
568 |
|
|
569 |
|
/** |
570 |
|
* Invoked when the engine type of the |
571 |
|
* specified sampler channel is changed. |
572 |
|
* @param ChannelId The numerical ID of the sampler |
573 |
|
* channel, which engine type has been changed. |
574 |
|
*/ |
575 |
|
virtual void EngineChanged(int ChannelId); |
576 |
|
|
577 |
|
/** |
578 |
|
* Invoked when the number of effect sends |
579 |
|
* on the specified sampler channel has changed. |
580 |
|
* @param ChannelId The numerical ID of the sampler channel. |
581 |
|
* @param NewCount The new number of effect sends. |
582 |
|
*/ |
583 |
|
virtual void FxSendCountChanged(int ChannelId, int NewCount); |
584 |
|
|
585 |
|
private: |
586 |
|
Sampler* pSampler; |
587 |
|
} eventHandler; |
588 |
}; |
}; |
589 |
} |
} |
590 |
|
|