/[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 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 123 by schoenebeck, Mon Jun 14 19:33:16 2004 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   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 33  Line 33 
33    
34  namespace LinuxSampler {  namespace LinuxSampler {
35    
     /**  
      * 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  
     };  
   
36      // just symbol prototyping      // just symbol prototyping
37      class Sampler;      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 {      class SamplerChannel {
48          public:          public:
49              SamplerChannel(Sampler* pS);              /**
50             ~SamplerChannel();               * Deploy a sampler engine of the given type for this sampler
51              void               LoadEngine(engine_type_t EngineType);               * channnel. If there was already a sampler engine deployed on
52              void               SetAudioOutputDevice(audio_output_type_t AudioType);               * this sampler channel, then the old engine will automatically
53              void               SetMidiInputDevice(midi_input_type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel = MidiInputDevice::midi_chan_all);               * be destroyed.
54              Engine*            GetEngine();               *
55              MidiInputDevice*   GetMidiInputDevice();               * @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 device (that
71                 * is MIDI input driver) of the given type. If the MIDI input
72                 * driver for the desired MIDI input system is not yet created,
73                 * then it will be created automatically, but with default
74                 * settings though. If this sampler channel was already
75                 * connected to a MIDI input device, then the old connection
76                 * will automatically be removed before.
77                 *
78                 * @param MidiType    - MIDI input system to connect to
79                 * @param MidiChannel - optional: MIDI channel on which the
80                 *                      sampler channel should listen to
81                 *                      (default: listen on all MIDI channels)
82                 */
83                void SetMidiInputDevice(MidiInputDevice::type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel = MidiInputDevice::midi_chan_all); // TODO: 'MidiType' type to be changed to 'MidiInputDevice*'
84    
85                /**
86                 * Returns the engine that was deployed on this sampler channel.
87                 *
88                 * @returns  pointer to engine or NULL if no engine deployed
89                 */
90                Engine* GetEngine();
91    
92                /**
93                 * Returns the MIDI input device to which this sampler channel
94                 * is currently connected to.
95                 *
96                 * @returns  pointer to MIDI input device or NULL if not
97                 *           connected
98                 */
99                MidiInputDevice* GetMidiInputDevice();
100    
101                /**
102                 * Returns the audio output device to which this sampler channel
103                 * is currently connected to.
104                 *
105                 * @returns  pointer to audio output device or NULL if not
106                 *           connected
107                 */
108              AudioOutputDevice* GetAudioOutputDevice();              AudioOutputDevice* GetAudioOutputDevice();
109              uint               Index();  
110                /**
111                 * Returns the index number of this sampler channel within the
112                 * Sampler instance.
113                 */
114                uint Index();
115    
116          protected:          protected:
117                SamplerChannel(Sampler* pS);
118               ~SamplerChannel();
119    
120              Sampler*           pSampler;              Sampler*           pSampler;
121              Engine*            pEngine;              Engine*            pEngine;
122              MidiInputDevice*   pMidiInputDevice;              MidiInputDevice*   pMidiInputDevice;
123              AudioOutputDevice* pAudioOutputDevice;              AudioOutputDevice* pAudioOutputDevice;
124              int                iIndex;              int                iIndex;
125    
126                friend class Sampler;
127      };      };
128    
129        /** LinuxSampler main class
130         *
131         * This is the toplevel class for a LinuxSampler instance.
132         *
133         * LinuxSampler can have arbitrary numbers of sampler channels. Each
134         * sampler channel can individually be deployed with it's own sampler
135         * engine, connected to an arbitrary MIDI input device and connected to
136         * an arbitrary audio output device. Here an example setup:
137         *
138         *  S.Channel.      MIDI in         S.Engine                Audio out
139         *  -------------------------------------------------------------------
140         *  0               Alsa    ->      gig::Engine     ->      Jack
141         *  1               VSTi    ->      Akai::Engine    ->      VSTi
142         *  2               Jack    ->      DLS::Engine     ->      Jack
143         *  3               Jack    ->      SF::Engine      ->      Alsa
144         *
145         *  ... (and so on) ...
146         *
147         * Note that not all audio and MIDI backends and sampler engines listed
148         * in the example above are already implemented!
149         *
150         * As you can see in the example setup, LinuxSampler is capable to use
151         * several, different audio output and MIDI input systems
152         * simultaniously at the same time. Here the example setup shown in the
153         * ascpect of MIDI input and audio output devices / drivers:
154         *
155         *                            ######################### #########################
156         *                            # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
157         *                            ######################### #########################
158         *                                          ^   ^           ^
159         *    /------------>|Sampler Channel 0|-----/   |           |
160         *    |  /--------->|Sampler Channel 1|---------------------/
161         *    |  |    /---->|Sampler Channel 2|---------/
162         *    |  |    |  /->|Sampler Channel 3|------------>#########################
163         *    |  |    |  |  ... (and so on) ...             # AudioOutputDeviceAlsa #
164         *    |  |    |  |                                  #########################
165         *    |  |    |  \----------------------------------------------------\
166         *    |  |    \-------------------------------------------\           |
167         *    |  \--------------------\                           |           |
168         *    |                       |                           |           |
169         *  ####################### ####################### #######################
170         *  # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
171         *  ####################### ####################### #######################
172         *
173         * As you can see in this example setup, one device (that is midi input
174         * driver / audio output driver) can be connected multiple times to
175         * different sampler channels.
176         */
177      class Sampler {      class Sampler {
178          public:          public:
179                /**
180                 * Constructor. Create a LinuxSampler instance.
181                 */
182              Sampler();              Sampler();
183    
184                /**
185                 * Destructor.
186                 */
187             ~Sampler();             ~Sampler();
188              uint               SamplerChannels();  
189              SamplerChannel*    AddSamplerChannel();              /**
190              SamplerChannel*    GetSamplerChannel(uint uiSamplerChannel);               * Returns the number of sampler channels currently allocated.
191              void               RemoveSamplerChannel(SamplerChannel* pSamplerChannel);               */
192              void               RemoveSamplerChannel(uint uiSamplerChannel);              uint SamplerChannels();
193              AudioOutputDevice* CreateAudioOutputDevice(audio_output_type_t AudioType);  
194              AudioOutputDevice* GetAudioOutputDevice(audio_output_type_t AudioType);              /**
195              MidiInputDevice*   CreateMidiInputDevice(midi_input_type_t MidiType);               * Create and add a new sampler channel to this Sampler instance.
196              MidiInputDevice*   GetMidiInputDevice(midi_input_type_t MidiType);               *
197                 * @returns  pointer to new sampler channel
198                 */
199                SamplerChannel* AddSamplerChannel();
200    
201                /**
202                 * Returns the sampler channel of the given sampler channel
203                 * index.
204                 *
205                 * @returns  pointer to sought sampler channel
206                 */
207                SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);
208    
209                /**
210                 * Destroy and remove the given sampler channel from this
211                 * Sampler instance.
212                 *
213                 * @param pSamplerChannel - pointer to sampler channel to remove
214                 */
215                void RemoveSamplerChannel(SamplerChannel* pSamplerChannel);
216    
217                /**
218                 * Destroy and remove the given sampler channel from this
219                 * Sampler instance.
220                 *
221                 * @param uiSamplerChannel - index of the sampler channel to
222                 *                           remove
223                 */
224                void RemoveSamplerChannel(uint uiSamplerChannel);
225    
226                std::vector<String> AvailableAudioOutputDrivers();
227    
228                /**
229                 * Create an audio output device of the given type.
230                 *
231                 * @param AudioDriver - name of the audio driver
232                 * @param Parameters - eventually needed driver parameters to
233                 *                     create the device
234                 * @returns  pointer to created audio output device
235                 * @throws LinuxSamplerException  if device could not be created
236                 */
237                AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);
238    
239                uint AudioOutputDevices();
240    
241                std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
242    
243                void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);
244    
245                /**
246                 * Create a MIDI input device of the given type.
247                 *
248                 * @param MidiType - desired MIDI input system to use
249                 * @returns  pointer to created MIDI input device
250                 */
251                MidiInputDevice* CreateMidiInputDevice(MidiInputDevice::type_t MidiType); //TODO: to be changed to 'MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);'
252    
253                /**
254                 * Returns the MIDI input device of the given type.
255                 *
256                 * @param MidiType - desired MIDI input system to use
257                 * @returns  pointer to MIDI input device or NULL if device of
258                 *           desired type is not yet created
259                 */
260                MidiInputDevice* GetMidiInputDevice(MidiInputDevice::type_t MidiType);
261    
262          protected:          protected:
263              typedef std::map<audio_output_type_t, AudioOutputDevice*> AudioOutputDeviceMap;              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
264              typedef std::map<midi_input_type_t, MidiInputDevice*> MidiInputDeviceMap;              typedef std::map<MidiInputDevice::type_t, MidiInputDevice*> MidiInputDeviceMap;
265    
266              std::vector<SamplerChannel*> vSamplerChannels;   ///< contains all created sampler channels              std::vector<SamplerChannel*> vSamplerChannels;   ///< contains all created sampler channels
267              AudioOutputDeviceMap         AudioOutputDevices; ///< contains all created audio output devices              AudioOutputDeviceMap         mAudioOutputDevices; ///< contains all created audio output devices
268              MidiInputDeviceMap           MidiInputDevices;              MidiInputDeviceMap           MidiInputDevices;
269    
270                template<class T> inline String ToString(T o) {
271                    std::stringstream ss;
272                    ss << o;
273                    return ss.str();
274                }
275    
276              friend class SamplerChannel;              friend class SamplerChannel;
277      };      };
278  }  }

Legend:
Removed from v.53  
changed lines
  Added in v.123

  ViewVC Help
Powered by ViewVC