2 |
* * |
* * |
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 |
|
* Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* 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 * |
23 |
***************************************************************************/ |
***************************************************************************/ |
24 |
|
|
25 |
#ifndef __LS_GIG_ENGINE_H__ |
#ifndef __LS_GIG_ENGINE_H__ |
26 |
#define __LS_GIG_ENGINE_H__ |
#define __LS_GIG_ENGINE_H__ |
27 |
|
|
28 |
#include "../../common/global.h" |
#include "DiskThread.h" |
29 |
|
#include "../EngineBase.h" |
30 |
#include <map> |
#include "Voice.h" |
31 |
#include <gig.h> |
#include <gig.h> |
32 |
|
|
|
#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 "../../network/lscp.h" |
|
|
#include "EngineChannel.h" |
|
|
|
|
|
// identifier of this sampler engine |
|
|
#define LS_GIG_ENGINE_NAME "GIG" |
|
|
|
|
33 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
34 |
|
|
35 |
// just symbol prototyping |
class Engine: public LinuxSampler::EngineBase<Voice, ::gig::Region, ::gig::DimensionRegion, DiskThread, InstrumentResourceManager, ::gig::Instrument> { |
|
class Voice; |
|
|
class DiskThread; |
|
|
class InstrumentResourceManager; |
|
|
class midi_key_info_t; |
|
|
class EngineChannel; |
|
|
|
|
|
/** |
|
|
* Sampler engine for the Gigasampler format. |
|
|
*/ |
|
|
class Engine : public LinuxSampler::Engine { |
|
36 |
public: |
public: |
37 |
// methods |
Engine() { } |
38 |
Engine(); |
virtual ~Engine() { } |
|
virtual ~Engine(); |
|
|
void Connect(AudioOutputDevice* pAudioOut); |
|
|
|
|
39 |
// implementation of abstract methods derived from class 'LinuxSampler::Engine' |
// implementation of abstract methods derived from class 'LinuxSampler::Engine' |
40 |
virtual int RenderAudio(uint Samples); |
virtual bool DiskStreamSupported(); |
41 |
virtual void SendSysex(void* pData, uint Size); |
virtual String Description(); |
42 |
virtual void Reset(); |
virtual String Version(); |
43 |
virtual void Enable(); |
|
44 |
virtual void Disable(); |
virtual Format GetEngineFormat(); |
45 |
virtual uint VoiceCount(); |
|
46 |
virtual uint VoiceCountMax(); |
virtual void ProcessControlChange ( |
47 |
virtual bool DiskStreamSupported(); |
LinuxSampler::EngineChannel* pEngineChannel, |
48 |
virtual uint DiskStreamCount(); |
Pool<Event>::Iterator& itControlChangeEvent |
49 |
virtual uint DiskStreamCountMax(); |
); |
|
virtual String DiskStreamBufferFillBytes(); |
|
|
virtual String DiskStreamBufferFillPercentage(); |
|
|
virtual String Description(); |
|
|
virtual String Version(); |
|
|
virtual String EngineName(); |
|
|
|
|
|
//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; |
|
|
RingBuffer<Event>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages). |
|
|
Pool<Voice>* pVoicePool; ///< Contains all voices that can be activated. |
|
|
EventGenerator* pEventGenerator; |
|
|
RTList<Event>* pVoiceStealingQueue; ///< All voice-launching events which had to be postponed due to free voice shortage. |
|
|
RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages). |
|
|
Pool<Event>* pEventPool; ///< Contains all Event objects that can be used. |
|
|
RingBuffer<uint8_t>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages. |
|
|
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 VoiceSpawnsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit. |
|
|
RTList<Voice>::Iterator itLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise. |
|
|
RTList<uint>::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<Voice>::Iterator itLastStolenVoiceGlobally; ///< Same as itLastStolenVoice, but engine globally |
|
|
RTList<uint>::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 |
|
|
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<Event>::Iterator& itNoteOnEvent); |
|
|
void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent); |
|
|
void ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent); |
|
|
void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent); |
|
|
void ProcessSysex(Pool<Event>::Iterator& itSysexEvent); |
|
|
Pool<Voice>::Iterator LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing, bool HandleKeyGroupConflicts); |
|
|
int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent); |
|
|
void FreeVoice(EngineChannel* pEngineChannel, Pool<Voice>::Iterator& itVoice); |
|
|
void FreeKey(EngineChannel* pEngineChannel, midi_key_info_t* pKey); |
|
|
void ResetInternal(); |
|
|
void ResetScaleTuning(); |
|
|
|
|
|
static Engine* AcquireEngine(LinuxSampler::gig::EngineChannel* pChannel, AudioOutputDevice* pDevice); |
|
|
static void FreeEngine(LinuxSampler::gig::EngineChannel* pChannel, AudioOutputDevice* pDevice); |
|
|
|
|
|
void DisableAndLock(); // FIXME: should at least be protected |
|
50 |
|
|
51 |
friend class Voice; |
friend class Voice; |
|
private: |
|
|
ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a gig::Engine instance. |
|
|
|
|
|
static std::map<AudioOutputDevice*,Engine*> engines; ///< All instances of gig::Engine. |
|
52 |
|
|
53 |
int SostenutoKeys[128]; |
protected: |
54 |
int SostenutoKeyCount; |
virtual DiskThread* CreateDiskThread(); |
55 |
|
|
56 |
uint8_t GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize); |
virtual Pool<Voice>::Iterator LaunchVoice ( |
57 |
void AdjustScale(int8_t ScaleTunes[12]); |
LinuxSampler::EngineChannel* pEngineChannel, |
58 |
void ReleaseAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itReleaseEvent); |
Pool<Event>::Iterator& itNoteOnEvent, |
59 |
void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent); |
int iLayer, |
60 |
bool ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key); |
bool ReleaseTriggerVoice, |
61 |
|
bool VoiceStealing, |
62 |
unsigned long FrameTime; ///< Time in frames of the start of the current audio fragment |
bool HandleKeyGroupConflicts |
63 |
|
); |
64 |
|
|
65 |
|
virtual void TriggerNewVoices ( |
66 |
|
LinuxSampler::EngineChannel* pEngineChannel, |
67 |
|
RTList<Event>::Iterator& itNoteOnEvent, |
68 |
|
bool HandleKeyGroupConflicts |
69 |
|
); |
70 |
|
|
71 |
|
void TriggerReleaseVoices ( |
72 |
|
LinuxSampler::EngineChannel* pEngineChannel, |
73 |
|
RTList<Event>::Iterator& itNoteOffEvent |
74 |
|
); |
75 |
}; |
}; |
76 |
|
|
77 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |
78 |
|
|
79 |
#endif // __LS_GIG_ENGINE_H__ |
#endif /* __LS_GIG_ENGINE_H__ */ |
80 |
|
|