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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 159 by capela, Tue Jun 29 21:11:50 2004 UTC revision 880 by schoenebeck, Tue Jun 27 22:57:37 2006 UTC
# Line 3  Line 3 
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  *
# Line 26  Line 27 
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/common/EngineChannel.h"
32  #include "mididriver/MidiInputDevice.h"  #include "drivers/midi/MidiInputDevice.h"
33  #include "audiodriver/AudioOutputDevice.h"  #include "drivers/audio/AudioOutputDevice.h"
34    
35  namespace LinuxSampler {  namespace LinuxSampler {
36    
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               */               */
56              void LoadEngine(Engine::type_t EngineType); // TODO: to be changed to 'void LoadEngine(String EngineType) throws (LinuxSamplerException);'              void SetEngineType(String EngineType) throw (Exception);
57    
58              /**              /**
59               * Connect this sampler channel to an audio output device, that               * Connect this sampler channel to an audio output device, that
# Line 67  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66              void SetAudioOutputDevice(AudioOutputDevice* pDevice);              void SetAudioOutputDevice(AudioOutputDevice* pDevice);
67    
68              /**              /**
69               * Connect this sampler channel to and MIDI input device.               * Connect this sampler channel to a MIDI input device.
70               *               *
71               * @param pDevice - MIDI input device to connect to               * @param pDevice - MIDI input device to connect to
72               */               */
73              void SetMidiInputDevice(MidiInputDevice *pDevice);              void SetMidiInputDevice(MidiInputDevice *pDevice);
74    
75              /**              /**
76               * Connect this sampler channel to and MIDI input port.               * Connect this sampler channel to a MIDI input port.
77               *               *
78               * @param MidiPort - MIDI port to connect to               * @param MidiPort - MIDI port to connect to
79               */               */
80              void SetMidiInputPort(int MidiPort);              void SetMidiInputPort(int MidiPort);
81    
82              /**              /**
83               * Connect this sampler channel to and MIDI input channel.               * 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 connect to               * @param MidiChannel - MIDI channel to listen
89               */               */
90              void SetMidiInputChannel(MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel);              void SetMidiInputChannel(midi_chan_t MidiChannel);
91    
92              /**              /**
93               * Connect this sampler channel to a MIDI input triplet.               * Connect this sampler channel to a MIDI input triplet.
94               *               *
95               * @param pDevice - MIDI input device to connect to               * @param pDevice - MIDI input device to connect to
96               * @param MidiPort - MIDI port to connect to               * @param iMidiPort - MIDI port to connect to
97               * @param MidiChannel - optional: MIDI channel on which the               * @param MidiChannel - optional: MIDI channel on which the
98               *                      sampler channel should listen to               *                      sampler channel should listen to
99               *                      (default: listen on all MIDI channels)               *                      (default: listen on all MIDI channels)
100               */               */
101              void SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel = MidiInputDevice::MidiInputPort::midi_chan_all);              void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all);
102    
103              /**              /**
104               * Returns the engine that was deployed on this sampler channel.               * 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               * @returns  pointer to engine or NULL if no engine deployed
108               */               */
109              Engine* GetEngine();              EngineChannel* GetEngineChannel();
110    
111              /**              /**
112               * Returns the MIDI input channel to which this sampler               * Returns the MIDI input channel to which this sampler
# Line 112  namespace LinuxSampler { Line 115  namespace LinuxSampler {
115               * @returns  The MIDI input channel on which the sampler               * @returns  The MIDI input channel on which the sampler
116               *           channel is listening to.               *           channel is listening to.
117               */               */
118              MidiInputDevice::MidiInputPort::midi_chan_t GetMidiInputChannel();              midi_chan_t GetMidiInputChannel();
119    
120              /**              /**
121               * Returns the MIDI input port number to which this sampler               * Returns the MIDI input port number to which this sampler
# Line 148  namespace LinuxSampler { Line 151  namespace LinuxSampler {
151    
152          protected:          protected:
153              SamplerChannel(Sampler* pS);              SamplerChannel(Sampler* pS);
154             ~SamplerChannel();              virtual ~SamplerChannel();
155    
156              /** Getting MIDI input device port given its index number. */              /** Getting MIDI input device port given its index number. */
157              MidiInputDevice::MidiInputPort* GetMidiInputDevicePort(int MidiPort);              MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);
158                
159              Sampler*           pSampler;              Sampler*           pSampler;
160              Engine*            pEngine;              EngineChannel*     pEngineChannel;
161              AudioOutputDevice* pAudioOutputDevice;              AudioOutputDevice* pAudioOutputDevice;
162              MidiInputDevice*   pMidiInputDevice;              MidiInputDevice*   pMidiInputDevice;
             int                midiPort;  
             MidiInputDevice::MidiInputPort::midi_chan_t midiChannel;  
163              int                iIndex;              int                iIndex;
164    
165              friend class Sampler;              friend class Sampler;
166            private:
167                int                iMidiPort;   ///< Don't access directly, read GetMidiInputPort() instead !
168                midi_chan_t        midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !
169      };      };
170    
171      /** LinuxSampler main class      /** @brief LinuxSampler main class
172       *       *
173       * This is the toplevel class for a LinuxSampler instance.       * This is the toplevel class for a LinuxSampler instance.
174       *       *
# Line 172  namespace LinuxSampler { Line 176  namespace LinuxSampler {
176       * sampler channel can individually be deployed with it's own sampler       * sampler channel can individually be deployed with it's own sampler
177       * engine, connected to an arbitrary MIDI input device and connected to       * engine, connected to an arbitrary MIDI input device and connected to
178       * an arbitrary audio output device. Here an example setup:       * an arbitrary audio output device. Here an example setup:
179         * @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       *       *
187       *  S.Channel.      MIDI in         S.Engine                Audio out       * ... (and so on) ...
188       *  -------------------------------------------------------------------       * @endcode
      *  0               Alsa    ->      gig::Engine     ->      Jack  
      *  1               VSTi    ->      Akai::Engine    ->      VSTi  
      *  2               Jack    ->      DLS::Engine     ->      Jack  
      *  3               Jack    ->      SF::Engine      ->      Alsa  
      *  
      *  ... (and so on) ...  
189       *       *
190       * Note that not all audio and MIDI backends and sampler engines listed       * Note that not all audio and MIDI backends and sampler engines listed
191       * in the example above are already implemented!       * in the example above are already implemented!
# Line 189  namespace LinuxSampler { Line 194  namespace LinuxSampler {
194       * several, different audio output and MIDI input systems       * several, different audio output and MIDI input systems
195       * simultaniously at the same time. Here the example setup shown in the       * simultaniously at the same time. Here the example setup shown in the
196       * ascpect of MIDI input and audio output devices / drivers:       * ascpect of MIDI input and audio output devices / drivers:
197       *       * @code
198       *                            ######################### #########################       *                    ######################### #########################
199       *                            # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #       *                    # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
200       *                            ######################### #########################       *                    ######################### #########################
201       *                                          ^   ^           ^       *                                   ^   ^           ^
202       *    /------------>|Sampler Channel 0|-----/   |           |       *   /------------>|Sampler Channel 0|-----/   |             |
203       *    |  /--------->|Sampler Channel 1|---------------------/       *   |  /--------->|Sampler Channel 1|---------------------/
204       *    |  |    /---->|Sampler Channel 2|---------/       *   |  |    /------>|Sampler Channel 2|---------/
205       *    |  |    |  /->|Sampler Channel 3|------------>#########################       *   |  |    |  /--->|Sampler Channel 3|------------>#########################
206       *    |  |    |  |  ... (and so on) ...             # AudioOutputDeviceAlsa #       *   |  |    |  |    ... (and so on) ...             # AudioOutputDeviceAlsa #
207       *    |  |    |  |                                  #########################       *   |  |    |  |                                    #########################
208       *    |  |    |  \----------------------------------------------------\       *   |  |    |  \-----------------------------------------------------\
209       *    |  |    \-------------------------------------------\           |       *   |  |    \--------------------------------------------\           |
210       *    |  \--------------------\                           |           |       *   |  \--------------------\                            |           |
211       *    |                       |                           |           |       *   |                         |                          |           |
212       *  ####################### ####################### #######################       * ####################### ####################### #######################
213       *  # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #       * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
214       *  ####################### ####################### #######################       * ####################### ####################### #######################
215         * @endcode
216       *       *
217       * 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
218       * driver / audio output driver) can be connected multiple times to       * driver / audio output driver) can be connected multiple times to
# Line 222  namespace LinuxSampler { Line 228  namespace LinuxSampler {
228              /**              /**
229               * Destructor.               * Destructor.
230               */               */
231             ~Sampler();              virtual ~Sampler();
232    
233              /**              /**
234               * Returns the number of sampler channels currently allocated.               * Returns the number of sampler channels currently allocated.
# Line 230  namespace LinuxSampler { Line 236  namespace LinuxSampler {
236              uint SamplerChannels();              uint SamplerChannels();
237    
238              /**              /**
239               * Create and add a new sampler channel to this Sampler instance.               * 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               *               *
245               * @returns  pointer to new sampler channel               * @returns  pointer to new sampler channel
246               */               */
# Line 245  namespace LinuxSampler { Line 255  namespace LinuxSampler {
255              SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);              SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);
256    
257              /**              /**
258                 * Returns all created sampler channels.
259                 */
260                std::map<uint, SamplerChannel*> GetSamplerChannels();
261    
262                /**
263               * Destroy and remove the given sampler channel from this               * Destroy and remove the given sampler channel from this
264               * Sampler instance.               * Sampler instance.
265               *               *
# Line 261  namespace LinuxSampler { Line 276  namespace LinuxSampler {
276               */               */
277              void RemoveSamplerChannel(uint uiSamplerChannel);              void RemoveSamplerChannel(uint uiSamplerChannel);
278    
279                /**
280                 * Returns the names of all available audio output drivers.
281                 */
282              std::vector<String> AvailableAudioOutputDrivers();              std::vector<String> AvailableAudioOutputDrivers();
283    
284              /**              /**
# Line 270  namespace LinuxSampler { Line 288  namespace LinuxSampler {
288               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
289               *                     create the device               *                     create the device
290               * @returns  pointer to created audio output device               * @returns  pointer to created audio output device
291               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
292               */               */
293              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
294    
295              /**              /**
296               * Create a midi input device.               * Create a midi input device.
# Line 281  namespace LinuxSampler { Line 299  namespace LinuxSampler {
299               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
300               *                     create the device               *                     create the device
301               * @returns  pointer to created midi input device               * @returns  pointer to created midi input device
302               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
303               */               */
304              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
305    
306                /**
307                 * Returns the number of all created audio output devices.
308                 */
309              uint AudioOutputDevices();              uint AudioOutputDevices();
310    
311                /**
312                 * Returns the number of all created MIDI input devices.
313                 */
314              uint MidiInputDevices();              uint MidiInputDevices();
315    
316                /**
317                 * Returns all created audio output devices.
318                 */
319              std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();              std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
320    
321                /**
322                 * Returns all created MIDI input devices.
323                 */
324              std::map<uint, MidiInputDevice*> GetMidiInputDevices();              std::map<uint, MidiInputDevice*> GetMidiInputDevices();
325    
326              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);              /**
327              void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException);               * Destroy the given audio output device and takes care if there
328                 * are still sampler angines connected to this device, etc.
329                 *
330                 * @throws Exception  if sampler channels are still
331                 *                    connected to the device
332                 */
333                void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
334    
335                /**
336                 * Destroy the given MIDI input device and takes care if there
337                 * are still sampler angines connected to this device, etc.
338                 *
339                 * @throws Exception  if sampler channels are still
340                 *                    connected to the device
341                 */
342                void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception);
343    
344                /**
345                 * Gets the current number of all active voices.
346                 * @returns The current number of all active voices.
347                 */
348                int GetVoiceCount();
349    
350                /**
351                 * Reset the whole sampler. Destroy all engines, sampler
352                 * channels, MIDI input devices and audio output devices.
353                 */
354                void Reset();
355    
356          protected:          protected:
357              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
358              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
359                typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
360    
361              std::vector<SamplerChannel*> vSamplerChannels;   ///< contains all created sampler channels              SamplerChannelMap     mSamplerChannels;    ///< contains all created sampler channels
362              AudioOutputDeviceMap         mAudioOutputDevices; ///< contains all created audio output devices              AudioOutputDeviceMap  mAudioOutputDevices; ///< contains all created audio output devices
363              MidiInputDeviceMap           mMidiInputDevices;              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices
   
             template<class T> inline String ToString(T o) {  
                 std::stringstream ss;  
                 ss << o;  
                 return ss.str();  
             }  
364    
365              friend class SamplerChannel;              friend class SamplerChannel;
366      };      };

Legend:
Removed from v.159  
changed lines
  Added in v.880

  ViewVC Help
Powered by ViewVC