--- linuxsampler/trunk/src/Sampler.h 2006/06/27 22:57:37 880 +++ linuxsampler/trunk/src/Sampler.h 2007/03/25 18:59:14 1130 @@ -26,9 +26,10 @@ #include #include +#include "EventListeners.h" #include "common/global.h" #include "common/Exception.h" -#include "engines/common/EngineChannel.h" +#include "engines/EngineChannel.h" #include "drivers/midi/MidiInputDevice.h" #include "drivers/audio/AudioOutputDevice.h" @@ -52,6 +53,7 @@ * * @param EngineType - type of the engine to use * @throws Exception - if \a EngineType is invalid + * @see Sampler::AvailableEngineTypes() */ void SetEngineType(String EngineType) throw (Exception); @@ -148,6 +150,29 @@ * Sampler instance. */ uint Index(); + + /** + * Registers the specified listener to be notified + * when the engine type of this sampler channel is changed. + */ + void AddEngineChangeListener(EngineChangeListener* l); + + /** + * Removes the specified listener. + */ + void RemoveEngineChangeListener(EngineChangeListener* l); + + /** + * Removes the specified listener. + */ + void RemoveAllEngineChangeListeners(); + + /** + * Notifies listeners that the engine + * type of this sampler channel is changed. + */ + void fireEngineChanged(); + protected: SamplerChannel(Sampler* pS); @@ -166,6 +191,7 @@ private: int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead ! + ListenerList llEngineChangeListeners; }; /** @brief LinuxSampler main class @@ -177,38 +203,38 @@ * engine, connected to an arbitrary MIDI input device and connected to * an arbitrary audio output device. Here an example setup: * @code - * S.Channel. MIDI in S.Engine Audio out + * S.Channel MIDI in S.Engine Audio out * ------------------------------------------------------------------- - * 0 Alsa -> gig::Engine -> Jack - * 1 VSTi -> Akai::Engine -> VSTi - * 2 Jack -> DLS::Engine -> Jack - * 3 Jack -> SF::Engine -> Alsa + * 0 Alsa -> gig::Engine -> Jack + * 1 VSTi -> Akai::Engine -> VSTi + * 2 Jack -> DLS::Engine -> Jack + * 3 Jack -> SF::Engine -> Alsa * * ... (and so on) ... * @endcode * * Note that not all audio and MIDI backends and sampler engines listed - * in the example above are already implemented! + * in the example above might already been implemented! * * As you can see in the example setup, LinuxSampler is capable to use * several, different audio output and MIDI input systems * simultaniously at the same time. Here the example setup shown in the - * ascpect of MIDI input and audio output devices / drivers: + * aspect of MIDI input and audio output devices / drivers: * @code - * ######################### ######################### - * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # - * ######################### ######################### - * ^ ^ ^ - * /------------>|Sampler Channel 0|-----/ | | - * | /--------->|Sampler Channel 1|---------------------/ - * | | /------>|Sampler Channel 2|---------/ - * | | | /--->|Sampler Channel 3|------------>######################### - * | | | | ... (and so on) ... # AudioOutputDeviceAlsa # - * | | | | ######################### - * | | | \-----------------------------------------------------\ - * | | \--------------------------------------------\ | - * | \--------------------\ | | - * | | | | + * ######################### ######################### + * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # + * ######################### ######################### + * ^ ^ ^ + * /------------>|Sampler Channel 0|-----/ | | + * | /--------->|Sampler Channel 1|---------------------/ + * | | /------>|Sampler Channel 2|---------/ + * | | | /--->|Sampler Channel 3|------------>######################### + * | | | | ... (and so on) ... # AudioOutputDeviceAlsa # + * | | | | ######################### + * | | | \-----------------------------------------------------\ + * | | \--------------------------------------------\ | + * | \--------------------\ | | + * | | | | * ####################### ####################### ####################### * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # * ####################### ####################### ####################### @@ -217,6 +243,11 @@ * As you can see in this example setup, one device (that is midi input * driver / audio output driver) can be connected multiple times to * different sampler channels. + * + * It's even possible to create multiple instances of the same driver, for + * example multiple instances of the Alsa output driver to use multiple + * sound cards at the same time, or multiple instances of the JACK audio + * output driver to leverage SMP systems or boxes with several hard discs. */ class Sampler { public: @@ -277,11 +308,142 @@ void RemoveSamplerChannel(uint uiSamplerChannel); /** + * Registers the specified listener to be notified + * when the number of sampler chanels is changed. + */ + void AddChannelCountListener(ChannelCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveChannelCountListener(ChannelCountListener* l); + + /** + * Registers the specified listener to be notified + * when the number of audio output devices is changed. + */ + void AddAudioDeviceCountListener(AudioDeviceCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l); + + + /** + * Registers the specified listener to be notified + * when the number of MIDI input devices is changed. + */ + void AddMidiDeviceCountListener(MidiDeviceCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l); + + /** + * Registers the specified listener to be notified when the number + * of active voices in a particular sampler channel is changed. + */ + void AddVoiceCountListener(VoiceCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveVoiceCountListener(VoiceCountListener* l); + + /** + * Notifies listeners that the number of active voices + * on the specified sampler channel is changed. + * @param ChannelId The numerical ID of the sampler channel. + * @param NewCount The new number of active voices. + */ + void fireVoiceCountChanged(int ChannelId, int NewCount); + + /** + * Registers the specified listener to be notified when the number + * of active disk streams in a particular sampler channel is changed. + */ + void AddStreamCountListener(StreamCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveStreamCountListener(StreamCountListener* l); + + /** + * Notifies listeners that the number of active disk streams + * on the specified sampler channel is changed. + * @param ChannelId The numerical ID of the sampler channel. + * @param NewCount The new number of active disk streams. + */ + void fireStreamCountChanged(int ChannelId, int NewCount); + + /** + * Registers the specified listener to be + * notified when the fill state of the disk stream + * buffers on a specific sampler channel is changed. + */ + void AddBufferFillListener(BufferFillListener* l); + + /** + * Removes the specified listener. + */ + void RemoveBufferFillListener(BufferFillListener* l); + + /** + * Notifies listeners that the fill state of the disk stream + * buffers on the specified sampler channel is changed. + * @param ChannelId The numerical ID of the sampler channel. + * @param FillData The buffer fill data for the specified sampler channel. + */ + void fireBufferFillChanged(int ChannelId, String FillData); + + /** + * Registers the specified listener to be notified + * when total number of active voices is changed. + */ + void AddTotalVoiceCountListener(TotalVoiceCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l); + + /** + * Notifies listeners that the total number of active voices is changed. + * @param NewCount The new number of active voices. + */ + void fireTotalVoiceCountChanged(int NewCount); + + /** + * Registers the specified listener to be notified when the number + * of effect sends on a particular sampler channel is changed. + */ + void AddFxSendCountListener(FxSendCountListener* l); + + /** + * Removes the specified listener. + */ + void RemoveFxSendCountListener(FxSendCountListener* l); + + /** * Returns the names of all available audio output drivers. */ std::vector AvailableAudioOutputDrivers(); /** + * Returns the names of all available MIDI input drivers. + */ + std::vector AvailableMidiInputDrivers(); + + /** + * Returns the names of all available sampler engine types. + * @see SamplerChannel::SetEngineType() + */ + std::vector AvailableEngineTypes(); + + /** * Create an audio output device. * * @param AudioDriver - name of the audio driver @@ -354,6 +516,32 @@ void Reset(); protected: + /** + * Notifies listeners that the number of sampler channels has been changed. + * @param NewCount The new number of sampler channels. + */ + void fireChannelCountChanged(int NewCount); + + /** + * Notifies listeners that the number of audio output devices has been changed. + * @param NewCount The new number of audio output devices. + */ + void fireAudioDeviceCountChanged(int NewCount); + + /** + * Notifies listeners that the number of MIDI input devices has been changed. + * @param NewCount The new number of MIDI input devices. + */ + void fireMidiDeviceCountChanged(int NewCount); + + /** + * Notifies listeners that the number of effect sends + * on a particular sampler channel is changed. + * @param ChannelId The numerical ID of the sampler channel. + * @param NewCount The new number of sampler channels. + */ + void fireFxSendCountChanged(int ChannelId, int NewCount); + typedef std::map AudioOutputDeviceMap; typedef std::map MidiInputDeviceMap; typedef std::map SamplerChannelMap; @@ -363,6 +551,40 @@ MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices friend class SamplerChannel; + + private: + ListenerList llChannelCountListeners; + ListenerList llAudioDeviceCountListeners; + ListenerList llMidiDeviceCountListeners; + ListenerList llVoiceCountListeners; + ListenerList llStreamCountListeners; + ListenerList llBufferFillListeners; + ListenerList llTotalVoiceCountListeners; + ListenerList llFxSendCountListeners; + + class EventHandler : public EngineChangeListener, public FxSendCountListener { + public: + void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; } + + /** + * Invoked when the engine type of the + * specified sampler channel is changed. + * @param ChannelId The numerical ID of the sampler + * channel, which engine type has been changed. + */ + virtual void EngineChanged(int ChannelId); + + /** + * Invoked when the number of effect sends + * on the specified sampler channel has changed. + * @param ChannelId The numerical ID of the sampler channel. + * @param NewCount The new number of effect sends. + */ + virtual void FxSendCountChanged(int ChannelId, int NewCount); + + private: + Sampler* pSampler; + } eventHandler; }; }