29 |
pMIDIKeyInfo = new midi_key_info_t[128]; |
pMIDIKeyInfo = new midi_key_info_t[128]; |
30 |
pEngine = NULL; |
pEngine = NULL; |
31 |
pInstrument = NULL; |
pInstrument = NULL; |
32 |
pEventQueue = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0); |
pEvents = NULL; // we allocate when we retrieve the right Engine object |
33 |
|
pCCEvents = NULL; // we allocate when we retrieve the right Engine object |
34 |
|
pEventQueue = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
35 |
pActiveKeys = new Pool<uint>(128); |
pActiveKeys = new Pool<uint>(128); |
36 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
37 |
pMIDIKeyInfo[i].pActiveVoices = NULL; // we allocate when we retrieve the right Engine object |
pMIDIKeyInfo[i].pActiveVoices = NULL; // we allocate when we retrieve the right Engine object |
39 |
pMIDIKeyInfo[i].Active = false; |
pMIDIKeyInfo[i].Active = false; |
40 |
pMIDIKeyInfo[i].ReleaseTrigger = false; |
pMIDIKeyInfo[i].ReleaseTrigger = false; |
41 |
pMIDIKeyInfo[i].pEvents = NULL; // we allocate when we retrieve the right Engine object |
pMIDIKeyInfo[i].pEvents = NULL; // we allocate when we retrieve the right Engine object |
42 |
|
pMIDIKeyInfo[i].VoiceTheftsQueued = 0; |
43 |
pMIDIKeyInfo[i].RoundRobinIndex = 0; |
pMIDIKeyInfo[i].RoundRobinIndex = 0; |
44 |
} |
} |
45 |
|
for (uint i = 0; i < Event::destination_count; i++) { |
46 |
|
pSynthesisEvents[i] = NULL; // we allocate when we retrieve the right Engine object |
47 |
|
} |
48 |
InstrumentIdx = -1; |
InstrumentIdx = -1; |
49 |
InstrumentStat = -1; |
InstrumentStat = -1; |
50 |
AudioDeviceChannelLeft = -1; |
AudioDeviceChannelLeft = -1; |
52 |
} |
} |
53 |
|
|
54 |
EngineChannel::~EngineChannel() { |
EngineChannel::~EngineChannel() { |
55 |
|
DisconnectAudioOutputDevice(); |
56 |
if (pInstrument) Engine::instruments.HandBack(pInstrument, this); |
if (pInstrument) Engine::instruments.HandBack(pInstrument, this); |
|
for (uint i = 0; i < 128; i++) { |
|
|
if (pMIDIKeyInfo[i].pActiveVoices) { |
|
|
pMIDIKeyInfo[i].pActiveVoices->clear(); |
|
|
delete pMIDIKeyInfo[i].pActiveVoices; |
|
|
} |
|
|
if (pMIDIKeyInfo[i].pEvents) { |
|
|
pMIDIKeyInfo[i].pEvents->clear(); |
|
|
delete pMIDIKeyInfo[i].pEvents; |
|
|
} |
|
|
} |
|
57 |
if (pEventQueue) delete pEventQueue; |
if (pEventQueue) delete pEventQueue; |
58 |
if (pActiveKeys) delete pActiveKeys; |
if (pActiveKeys) delete pActiveKeys; |
59 |
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
70 |
GlobalPanRight = 1.0f; |
GlobalPanRight = 1.0f; |
71 |
CurrentKeyDimension = 0; |
CurrentKeyDimension = 0; |
72 |
|
|
73 |
// set all MIDI controller values to zero |
ResetControllers(); |
|
memset(ControllerTable, 0x00, 128); |
|
|
|
|
|
// reset voice stealing parameters |
|
|
itLastStolenVoice = RTList<Voice>::Iterator(); |
|
|
iuiLastStolenKey = RTList<uint>::Iterator(); |
|
74 |
|
|
75 |
// reset key info |
// reset key info |
76 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
82 |
pMIDIKeyInfo[i].Active = false; |
pMIDIKeyInfo[i].Active = false; |
83 |
pMIDIKeyInfo[i].ReleaseTrigger = false; |
pMIDIKeyInfo[i].ReleaseTrigger = false; |
84 |
pMIDIKeyInfo[i].itSelf = Pool<uint>::Iterator(); |
pMIDIKeyInfo[i].itSelf = Pool<uint>::Iterator(); |
85 |
|
pMIDIKeyInfo[i].VoiceTheftsQueued = 0; |
86 |
} |
} |
87 |
|
|
88 |
// reset all key groups |
// reset all key groups |
191 |
|
|
192 |
/** |
/** |
193 |
* Will be called by the InstrumentResourceManager when the instrument |
* Will be called by the InstrumentResourceManager when the instrument |
194 |
* we are currently using in this engine is going to be updated, so we |
* we are currently using on this EngineChannel is going to be updated, |
195 |
* can stop playback before that happens. |
* so we can stop playback before that happens. |
196 |
*/ |
*/ |
197 |
void EngineChannel::ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) { |
void EngineChannel::ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) { |
198 |
dmsg(3,("gig::Engine: Received instrument update message.\n")); |
dmsg(3,("gig::Engine: Received instrument update message.\n")); |
210 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
211 |
} |
} |
212 |
|
|
213 |
|
/** |
214 |
|
* Will be called by the InstrumentResourceManager on progress changes |
215 |
|
* while loading or realoading an instrument for this EngineChannel. |
216 |
|
* |
217 |
|
* @param fProgress - current progress as value between 0.0 and 1.0 |
218 |
|
*/ |
219 |
|
void EngineChannel::OnResourceProgress(float fProgress) { |
220 |
|
this->InstrumentStat = int(fProgress * 100.0f); |
221 |
|
dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat)); |
222 |
|
} |
223 |
|
|
224 |
void EngineChannel::Connect(AudioOutputDevice* pAudioOut) { |
void EngineChannel::Connect(AudioOutputDevice* pAudioOut) { |
225 |
if (pEngine && pEngine->pAudioOutputDevice != pAudioOut) { |
if (pEngine) { |
226 |
|
if (pEngine->pAudioOutputDevice == pAudioOut) return; |
227 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
228 |
} |
} |
229 |
pEngine = Engine::AcquireEngine(this, pAudioOut); |
pEngine = Engine::AcquireEngine(this, pAudioOut); |
230 |
ResetInternal(); |
ResetInternal(); |
231 |
|
pEvents = new RTList<Event>(pEngine->pEventPool); |
232 |
|
pCCEvents = new RTList<Event>(pEngine->pEventPool); |
233 |
|
for (uint i = 0; i < Event::destination_count; i++) { |
234 |
|
pSynthesisEvents[i] = new RTList<Event>(pEngine->pEventPool); |
235 |
|
} |
236 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
237 |
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
238 |
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
246 |
void EngineChannel::DisconnectAudioOutputDevice() { |
void EngineChannel::DisconnectAudioOutputDevice() { |
247 |
if (pEngine) { // if clause to prevent disconnect loops |
if (pEngine) { // if clause to prevent disconnect loops |
248 |
ResetInternal(); |
ResetInternal(); |
249 |
|
if (pEvents) { |
250 |
|
delete pEvents; |
251 |
|
pEvents = NULL; |
252 |
|
} |
253 |
|
if (pCCEvents) { |
254 |
|
delete pCCEvents; |
255 |
|
pCCEvents = NULL; |
256 |
|
} |
257 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
258 |
if (pMIDIKeyInfo[i].pActiveVoices) { |
if (pMIDIKeyInfo[i].pActiveVoices) { |
259 |
delete pMIDIKeyInfo[i].pActiveVoices; |
delete pMIDIKeyInfo[i].pActiveVoices; |
264 |
pMIDIKeyInfo[i].pEvents = NULL; |
pMIDIKeyInfo[i].pEvents = NULL; |
265 |
} |
} |
266 |
} |
} |
267 |
|
for (uint i = 0; i < Event::destination_count; i++) { |
268 |
|
if (pSynthesisEvents[i]) { |
269 |
|
delete pSynthesisEvents[i]; |
270 |
|
pSynthesisEvents[i] = NULL; |
271 |
|
} |
272 |
|
} |
273 |
Engine* oldEngine = pEngine; |
Engine* oldEngine = pEngine; |
274 |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
275 |
pEngine = NULL; |
pEngine = NULL; |
383 |
} |
} |
384 |
} |
} |
385 |
|
|
386 |
|
void EngineChannel::ClearEventLists() { |
387 |
|
pEvents->clear(); |
388 |
|
pCCEvents->clear(); |
389 |
|
for (uint i = 0; i < Event::destination_count; i++) { |
390 |
|
pSynthesisEvents[i]->clear(); |
391 |
|
} |
392 |
|
// empty MIDI key specific event lists |
393 |
|
{ |
394 |
|
RTList<uint>::Iterator iuiKey = pActiveKeys->first(); |
395 |
|
RTList<uint>::Iterator end = pActiveKeys->end(); |
396 |
|
for(; iuiKey != end; ++iuiKey) { |
397 |
|
pMIDIKeyInfo[*iuiKey].pEvents->clear(); // free all events on the key |
398 |
|
} |
399 |
|
} |
400 |
|
} |
401 |
|
|
402 |
|
void EngineChannel::ResetControllers() { |
403 |
|
// set all MIDI controller values to zero |
404 |
|
memset(ControllerTable, 0x00, 128); |
405 |
|
} |
406 |
|
|
407 |
|
/** |
408 |
|
* Copy all events from the engine channel's input event queue buffer to |
409 |
|
* the internal event list. This will be done at the beginning of each |
410 |
|
* audio cycle (that is each RenderAudio() call) to distinguish all |
411 |
|
* events which have to be processed in the current audio cycle. Each |
412 |
|
* EngineChannel has it's own input event queue for the common channel |
413 |
|
* specific events (like NoteOn, NoteOff and ControlChange events). |
414 |
|
* Beside that, the engine also has a input event queue for global |
415 |
|
* events (usually SysEx messages). |
416 |
|
* |
417 |
|
* @param Samples - number of sample points to be processed in the |
418 |
|
* current audio cycle |
419 |
|
*/ |
420 |
|
void EngineChannel::ImportEvents(uint Samples) { |
421 |
|
RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
422 |
|
Event* pEvent; |
423 |
|
while (true) { |
424 |
|
// get next event from input event queue |
425 |
|
if (!(pEvent = eventQueueReader.pop())) break; |
426 |
|
// if younger event reached, ignore that and all subsequent ones for now |
427 |
|
if (pEvent->FragmentPos() >= Samples) { |
428 |
|
eventQueueReader--; |
429 |
|
dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples)); |
430 |
|
pEvent->ResetFragmentPos(); |
431 |
|
break; |
432 |
|
} |
433 |
|
// copy event to internal event list |
434 |
|
if (pEvents->poolIsEmpty()) { |
435 |
|
dmsg(1,("Event pool emtpy!\n")); |
436 |
|
break; |
437 |
|
} |
438 |
|
*pEvents->allocAppend() = *pEvent; |
439 |
|
} |
440 |
|
eventQueueReader.free(); // free all copied events from input queue |
441 |
|
} |
442 |
|
|
443 |
float EngineChannel::Volume() { |
float EngineChannel::Volume() { |
444 |
return GlobalVolume; |
return GlobalVolume; |
445 |
} |
} |
468 |
return InstrumentStat; |
return InstrumentStat; |
469 |
} |
} |
470 |
|
|
471 |
|
String EngineChannel::EngineName() { |
472 |
|
return LS_GIG_ENGINE_NAME; |
473 |
|
} |
474 |
|
|
475 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |