3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005, 2006 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 * |
27 |
#include <vector> |
#include <vector> |
28 |
#include <map> |
#include <map> |
29 |
#include "common/global.h" |
#include "common/global.h" |
30 |
#include "common/LinuxSamplerException.h" |
#include "common/Exception.h" |
31 |
#include "engines/common/Engine.h" |
#include "engines/EngineChannel.h" |
32 |
#include "drivers/midi/MidiInputDevice.h" |
#include "drivers/midi/MidiInputDevice.h" |
33 |
#include "drivers/audio/AudioOutputDevice.h" |
#include "drivers/audio/AudioOutputDevice.h" |
34 |
|
|
37 |
// just symbol prototyping |
// just symbol prototyping |
38 |
class Sampler; |
class Sampler; |
39 |
|
|
40 |
/** LinuxSampler sampler channel |
/** @brief LinuxSampler sampler channel |
41 |
* |
* |
42 |
* Encapsulates one sampler engine, one connection to a MIDI input |
* Encapsulates a channel of a specific sampler engine type, one |
43 |
* device and one connection to an audio output device. You cannot |
* connection to a MIDI input device and one connection to an audio |
44 |
* create an instance of this class on your own, you have to use the |
* output device. You cannot create an instance of this class on your |
45 |
* AddSamplerChannel() method of the Sampler object to create a new |
* own, you have to use the AddSamplerChannel() method of the Sampler |
46 |
* sampler channel. |
* object to create a new sampler channel. |
47 |
*/ |
*/ |
48 |
class SamplerChannel { |
class SamplerChannel { |
49 |
public: |
public: |
50 |
/** |
/** |
51 |
* 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. |
|
52 |
* |
* |
53 |
* @param EngineType - type of the engine to deploy |
* @param EngineType - type of the engine to use |
54 |
|
* @throws Exception - if \a EngineType is invalid |
55 |
|
* @see Sampler::AvailableEngineTypes() |
56 |
*/ |
*/ |
57 |
void LoadEngine(Engine::type_t EngineType); // TODO: to be changed to 'void LoadEngine(String EngineType) throws (LinuxSamplerException);' |
void SetEngineType(String EngineType) throw (Exception); |
58 |
|
|
59 |
/** |
/** |
60 |
* Connect this sampler channel to an audio output device, that |
* Connect this sampler channel to an audio output device, that |
67 |
void SetAudioOutputDevice(AudioOutputDevice* pDevice); |
void SetAudioOutputDevice(AudioOutputDevice* pDevice); |
68 |
|
|
69 |
/** |
/** |
70 |
* Connect this sampler channel to and MIDI input device. |
* Connect this sampler channel to a MIDI input device. |
71 |
* |
* |
72 |
* @param pDevice - MIDI input device to connect to |
* @param pDevice - MIDI input device to connect to |
73 |
*/ |
*/ |
74 |
void SetMidiInputDevice(MidiInputDevice *pDevice); |
void SetMidiInputDevice(MidiInputDevice *pDevice); |
75 |
|
|
76 |
/** |
/** |
77 |
* Connect this sampler channel to and MIDI input port. |
* Connect this sampler channel to a MIDI input port. |
78 |
* |
* |
79 |
* @param MidiPort - MIDI port to connect to |
* @param MidiPort - MIDI port to connect to |
80 |
*/ |
*/ |
81 |
void SetMidiInputPort(int MidiPort); |
void SetMidiInputPort(int MidiPort); |
82 |
|
|
83 |
/** |
/** |
84 |
* Connect this sampler channel to and MIDI input channel. |
* Define on which MIDI channel(s) this sampler channel should |
85 |
|
* listen to. By default, that is after creation of a new |
86 |
|
* sampler channel, the sampler channel will listen to all MIDI |
87 |
|
* channels. |
88 |
* |
* |
89 |
* @param MidiChannel - MIDI channel to connect to |
* @param MidiChannel - MIDI channel to listen |
90 |
*/ |
*/ |
91 |
void SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel); |
void SetMidiInputChannel(midi_chan_t MidiChannel); |
92 |
|
|
93 |
/** |
/** |
94 |
* Connect this sampler channel to a MIDI input triplet. |
* Connect this sampler channel to a MIDI input triplet. |
99 |
* sampler channel should listen to |
* sampler channel should listen to |
100 |
* (default: listen on all MIDI channels) |
* (default: listen on all MIDI channels) |
101 |
*/ |
*/ |
102 |
void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel = MidiInputPort::midi_chan_all); |
void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all); |
103 |
|
|
104 |
/** |
/** |
105 |
* Returns the engine that was deployed on this sampler channel. |
* Returns the EngineChannel object that was deployed on this |
106 |
|
* sampler channel appropriate to the given sampler engine type. |
107 |
* |
* |
108 |
* @returns pointer to engine or NULL if no engine deployed |
* @returns pointer to engine or NULL if no engine deployed |
109 |
*/ |
*/ |
110 |
Engine* GetEngine(); |
EngineChannel* GetEngineChannel(); |
111 |
|
|
112 |
/** |
/** |
113 |
* Returns the MIDI input channel to which this sampler |
* Returns the MIDI input channel to which this sampler |
116 |
* @returns The MIDI input channel on which the sampler |
* @returns The MIDI input channel on which the sampler |
117 |
* channel is listening to. |
* channel is listening to. |
118 |
*/ |
*/ |
119 |
MidiInputPort::midi_chan_t GetMidiInputChannel(); |
midi_chan_t GetMidiInputChannel(); |
120 |
|
|
121 |
/** |
/** |
122 |
* Returns the MIDI input port number to which this sampler |
* Returns the MIDI input port number to which this sampler |
152 |
|
|
153 |
protected: |
protected: |
154 |
SamplerChannel(Sampler* pS); |
SamplerChannel(Sampler* pS); |
155 |
~SamplerChannel(); |
virtual ~SamplerChannel(); |
156 |
|
|
157 |
/** Getting MIDI input device port given its index number. */ |
/** Getting MIDI input device port given its index number. */ |
158 |
MidiInputPort* GetMidiInputDevicePort(int iMidiPort); |
MidiInputPort* __GetMidiInputDevicePort(int iMidiPort); |
159 |
|
|
160 |
Sampler* pSampler; |
Sampler* pSampler; |
161 |
Engine* pEngine; |
EngineChannel* pEngineChannel; |
162 |
AudioOutputDevice* pAudioOutputDevice; |
AudioOutputDevice* pAudioOutputDevice; |
163 |
MidiInputDevice* pMidiInputDevice; |
MidiInputDevice* pMidiInputDevice; |
|
int midiPort; |
|
|
MidiInputPort::midi_chan_t midiChannel; |
|
164 |
int iIndex; |
int iIndex; |
165 |
|
|
166 |
friend class Sampler; |
friend class Sampler; |
167 |
|
private: |
168 |
|
int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! |
169 |
|
midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead ! |
170 |
}; |
}; |
171 |
|
|
172 |
/** LinuxSampler main class |
/** @brief LinuxSampler main class |
173 |
* |
* |
174 |
* This is the toplevel class for a LinuxSampler instance. |
* This is the toplevel class for a LinuxSampler instance. |
175 |
* |
* |
177 |
* sampler channel can individually be deployed with it's own sampler |
* sampler channel can individually be deployed with it's own sampler |
178 |
* engine, connected to an arbitrary MIDI input device and connected to |
* engine, connected to an arbitrary MIDI input device and connected to |
179 |
* an arbitrary audio output device. Here an example setup: |
* an arbitrary audio output device. Here an example setup: |
180 |
|
* @code |
181 |
|
* S.Channel MIDI in S.Engine Audio out |
182 |
|
* ------------------------------------------------------------------- |
183 |
|
* 0 Alsa -> gig::Engine -> Jack |
184 |
|
* 1 VSTi -> Akai::Engine -> VSTi |
185 |
|
* 2 Jack -> DLS::Engine -> Jack |
186 |
|
* 3 Jack -> SF::Engine -> Alsa |
187 |
* |
* |
188 |
* S.Channel. MIDI in S.Engine Audio out |
* ... (and so on) ... |
189 |
* ------------------------------------------------------------------- |
* @endcode |
|
* 0 Alsa -> gig::Engine -> Jack |
|
|
* 1 VSTi -> Akai::Engine -> VSTi |
|
|
* 2 Jack -> DLS::Engine -> Jack |
|
|
* 3 Jack -> SF::Engine -> Alsa |
|
|
* |
|
|
* ... (and so on) ... |
|
190 |
* |
* |
191 |
* Note that not all audio and MIDI backends and sampler engines listed |
* Note that not all audio and MIDI backends and sampler engines listed |
192 |
* in the example above are already implemented! |
* in the example above might already been implemented! |
193 |
* |
* |
194 |
* 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 |
195 |
* several, different audio output and MIDI input systems |
* several, different audio output and MIDI input systems |
196 |
* simultaniously at the same time. Here the example setup shown in the |
* simultaniously at the same time. Here the example setup shown in the |
197 |
* ascpect of MIDI input and audio output devices / drivers: |
* aspect of MIDI input and audio output devices / drivers: |
198 |
* |
* @code |
199 |
* ######################### ######################### |
* ######################### ######################### |
200 |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
201 |
* ######################### ######################### |
* ######################### ######################### |
202 |
* ^ ^ ^ |
* ^ ^ ^ |
203 |
* /------------>|Sampler Channel 0|-----/ | | |
* /------------>|Sampler Channel 0|-----/ | | |
204 |
* | /--------->|Sampler Channel 1|---------------------/ |
* | /--------->|Sampler Channel 1|---------------------/ |
205 |
* | | /---->|Sampler Channel 2|---------/ |
* | | /------>|Sampler Channel 2|---------/ |
206 |
* | | | /->|Sampler Channel 3|------------>######################### |
* | | | /--->|Sampler Channel 3|------------>######################### |
207 |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
208 |
* | | | | ######################### |
* | | | | ######################### |
209 |
* | | | \----------------------------------------------------\ |
* | | | \-----------------------------------------------------\ |
210 |
* | | \-------------------------------------------\ | |
* | | \--------------------------------------------\ | |
211 |
* | \--------------------\ | | |
* | \--------------------\ | | |
212 |
* | | | | |
* | | | | |
213 |
* ####################### ####################### ####################### |
* ####################### ####################### ####################### |
214 |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
215 |
* ####################### ####################### ####################### |
* ####################### ####################### ####################### |
216 |
|
* @endcode |
217 |
* |
* |
218 |
* 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 |
219 |
* driver / audio output driver) can be connected multiple times to |
* driver / audio output driver) can be connected multiple times to |
220 |
* different sampler channels. |
* different sampler channels. |
221 |
|
* |
222 |
|
* It's even possible to create multiple instances of the same driver, for |
223 |
|
* example multiple instances of the Alsa output driver to use multiple |
224 |
|
* sound cards at the same time, or multiple instances of the JACK audio |
225 |
|
* output driver to leverage SMP systems or boxes with several hard discs. |
226 |
*/ |
*/ |
227 |
class Sampler { |
class Sampler { |
228 |
public: |
public: |
234 |
/** |
/** |
235 |
* Destructor. |
* Destructor. |
236 |
*/ |
*/ |
237 |
~Sampler(); |
virtual ~Sampler(); |
238 |
|
|
239 |
/** |
/** |
240 |
* Returns the number of sampler channels currently allocated. |
* Returns the number of sampler channels currently allocated. |
288 |
std::vector<String> AvailableAudioOutputDrivers(); |
std::vector<String> AvailableAudioOutputDrivers(); |
289 |
|
|
290 |
/** |
/** |
291 |
|
* Returns the names of all available MIDI input drivers. |
292 |
|
*/ |
293 |
|
std::vector<String> AvailableMidiInputDrivers(); |
294 |
|
|
295 |
|
/** |
296 |
|
* Returns the names of all available sampler engine types. |
297 |
|
* @see SamplerChannel::SetEngineType() |
298 |
|
*/ |
299 |
|
std::vector<String> AvailableEngineTypes(); |
300 |
|
|
301 |
|
/** |
302 |
* Create an audio output device. |
* Create an audio output device. |
303 |
* |
* |
304 |
* @param AudioDriver - name of the audio driver |
* @param AudioDriver - name of the audio driver |
305 |
* @param Parameters - eventually needed driver parameters to |
* @param Parameters - eventually needed driver parameters to |
306 |
* create the device |
* create the device |
307 |
* @returns pointer to created audio output device |
* @returns pointer to created audio output device |
308 |
* @throws LinuxSamplerException if device could not be created |
* @throws Exception if device could not be created |
309 |
*/ |
*/ |
310 |
AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException); |
AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception); |
311 |
|
|
312 |
/** |
/** |
313 |
* Create a midi input device. |
* Create a midi input device. |
316 |
* @param Parameters - eventually needed driver parameters to |
* @param Parameters - eventually needed driver parameters to |
317 |
* create the device |
* create the device |
318 |
* @returns pointer to created midi input device |
* @returns pointer to created midi input device |
319 |
* @throws LinuxSamplerException if device could not be created |
* @throws Exception if device could not be created |
320 |
*/ |
*/ |
321 |
MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException); |
MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception); |
322 |
|
|
323 |
/** |
/** |
324 |
* Returns the number of all created audio output devices. |
* Returns the number of all created audio output devices. |
344 |
* Destroy the given audio output device and takes care if there |
* Destroy the given audio output device and takes care if there |
345 |
* are still sampler angines connected to this device, etc. |
* are still sampler angines connected to this device, etc. |
346 |
* |
* |
347 |
* @throws LinuxSamplerException if sampler channels are still |
* @throws Exception if sampler channels are still |
348 |
* connected to the device |
* connected to the device |
349 |
*/ |
*/ |
350 |
void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException); |
void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception); |
351 |
|
|
352 |
/** |
/** |
353 |
* Destroy the given MIDI input device and takes care if there |
* Destroy the given MIDI input device and takes care if there |
354 |
* are still sampler angines connected to this device, etc. |
* are still sampler angines connected to this device, etc. |
355 |
* |
* |
356 |
* @throws LinuxSamplerException if sampler channels are still |
* @throws Exception if sampler channels are still |
357 |
* connected to the device |
* connected to the device |
358 |
|
*/ |
359 |
|
void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception); |
360 |
|
|
361 |
|
/** |
362 |
|
* Gets the current number of all active voices. |
363 |
|
* @returns The current number of all active voices. |
364 |
*/ |
*/ |
365 |
void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException); |
int GetVoiceCount(); |
366 |
|
|
367 |
/** |
/** |
368 |
* Reset the whole sampler. Destroy all engines, sampler |
* Reset the whole sampler. Destroy all engines, sampler |