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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 890 - (hide annotations) (download) (as text)
Sat Jul 1 13:43:04 2006 UTC (17 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 15246 byte(s)
just some refactoring work, moved the following files:

- src/engines/common/Engine.h -> src/engines/Engine.h,

- src/engines/common/EngineChannel.h ->
  src/engines/EngineChannel.h,

- src/engines/common/EngineChannel.cpp ->
  src/engines/EngineChannel.cpp

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 61 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 880 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 schoenebeck 53 * *
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 schoenebeck 880 #include "common/Exception.h"
31 schoenebeck 890 #include "engines/EngineChannel.h"
32 schoenebeck 203 #include "drivers/midi/MidiInputDevice.h"
33     #include "drivers/audio/AudioOutputDevice.h"
34 schoenebeck 53
35     namespace LinuxSampler {
36    
37     // just symbol prototyping
38     class Sampler;
39    
40 schoenebeck 411 /** @brief LinuxSampler sampler channel
41 schoenebeck 57 *
42 persson 840 * Encapsulates a channel of a specific sampler engine type, one
43 schoenebeck 411 * 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 schoenebeck 57 */
48 schoenebeck 53 class SamplerChannel {
49     public:
50 schoenebeck 57 /**
51 schoenebeck 411 * Assign a sampler engine type to this sampler channel.
52 schoenebeck 57 *
53 schoenebeck 411 * @param EngineType - type of the engine to use
54 schoenebeck 880 * @throws Exception - if \a EngineType is invalid
55 schoenebeck 57 */
56 schoenebeck 880 void SetEngineType(String EngineType) throw (Exception);
57 schoenebeck 57
58     /**
59 schoenebeck 123 * 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 schoenebeck 57 *
64 schoenebeck 123 * @param pDevice - audio output device to connect to
65 schoenebeck 57 */
66 schoenebeck 123 void SetAudioOutputDevice(AudioOutputDevice* pDevice);
67 schoenebeck 57
68     /**
69 schoenebeck 411 * Connect this sampler channel to a MIDI input device.
70 schoenebeck 57 *
71 capela 159 * @param pDevice - MIDI input device to connect to
72     */
73     void SetMidiInputDevice(MidiInputDevice *pDevice);
74    
75     /**
76 schoenebeck 411 * Connect this sampler channel to a MIDI input port.
77 capela 159 *
78     * @param MidiPort - MIDI port to connect to
79     */
80     void SetMidiInputPort(int MidiPort);
81    
82     /**
83 schoenebeck 411 * 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 capela 159 *
88 schoenebeck 411 * @param MidiChannel - MIDI channel to listen
89 capela 159 */
90 schoenebeck 675 void SetMidiInputChannel(midi_chan_t MidiChannel);
91 capela 159
92     /**
93     * Connect this sampler channel to a MIDI input triplet.
94     *
95     * @param pDevice - MIDI input device to connect to
96 schoenebeck 221 * @param iMidiPort - MIDI port to connect to
97 schoenebeck 57 * @param MidiChannel - optional: MIDI channel on which the
98     * sampler channel should listen to
99     * (default: listen on all MIDI channels)
100     */
101 schoenebeck 675 void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all);
102 schoenebeck 57
103     /**
104 schoenebeck 411 * Returns the EngineChannel object that was deployed on this
105     * sampler channel appropriate to the given sampler engine type.
106 schoenebeck 57 *
107     * @returns pointer to engine or NULL if no engine deployed
108     */
109 schoenebeck 411 EngineChannel* GetEngineChannel();
110 schoenebeck 57
111     /**
112 capela 159 * Returns the MIDI input channel to which this sampler
113     * channel is currently connected to.
114 schoenebeck 57 *
115 capela 159 * @returns The MIDI input channel on which the sampler
116     * channel is listening to.
117 schoenebeck 57 */
118 schoenebeck 675 midi_chan_t GetMidiInputChannel();
119 schoenebeck 57
120     /**
121 capela 159 * 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 schoenebeck 57 * 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 capela 159 * Returns the MIDI input device to which this sampler channel
139 senkov 155 * is currently connected to.
140     *
141 capela 159 * @returns pointer to MIDI input device or NULL if not
142 senkov 155 * connected
143     */
144     MidiInputDevice* GetMidiInputDevice();
145    
146     /**
147 schoenebeck 57 * Returns the index number of this sampler channel within the
148     * Sampler instance.
149     */
150     uint Index();
151    
152     protected:
153 schoenebeck 53 SamplerChannel(Sampler* pS);
154 letz 502 virtual ~SamplerChannel();
155 schoenebeck 57
156 capela 159 /** Getting MIDI input device port given its index number. */
157 schoenebeck 675 MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);
158 schoenebeck 203
159 schoenebeck 53 Sampler* pSampler;
160 schoenebeck 411 EngineChannel* pEngineChannel;
161 schoenebeck 53 AudioOutputDevice* pAudioOutputDevice;
162 capela 159 MidiInputDevice* pMidiInputDevice;
163 schoenebeck 53 int iIndex;
164 schoenebeck 57
165     friend class Sampler;
166 schoenebeck 675 private:
167     int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead !
168     midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !
169 schoenebeck 53 };
170    
171 schoenebeck 411 /** @brief LinuxSampler main class
172 schoenebeck 57 *
173     * This is the toplevel class for a LinuxSampler instance.
174     *
175     * LinuxSampler can have arbitrary numbers of sampler channels. Each
176     * sampler channel can individually be deployed with it's own sampler
177     * engine, connected to an arbitrary MIDI input device and connected to
178     * an arbitrary audio output device. Here an example setup:
179 schoenebeck 675 * @code
180     * S.Channel. MIDI in S.Engine Audio out
181     * -------------------------------------------------------------------
182     * 0 Alsa -> gig::Engine -> Jack
183     * 1 VSTi -> Akai::Engine -> VSTi
184     * 2 Jack -> DLS::Engine -> Jack
185     * 3 Jack -> SF::Engine -> Alsa
186 schoenebeck 57 *
187 schoenebeck 675 * ... (and so on) ...
188     * @endcode
189 schoenebeck 57 *
190     * Note that not all audio and MIDI backends and sampler engines listed
191     * in the example above are already implemented!
192     *
193     * As you can see in the example setup, LinuxSampler is capable to use
194     * several, different audio output and MIDI input systems
195     * simultaniously at the same time. Here the example setup shown in the
196     * ascpect of MIDI input and audio output devices / drivers:
197 schoenebeck 675 * @code
198     * ######################### #########################
199     * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
200     * ######################### #########################
201     * ^ ^ ^
202     * /------------>|Sampler Channel 0|-----/ | |
203     * | /--------->|Sampler Channel 1|---------------------/
204     * | | /------>|Sampler Channel 2|---------/
205     * | | | /--->|Sampler Channel 3|------------>#########################
206     * | | | | ... (and so on) ... # AudioOutputDeviceAlsa #
207     * | | | | #########################
208     * | | | \-----------------------------------------------------\
209     * | | \--------------------------------------------\ |
210     * | \--------------------\ | |
211     * | | | |
212     * ####################### ####################### #######################
213     * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
214     * ####################### ####################### #######################
215     * @endcode
216 schoenebeck 57 *
217     * As you can see in this example setup, one device (that is midi input
218     * driver / audio output driver) can be connected multiple times to
219     * different sampler channels.
220     */
221 schoenebeck 53 class Sampler {
222     public:
223 schoenebeck 57 /**
224     * Constructor. Create a LinuxSampler instance.
225     */
226 schoenebeck 53 Sampler();
227 schoenebeck 57
228     /**
229     * Destructor.
230     */
231 letz 502 virtual ~Sampler();
232 schoenebeck 57
233     /**
234     * Returns the number of sampler channels currently allocated.
235     */
236     uint SamplerChannels();
237    
238     /**
239 schoenebeck 209 * Create and add a new sampler channel to this Sampler
240     * instance. For race condition reasons the new channel will use
241     * an index past the last already existing sampler channel
242     * index (in case the index limit was not reached yet, otherwise
243     * a free index starting from 0 is searched).
244 schoenebeck 57 *
245     * @returns pointer to new sampler channel
246     */
247     SamplerChannel* AddSamplerChannel();
248    
249     /**
250     * Returns the sampler channel of the given sampler channel
251     * index.
252     *
253     * @returns pointer to sought sampler channel
254     */
255     SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);
256    
257     /**
258 schoenebeck 209 * Returns all created sampler channels.
259     */
260     std::map<uint, SamplerChannel*> GetSamplerChannels();
261    
262     /**
263 schoenebeck 57 * Destroy and remove the given sampler channel from this
264     * Sampler instance.
265     *
266     * @param pSamplerChannel - pointer to sampler channel to remove
267     */
268     void RemoveSamplerChannel(SamplerChannel* pSamplerChannel);
269    
270     /**
271     * Destroy and remove the given sampler channel from this
272     * Sampler instance.
273     *
274     * @param uiSamplerChannel - index of the sampler channel to
275     * remove
276     */
277     void RemoveSamplerChannel(uint uiSamplerChannel);
278    
279 schoenebeck 209 /**
280     * Returns the names of all available audio output drivers.
281     */
282 schoenebeck 123 std::vector<String> AvailableAudioOutputDrivers();
283    
284 schoenebeck 57 /**
285 senkov 155 * Create an audio output device.
286 schoenebeck 57 *
287 schoenebeck 123 * @param AudioDriver - name of the audio driver
288     * @param Parameters - eventually needed driver parameters to
289     * create the device
290 schoenebeck 57 * @returns pointer to created audio output device
291 schoenebeck 880 * @throws Exception if device could not be created
292 schoenebeck 57 */
293 schoenebeck 880 AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
294 schoenebeck 57
295 senkov 155 /**
296     * Create a midi input device.
297     *
298     * @param MidiDriver - name of the midi driver
299     * @param Parameters - eventually needed driver parameters to
300     * create the device
301     * @returns pointer to created midi input device
302 schoenebeck 880 * @throws Exception if device could not be created
303 senkov 155 */
304 schoenebeck 880 MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
305 senkov 155
306 schoenebeck 209 /**
307     * Returns the number of all created audio output devices.
308     */
309 schoenebeck 123 uint AudioOutputDevices();
310 schoenebeck 209
311     /**
312     * Returns the number of all created MIDI input devices.
313     */
314 senkov 155 uint MidiInputDevices();
315 schoenebeck 57
316 schoenebeck 209 /**
317     * Returns all created audio output devices.
318     */
319 schoenebeck 123 std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
320    
321 schoenebeck 209 /**
322     * Returns all created MIDI input devices.
323     */
324 senkov 155 std::map<uint, MidiInputDevice*> GetMidiInputDevices();
325    
326 schoenebeck 209 /**
327     * Destroy the given audio output device and takes care if there
328     * are still sampler angines connected to this device, etc.
329     *
330 schoenebeck 880 * @throws Exception if sampler channels are still
331     * connected to the device
332 schoenebeck 209 */
333 schoenebeck 880 void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
334 schoenebeck 123
335 schoenebeck 209 /**
336     * Destroy the given MIDI input device and takes care if there
337     * are still sampler angines connected to this device, etc.
338     *
339 schoenebeck 880 * @throws Exception if sampler channels are still
340     * connected to the device
341 schoenebeck 209 */
342 schoenebeck 880 void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception);
343 schoenebeck 209
344 schoenebeck 212 /**
345 iliev 778 * Gets the current number of all active voices.
346     * @returns The current number of all active voices.
347     */
348     int GetVoiceCount();
349    
350     /**
351 schoenebeck 212 * Reset the whole sampler. Destroy all engines, sampler
352     * channels, MIDI input devices and audio output devices.
353     */
354     void Reset();
355    
356 schoenebeck 53 protected:
357 schoenebeck 123 typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
358 senkov 155 typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
359 schoenebeck 209 typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
360 schoenebeck 53
361 schoenebeck 209 SamplerChannelMap mSamplerChannels; ///< contains all created sampler channels
362     AudioOutputDeviceMap mAudioOutputDevices; ///< contains all created audio output devices
363     MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices
364 schoenebeck 53
365     friend class SamplerChannel;
366     };
367     }
368    
369     #endif // __LS_SAMPLER_H__

  ViewVC Help
Powered by ViewVC