--- linuxsampler/trunk/src/engines/gig/Engine.h 2005/02/26 02:01:14 411 +++ linuxsampler/trunk/src/engines/gig/Engine.h 2005/06/16 21:35:30 659 @@ -26,23 +26,23 @@ #include "../../common/global.h" -#if DEBUG_HEADERS -# warning Engine.h included -#endif // DEBUG_HEADERS - #include +#include #include "EngineGlobals.h" #include "../../common/RingBuffer.h" #include "../../common/Pool.h" +#include "../../common/ArrayList.h" #include "../../common/ConditionServer.h" #include "../common/Engine.h" #include "../common/Event.h" #include "../common/BiquadFilter.h" -#include "../../lib/fileloader/libgig/gig.h" #include "../../network/lscp.h" #include "EngineChannel.h" +// identifier of this sampler engine +#define LS_GIG_ENGINE_NAME "GigEngine" + namespace LinuxSampler { namespace gig { // just symbol prototyping @@ -56,14 +56,14 @@ * Sampler engine for the Gigasampler format. */ class Engine : public LinuxSampler::Engine { - public: + public: // methods Engine(); - ~Engine(); - int RenderAudio(LinuxSampler::gig::EngineChannel* pEngineChannel, uint Samples); + virtual ~Engine(); void Connect(AudioOutputDevice* pAudioOut); // implementation of abstract methods derived from class 'LinuxSampler::Engine' + virtual int RenderAudio(uint Samples); virtual void SendSysex(void* pData, uint Size); virtual void Reset(); virtual void Enable(); @@ -78,46 +78,57 @@ virtual String Description(); virtual String Version(); virtual String EngineName(); - - //protected: + + //protected: static InstrumentResourceManager instruments; AudioOutputDevice* pAudioOutputDevice; uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz) uint MaxSamplesPerCycle; ///< Size of each audio output buffer - DiskThread* pDiskThread; + DiskThread* pDiskThread; RingBuffer* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages). - Pool* pVoicePool; ///< Contains all voices that can be activated. - EventGenerator* pEventGenerator; + Pool* pVoicePool; ///< Contains all voices that can be activated. + EventGenerator* pEventGenerator; RTList* pVoiceStealingQueue; ///< All voice-launching events which had to be postponed due to free voice shortage. - RTList* pEvents; ///< All events for the current audio fragment. + RTList* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages). Pool* pEventPool; ///< Contains all Event objects that can be used. - RTList* pCCEvents; ///< All control change events for the current audio fragment. RingBuffer* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages. - RTList* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter). float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop. biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter. biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass). - int ActiveVoiceCount; ///< number of currently active voices + int ActiveVoiceCount; ///< number of currently active voices (this value will be returned for public calls) + int ActiveVoiceCountTemp; ///< number of currently active voices (for internal usage, will be used for incrementation) int ActiveVoiceCountMax; ///< the maximum voice usage since application start + int VoiceTheftsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be stolen per audio fragment, we use this variable to ensure this limit. + RTList::Iterator itLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise. + RTList::Iterator iuiLastStolenKey; ///< Only for voice stealing: key number of last key on which the last voice was theft in current audio fragment, NULL otherwise. + EngineChannel* pLastStolenChannel; ///< Only for voice stealing: points to the engine channel on which the previous voice was stolen in this audio fragment. + RTList::Iterator itLastStolenVoiceGlobally; ///< Same as itLastStolenVoice, but engine globally + RTList::Iterator iuiLastStolenKeyGlobally; ///< Same as iuiLastStolenKey, but engine globally bool SuspensionRequested; ConditionServer EngineDisabled; int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave - RTList::Iterator itLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise. - RTList::Iterator iuiLastStolenKey; ///< Only for voice stealing: key number of last key on which the last voice was theft in current audio fragment, NULL otherwise. int MaxFadeOutPos; ///< The last position in an audio fragment to allow an instant fade out (e.g. for voice stealing) without leading to clicks. + uint32_t RandomSeed; ///< State of the random number generator used by the random dimension. + void ProcessEvents(EngineChannel* pEngineChannel, uint Samples); + void RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples); + void RenderStolenVoices(uint Samples); + void PostProcess(EngineChannel* pEngineChannel); + void ClearEventLists(); + void ImportEvents(uint Samples); void ProcessNoteOn(EngineChannel* pEngineChannel, Pool::Iterator& itNoteOnEvent); void ProcessNoteOff(EngineChannel* pEngineChannel, Pool::Iterator& itNoteOffEvent); void ProcessPitchbend(EngineChannel* pEngineChannel, Pool::Iterator& itPitchbendEvent); void ProcessControlChange(EngineChannel* pEngineChannel, Pool::Iterator& itControlChangeEvent); void ProcessSysex(Pool::Iterator& itSysexEvent); Pool::Iterator LaunchVoice(EngineChannel* pEngineChannel, Pool::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing); - void StealVoice(EngineChannel* pEngineChannel, Pool::Iterator& itNoteOnEvent); + int StealVoice(EngineChannel* pEngineChannel, Pool::Iterator& itNoteOnEvent); void FreeVoice(EngineChannel* pEngineChannel, Pool::Iterator& itVoice); void FreeKey(EngineChannel* pEngineChannel, midi_key_info_t* pKey); void ResetSynthesisParameters(Event::destination_t dst, float val); void ResetInternal(); + void ResetScaleTuning(); static Engine* AcquireEngine(LinuxSampler::gig::EngineChannel* pChannel, AudioOutputDevice* pDevice); static void FreeEngine(LinuxSampler::gig::EngineChannel* pChannel, AudioOutputDevice* pDevice); @@ -129,14 +140,18 @@ friend class EGDecay; friend class VCAManipulator; friend class VCFCManipulator; - friend class VCOManipulator; + friend class VCOManipulator; private: - std::list samplerChannels; ///< All sampler channels of a gig::Engine instance. - + ArrayList engineChannels; ///< All engine channels of a gig::Engine instance. + static std::map engines; ///< All instances of gig::Engine. - + uint8_t GSCheckSum(const RingBuffer::NonVolatileReader AddrReader, uint DataSize); void AdjustScale(int8_t ScaleTunes[12]); + void ReleaseAllVoices(EngineChannel* pEngineChannel, Pool::Iterator& itReleaseEvent); + void KillAllVoices(EngineChannel* pEngineChannel, Pool::Iterator& itKillEvent); + + unsigned long FrameTime; ///< Time in frames of the start of the current audio fragment }; }} // namespace LinuxSampler::gig