--- linuxsampler/trunk/src/Sampler.h 2006/07/05 17:53:22 900 +++ linuxsampler/trunk/src/Sampler.h 2008/04/20 08:53:39 1723 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005, 2006 Christian Schoenebeck * + * Copyright (C) 2005 - 2008 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -26,6 +26,7 @@ #include #include +#include "EventListeners.h" #include "common/global.h" #include "common/Exception.h" #include "engines/EngineChannel.h" @@ -149,6 +150,35 @@ * 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 going to be changed soon. + */ + void fireEngineToBeChanged(); + + /** + * Notifies listeners that the engine + * type of this sampler channel is changed. + */ + void fireEngineChanged(); + protected: SamplerChannel(Sampler* pS); @@ -167,6 +197,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 @@ -283,6 +314,130 @@ 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); + + void AddTotalStreamCountListener(TotalStreamCountListener* l); + void RemoveTotalStreamCountListener(TotalStreamCountListener* l); + void fireTotalStreamCountChanged(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(); @@ -358,6 +513,12 @@ */ void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception); + /** + * Gets the current number of all active streams. + * @returns The current number of all active streams. + */ + int GetDiskStreamCount(); + /** * Gets the current number of all active voices. * @returns The current number of all active voices. @@ -370,7 +531,70 @@ */ void Reset(); + /** + * Advise the FPU to treat denormal floating point numbers as + * zero, to avoid severe performance penalty when dealing with + * such extreme floating point values. + * + * @returns @c true if FPU supports it, @c false otherwise + */ + static bool EnableDenormalsAreZeroMode(); + 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 specified sampler channel has just + * been added. + * @param pChannel The new sampler channel. + */ + void fireChannelAdded(SamplerChannel* pChannel); + + /** + * Notifies listeners that the specified sampler channel is + * going to be removed soon. + * @param pChannel sampler channel to be removed. + */ + void fireChannelToBeRemoved(SamplerChannel* pChannel); + + /** + * 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 supplied MIDI input device is + * going to be destroyed soon. + * @param pDevice MIDI input device to be destroyed + */ + void fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice); + + /** + * Notifies listeners that the supplied MIDI input device was + * just created. + * @param pDevice new MIDI input device + */ + void fireMidiDeviceCreated(MidiInputDevice* pDevice); + + /** + * 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; @@ -380,6 +604,48 @@ 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 llTotalStreamCountListeners; + 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 going to be changed soon. + * @param ChannelId The numerical ID of the sampler channel + */ + virtual void EngineToBeChanged(int ChannelId); + + /** + * 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; }; }