/[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 57 by schoenebeck, Sun May 2 17:45:43 2004 UTC revision 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck         *   *   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  *   *   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 27  Line 28 
28  #include <map>  #include <map>
29  #include "common/global.h"  #include "common/global.h"
30  #include "common/LinuxSamplerException.h"  #include "common/LinuxSamplerException.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    
     /**  
      * Which sampler engine to be used.  
      */  
     enum engine_type_t {  
         engine_type_gig  
     };  
   
     /**  
      * Which audio output system to be used.  
      */  
     enum audio_output_type_t {  
         audio_output_type_alsa,  
         audio_output_type_jack  
     };  
   
     /**  
      * Which MIDI input system to be used.  
      */  
     enum midi_input_type_t {  
         midi_input_type_alsa  
     };  
   
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 typ, 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 you 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.
52               * channnel. If there was already a sampler engine deployed on               *
53               * this sampler channel, then the old engine will automatically               * @param EngineType - type of the engine to use
54               * be destroyed.               * @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 EngineType - type of the engine to deploy               * @param pDevice - MIDI input device to connect to
72               */               */
73              void LoadEngine(engine_type_t EngineType);              void SetMidiInputDevice(MidiInputDevice *pDevice);
74    
75              /**              /**
76               * Connect this sampler channel to an audio output device (that               * Connect this sampler channel to a MIDI input port.
              * is audio output driver) of the given type. If the audio  
              * output for the desired audio output system is not yet  
              * created, then it will be created automatically, but with  
              * default settings though. If this sampler channel was already  
              * connected to an audio output device, then the old connection  
              * will automatically be removed before.  
77               *               *
78               * @param AudioType - audio output system to connect to               * @param MidiPort - MIDI port to connect to
79               */               */
80              void SetAudioOutputDevice(audio_output_type_t AudioType);              void SetMidiInputPort(int MidiPort);
81    
82              /**              /**
83               * Connect this sampler channel to and MIDI input device (that               * Define on which MIDI channel(s) this sampler channel should
84               * is MIDI input driver) of the given type. If the MIDI input               * listen to. By default, that is after creation of a new
85               * driver for the desired MIDI input system is not yet created,               * sampler channel, the sampler channel will listen to all MIDI
86               * then it will be created automatically, but with default               * channels.
              * settings though. If this sampler channel was already  
              * connected to a MIDI input device, then the old connection  
              * will automatically be removed before.  
87               *               *
88               * @param MidiType    - MIDI input system to connect to               * @param MidiChannel - MIDI channel to listen
89                 */
90                void SetMidiInputChannel(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               * @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 SetMidiInputDevice(midi_input_type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel = MidiInputDevice::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 device to which this sampler channel               * Returns the MIDI input channel to which this sampler
113               * is currently connected to.               * channel is currently connected to.
114               *               *
115               * @returns  pointer to MIDI input device or NULL if not               * @returns  The MIDI input channel on which the sampler
116               *           connected               *           channel is listening to.
117               */               */
118              MidiInputDevice* GetMidiInputDevice();              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               * Returns the audio output device to which this sampler channel
# Line 133  namespace LinuxSampler { Line 135  namespace LinuxSampler {
135              AudioOutputDevice* GetAudioOutputDevice();              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               * Returns the index number of this sampler channel within the
148               * Sampler instance.               * Sampler instance.
149               */               */
# Line 140  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. */
157                MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);
158                midi_chan_t    __GetMidiChannel();
159    
160              Sampler*           pSampler;              Sampler*           pSampler;
161              Engine*            pEngine;              EngineChannel*     pEngineChannel;
             MidiInputDevice*   pMidiInputDevice;  
162              AudioOutputDevice* pAudioOutputDevice;              AudioOutputDevice* pAudioOutputDevice;
163                MidiInputDevice*   pMidiInputDevice;
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       *       *
# Line 159  namespace LinuxSampler { Line 177  namespace LinuxSampler {
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 are already implemented!
# Line 176  namespace LinuxSampler { Line 195  namespace LinuxSampler {
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:       * ascpect 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
# Line 209  namespace LinuxSampler { Line 229  namespace LinuxSampler {
229              /**              /**
230               * Destructor.               * Destructor.
231               */               */
232             ~Sampler();              virtual ~Sampler();
233    
234              /**              /**
235               * Returns the number of sampler channels currently allocated.               * Returns the number of sampler channels currently allocated.
# Line 217  namespace LinuxSampler { Line 237  namespace LinuxSampler {
237              uint SamplerChannels();              uint SamplerChannels();
238    
239              /**              /**
240               * Create and add a new sampler channel to this Sampler instance.               * Create and add a new sampler channel to this Sampler
241                 * instance. For race condition reasons the new channel will use
242                 * an index past the last already existing sampler channel
243                 * index (in case the index limit was not reached yet, otherwise
244                 * a free index starting from 0 is searched).
245               *               *
246               * @returns  pointer to new sampler channel               * @returns  pointer to new sampler channel
247               */               */
# Line 232  namespace LinuxSampler { Line 256  namespace LinuxSampler {
256              SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);              SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);
257    
258              /**              /**
259                 * Returns all created sampler channels.
260                 */
261                std::map<uint, SamplerChannel*> GetSamplerChannels();
262    
263                /**
264               * Destroy and remove the given sampler channel from this               * Destroy and remove the given sampler channel from this
265               * Sampler instance.               * Sampler instance.
266               *               *
# Line 249  namespace LinuxSampler { Line 278  namespace LinuxSampler {
278              void RemoveSamplerChannel(uint uiSamplerChannel);              void RemoveSamplerChannel(uint uiSamplerChannel);
279    
280              /**              /**
281               * Create an audio output device of the given type.               * Returns the names of all available audio output drivers.
282                 */
283                std::vector<String> AvailableAudioOutputDrivers();
284    
285                /**
286                 * Create an audio output device.
287               *               *
288               * @param AudioType - desired audio output system to use               * @param AudioDriver - name of the audio driver
289                 * @param Parameters - eventually needed driver parameters to
290                 *                     create the device
291               * @returns  pointer to created audio output device               * @returns  pointer to created audio output device
292                 * @throws LinuxSamplerException  if device could not be created
293               */               */
294              AudioOutputDevice* CreateAudioOutputDevice(audio_output_type_t AudioType);              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);
295    
296              /**              /**
297               * Returns the audio output device of the given type.               * Create a midi input device.
298               *               *
299               * @param AudioType - desired audio output system to use               * @param MidiDriver - name of the midi driver
300               * @returns  pointer to audio output device or NULL if device of               * @param Parameters - eventually needed driver parameters to
301               *           desired type is not yet created               *                     create the device
302                 * @returns  pointer to created midi input device
303                 * @throws LinuxSamplerException  if device could not be created
304               */               */
305              AudioOutputDevice* GetAudioOutputDevice(audio_output_type_t AudioType);              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);
306    
307              /**              /**
308               * Create a MIDI input device of the given type.               * Returns the number of all created audio output devices.
309                 */
310                uint AudioOutputDevices();
311    
312                /**
313                 * Returns the number of all created MIDI input devices.
314                 */
315                uint MidiInputDevices();
316    
317                /**
318                 * Returns all created audio output devices.
319                 */
320                std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
321    
322                /**
323                 * Returns all created MIDI input devices.
324                 */
325                std::map<uint, MidiInputDevice*> GetMidiInputDevices();
326    
327                /**
328                 * Destroy the given audio output device and takes care if there
329                 * are still sampler angines connected to this device, etc.
330               *               *
331               * @param MidiType - desired MIDI input system to use               * @throws LinuxSamplerException  if sampler channels are still
332               * @returns  pointer to created MIDI input device               *                                connected to the device
333               */               */
334              MidiInputDevice* CreateMidiInputDevice(midi_input_type_t MidiType);              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);
335    
336              /**              /**
337               * Returns the MIDI input device of the given type.               * Destroy the given MIDI input device and takes care if there
338                 * are still sampler angines connected to this device, etc.
339               *               *
340               * @param MidiType - desired MIDI input system to use               * @throws LinuxSamplerException  if sampler channels are still
341               * @returns  pointer to MIDI input device or NULL if device of               *                                connected to the device
              *           desired type is not yet created  
342               */               */
343              MidiInputDevice* GetMidiInputDevice(midi_input_type_t MidiType);              void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException);
344    
345          protected:              /**
346              typedef std::map<audio_output_type_t, AudioOutputDevice*> AudioOutputDeviceMap;               * Reset the whole sampler. Destroy all engines, sampler
347              typedef std::map<midi_input_type_t, MidiInputDevice*> MidiInputDeviceMap;               * channels, MIDI input devices and audio output devices.
348                 */
349                void Reset();
350    
351              std::vector<SamplerChannel*> vSamplerChannels;   ///< contains all created sampler channels          protected:
352              AudioOutputDeviceMap         AudioOutputDevices; ///< contains all created audio output devices              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
353              MidiInputDeviceMap           MidiInputDevices;              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
354                typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
355    
356                SamplerChannelMap     mSamplerChannels;    ///< contains all created sampler channels
357                AudioOutputDeviceMap  mAudioOutputDevices; ///< contains all created audio output devices
358                MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices
359    
360              friend class SamplerChannel;              friend class SamplerChannel;
361      };      };

Legend:
Removed from v.57  
changed lines
  Added in v.675

  ViewVC Help
Powered by ViewVC