1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
9 |
* the Free Software Foundation; either version 2 of the License, or * |
10 |
* (at your option) any later version. * |
11 |
* * |
12 |
* This program is distributed in the hope that it will be useful, * |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
* GNU General Public License for more details. * |
16 |
* * |
17 |
* You should have received a copy of the GNU General Public License * |
18 |
* along with this program; if not, write to the Free Software * |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
22 |
|
23 |
#ifndef __LS_SAMPLER_H__ |
24 |
#define __LS_SAMPLER_H__ |
25 |
|
26 |
#include <vector> |
27 |
#include <map> |
28 |
#include "common/global.h" |
29 |
#include "common/LinuxSamplerException.h" |
30 |
#include "engines/common/Engine.h" |
31 |
#include "mididriver/MidiInputDevice.h" |
32 |
#include "audiodriver/AudioOutputDevice.h" |
33 |
|
34 |
namespace LinuxSampler { |
35 |
|
36 |
// just symbol prototyping |
37 |
class Sampler; |
38 |
|
39 |
/** LinuxSampler sampler channel |
40 |
* |
41 |
* Encapsulates one sampler engine, one connection to a MIDI input |
42 |
* device and one connection to an audio output device. You cannot |
43 |
* create an instance of this class on your own, you have to use the |
44 |
* AddSamplerChannel() method of the Sampler object to create a new |
45 |
* sampler channel. |
46 |
*/ |
47 |
class SamplerChannel { |
48 |
public: |
49 |
/** |
50 |
* Deploy a sampler engine of the given type for this sampler |
51 |
* channnel. If there was already a sampler engine deployed on |
52 |
* this sampler channel, then the old engine will automatically |
53 |
* be destroyed. |
54 |
* |
55 |
* @param EngineType - type of the engine to deploy |
56 |
*/ |
57 |
void LoadEngine(Engine::type_t EngineType); // TODO: to be changed to 'void LoadEngine(String EngineType) throws (LinuxSamplerException);' |
58 |
|
59 |
/** |
60 |
* Connect this sampler channel to an audio output device, that |
61 |
* is an instance of an audio output driver. If this sampler |
62 |
* channel was already connected to an audio output device, then |
63 |
* the old connection will automatically be removed before. |
64 |
* |
65 |
* @param pDevice - audio output device to connect to |
66 |
*/ |
67 |
void SetAudioOutputDevice(AudioOutputDevice* pDevice); |
68 |
|
69 |
/** |
70 |
* Connect this sampler channel to and MIDI input port |
71 |
* |
72 |
* @param MidiInputDevice - MIDI input device to connect to |
73 |
* @param MidiInputPort - MIDI port to connect to |
74 |
* @param MidiChannel - optional: MIDI channel on which the |
75 |
* sampler channel should listen to |
76 |
* (default: listen on all MIDI channels) |
77 |
*/ |
78 |
void SetMidiInputPort(MidiInputDevice* pDevice, int midiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel = MidiInputDevice::MidiInputPort::midi_chan_all); |
79 |
|
80 |
/** |
81 |
* Returns the engine that was deployed on this sampler channel. |
82 |
* |
83 |
* @returns pointer to engine or NULL if no engine deployed |
84 |
*/ |
85 |
Engine* GetEngine(); |
86 |
|
87 |
/** |
88 |
* Returns the MIDI input device to which this sampler channel |
89 |
* is currently connected to. |
90 |
* |
91 |
* @returns pointer to MIDI input device or NULL if not |
92 |
* connected |
93 |
*/ |
94 |
MidiInputDevice::MidiInputPort* GetMidiInputPort(); |
95 |
|
96 |
/** |
97 |
* Returns the audio output device to which this sampler channel |
98 |
* is currently connected to. |
99 |
* |
100 |
* @returns pointer to audio output device or NULL if not |
101 |
* connected |
102 |
*/ |
103 |
AudioOutputDevice* GetAudioOutputDevice(); |
104 |
|
105 |
/** |
106 |
* Returns the audio output device to which this sampler channel |
107 |
* is currently connected to. |
108 |
* |
109 |
* @returns pointer to audio output device or NULL if not |
110 |
* connected |
111 |
*/ |
112 |
MidiInputDevice* GetMidiInputDevice(); |
113 |
|
114 |
/** |
115 |
* Returns the index number of this sampler channel within the |
116 |
* Sampler instance. |
117 |
*/ |
118 |
uint Index(); |
119 |
|
120 |
/** |
121 |
* Returns midi channel |
122 |
*/ |
123 |
MidiInputDevice::MidiInputPort::midi_chan_t GetMidiInputChannel() { return midiChannel; } |
124 |
|
125 |
protected: |
126 |
SamplerChannel(Sampler* pS); |
127 |
~SamplerChannel(); |
128 |
|
129 |
Sampler* pSampler; |
130 |
Engine* pEngine; |
131 |
MidiInputDevice::MidiInputPort* pMidiInputPort; |
132 |
AudioOutputDevice* pAudioOutputDevice; |
133 |
int iIndex; |
134 |
MidiInputDevice::MidiInputPort::midi_chan_t midiChannel; |
135 |
|
136 |
friend class Sampler; |
137 |
}; |
138 |
|
139 |
/** LinuxSampler main class |
140 |
* |
141 |
* This is the toplevel class for a LinuxSampler instance. |
142 |
* |
143 |
* LinuxSampler can have arbitrary numbers of sampler channels. Each |
144 |
* sampler channel can individually be deployed with it's own sampler |
145 |
* engine, connected to an arbitrary MIDI input device and connected to |
146 |
* an arbitrary audio output device. Here an example setup: |
147 |
* |
148 |
* S.Channel. MIDI in S.Engine Audio out |
149 |
* ------------------------------------------------------------------- |
150 |
* 0 Alsa -> gig::Engine -> Jack |
151 |
* 1 VSTi -> Akai::Engine -> VSTi |
152 |
* 2 Jack -> DLS::Engine -> Jack |
153 |
* 3 Jack -> SF::Engine -> Alsa |
154 |
* |
155 |
* ... (and so on) ... |
156 |
* |
157 |
* Note that not all audio and MIDI backends and sampler engines listed |
158 |
* in the example above are already implemented! |
159 |
* |
160 |
* As you can see in the example setup, LinuxSampler is capable to use |
161 |
* several, different audio output and MIDI input systems |
162 |
* simultaniously at the same time. Here the example setup shown in the |
163 |
* ascpect of MIDI input and audio output devices / drivers: |
164 |
* |
165 |
* ######################### ######################### |
166 |
* # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # |
167 |
* ######################### ######################### |
168 |
* ^ ^ ^ |
169 |
* /------------>|Sampler Channel 0|-----/ | | |
170 |
* | /--------->|Sampler Channel 1|---------------------/ |
171 |
* | | /---->|Sampler Channel 2|---------/ |
172 |
* | | | /->|Sampler Channel 3|------------>######################### |
173 |
* | | | | ... (and so on) ... # AudioOutputDeviceAlsa # |
174 |
* | | | | ######################### |
175 |
* | | | \----------------------------------------------------\ |
176 |
* | | \-------------------------------------------\ | |
177 |
* | \--------------------\ | | |
178 |
* | | | | |
179 |
* ####################### ####################### ####################### |
180 |
* # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # |
181 |
* ####################### ####################### ####################### |
182 |
* |
183 |
* As you can see in this example setup, one device (that is midi input |
184 |
* driver / audio output driver) can be connected multiple times to |
185 |
* different sampler channels. |
186 |
*/ |
187 |
class Sampler { |
188 |
public: |
189 |
/** |
190 |
* Constructor. Create a LinuxSampler instance. |
191 |
*/ |
192 |
Sampler(); |
193 |
|
194 |
/** |
195 |
* Destructor. |
196 |
*/ |
197 |
~Sampler(); |
198 |
|
199 |
/** |
200 |
* Returns the number of sampler channels currently allocated. |
201 |
*/ |
202 |
uint SamplerChannels(); |
203 |
|
204 |
/** |
205 |
* Create and add a new sampler channel to this Sampler instance. |
206 |
* |
207 |
* @returns pointer to new sampler channel |
208 |
*/ |
209 |
SamplerChannel* AddSamplerChannel(); |
210 |
|
211 |
/** |
212 |
* Returns the sampler channel of the given sampler channel |
213 |
* index. |
214 |
* |
215 |
* @returns pointer to sought sampler channel |
216 |
*/ |
217 |
SamplerChannel* GetSamplerChannel(uint uiSamplerChannel); |
218 |
|
219 |
/** |
220 |
* Destroy and remove the given sampler channel from this |
221 |
* Sampler instance. |
222 |
* |
223 |
* @param pSamplerChannel - pointer to sampler channel to remove |
224 |
*/ |
225 |
void RemoveSamplerChannel(SamplerChannel* pSamplerChannel); |
226 |
|
227 |
/** |
228 |
* Destroy and remove the given sampler channel from this |
229 |
* Sampler instance. |
230 |
* |
231 |
* @param uiSamplerChannel - index of the sampler channel to |
232 |
* remove |
233 |
*/ |
234 |
void RemoveSamplerChannel(uint uiSamplerChannel); |
235 |
|
236 |
std::vector<String> AvailableAudioOutputDrivers(); |
237 |
|
238 |
/** |
239 |
* Create an audio output device. |
240 |
* |
241 |
* @param AudioDriver - name of the audio driver |
242 |
* @param Parameters - eventually needed driver parameters to |
243 |
* create the device |
244 |
* @returns pointer to created audio output device |
245 |
* @throws LinuxSamplerException if device could not be created |
246 |
*/ |
247 |
AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException); |
248 |
|
249 |
/** |
250 |
* Create a midi input device. |
251 |
* |
252 |
* @param MidiDriver - name of the midi driver |
253 |
* @param Parameters - eventually needed driver parameters to |
254 |
* create the device |
255 |
* @returns pointer to created midi input device |
256 |
* @throws LinuxSamplerException if device could not be created |
257 |
*/ |
258 |
MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException); |
259 |
|
260 |
uint AudioOutputDevices(); |
261 |
uint MidiInputDevices(); |
262 |
|
263 |
std::map<uint, AudioOutputDevice*> GetAudioOutputDevices(); |
264 |
|
265 |
std::map<uint, MidiInputDevice*> GetMidiInputDevices(); |
266 |
|
267 |
void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException); |
268 |
void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException); |
269 |
|
270 |
protected: |
271 |
typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap; |
272 |
typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap; |
273 |
|
274 |
std::vector<SamplerChannel*> vSamplerChannels; ///< contains all created sampler channels |
275 |
AudioOutputDeviceMap mAudioOutputDevices; ///< contains all created audio output devices |
276 |
MidiInputDeviceMap mMidiInputDevices; |
277 |
|
278 |
template<class T> inline String ToString(T o) { |
279 |
std::stringstream ss; |
280 |
ss << o; |
281 |
return ss.str(); |
282 |
} |
283 |
|
284 |
friend class SamplerChannel; |
285 |
}; |
286 |
} |
287 |
|
288 |
#endif // __LS_SAMPLER_H__ |