/[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 1541 by iliev, Tue Dec 4 18:09:26 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                void AddTotalStreamCountListener(TotalStreamCountListener* l);
420                void RemoveTotalStreamCountListener(TotalStreamCountListener* l);
421                void fireTotalStreamCountChanged(int NewCount);
422    
423                /**
424                 * Registers the specified listener to be notified when the number
425                 * of effect sends on a particular sampler channel is changed.
426                 */
427                void AddFxSendCountListener(FxSendCountListener* l);
428    
429                /**
430                 * Removes the specified listener.
431                 */
432                void RemoveFxSendCountListener(FxSendCountListener* l);
433    
434                /**
435               * Returns the names of all available audio output drivers.               * Returns the names of all available audio output drivers.
436               */               */
437              std::vector<String> AvailableAudioOutputDrivers();              std::vector<String> AvailableAudioOutputDrivers();
438    
439              /**              /**
440                 * Returns the names of all available MIDI input drivers.
441                 */
442                std::vector<String> AvailableMidiInputDrivers();
443    
444                /**
445                 * Returns the names of all available sampler engine types.
446                 * @see SamplerChannel::SetEngineType()
447                 */
448                std::vector<String> AvailableEngineTypes();
449    
450                /**
451               * Create an audio output device.               * Create an audio output device.
452               *               *
453               * @param AudioDriver - name of the audio driver               * @param AudioDriver - name of the audio driver
454               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
455               *                     create the device               *                     create the device
456               * @returns  pointer to created audio output device               * @returns  pointer to created audio output device
457               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
458               */               */
459              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
460    
461              /**              /**
462               * Create a midi input device.               * Create a midi input device.
# Line 300  namespace LinuxSampler { Line 465  namespace LinuxSampler {
465               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
466               *                     create the device               *                     create the device
467               * @returns  pointer to created midi input device               * @returns  pointer to created midi input device
468               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
469               */               */
470              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
471    
472              /**              /**
473               * Returns the number of all created audio output devices.               * Returns the number of all created audio output devices.
# Line 328  namespace LinuxSampler { Line 493  namespace LinuxSampler {
493               * Destroy the given audio output device and takes care if there               * Destroy the given audio output device and takes care if there
494               * are still sampler angines connected to this device, etc.               * are still sampler angines connected to this device, etc.
495               *               *
496               * @throws LinuxSamplerException  if sampler channels are still               * @throws Exception  if sampler channels are still
497               *                                connected to the device               *                    connected to the device
498               */               */
499              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
500    
501              /**              /**
502               * Destroy the given MIDI input device and takes care if there               * Destroy the given MIDI input device and takes care if there
503               * are still sampler angines connected to this device, etc.               * are still sampler angines connected to this device, etc.
504               *               *
505               * @throws LinuxSamplerException  if sampler channels are still               * @throws Exception  if sampler channels are still
506               *                                connected to the device               *                    connected to the device
507                 */
508                void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception);
509    
510                 /**
511                 * Gets the current number of all active streams.
512                 * @returns The current number of all active streams.
513                 */
514                int GetDiskStreamCount();
515    
516                /**
517                 * Gets the current number of all active voices.
518                 * @returns The current number of all active voices.
519               */               */
520              void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException);              int GetVoiceCount();
521    
522              /**              /**
523               * Reset the whole sampler. Destroy all engines, sampler               * Reset the whole sampler. Destroy all engines, sampler
# Line 349  namespace LinuxSampler { Line 526  namespace LinuxSampler {
526              void Reset();              void Reset();
527    
528          protected:          protected:
529                /**
530                 * Notifies listeners that the number of sampler channels has been changed.
531                 * @param NewCount The new number of sampler channels.
532                 */
533                void fireChannelCountChanged(int NewCount);
534    
535                /**
536                 * Notifies listeners that the number of audio output devices has been changed.
537                 * @param NewCount The new number of audio output devices.
538                 */
539                void fireAudioDeviceCountChanged(int NewCount);
540    
541                /**
542                 * Notifies listeners that the number of MIDI input devices has been changed.
543                 * @param NewCount The new number of MIDI input devices.
544                 */
545                void fireMidiDeviceCountChanged(int NewCount);
546    
547                /**
548                 * Notifies listeners that the number of effect sends
549                 * on a particular sampler channel is changed.
550                 * @param ChannelId The numerical ID of the sampler channel.
551                 * @param NewCount The new number of sampler channels.
552                 */
553                void fireFxSendCountChanged(int ChannelId, int NewCount);
554    
555              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
556              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
557              typedef std::map<uint, SamplerChannel*> SamplerChannelMap;              typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
# Line 358  namespace LinuxSampler { Line 561  namespace LinuxSampler {
561              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices
562    
563              friend class SamplerChannel;              friend class SamplerChannel;
564    
565            private:
566                ListenerList<ChannelCountListener*> llChannelCountListeners;
567                ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners;
568                ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners;
569                ListenerList<VoiceCountListener*> llVoiceCountListeners;
570                ListenerList<StreamCountListener*> llStreamCountListeners;
571                ListenerList<BufferFillListener*> llBufferFillListeners;
572                ListenerList<TotalStreamCountListener*> llTotalStreamCountListeners;
573                ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners;
574                ListenerList<FxSendCountListener*> llFxSendCountListeners;
575    
576                class EventHandler : public EngineChangeListener, public FxSendCountListener {
577                    public:
578                        void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; }
579    
580                        /**
581                         * Invoked when the engine type of the
582                         * specified sampler channel is changed.
583                         * @param ChannelId The numerical ID of the sampler
584                         * channel, which engine type has been changed.
585                         */
586                        virtual void EngineChanged(int ChannelId);
587    
588                        /**
589                         * Invoked when the number of effect sends
590                         * on the specified sampler channel has changed.
591                         * @param ChannelId The numerical ID of the sampler channel.
592                         * @param NewCount The new number of effect sends.
593                         */
594                        virtual void FxSendCountChanged(int ChannelId, int NewCount);
595    
596                    private:
597                        Sampler* pSampler;
598                } eventHandler;
599      };      };
600  }  }
601    

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

  ViewVC Help
Powered by ViewVC