/[svn]/linuxsampler/trunk/src/Sampler.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/Sampler.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 502 - (show annotations) (download) (as text)
Fri Apr 29 14:20:22 2005 UTC (18 years, 11 months ago) by letz
File MIME type: text/x-c++hdr
File size: 15084 byte(s)
Fix destructor

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 Christian Schoenebeck *
7 * *
8 * 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 *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #ifndef __LS_SAMPLER_H__
25 #define __LS_SAMPLER_H__
26
27 #include <vector>
28 #include <map>
29 #include "common/global.h"
30 #include "common/LinuxSamplerException.h"
31 #include "engines/common/EngineChannel.h"
32 #include "drivers/midi/MidiInputDevice.h"
33 #include "drivers/audio/AudioOutputDevice.h"
34
35 namespace LinuxSampler {
36
37 // just symbol prototyping
38 class Sampler;
39
40 /** @brief LinuxSampler sampler channel
41 *
42 * Encapsulates a channel of a specific sampler engine typ, one
43 * connection to a MIDI input device and one connection to an audio
44 * output device. You cannot create an instance of this class on your
45 * own, you have to use the AddSamplerChannel() method of the Sampler
46 * object to create a new sampler channel.
47 */
48 class SamplerChannel {
49 public:
50 /**
51 * Assign a sampler engine type to this sampler channel.
52 *
53 * @param EngineType - type of the engine to use
54 * @throws LinuxSamplerException - if \a EngineType is invalid
55 */
56 void SetEngineType(String EngineType) throw (LinuxSamplerException);
57
58 /**
59 * Connect this sampler channel to an audio output device, that
60 * is an instance of an audio output driver. If this sampler
61 * channel was already connected to an audio output device, then
62 * the old connection will automatically be removed before.
63 *
64 * @param pDevice - audio output device to connect to
65 */
66 void SetAudioOutputDevice(AudioOutputDevice* pDevice);
67
68 /**
69 * Connect this sampler channel to a MIDI input device.
70 *
71 * @param pDevice - MIDI input device to connect to
72 */
73 void SetMidiInputDevice(MidiInputDevice *pDevice);
74
75 /**
76 * Connect this sampler channel to a MIDI input port.
77 *
78 * @param MidiPort - MIDI port to connect to
79 */
80 void SetMidiInputPort(int MidiPort);
81
82 /**
83 * Define on which MIDI channel(s) this sampler channel should
84 * listen to. By default, that is after creation of a new
85 * sampler channel, the sampler channel will listen to all MIDI
86 * channels.
87 *
88 * @param MidiChannel - MIDI channel to listen
89 */
90 void SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel);
91
92 /**
93 * Connect this sampler channel to a MIDI input triplet.
94 *
95 * @param pDevice - MIDI input device to connect to
96 * @param iMidiPort - MIDI port to connect to
97 * @param MidiChannel - optional: MIDI channel on which the
98 * sampler channel should listen to
99 * (default: listen on all MIDI channels)
100 */
101 void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel = MidiInputPort::midi_chan_all);
102
103 /**
104 * Returns the EngineChannel object that was deployed on this
105 * sampler channel appropriate to the given sampler engine type.
106 *
107 * @returns pointer to engine or NULL if no engine deployed
108 */
109 EngineChannel* GetEngineChannel();
110
111 /**
112 * Returns the MIDI input channel to which this sampler
113 * channel is currently connected to.
114 *
115 * @returns The MIDI input channel on which the sampler
116 * channel is listening to.
117 */
118 MidiInputPort::midi_chan_t GetMidiInputChannel();
119
120 /**
121 * Returns the MIDI input port number to which this sampler
122 * channel is currently connected to.
123 *
124 * @returns MIDI input port number or -1 if not connected
125 */
126 int GetMidiInputPort();
127
128 /**
129 * Returns the audio output device to which this sampler channel
130 * is currently connected to.
131 *
132 * @returns pointer to audio output device or NULL if not
133 * connected
134 */
135 AudioOutputDevice* GetAudioOutputDevice();
136
137 /**
138 * Returns the MIDI input device to which this sampler channel
139 * is currently connected to.
140 *
141 * @returns pointer to MIDI input device or NULL if not
142 * connected
143 */
144 MidiInputDevice* GetMidiInputDevice();
145
146 /**
147 * Returns the index number of this sampler channel within the
148 * Sampler instance.
149 */
150 uint Index();
151
152 protected:
153 SamplerChannel(Sampler* pS);
154 virtual ~SamplerChannel();
155
156 /** Getting MIDI input device port given its index number. */
157 MidiInputPort* GetMidiInputDevicePort(int iMidiPort);
158
159 Sampler* pSampler;
160 EngineChannel* pEngineChannel;
161 AudioOutputDevice* pAudioOutputDevice;
162 MidiInputDevice* pMidiInputDevice;
163 int midiPort;
164 MidiInputPort::midi_chan_t midiChannel;
165 int iIndex;
166
167 friend class Sampler;
168 };
169
170 /** @brief LinuxSampler main class
171 *
172 * This is the toplevel class for a LinuxSampler instance.
173 *
174 * LinuxSampler can have arbitrary numbers of sampler channels. Each
175 * sampler channel can individually be deployed with it's own sampler
176 * engine, connected to an arbitrary MIDI input device and connected to
177 * an arbitrary audio output device. Here an example setup:
178 *
179 * S.Channel. MIDI in S.Engine Audio out
180 * -------------------------------------------------------------------
181 * 0 Alsa -> gig::Engine -> Jack
182 * 1 VSTi -> Akai::Engine -> VSTi
183 * 2 Jack -> DLS::Engine -> Jack
184 * 3 Jack -> SF::Engine -> Alsa
185 *
186 * ... (and so on) ...
187 *
188 * Note that not all audio and MIDI backends and sampler engines listed
189 * in the example above are already implemented!
190 *
191 * As you can see in the example setup, LinuxSampler is capable to use
192 * several, different audio output and MIDI input systems
193 * simultaniously at the same time. Here the example setup shown in the
194 * ascpect of MIDI input and audio output devices / drivers:
195 *
196 * ######################### #########################
197 * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
198 * ######################### #########################
199 * ^ ^ ^
200 * /------------>|Sampler Channel 0|-----/ | |
201 * | /--------->|Sampler Channel 1|---------------------/
202 * | | /---->|Sampler Channel 2|---------/
203 * | | | /->|Sampler Channel 3|------------>#########################
204 * | | | | ... (and so on) ... # AudioOutputDeviceAlsa #
205 * | | | | #########################
206 * | | | \----------------------------------------------------\
207 * | | \-------------------------------------------\ |
208 * | \--------------------\ | |
209 * | | | |
210 * ####################### ####################### #######################
211 * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
212 * ####################### ####################### #######################
213 *
214 * As you can see in this example setup, one device (that is midi input
215 * driver / audio output driver) can be connected multiple times to
216 * different sampler channels.
217 */
218 class Sampler {
219 public:
220 /**
221 * Constructor. Create a LinuxSampler instance.
222 */
223 Sampler();
224
225 /**
226 * Destructor.
227 */
228 virtual ~Sampler();
229
230 /**
231 * Returns the number of sampler channels currently allocated.
232 */
233 uint SamplerChannels();
234
235 /**
236 * Create and add a new sampler channel to this Sampler
237 * instance. For race condition reasons the new channel will use
238 * an index past the last already existing sampler channel
239 * index (in case the index limit was not reached yet, otherwise
240 * a free index starting from 0 is searched).
241 *
242 * @returns pointer to new sampler channel
243 */
244 SamplerChannel* AddSamplerChannel();
245
246 /**
247 * Returns the sampler channel of the given sampler channel
248 * index.
249 *
250 * @returns pointer to sought sampler channel
251 */
252 SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);
253
254 /**
255 * Returns all created sampler channels.
256 */
257 std::map<uint, SamplerChannel*> GetSamplerChannels();
258
259 /**
260 * Destroy and remove the given sampler channel from this
261 * Sampler instance.
262 *
263 * @param pSamplerChannel - pointer to sampler channel to remove
264 */
265 void RemoveSamplerChannel(SamplerChannel* pSamplerChannel);
266
267 /**
268 * Destroy and remove the given sampler channel from this
269 * Sampler instance.
270 *
271 * @param uiSamplerChannel - index of the sampler channel to
272 * remove
273 */
274 void RemoveSamplerChannel(uint uiSamplerChannel);
275
276 /**
277 * Returns the names of all available audio output drivers.
278 */
279 std::vector<String> AvailableAudioOutputDrivers();
280
281 /**
282 * Create an audio output device.
283 *
284 * @param AudioDriver - name of the audio driver
285 * @param Parameters - eventually needed driver parameters to
286 * create the device
287 * @returns pointer to created audio output device
288 * @throws LinuxSamplerException if device could not be created
289 */
290 AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);
291
292 /**
293 * Create a midi input device.
294 *
295 * @param MidiDriver - name of the midi driver
296 * @param Parameters - eventually needed driver parameters to
297 * create the device
298 * @returns pointer to created midi input device
299 * @throws LinuxSamplerException if device could not be created
300 */
301 MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);
302
303 /**
304 * Returns the number of all created audio output devices.
305 */
306 uint AudioOutputDevices();
307
308 /**
309 * Returns the number of all created MIDI input devices.
310 */
311 uint MidiInputDevices();
312
313 /**
314 * Returns all created audio output devices.
315 */
316 std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
317
318 /**
319 * Returns all created MIDI input devices.
320 */
321 std::map<uint, MidiInputDevice*> GetMidiInputDevices();
322
323 /**
324 * Destroy the given audio output device and takes care if there
325 * are still sampler angines connected to this device, etc.
326 *
327 * @throws LinuxSamplerException if sampler channels are still
328 * connected to the device
329 */
330 void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);
331
332 /**
333 * Destroy the given MIDI input device and takes care if there
334 * are still sampler angines connected to this device, etc.
335 *
336 * @throws LinuxSamplerException if sampler channels are still
337 * connected to the device
338 */
339 void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException);
340
341 /**
342 * Reset the whole sampler. Destroy all engines, sampler
343 * channels, MIDI input devices and audio output devices.
344 */
345 void Reset();
346
347 protected:
348 typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
349 typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
350 typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
351
352 SamplerChannelMap mSamplerChannels; ///< contains all created sampler channels
353 AudioOutputDeviceMap mAudioOutputDevices; ///< contains all created audio output devices
354 MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices
355
356 friend class SamplerChannel;
357 };
358 }
359
360 #endif // __LS_SAMPLER_H__

  ViewVC Help
Powered by ViewVC