/[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 1723 by schoenebeck, Sun Apr 20 08:53:39 2008 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 - 2008 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 type of this sampler
172                 * channel is going to be changed soon.
173                 */
174                void fireEngineToBeChanged();
175    
176                /**
177                 * Notifies listeners that the engine
178                 * type of this sampler channel is changed.
179                 */
180                void fireEngineChanged();
181    
182    
183          protected:          protected:
184              SamplerChannel(Sampler* pS);              SamplerChannel(Sampler* pS);
# Line 155  namespace LinuxSampler { Line 186  namespace LinuxSampler {
186    
187              /** Getting MIDI input device port given its index number. */              /** Getting MIDI input device port given its index number. */
188              MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);              MidiInputPort* __GetMidiInputDevicePort(int iMidiPort);
             midi_chan_t    __GetMidiChannel();  
189    
190              Sampler*           pSampler;              Sampler*           pSampler;
191              EngineChannel*     pEngineChannel;              EngineChannel*     pEngineChannel;
# Line 167  namespace LinuxSampler { Line 197  namespace LinuxSampler {
197          private:          private:
198              int                iMidiPort;   ///< Don't access directly, read GetMidiInputPort() instead !              int                iMidiPort;   ///< Don't access directly, read GetMidiInputPort() instead !
199              midi_chan_t        midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !              midi_chan_t        midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !
200                ListenerList<EngineChangeListener*> llEngineChangeListeners;
201      };      };
202    
203      /** @brief LinuxSampler main class      /** @brief LinuxSampler main class
# Line 178  namespace LinuxSampler { Line 209  namespace LinuxSampler {
209       * engine, connected to an arbitrary MIDI input device and connected to       * engine, connected to an arbitrary MIDI input device and connected to
210       * an arbitrary audio output device. Here an example setup:       * an arbitrary audio output device. Here an example setup:
211       * @code       * @code
212       * S.Channel.       MIDI in         S.Engine                Audio out       * S.Channel    MIDI in    S.Engine         Audio out
213       * -------------------------------------------------------------------       * -------------------------------------------------------------------
214       * 0                Alsa    ->      gig::Engine     ->      Jack       *   0          Alsa   ->  gig::Engine  ->  Jack
215       * 1                VSTi    ->      Akai::Engine    ->      VSTi       *   1          VSTi   ->  Akai::Engine ->  VSTi
216       * 2                Jack    ->      DLS::Engine     ->      Jack       *   2          Jack   ->  DLS::Engine  ->  Jack
217       * 3                Jack    ->      SF::Engine      ->      Alsa       *   3          Jack   ->  SF::Engine   ->  Alsa
218       *       *
219       * ... (and so on) ...       * ... (and so on) ...
220       * @endcode       * @endcode
221       *       *
222       * Note that not all audio and MIDI backends and sampler engines listed       * Note that not all audio and MIDI backends and sampler engines listed
223       * in the example above are already implemented!       * in the example above might already been implemented!
224       *       *
225       * 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
226       * several, different audio output and MIDI input systems       * several, different audio output and MIDI input systems
227       * simultaniously at the same time. Here the example setup shown in the       * simultaniously at the same time. Here the example setup shown in the
228       * ascpect of MIDI input and audio output devices / drivers:       * aspect of MIDI input and audio output devices / drivers:
229       * @code       * @code
230       *                    ######################### #########################       *                      ######################### #########################
231       *                    # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #       *                      # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
232       *                    ######################### #########################       *                      ######################### #########################
233       *                                   ^   ^           ^       *                                        ^   ^           ^
234       *   /------------>|Sampler Channel 0|-----/   |             |       *  /------------>|Sampler Channel 0|-----/   |           |
235       *   |  /--------->|Sampler Channel 1|---------------------/       *  |  /--------->|Sampler Channel 1|---------------------/
236       *   |  |    /------>|Sampler Channel 2|---------/       *  |  |  /------>|Sampler Channel 2|---------/
237       *   |  |    |  /--->|Sampler Channel 3|------------>#########################       *  |  |  |  /--->|Sampler Channel 3|------------>#########################
238       *   |  |    |  |    ... (and so on) ...             # AudioOutputDeviceAlsa #       *  |  |  |  |    ... (and so on) ...             # AudioOutputDeviceAlsa #
239       *   |  |    |  |                                    #########################       *  |  |  |  |                                    #########################
240       *   |  |    |  \-----------------------------------------------------\       *  |  |  |  \-----------------------------------------------------\
241       *   |  |    \--------------------------------------------\           |       *  |  |  \--------------------------------------------\           |
242       *   |  \--------------------\                            |           |       *  |  \--------------------\                          |           |
243       *   |                         |                          |           |       *  |                       |                          |           |
244       * ####################### ####################### #######################       * ####################### ####################### #######################
245       * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #       * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
246       * ####################### ####################### #######################       * ####################### ####################### #######################
# Line 218  namespace LinuxSampler { Line 249  namespace LinuxSampler {
249       * 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
250       * driver / audio output driver) can be connected multiple times to       * driver / audio output driver) can be connected multiple times to
251       * different sampler channels.       * different sampler channels.
252         *
253         * It's even possible to create multiple instances of the same driver, for
254         * example multiple instances of the Alsa output driver to use multiple
255         * sound cards at the same time, or multiple instances of the JACK audio
256         * output driver to leverage SMP systems or boxes with several hard discs.
257       */       */
258      class Sampler {      class Sampler {
259          public:          public:
# Line 278  namespace LinuxSampler { Line 314  namespace LinuxSampler {
314              void RemoveSamplerChannel(uint uiSamplerChannel);              void RemoveSamplerChannel(uint uiSamplerChannel);
315    
316              /**              /**
317                 * Registers the specified listener to be notified
318                 * when the number of sampler chanels is changed.
319                 */
320                void AddChannelCountListener(ChannelCountListener* l);
321    
322                /**
323                 * Removes the specified listener.
324                 */
325                void RemoveChannelCountListener(ChannelCountListener* l);
326    
327                /**
328                 * Registers the specified listener to be notified
329                 * when the number of audio output devices is changed.
330                 */
331                void AddAudioDeviceCountListener(AudioDeviceCountListener* l);
332    
333                /**
334                 * Removes the specified listener.
335                 */
336                void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l);
337    
338                
339                /**
340                 * Registers the specified listener to be notified
341                 * when the number of MIDI input devices is changed.
342                 */
343                void AddMidiDeviceCountListener(MidiDeviceCountListener* l);
344    
345                /**
346                 * Removes the specified listener.
347                 */
348                void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l);
349    
350                /**
351                 * Registers the specified listener to be notified when the number
352                 * of active voices in a particular sampler channel is changed.
353                 */
354                void AddVoiceCountListener(VoiceCountListener* l);
355    
356                /**
357                 * Removes the specified listener.
358                 */
359                void RemoveVoiceCountListener(VoiceCountListener* l);
360    
361                /**
362                 * Notifies listeners that the number of active voices
363                 * on the specified sampler channel is changed.
364                 * @param ChannelId The numerical ID of the sampler channel.
365                 * @param NewCount The new number of active voices.
366                 */
367                void fireVoiceCountChanged(int ChannelId, int NewCount);
368    
369                /**
370                 * Registers the specified listener to be notified when the number
371                 * of active disk streams in a particular sampler channel is changed.
372                 */
373                void AddStreamCountListener(StreamCountListener* l);
374    
375                /**
376                 * Removes the specified listener.
377                 */
378                void RemoveStreamCountListener(StreamCountListener* l);
379    
380                /**
381                 * Notifies listeners that the number of active disk streams
382                 * on the specified sampler channel is changed.
383                 * @param ChannelId The numerical ID of the sampler channel.
384                 * @param NewCount The new number of active disk streams.
385                 */
386                void fireStreamCountChanged(int ChannelId, int NewCount);
387    
388                /**
389                 * Registers the specified listener to be
390                 * notified when the fill state of the disk stream
391                 * buffers on a specific sampler channel is changed.
392                 */
393                void AddBufferFillListener(BufferFillListener* l);
394    
395                /**
396                 * Removes the specified listener.
397                 */
398                void RemoveBufferFillListener(BufferFillListener* l);
399    
400                /**
401                 * Notifies listeners that the fill state of the disk stream
402                 * buffers on the specified sampler channel is changed.
403                 * @param ChannelId The numerical ID of the sampler channel.
404                 * @param FillData The buffer fill data for the specified sampler channel.
405                 */
406                void fireBufferFillChanged(int ChannelId, String FillData);
407    
408                /**
409                 * Registers the specified listener to be notified
410                 * when total number of active voices is changed.
411                 */
412                void AddTotalVoiceCountListener(TotalVoiceCountListener* l);
413    
414                /**
415                 * Removes the specified listener.
416                 */
417                void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l);
418    
419                /**
420                 * Notifies listeners that the total number of active voices is changed.
421                 * @param NewCount The new number of active voices.
422                 */
423                void fireTotalVoiceCountChanged(int NewCount);
424                
425                void AddTotalStreamCountListener(TotalStreamCountListener* l);
426                void RemoveTotalStreamCountListener(TotalStreamCountListener* l);
427                void fireTotalStreamCountChanged(int NewCount);
428    
429                /**
430                 * Registers the specified listener to be notified when the number
431                 * of effect sends on a particular sampler channel is changed.
432                 */
433                void AddFxSendCountListener(FxSendCountListener* l);
434    
435                /**
436                 * Removes the specified listener.
437                 */
438                void RemoveFxSendCountListener(FxSendCountListener* l);
439    
440                /**
441               * Returns the names of all available audio output drivers.               * Returns the names of all available audio output drivers.
442               */               */
443              std::vector<String> AvailableAudioOutputDrivers();              std::vector<String> AvailableAudioOutputDrivers();
444    
445              /**              /**
446                 * Returns the names of all available MIDI input drivers.
447                 */
448                std::vector<String> AvailableMidiInputDrivers();
449    
450                /**
451                 * Returns the names of all available sampler engine types.
452                 * @see SamplerChannel::SetEngineType()
453                 */
454                std::vector<String> AvailableEngineTypes();
455    
456                /**
457               * Create an audio output device.               * Create an audio output device.
458               *               *
459               * @param AudioDriver - name of the audio driver               * @param AudioDriver - name of the audio driver
460               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
461               *                     create the device               *                     create the device
462               * @returns  pointer to created audio output device               * @returns  pointer to created audio output device
463               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
464               */               */
465              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
466    
467              /**              /**
468               * Create a midi input device.               * Create a midi input device.
# Line 300  namespace LinuxSampler { Line 471  namespace LinuxSampler {
471               * @param Parameters - eventually needed driver parameters to               * @param Parameters - eventually needed driver parameters to
472               *                     create the device               *                     create the device
473               * @returns  pointer to created midi input device               * @returns  pointer to created midi input device
474               * @throws LinuxSamplerException  if device could not be created               * @throws Exception  if device could not be created
475               */               */
476              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException);              MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
477    
478              /**              /**
479               * Returns the number of all created audio output devices.               * Returns the number of all created audio output devices.
# Line 328  namespace LinuxSampler { Line 499  namespace LinuxSampler {
499               * Destroy the given audio output device and takes care if there               * Destroy the given audio output device and takes care if there
500               * are still sampler angines connected to this device, etc.               * are still sampler angines connected to this device, etc.
501               *               *
502               * @throws LinuxSamplerException  if sampler channels are still               * @throws Exception  if sampler channels are still
503               *                                connected to the device               *                    connected to the device
504               */               */
505              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException);              void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
506    
507              /**              /**
508               * Destroy the given MIDI input device and takes care if there               * Destroy the given MIDI input device and takes care if there
509               * are still sampler angines connected to this device, etc.               * are still sampler angines connected to this device, etc.
510               *               *
511               * @throws LinuxSamplerException  if sampler channels are still               * @throws Exception  if sampler channels are still
512               *                                connected to the device               *                    connected to the device
513                 */
514                void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception);
515    
516                 /**
517                 * Gets the current number of all active streams.
518                 * @returns The current number of all active streams.
519               */               */
520              void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException);              int GetDiskStreamCount();
521    
522                /**
523                 * Gets the current number of all active voices.
524                 * @returns The current number of all active voices.
525                 */
526                int GetVoiceCount();
527    
528              /**              /**
529               * Reset the whole sampler. Destroy all engines, sampler               * Reset the whole sampler. Destroy all engines, sampler
# Line 348  namespace LinuxSampler { Line 531  namespace LinuxSampler {
531               */               */
532              void Reset();              void Reset();
533    
534                /**
535                 * Advise the FPU to treat denormal floating point numbers as
536                 * zero, to avoid severe performance penalty when dealing with
537                 * such extreme floating point values.
538                 *
539                 * @returns @c true if FPU supports it, @c false otherwise
540                 */
541                static bool EnableDenormalsAreZeroMode();
542    
543          protected:          protected:
544                /**
545                 * Notifies listeners that the number of sampler channels has been changed.
546                 * @param NewCount The new number of sampler channels.
547                 */
548                void fireChannelCountChanged(int NewCount);
549    
550                /**
551                 * Notifies listeners that the specified sampler channel has just
552                 * been added.
553                 * @param pChannel The new sampler channel.
554                 */
555                void fireChannelAdded(SamplerChannel* pChannel);
556    
557                /**
558                 * Notifies listeners that the specified sampler channel is
559                 * going to be removed soon.
560                 * @param pChannel sampler channel to be removed.
561                 */
562                void fireChannelToBeRemoved(SamplerChannel* pChannel);
563    
564                /**
565                 * Notifies listeners that the number of audio output devices has been changed.
566                 * @param NewCount The new number of audio output devices.
567                 */
568                void fireAudioDeviceCountChanged(int NewCount);
569    
570                /**
571                 * Notifies listeners that the number of MIDI input devices has been changed.
572                 * @param NewCount The new number of MIDI input devices.
573                 */
574                void fireMidiDeviceCountChanged(int NewCount);
575    
576                /**
577                 * Notifies listeners that the supplied MIDI input device is
578                 * going to be destroyed soon.
579                 * @param pDevice MIDI input device to be destroyed
580                 */
581                void fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice);
582    
583                /**
584                 * Notifies listeners that the supplied MIDI input device was
585                 * just created.
586                 * @param pDevice new MIDI input device
587                 */
588                void fireMidiDeviceCreated(MidiInputDevice* pDevice);
589    
590                /**
591                 * Notifies listeners that the number of effect sends
592                 * on a particular sampler channel is changed.
593                 * @param ChannelId The numerical ID of the sampler channel.
594                 * @param NewCount The new number of sampler channels.
595                 */
596                void fireFxSendCountChanged(int ChannelId, int NewCount);
597    
598              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;              typedef std::map<uint, AudioOutputDevice*> AudioOutputDeviceMap;
599              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;              typedef std::map<uint, MidiInputDevice*> MidiInputDeviceMap;
600              typedef std::map<uint, SamplerChannel*> SamplerChannelMap;              typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
# Line 358  namespace LinuxSampler { Line 604  namespace LinuxSampler {
604              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices              MidiInputDeviceMap    mMidiInputDevices;   ///< contains all created MIDI input devices
605    
606              friend class SamplerChannel;              friend class SamplerChannel;
607    
608            private:
609                ListenerList<ChannelCountListener*> llChannelCountListeners;
610                ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners;
611                ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners;
612                ListenerList<VoiceCountListener*> llVoiceCountListeners;
613                ListenerList<StreamCountListener*> llStreamCountListeners;
614                ListenerList<BufferFillListener*> llBufferFillListeners;
615                ListenerList<TotalStreamCountListener*> llTotalStreamCountListeners;
616                ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners;
617                ListenerList<FxSendCountListener*> llFxSendCountListeners;
618    
619                class EventHandler : public EngineChangeListener, public FxSendCountListener {
620                    public:
621                        void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; }
622    
623                        /**
624                         * Invoked when the engine type of the specified sampler
625                         * channel is going to be changed soon.
626                         * @param ChannelId The numerical ID of the sampler channel
627                         */
628                        virtual void EngineToBeChanged(int ChannelId);
629    
630                        /**
631                         * Invoked when the engine type of the
632                         * specified sampler channel is changed.
633                         * @param ChannelId The numerical ID of the sampler
634                         * channel, which engine type has been changed.
635                         */
636                        virtual void EngineChanged(int ChannelId);
637    
638                        /**
639                         * Invoked when the number of effect sends
640                         * on the specified sampler channel has changed.
641                         * @param ChannelId The numerical ID of the sampler channel.
642                         * @param NewCount The new number of effect sends.
643                         */
644                        virtual void FxSendCountChanged(int ChannelId, int NewCount);
645    
646                    private:
647                        Sampler* pSampler;
648                } eventHandler;
649      };      };
650  }  }
651    

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

  ViewVC Help
Powered by ViewVC