32 |
#include <map> |
#include <map> |
33 |
|
|
34 |
#include "../../common/RingBuffer.h" |
#include "../../common/RingBuffer.h" |
35 |
#include "../../common/RTELMemoryPool.h" |
#include "../../common/Pool.h" |
36 |
#include "../../common/ConditionServer.h" |
#include "../../common/ConditionServer.h" |
37 |
#include "../common/Engine.h" |
#include "../common/Engine.h" |
38 |
#include "../common/Event.h" |
#include "../common/Event.h" |
58 |
/** |
/** |
59 |
* Sampler engine for the Gigasampler format. |
* Sampler engine for the Gigasampler format. |
60 |
*/ |
*/ |
61 |
class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer { |
class Engine : public LinuxSampler::Engine, public InstrumentConsumer { |
62 |
public: |
public: |
63 |
// types |
// types |
64 |
enum voice_steal_algo_t { |
enum voice_steal_algo_t { |
100 |
virtual String Version(); |
virtual String Version(); |
101 |
virtual String EngineName(); |
virtual String EngineName(); |
102 |
virtual String InstrumentFileName(); |
virtual String InstrumentFileName(); |
103 |
|
virtual String InstrumentName(); |
104 |
virtual int InstrumentIndex(); |
virtual int InstrumentIndex(); |
105 |
virtual int InstrumentStatus(); |
virtual int InstrumentStatus(); |
106 |
|
|
107 |
// abstract methods derived from interface class 'InstrumentConsumer' |
// abstract methods derived from interface class 'InstrumentConsumer' |
108 |
virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg); |
virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg); |
109 |
virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg); |
virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg); |
110 |
protected: |
//protected: |
111 |
struct midi_key_info_t { |
struct midi_key_info_t { |
112 |
RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key. |
RTList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key. |
113 |
bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed. |
bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed. |
114 |
bool Active; ///< If the key contains active voices. |
bool Active; ///< If the key contains active voices. |
115 |
bool ReleaseTrigger; ///< If we have to launch release triggered voice(s) when the key is released |
bool ReleaseTrigger; ///< If we have to launch release triggered voice(s) when the key is released |
116 |
uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys |
Pool<uint>::Iterator itSelf; ///< hack to allow fast deallocation of the key from the list of active keys |
117 |
RTEList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently) |
RTList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently) |
118 |
}; |
}; |
119 |
|
|
120 |
static InstrumentResourceManager Instruments; |
static InstrumentResourceManager Instruments; |
131 |
RingBuffer<Event>* pEventQueue; ///< Input event queue. |
RingBuffer<Event>* pEventQueue; ///< Input event queue. |
132 |
RingBuffer<uint8_t>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages. |
RingBuffer<uint8_t>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages. |
133 |
midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key |
midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key |
134 |
RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated. |
Pool<Voice>* pVoicePool; ///< Contains all voices that can be activated. |
135 |
RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices. |
Pool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices. |
136 |
RTELMemoryPool<Event>* pEventPool; ///< Contains all Event objects that can be used. |
Pool<Event>* pEventPool; ///< Contains all Event objects that can be used. |
137 |
EventGenerator* pEventGenerator; |
EventGenerator* pEventGenerator; |
138 |
RTEList<Event>* pVoiceStealingQueue; ///< All voice-launching events which had to be postponed due to free voice shortage. |
RTList<Event>* pVoiceStealingQueue; ///< All voice-launching events which had to be postponed due to free voice shortage. |
139 |
RTEList<Event>* pEvents; ///< All events for the current audio fragment. |
RTList<Event>* pEvents; ///< All events for the current audio fragment. |
140 |
RTEList<Event>* pCCEvents; ///< All control change events for the current audio fragment. |
RTList<Event>* pCCEvents; ///< All control change events for the current audio fragment. |
141 |
RTEList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter). |
RTList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter). |
142 |
float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop. |
float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop. |
143 |
biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter. |
biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter. |
144 |
biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass). |
biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass). |
149 |
bool SustainPedal; ///< true if sustain pedal is down |
bool SustainPedal; ///< true if sustain pedal is down |
150 |
double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification) |
double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification) |
151 |
int Pitch; ///< Current (absolute) MIDI pitch value. |
int Pitch; ///< Current (absolute) MIDI pitch value. |
152 |
|
int CurrentKeyDimension; ///< Current value (0-127) for the keyboard dimension, altered by pressing a keyswitching key. |
153 |
int ActiveVoiceCount; ///< number of currently active voices |
int ActiveVoiceCount; ///< number of currently active voices |
154 |
int ActiveVoiceCountMax; ///< the maximum voice usage since application start |
int ActiveVoiceCountMax; ///< the maximum voice usage since application start |
155 |
bool SuspensionRequested; |
bool SuspensionRequested; |
156 |
ConditionServer EngineDisabled; |
ConditionServer EngineDisabled; |
157 |
String InstrumentFile; |
String InstrumentFile; |
158 |
int InstrumentIdx; |
int InstrumentIdx; |
159 |
|
String InstrumentIdxName; |
160 |
int InstrumentStat; |
int InstrumentStat; |
161 |
int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave |
int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave |
162 |
Voice* pLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise. |
RTList<Voice>::Iterator itLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise. |
163 |
uint* puiLastStolenKey; ///< Only for voice stealing: key number of last key on which the last voice 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. |
164 |
|
int MaxFadeOutPos; ///< The last position in an audio fragment to allow a instant fade out (e.g. for voice stealing) without leading to clicks. |
165 |
void ProcessNoteOn(Event* pNoteOnEvent); |
|
166 |
void ProcessNoteOff(Event* pNoteOffEvent); |
void ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent); |
167 |
void ProcessPitchbend(Event* pPitchbendEvent); |
void ProcessNoteOff(Pool<Event>::Iterator& itNoteOffEvent); |
168 |
void ProcessControlChange(Event* pControlChangeEvent); |
void ProcessPitchbend(Pool<Event>::Iterator& itPitchbendEvent); |
169 |
void ProcessSysex(Event* pSysexEvent); |
void ProcessControlChange(Pool<Event>::Iterator& itControlChangeEvent); |
170 |
Voice* LaunchVoice(Event* pNoteOnEvent, int iLayer = 0, bool ReleaseTriggerVoice = false, bool VoiceStealing = true); |
void ProcessSysex(Pool<Event>::Iterator& itSysexEvent); |
171 |
void StealVoice(Event* pNoteOnEvent, int iLayer, bool ReleaseTriggerVoice); |
Pool<Voice>::Iterator LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing); |
172 |
void KillVoiceImmediately(Voice* pVoice); |
void StealVoice(Pool<Event>::Iterator& itNoteOnEvent); |
173 |
|
void FreeVoice(Pool<Voice>::Iterator& itVoice); |
174 |
|
void FreeKey(midi_key_info_t* pKey); |
175 |
void ResetSynthesisParameters(Event::destination_t dst, float val); |
void ResetSynthesisParameters(Event::destination_t dst, float val); |
176 |
void ResetInternal(); |
void ResetInternal(); |
177 |
|
|