/[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 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC revision 1130 by iliev, Sun Mar 25 18:59:14 2007 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                              *   *   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 26 
26    
27  #include <vector>  #include <vector>
28  #include <map>  #include <map>
29    #include "EventListeners.h"
30  #include "common/global.h"  #include "common/global.h"
31  #include "common/LinuxSamplerException.h"  #include "common/Exception.h"
32  #include "engines/common/EngineChannel.h"  #include "engines/EngineChannel.h"
33  #include "drivers/midi/MidiInputDevice.h"  #include "drivers/midi/MidiInputDevice.h"
34  #include "drivers/audio/AudioOutputDevice.h"  #include "drivers/audio/AudioOutputDevice.h"
35    
# Line 39  namespace LinuxSampler { Line 40  namespace LinuxSampler {
40    
41      /** @brief LinuxSampler sampler channel      /** @brief LinuxSampler sampler channel
42       *       *
43       * Encapsulates a channel of a specific sampler engine typ, one       * Encapsulates a channel of a specific sampler engine type, one
44       * connection to a MIDI input device and one connection to an audio       * connection to a MIDI input device and one connection to an audio
45       * output device. You cannot create an instance of this class on your       * output device. You cannot create an instance of this class on your
46       * own, you have to use the AddSamplerChannel() method of the Sampler       * own, you have to use the AddSamplerChannel() method of the Sampler
# Line 51  namespace LinuxSampler { Line 52  namespace LinuxSampler {
52               * Assign a sampler engine type to this sampler channel.               * Assign a sampler engine type to this sampler channel.
53               *               *
54               * @param EngineType - type of the engine to use               * @param EngineType - type of the engine to use
55               * @throws LinuxSamplerException - if \a EngineType is invalid               * @throws Exception - if \a EngineType is invalid
56                 * @see Sampler::AvailableEngineTypes()
57               */               */
58              void SetEngineType(String EngineType) throw (LinuxSamplerException);              void SetEngineType(String EngineType) throw (Exception);
59    
60              /**              /**
61               * Connect this sampler channel to an audio output device, that               * Connect this sampler channel to an audio output device, that
# Line 148  namespace LinuxSampler { Line 150  namespace LinuxSampler {
150               * Sampler instance.               * Sampler instance.
151               */               */
152              uint Index();              uint Index();
153                
154                /**
155                 * Registers the specified listener to be notified
156                 * when the engine type of this sampler channel is changed.
157                 */
158                void AddEngineChangeListener(EngineChangeListener* l);
159    
160                /**
161                 * Removes the specified listener.
162                 */
163                void RemoveEngineChangeListener(EngineChangeListener* l);
164    
165                /**
166                 * Removes the specified listener.
167                 */
168                void RemoveAllEngineChangeListeners();
169    
170                /**
171                 * Notifies listeners that the engine
172                 * type of this sampler channel is changed.
173                 */
174                void fireEngineChanged();
175    
176    
177          protected:          protected:
178              SamplerChannel(Sampler* pS);              SamplerChannel(Sampler* pS);
# Line 155  namespace LinuxSampler { Line 180  namespace LinuxSampler {
180    
181              /** Getting MIDI input device port given its index number. */              /** Getting MIDI input device port given its index number. */
182              MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);              MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);
             midi_chan_t    __GetMidiChannel();  
183    
184              Sampler*           pSampler;              Sampler*           pSampler;
185              EngineChannel*     pEngineChannel;              EngineChannel*     pEngineChannel;
# Line 167  namespace LinuxSampler { Line 191  namespace LinuxSampler {
191          private:          private:
192              int                iMidiPort;   ///< Don't access directly, read GetMidiInputPort() instead !              int                iMidiPort;   ///< Don't access directly, read GetMidiInputPort() instead !
193              midi_chan_t        midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !              midi_chan_t        midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !
194                ListenerList<EngineChangeListener*> llEngineChangeListeners;
195      };      };
196    
197      /** @brief LinuxSampler main class      /** @brief LinuxSampler main class
# Line 178  namespace LinuxSampler { Line 203  namespace LinuxSampler {
203       * engine, connected to an arbitrary MIDI input device and connected to       * engine, connected to an arbitrary MIDI input device and connected to
204       * an arbitrary audio output device. Here an example setup:       * an arbitrary audio output device. Here an example setup:
205       * @code       * @code
206       * S.Channel.       MIDI in         S.Engine                Audio out       * S.Channel    MIDI in    S.Engine         Audio out
207       * -------------------------------------------------------------------       * -------------------------------------------------------------------
208       * 0                Alsa    ->      gig::Engine     ->      Jack       *   0          Alsa   ->  gig::Engine  ->  Jack
209       * 1                VSTi    ->      Akai::Engine    ->      VSTi       *   1          VSTi   ->  Akai::Engine ->  VSTi
210       * 2                Jack    ->      DLS::Engine     ->      Jack       *   2          Jack   ->  DLS::Engine  ->  Jack
211       * 3                Jack    ->      SF::Engine      ->      Alsa       *   3          Jack   ->  SF::Engine   ->  Alsa
212       *       *
213       * ... (and so on) ...       * ... (and so on) ...
214       * @endcode       * @endcode
215       *       *
216       * Note that not all audio and MIDI backends and sampler engines listed       * Note that not all audio and MIDI backends and sampler engines listed
217       * in the example above are already implemented!       * in the example above might already been implemented!
218       *       *
219       * As you can see in the example setup, LinuxSampler is capable to use       * As you can see in the example setup, LinuxSampler is capable to use
220       * several, different audio output and MIDI input systems       * several, different audio output and MIDI input systems
221       * simultaniously at the same time. Here the example setup shown in the       * simultaniously at the same time. Here the example setup shown in the
222       * ascpect of MIDI input and audio output devices / drivers:       * aspect of MIDI input and audio output devices / drivers:
223       * @code       * @code
224       *                    ######################### #########################       *                      ######################### #########################
225       *                    # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #       *                      # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
226       *                    ######################### #########################       *                      ######################### #########################
227       *                                   ^   ^           ^       *                                        ^   ^           ^
228       *   /------------>|Sampler Channel 0|-----/   |             |       *  /------------>|Sampler Channel 0|-----/   |           |
229       *   |  /--------->|Sampler Channel 1|---------------------/       *  |  /--------->|Sampler Channel 1|---------------------/
230       *   |  |    /------>|Sampler Channel 2|---------/       *  |  |  /------>|Sampler Channel 2|---------/
231       *   |  |    |  /--->|Sampler Channel 3|------------>#########################       *  |  |  |  /--->|Sampler Channel 3|------------>#########################
232       *   |  |    |  |    ... (and so on) ...             # AudioOutputDeviceAlsa #       *  |  |  |  |    ... (and so on) ...             # AudioOutputDeviceAlsa #
233       *   |  |    |  |                                    #########################       *  |  |  |  |                                    #########################
234       *   |  |    |  \-----------------------------------------------------\       *  |  |  |  \-----------------------------------------------------\
235       *   |  |    \--------------------------------------------\           |       *  |  |  \--------------------------------------------\           |
236       *   |  \--------------------\                            |           |       *  |  \--------------------\                          |           |
237       *   |                         |                          |           |       *  |                       |                          |           |
238       * ####################### ####################### #######################       * ####################### ####################### #######################
239       * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #       * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
240       * ####################### ####################### #######################       * ####################### ####################### #######################
# Line 218  namespace LinuxSampler { Line 243  namespace LinuxSampler {
243       * 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
244       * driver / audio output driver) can be connected multiple times to       * driver / audio output driver) can be connected multiple times to
245       * different sampler channels.       * different sampler channels.
246         *
247         * It's even possible to create multiple instances of the same driver, for
248         * example multiple instances of the Alsa output driver to use multiple
249         * sound cards at the same time, or multiple instances of the JACK audio
250         * output driver to leverage SMP systems or boxes with several hard discs.
251       */       */
252      class Sampler {      class Sampler {
253          public:          public:
# Line 278  namespace LinuxSampler { Line 308  namespace LinuxSampler {
308              void RemoveSamplerChannel(uint uiSamplerChannel);              void RemoveSamplerChannel(uint uiSamplerChannel);
309    
310              /**              /**
311                 * Registers the specified listener to be notified
312                 * when the number of sampler chanels is changed.
313                 */
314                void AddChannelCountListener(ChannelCountListener* l);
315    
316                /**
317                 * Removes the specified listener.
318                 */
319                void RemoveChannelCountListener(ChannelCountListener* l);
320    
321                /**
322                 * Registers the specified listener to be notified
323                 * when the number of audio output devices is changed.
324                 */
325                void AddAudioDeviceCountListener(AudioDeviceCountListener* l);
326    
327                /**
328                 * Removes the specified listener.
329                 */
330                void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l);
331    
332                
333                /**
334                 * Registers the specified listener to be notified
335                 * when the number of MIDI input devices is changed.
336                 */
337                void AddMidiDeviceCountListener(MidiDeviceCountListener* l);
338    
339                /**
340                 * Removes the specified listener.
341                 */
342                void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l);
343    
344                /**
345                 * Registers the specified listener to be notified when the number
346                 * of active voices in a particular sampler channel is changed.
347                 */
348                void AddVoiceCountListener(VoiceCountListener* l);
349    
350                /**
351                 * Removes the specified listener.
352                 */
353                void RemoveVoiceCountListener(VoiceCountListener* l);
354    
355                /**
356                 * Notifies listeners that the number of active voices
357                 * on the specified sampler channel is changed.
358                 * @param ChannelId The numerical ID of the sampler channel.
359                 * @param NewCount The new number of active voices.
360                 */
361                void fireVoiceCountChanged(int ChannelId, int NewCount);
362    
363                /**
364                 * Registers the specified listener to be notified when the number
365                 * of active disk streams in a particular sampler channel is changed.
366                 */
367                void AddStreamCountListener(StreamCountListener* l);
368    
369                /**
370                 * Removes the specified listener.
371                 */
372                void RemoveStreamCountListener(StreamCountListener* l);
373    
374                /**
375                 * Notifies listeners that the number of active disk streams
376                 * on the specified sampler channel is changed.
377                 * @param ChannelId The numerical ID of the sampler channel.
378                 * @param NewCount The new number of active disk streams.
379                 */
380                void fireStreamCountChanged(int ChannelId, int NewCount);
381    
382                /**
383                 * Registers the specified listener to be
384                 * notified when the fill state of the disk stream
385                 * buffers on a specific sampler channel is changed.
386                 */
387                void AddBufferFillListener(BufferFillListener* l);
388    
389                /**
390                 * Removes the specified listener.
391                 */
392                void RemoveBufferFillListener(BufferFillListener* l);
393    
394                /**
395                 * Notifies listeners that the fill state of the disk stream
396                 * buffers on the specified sampler channel is changed.
397                 * @param ChannelId The numerical ID of the sampler channel.
398                 * @param FillData The buffer fill data for the specified sampler channel.
399                 */
400                void fireBufferFillChanged(int ChannelId, String FillData);
401    
402                /**
403                 * Registers the specified listener to be notified
404                 * when total number of active voices is changed.
405                 */
406                void AddTotalVoiceCountListener(TotalVoiceCountListener* l);
407    
408                /**
409                 * Removes the specified listener.
410                 */
411                void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l);
412    
413                /**
414                 * Notifies listeners that the total number of active voices is changed.
415                 * @param NewCount The new number of active voices.
416                 */
417                void fireTotalVoiceCountChanged(int NewCount);
418    
419                /**
420                 * Registers the specified listener to be notified when the number
421                 * of effect sends on a particular sampler channel is changed.
422                 */
423                void AddFxSendCountListener(FxSendCountListener* l);
424    
425                /**
426                 * Removes the specified listener.
427                 */
428                void RemoveFxSendCountListener(FxSendCountListener* l);
429    
430                /**
431               * Returns the names of all available audio output drivers.               * Returns the names of all available audio output drivers.
432               */               */
433              std::vector<String> AvailableAudioOutputDrivers();              std::vector<String> AvailableAudioOutputDrivers();
434    
435              /**              /**
436                 * Returns the names of all available MIDI input drivers.
437                 */
438                std::vector<String> AvailableMidiInputDrivers();
439    
440                /**
441                 * Returns the names of all available sampler engine types.
442                 * @see SamplerChannel::SetEngineType()
443                 */
444                std::vector<String> AvailableEngineTypes();
445    
446                /**
447               * Create an audio output device.               * Create an audio output device.
448               *               *
449               * @param AudioDriver - name of the audio driver               * @param AudioDriver - name of the audio driver
450               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
451               *                     create the device               *                     create the device
452               * @returns  pointer to created audio output device               * @returns  pointer to created audio output device
453               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
454               */               */
455              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
456    
457              /**              /**
458               * Create a midi input device.               * Create a midi input device.
# Line 300  namespace LinuxSampler { Line 461  namespace LinuxSampler {
461               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
462               *                     create the device               *                     create the device
463               * @returns  pointer to created midi input device               * @returns  pointer to created midi input device
464               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
465               */               */
466              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
467    
468              /**              /**
469               * Returns the number of all created audio output devices.               * Returns the number of all created audio output devices.
# Line 328  namespace LinuxSampler { Line 489  namespace LinuxSampler {
489               * Destroy the given audio output device and takes care if there               * Destroy the given audio output device and takes care if there
490               * are still sampler angines connected to this device, etc.               * are still sampler angines connected to this device, etc.
491               *               *
492               * @throws LinuxSamplerException  if sampler channels are still               * @throws Exception  if sampler channels are still
493               *                                connected to the device               *                    connected to the device
494               */               */
495              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
496    
497              /**              /**
498               * Destroy the given MIDI input device and takes care if there               * Destroy the given MIDI input device and takes care if there
499               * are still sampler angines connected to this device, etc.               * are still sampler angines connected to this device, etc.
500               *               *
501               * @throws LinuxSamplerException  if sampler channels are still               * @throws Exception  if sampler channels are still
502               *                                connected to the device               *                    connected to the device
503                 */
504                void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception);
505    
506                /**
507                 * Gets the current number of all active voices.
508                 * @returns The current number of all active voices.
509               */               */
510              void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException);              int GetVoiceCount();
511    
512              /**              /**
513               * Reset the whole sampler. Destroy all engines, sampler               * Reset the whole sampler. Destroy all engines, sampler
# Line 349  namespace LinuxSampler { Line 516  namespace LinuxSampler {
516              void Reset();              void Reset();
517    
518          protected:          protected:
519                /**
520                 * Notifies listeners that the number of sampler channels has been changed.
521                 * @param NewCount The new number of sampler channels.
522                 */
523                void fireChannelCountChanged(int NewCount);
524    
525                /**
526                 * Notifies listeners that the number of audio output devices has been changed.
527                 * @param NewCount The new number of audio output devices.
528                 */
529                void fireAudioDeviceCountChanged(int NewCount);
530    
531                /**
532                 * Notifies listeners that the number of MIDI input devices has been changed.
533                 * @param NewCount The new number of MIDI input devices.
534                 */
535                void fireMidiDeviceCountChanged(int NewCount);
536    
537                /**
538                 * Notifies listeners that the number of effect sends
539                 * on a particular sampler channel is changed.
540                 * @param ChannelId The numerical ID of the sampler channel.
541                 * @param NewCount The new number of sampler channels.
542                 */
543                void fireFxSendCountChanged(int ChannelId, int NewCount);
544    
545              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
546              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
547              typedef std::map<uint, SamplerChannel*> SamplerChannelMap;              typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
# Line 358  namespace LinuxSampler { Line 551  namespace LinuxSampler {
551              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices
552    
553              friend class SamplerChannel;              friend class SamplerChannel;
554    
555            private:
556                ListenerList<ChannelCountListener*> llChannelCountListeners;
557                ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners;
558                ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners;
559                ListenerList<VoiceCountListener*> llVoiceCountListeners;
560                ListenerList<StreamCountListener*> llStreamCountListeners;
561                ListenerList<BufferFillListener*> llBufferFillListeners;
562                ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners;
563                ListenerList<FxSendCountListener*> llFxSendCountListeners;
564    
565                class EventHandler : public EngineChangeListener, public FxSendCountListener {
566                    public:
567                        void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; }
568    
569                        /**
570                         * Invoked when the engine type of the
571                         * specified sampler channel is changed.
572                         * @param ChannelId The numerical ID of the sampler
573                         * channel, which engine type has been changed.
574                         */
575                        virtual void EngineChanged(int ChannelId);
576    
577                        /**
578                         * Invoked when the number of effect sends
579                         * on the specified sampler channel has changed.
580                         * @param ChannelId The numerical ID of the sampler channel.
581                         * @param NewCount The new number of effect sends.
582                         */
583                        virtual void FxSendCountChanged(int ChannelId, int NewCount);
584    
585                    private:
586                        Sampler* pSampler;
587                } eventHandler;
588      };      };
589  }  }
590    

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

  ViewVC Help
Powered by ViewVC