/[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 123 by schoenebeck, Mon Jun 14 19:33:16 2004 UTC revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 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 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    
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 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 LinuxSamplerException - 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 (LinuxSamplerException);
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 (that               * Connect this sampler channel to a MIDI input device.
              * is MIDI input driver) of the given type. If the MIDI input  
              * driver for the desired MIDI input system is not yet created,  
              * then it will be created automatically, but with default  
              * settings though. If this sampler channel was already  
              * connected to a MIDI input device, then the old connection  
              * will automatically be removed before.  
70               *               *
71               * @param MidiType    - MIDI input system to connect to               * @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               * @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(MidiInputDevice::type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel = MidiInputDevice::midi_chan_all); // TODO: 'MidiType' type to be changed to 'MidiInputDevice*'              void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel = MidiInputPort::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();              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               * Returns the audio output device to which this sampler channel
# Line 108  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 117  namespace LinuxSampler { Line 153  namespace LinuxSampler {
153              SamplerChannel(Sampler* pS);              SamplerChannel(Sampler* pS);
154             ~SamplerChannel();             ~SamplerChannel();
155    
156                /** Getting MIDI input device port given its index number. */
157                MidiInputPort* GetMidiInputDevicePort(int iMidiPort);
158    
159              Sampler*           pSampler;              Sampler*           pSampler;
160              Engine*            pEngine;              EngineChannel*     pEngineChannel;
             MidiInputDevice*   pMidiInputDevice;  
161              AudioOutputDevice* pAudioOutputDevice;              AudioOutputDevice* pAudioOutputDevice;
162                MidiInputDevice*   pMidiInputDevice;
163                int                midiPort;
164                MidiInputPort::midi_chan_t midiChannel;
165              int                iIndex;              int                iIndex;
166    
167              friend class Sampler;              friend class Sampler;
168      };      };
169    
170      /** LinuxSampler main class      /** @brief LinuxSampler main class
171       *       *
172       * This is the toplevel class for a LinuxSampler instance.       * This is the toplevel class for a LinuxSampler instance.
173       *       *
# Line 192  namespace LinuxSampler { Line 233  namespace LinuxSampler {
233              uint SamplerChannels();              uint SamplerChannels();
234    
235              /**              /**
236               * Create and add a new sampler channel to this Sampler instance.               * 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               * @returns  pointer to new sampler channel
243               */               */
# Line 207  namespace LinuxSampler { Line 252  namespace LinuxSampler {
252              SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);              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               * Destroy and remove the given sampler channel from this
261               * Sampler instance.               * Sampler instance.
262               *               *
# Line 223  namespace LinuxSampler { Line 273  namespace LinuxSampler {
273               */               */
274              void RemoveSamplerChannel(uint uiSamplerChannel);              void RemoveSamplerChannel(uint uiSamplerChannel);
275    
276                /**
277                 * Returns the names of all available audio output drivers.
278                 */
279              std::vector<String> AvailableAudioOutputDrivers();              std::vector<String> AvailableAudioOutputDrivers();
280    
281              /**              /**
282               * Create an audio output device of the given type.               * Create an audio output device.
283               *               *
284               * @param AudioDriver - name of the audio driver               * @param AudioDriver - name of the audio driver
285               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
# Line 236  namespace LinuxSampler { Line 289  namespace LinuxSampler {
289               */               */
290              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              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();              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();              std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
317    
318              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);              /**
319                 * Returns all created MIDI input devices.
320                 */
321                std::map<uint, MidiInputDevice*> GetMidiInputDevices();
322    
323              /**              /**
324               * Create a MIDI input device of the given type.               * Destroy the given audio output device and takes care if there
325                 * are still sampler angines connected to this device, etc.
326               *               *
327               * @param MidiType - desired MIDI input system to use               * @throws LinuxSamplerException  if sampler channels are still
328               * @returns  pointer to created MIDI input device               *                                connected to the device
329               */               */
330              MidiInputDevice* CreateMidiInputDevice(MidiInputDevice::type_t MidiType); //TODO: to be changed to 'MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);'              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);
331    
332              /**              /**
333               * Returns the MIDI input device of the given type.               * Destroy the given MIDI input device and takes care if there
334                 * are still sampler angines connected to this device, etc.
335               *               *
336               * @param MidiType - desired MIDI input system to use               * @throws LinuxSamplerException  if sampler channels are still
337               * @returns  pointer to MIDI input device or NULL if device of               *                                connected to the device
338               *           desired type is not yet created               */
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              MidiInputDevice* GetMidiInputDevice(MidiInputDevice::type_t MidiType);              void Reset();
346    
347          protected:          protected:
348              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
349              typedef std::map<MidiInputDevice::type_t, MidiInputDevice*> MidiInputDeviceMap;              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
350                typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
351    
352              std::vector<SamplerChannel*> vSamplerChannels;   ///< contains all created sampler channels              SamplerChannelMap     mSamplerChannels;    ///< contains all created sampler channels
353              AudioOutputDeviceMap         mAudioOutputDevices; ///< contains all created audio output devices              AudioOutputDeviceMap  mAudioOutputDevices; ///< contains all created audio output devices
354              MidiInputDeviceMap           MidiInputDevices;              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices
   
             template<class T> inline String ToString(T o) {  
                 std::stringstream ss;  
                 ss << o;  
                 return ss.str();  
             }  
355    
356              friend class SamplerChannel;              friend class SamplerChannel;
357      };      };

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

  ViewVC Help
Powered by ViewVC