64 |
engines[pDevice] = pEngine; |
engines[pDevice] = pEngine; |
65 |
} |
} |
66 |
// register engine channel to the engine instance |
// register engine channel to the engine instance |
67 |
pEngine->engineChannels.push_back(pChannel); |
pEngine->engineChannels.add(pChannel); |
68 |
|
// remember index in the ArrayList |
69 |
|
pChannel->iEngineIndexSelf = pEngine->engineChannels.size() - 1; |
70 |
dmsg(4,("This gig::Engine has now %d EngineChannels.\n",pEngine->engineChannels.size())); |
dmsg(4,("This gig::Engine has now %d EngineChannels.\n",pEngine->engineChannels.size())); |
71 |
return pEngine; |
return pEngine; |
72 |
} |
} |
105 |
pEventPool = new Pool<Event>(MAX_EVENTS_PER_FRAGMENT); |
pEventPool = new Pool<Event>(MAX_EVENTS_PER_FRAGMENT); |
106 |
pVoicePool = new Pool<Voice>(MAX_AUDIO_VOICES); |
pVoicePool = new Pool<Voice>(MAX_AUDIO_VOICES); |
107 |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
108 |
pEvents = new RTList<Event>(pEventPool); |
pGlobalEvents = new RTList<Event>(pEventPool); |
|
pCCEvents = new RTList<Event>(pEventPool); |
|
|
|
|
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
pSynthesisEvents[i] = new RTList<Event>(pEventPool); |
|
|
} |
|
109 |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
110 |
iterVoice->SetEngine(this); |
iterVoice->SetEngine(this); |
111 |
} |
} |
125 |
delete pDiskThread; |
delete pDiskThread; |
126 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
127 |
} |
} |
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
if (pSynthesisEvents[i]) delete pSynthesisEvents[i]; |
|
|
} |
|
|
if (pEvents) delete pEvents; |
|
|
if (pCCEvents) delete pCCEvents; |
|
128 |
if (pEventQueue) delete pEventQueue; |
if (pEventQueue) delete pEventQueue; |
129 |
if (pEventPool) delete pEventPool; |
if (pEventPool) delete pEventPool; |
130 |
if (pVoicePool) { |
if (pVoicePool) { |
178 |
|
|
179 |
// reset voice stealing parameters |
// reset voice stealing parameters |
180 |
pVoiceStealingQueue->clear(); |
pVoiceStealingQueue->clear(); |
181 |
|
itLastStolenVoice = RTList<Voice>::Iterator(); |
182 |
|
iuiLastStolenKey = RTList<uint>::Iterator(); |
183 |
|
pLastStolenChannel = NULL; |
184 |
|
|
185 |
// reset to normal chromatic scale (means equal temper) |
// reset to normal chromatic scale (means equal temper) |
186 |
memset(&ScaleTuning[0], 0x00, 12); |
memset(&ScaleTuning[0], 0x00, 12); |
212 |
throw LinuxSamplerException(msg); |
throw LinuxSamplerException(msg); |
213 |
} |
} |
214 |
|
|
215 |
this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle(); |
this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle(); |
216 |
this->SampleRate = pAudioOutputDevice->SampleRate(); |
this->SampleRate = pAudioOutputDevice->SampleRate(); |
217 |
|
|
218 |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
219 |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * EG_MIN_RELEASE_TIME) - 1; |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * EG_MIN_RELEASE_TIME) - 1; |
273 |
} |
} |
274 |
|
|
275 |
void Engine::ClearEventLists() { |
void Engine::ClearEventLists() { |
276 |
pEvents->clear(); |
pGlobalEvents->clear(); |
|
pCCEvents->clear(); |
|
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
pSynthesisEvents[i]->clear(); |
|
|
} |
|
277 |
} |
} |
278 |
|
|
279 |
/** |
/** |
280 |
* Copy all events from the given input queue buffer to the engine's |
* Copy all events from the engine's global input queue buffer to the |
281 |
* internal event list. This will be done at the beginning of each audio |
* engine's internal event list. This will be done at the beginning of |
282 |
* cycle (that is each RenderAudio() call) to get all events which have |
* each audio cycle (that is each RenderAudio() call) to distinguish |
283 |
* to be processed in the current audio cycle. Each EngineChannel has |
* all global events which have to be processed in the current audio |
284 |
* it's own input event queue for the common channel specific events |
* cycle. These events are usually just SysEx messages. Every |
285 |
* (like NoteOn, NoteOff and ControlChange events). Beside that, the |
* EngineChannel has it's own input event queue buffer and event list |
286 |
* engine also has a input event queue for global events (usually SysEx |
* to handle common events like NoteOn, NoteOff and ControlChange |
287 |
* message). |
* events. |
288 |
* |
* |
289 |
* @param pEventQueue - input event buffer to read from |
* @param Samples - number of sample points to be processed in the |
290 |
* @param Samples - number of sample points to be processed in the |
* current audio cycle |
|
* current audio cycle |
|
291 |
*/ |
*/ |
292 |
void Engine::ImportEvents(RingBuffer<Event>* pEventQueue, uint Samples) { |
void Engine::ImportEvents(uint Samples) { |
293 |
RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
294 |
Event* pEvent; |
Event* pEvent; |
295 |
while (true) { |
while (true) { |
303 |
break; |
break; |
304 |
} |
} |
305 |
// copy event to internal event list |
// copy event to internal event list |
306 |
if (pEvents->poolIsEmpty()) { |
if (pGlobalEvents->poolIsEmpty()) { |
307 |
dmsg(1,("Event pool emtpy!\n")); |
dmsg(1,("Event pool emtpy!\n")); |
308 |
break; |
break; |
309 |
} |
} |
310 |
*pEvents->allocAppend() = *pEvent; |
*pGlobalEvents->allocAppend() = *pEvent; |
311 |
} |
} |
312 |
eventQueueReader.free(); // free all copied events from input queue |
eventQueueReader.free(); // free all copied events from input queue |
313 |
} |
} |
334 |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
335 |
pEventGenerator->UpdateFragmentTime(Samples); |
pEventGenerator->UpdateFragmentTime(Samples); |
336 |
|
|
|
// empty the engine's event lists for the new fragment |
|
|
ClearEventLists(); |
|
|
|
|
337 |
// get all events from the engine's global input event queue which belong to the current fragment |
// get all events from the engine's global input event queue which belong to the current fragment |
338 |
// (these are usually just SysEx messages) |
// (these are usually just SysEx messages) |
339 |
ImportEvents(this->pEventQueue, Samples); |
ImportEvents(Samples); |
340 |
|
|
341 |
// process engine global events (these are currently only MIDI System Exclusive messages) |
// process engine global events (these are currently only MIDI System Exclusive messages) |
342 |
{ |
{ |
343 |
RTList<Event>::Iterator itEvent = pEvents->first(); |
RTList<Event>::Iterator itEvent = pGlobalEvents->first(); |
344 |
RTList<Event>::Iterator end = pEvents->end(); |
RTList<Event>::Iterator end = pGlobalEvents->end(); |
345 |
for (; itEvent != end; ++itEvent) { |
for (; itEvent != end; ++itEvent) { |
346 |
switch (itEvent->Type) { |
switch (itEvent->Type) { |
347 |
case Event::type_sysex: |
case Event::type_sysex: |
352 |
} |
} |
353 |
} |
} |
354 |
|
|
355 |
|
// We only allow a maximum of MAX_AUDIO_VOICES voices to be stolen |
356 |
|
// in each audio fragment. All subsequent request for spawning new |
357 |
|
// voices in the same audio fragment will be ignored. |
358 |
|
VoiceTheftsLeft = MAX_AUDIO_VOICES; |
359 |
|
|
360 |
// reset internal voice counter (just for statistic of active voices) |
// reset internal voice counter (just for statistic of active voices) |
361 |
ActiveVoiceCountTemp = 0; |
ActiveVoiceCountTemp = 0; |
362 |
|
|
363 |
// render audio for all engine channels |
|
364 |
// TODO: should we make voice stealing engine globally? unfortunately this would mean other disadvantages so I left voice stealing in the engine channel space for now |
// render audio on all engine channels |
365 |
{ |
for (int i = 0; i < engineChannels.size(); i++) { |
366 |
std::list<EngineChannel*>::iterator itChannel = engineChannels.begin(); |
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
367 |
std::list<EngineChannel*>::iterator end = engineChannels.end(); |
// handle events on that engine channel |
368 |
for (; itChannel != end; itChannel++) { |
ProcessEvents(engineChannels[i], Samples); |
369 |
if (!(*itChannel)->pInstrument) continue; // ignore if no instrument loaded |
// render all 'normal', active voices |
370 |
RenderAudio(*itChannel, Samples); |
RenderActiveVoices(engineChannels[i], Samples); |
371 |
} |
} |
372 |
|
|
373 |
|
// now that all ordinary voices on ALL engine channels are rendered, render new stolen voices |
374 |
|
RenderStolenVoices(Samples); |
375 |
|
|
376 |
|
// handle cleanup on all engine channels for the next audio fragment |
377 |
|
for (int i = 0; i < engineChannels.size(); i++) { |
378 |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
379 |
|
PostProcess(engineChannels[i]); |
380 |
} |
} |
381 |
|
|
382 |
|
|
383 |
|
// empty the engine's event list for the next audio fragment |
384 |
|
ClearEventLists(); |
385 |
|
|
386 |
|
// reset voice stealing for the next audio fragment |
387 |
|
pVoiceStealingQueue->clear(); |
388 |
|
itLastStolenVoice = RTList<Voice>::Iterator(); |
389 |
|
iuiLastStolenKey = RTList<uint>::Iterator(); |
390 |
|
pLastStolenChannel = NULL; |
391 |
|
|
392 |
// just some statistics about this engine instance |
// just some statistics about this engine instance |
393 |
ActiveVoiceCount = ActiveVoiceCountTemp; |
ActiveVoiceCount = ActiveVoiceCountTemp; |
394 |
if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount; |
if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount; |
396 |
return 0; |
return 0; |
397 |
} |
} |
398 |
|
|
399 |
void Engine::RenderAudio(EngineChannel* pEngineChannel, uint Samples) { |
void Engine::ProcessEvents(EngineChannel* pEngineChannel, uint Samples) { |
|
// empty the engine's event lists for the new fragment |
|
|
ClearEventLists(); |
|
|
// empty the engine channel's, MIDI key specific event lists |
|
|
{ |
|
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
|
|
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
|
|
for(; iuiKey != end; ++iuiKey) { |
|
|
pEngineChannel->pMIDIKeyInfo[*iuiKey].pEvents->clear(); // free all events on the key |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
400 |
// get all events from the engine channels's input event queue which belong to the current fragment |
// get all events from the engine channels's input event queue which belong to the current fragment |
401 |
// (these are the common events like NoteOn, NoteOff, ControlChange, etc.) |
// (these are the common events like NoteOn, NoteOff, ControlChange, etc.) |
402 |
ImportEvents(pEngineChannel->pEventQueue, Samples); |
pEngineChannel->ImportEvents(Samples); |
|
|
|
403 |
|
|
404 |
// process events |
// process events |
405 |
{ |
{ |
406 |
RTList<Event>::Iterator itEvent = pEvents->first(); |
RTList<Event>::Iterator itEvent = pEngineChannel->pEvents->first(); |
407 |
RTList<Event>::Iterator end = pEvents->end(); |
RTList<Event>::Iterator end = pEngineChannel->pEvents->end(); |
408 |
for (; itEvent != end; ++itEvent) { |
for (; itEvent != end; ++itEvent) { |
409 |
switch (itEvent->Type) { |
switch (itEvent->Type) { |
410 |
case Event::type_note_on: |
case Event::type_note_on: |
426 |
} |
} |
427 |
} |
} |
428 |
} |
} |
429 |
|
} |
430 |
|
|
431 |
|
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
432 |
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
433 |
|
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
434 |
|
while (iuiKey != end) { // iterate through all active keys |
435 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
436 |
|
++iuiKey; |
437 |
|
|
438 |
// render audio from all active voices |
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
439 |
{ |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
440 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
441 |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
// now render current voice |
442 |
while (iuiKey != end) { // iterate through all active keys |
itVoice->Render(Samples); |
443 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
if (itVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
444 |
++iuiKey; |
else { // voice reached end, is now inactive |
445 |
|
FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices |
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
|
|
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
|
|
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
|
|
// now render current voice |
|
|
itVoice->Render(Samples); |
|
|
if (itVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
|
|
else { // voice reached end, is now inactive |
|
|
FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices |
|
|
} |
|
446 |
} |
} |
447 |
} |
} |
448 |
} |
} |
449 |
|
} |
450 |
|
|
451 |
|
void Engine::RenderStolenVoices(uint Samples) { |
452 |
// now render all postponed voices from voice stealing |
RTList<Event>::Iterator itVoiceStealEvent = pVoiceStealingQueue->first(); |
453 |
{ |
RTList<Event>::Iterator end = pVoiceStealingQueue->end(); |
454 |
RTList<Event>::Iterator itVoiceStealEvent = pVoiceStealingQueue->first(); |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
455 |
RTList<Event>::Iterator end = pVoiceStealingQueue->end(); |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
456 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
Pool<Voice>::Iterator itNewVoice = |
457 |
Pool<Voice>::Iterator itNewVoice = |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false); |
458 |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false); |
if (itNewVoice) { |
459 |
if (itNewVoice) { |
itNewVoice->Render(Samples); |
460 |
for (; itNewVoice; itNewVoice = itNewVoice->itChildVoice) { |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
461 |
itNewVoice->Render(Samples); |
else { // voice reached end, is now inactive |
462 |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
FreeVoice(pEngineChannel, itNewVoice); // remove voice from the list of active voices |
|
else { // voice reached end, is now inactive |
|
|
FreeVoice(pEngineChannel, itNewVoice); // remove voice from the list of active voices |
|
|
} |
|
|
} |
|
463 |
} |
} |
|
else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n")); |
|
464 |
} |
} |
465 |
|
else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n")); |
466 |
} |
} |
467 |
// reset voice stealing for the new fragment |
} |
|
pVoiceStealingQueue->clear(); |
|
|
pEngineChannel->itLastStolenVoice = RTList<Voice>::Iterator(); |
|
|
pEngineChannel->iuiLastStolenKey = RTList<uint>::Iterator(); |
|
|
|
|
468 |
|
|
469 |
|
void Engine::PostProcess(EngineChannel* pEngineChannel) { |
470 |
// free all keys which have no active voices left |
// free all keys which have no active voices left |
471 |
{ |
{ |
472 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
488 |
#endif // DEVMODE |
#endif // DEVMODE |
489 |
} |
} |
490 |
} |
} |
491 |
|
|
492 |
|
// empty the engine channel's own event lists |
493 |
|
pEngineChannel->ClearEventLists(); |
494 |
} |
} |
495 |
|
|
496 |
/** |
/** |
560 |
// move note on event to the key's own event list |
// move note on event to the key's own event list |
561 |
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
562 |
|
|
563 |
// allocate and trigger a new voice for the key |
// allocate and trigger new voice(s) for the key |
564 |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, 0, false, true); |
{ |
565 |
|
// first, get total amount of required voices (dependant on amount of layers) |
566 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOnEventOnKeyList->Param.Note.Key); |
567 |
|
if (pRegion) { |
568 |
|
int voicesRequired = pRegion->Layers; |
569 |
|
// now launch the required amount of voices |
570 |
|
for (int i = 0; i < voicesRequired; i++) |
571 |
|
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true); |
572 |
|
} |
573 |
|
} |
574 |
|
|
575 |
pKey->RoundRobinIndex++; |
pKey->RoundRobinIndex++; |
576 |
} |
} |
599 |
|
|
600 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
601 |
if (pKey->ReleaseTrigger) { |
if (pKey->ReleaseTrigger) { |
602 |
LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, 0, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
// first, get total amount of required voices (dependant on amount of layers) |
603 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
604 |
|
if (pRegion) { |
605 |
|
int voicesRequired = pRegion->Layers; |
606 |
|
// now launch the required amount of voices |
607 |
|
for (int i = 0; i < voicesRequired; i++) |
608 |
|
LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
609 |
|
} |
610 |
pKey->ReleaseTrigger = false; |
pKey->ReleaseTrigger = false; |
611 |
} |
} |
612 |
} |
} |
620 |
*/ |
*/ |
621 |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
622 |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
623 |
itPitchbendEvent.moveToEndOf(pSynthesisEvents[Event::destination_vco]); |
itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]); |
624 |
} |
} |
625 |
|
|
626 |
/** |
/** |
679 |
} |
} |
680 |
} |
} |
681 |
else if (VoiceStealing) { |
else if (VoiceStealing) { |
682 |
// first, get total amount of required voices (dependant on amount of layers) |
|
683 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key); |
// try to steal one voice |
684 |
if (!pRegion) return Pool<Voice>::Iterator(); // nothing defined for this MIDI key, so no voice needed |
StealVoice(pEngineChannel, itNoteOnEvent); |
|
int voicesRequired = pRegion->Layers; |
|
|
|
|
|
// now steal the (remaining) amount of voices |
|
|
for (int i = iLayer; i < voicesRequired; i++) |
|
|
StealVoice(pEngineChannel, itNoteOnEvent); |
|
685 |
|
|
686 |
// put note-on event into voice-stealing queue, so it will be reprocessed after killed voice died |
// put note-on event into voice-stealing queue, so it will be reprocessed after killed voice died |
687 |
RTList<Event>::Iterator itStealEvent = pVoiceStealingQueue->allocAppend(); |
RTList<Event>::Iterator itStealEvent = pVoiceStealingQueue->allocAppend(); |
706 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
707 |
*/ |
*/ |
708 |
void Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
void Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
709 |
|
if (!VoiceTheftsLeft) { |
710 |
|
dmsg(1,("Max. voice thefts per audio fragment reached (you may raise MAX_AUDIO_VOICES).\n")); |
711 |
|
return; |
712 |
|
} |
713 |
if (!pEventPool->poolIsEmpty()) { |
if (!pEventPool->poolIsEmpty()) { |
714 |
|
|
715 |
RTList<uint>::Iterator iuiOldestKey; |
RTList<Voice>::Iterator itSelectedVoice; |
|
RTList<Voice>::Iterator itOldestVoice; |
|
716 |
|
|
717 |
// Select one voice for voice stealing |
// Select one voice for voice stealing |
718 |
switch (VOICE_STEAL_ALGORITHM) { |
switch (VOICE_STEAL_ALGORITHM) { |
721 |
// voice should be spawned, if there is no voice on that |
// voice should be spawned, if there is no voice on that |
722 |
// key, or no voice left to kill there, then procceed with |
// key, or no voice left to kill there, then procceed with |
723 |
// 'oldestkey' algorithm |
// 'oldestkey' algorithm |
724 |
case voice_steal_algo_keymask: { |
case voice_steal_algo_oldestvoiceonkey: { |
725 |
midi_key_info_t* pOldestKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
#if 0 // FIXME: broken |
726 |
if (pEngineChannel->itLastStolenVoice) { |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
727 |
itOldestVoice = pEngineChannel->itLastStolenVoice; |
if (this->itLastStolenVoice) { |
728 |
++itOldestVoice; |
itSelectedVoice = this->itLastStolenVoice; |
729 |
|
++itSelectedVoice; |
730 |
} |
} |
731 |
else { // no voice stolen in this audio fragment cycle yet |
else { // no voice stolen in this audio fragment cycle yet |
732 |
itOldestVoice = pOldestKey->pActiveVoices->first(); |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
733 |
} |
} |
734 |
if (itOldestVoice) { |
if (itSelectedVoice) { |
735 |
iuiOldestKey = pOldestKey->itSelf; |
iuiSelectedKey = pSelectedKey->itSelf; |
736 |
break; // selection succeeded |
break; // selection succeeded |
737 |
} |
} |
738 |
|
#endif |
739 |
} // no break - intentional ! |
} // no break - intentional ! |
740 |
|
|
741 |
// try to pick the oldest voice on the oldest active key |
// try to pick the oldest voice on the oldest active key |
742 |
// (caution: must stay after 'keymask' algorithm !) |
// (caution: must stay after 'oldestvoiceonkey' algorithm !) |
743 |
case voice_steal_algo_oldestkey: { |
case voice_steal_algo_oldestkey: { |
744 |
if (pEngineChannel->itLastStolenVoice) { |
if (this->itLastStolenVoice) { |
745 |
midi_key_info_t* pOldestKey = &pEngineChannel->pMIDIKeyInfo[*pEngineChannel->iuiLastStolenKey]; |
itSelectedVoice = this->itLastStolenVoice; |
746 |
itOldestVoice = pEngineChannel->itLastStolenVoice; |
++itSelectedVoice; |
747 |
++itOldestVoice; |
if (itSelectedVoice) break; // selection succeeded |
748 |
if (!itOldestVoice) { |
RTList<uint>::Iterator iuiSelectedKey = this->iuiLastStolenKey; |
749 |
iuiOldestKey = pEngineChannel->iuiLastStolenKey; |
++iuiSelectedKey; |
750 |
++iuiOldestKey; |
if (iuiSelectedKey) { |
751 |
if (iuiOldestKey) { |
this->iuiLastStolenKey = iuiSelectedKey; |
752 |
midi_key_info_t* pOldestKey = &pEngineChannel->pMIDIKeyInfo[*iuiOldestKey]; |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
753 |
itOldestVoice = pOldestKey->pActiveVoices->first(); |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
754 |
} |
break; // selection succeeded |
|
else { |
|
|
dmsg(1,("gig::Engine: Warning, too less voices, even for voice stealing! - Better recompile with higher MAX_AUDIO_VOICES.\n")); |
|
|
return; |
|
|
} |
|
755 |
} |
} |
|
else iuiOldestKey = pEngineChannel->iuiLastStolenKey; |
|
|
} |
|
|
else { // no voice stolen in this audio fragment cycle yet |
|
|
iuiOldestKey = pEngineChannel->pActiveKeys->first(); |
|
|
midi_key_info_t* pOldestKey = &pEngineChannel->pMIDIKeyInfo[*iuiOldestKey]; |
|
|
itOldestVoice = pOldestKey->pActiveVoices->first(); |
|
756 |
} |
} |
757 |
break; |
break; |
758 |
} |
} |
765 |
} |
} |
766 |
} |
} |
767 |
|
|
768 |
|
// steal oldest voice on the oldest key from this or any other engine channel |
769 |
|
if (!itSelectedVoice) { |
770 |
|
EngineChannel* pSelectedChannel = (pLastStolenChannel) ? pLastStolenChannel : pEngineChannel; |
771 |
|
int iChannelIndex = pSelectedChannel->iEngineIndexSelf; |
772 |
|
while (true) { |
773 |
|
RTList<uint>::Iterator iuiSelectedKey = pSelectedChannel->pActiveKeys->first(); |
774 |
|
if (iuiSelectedKey) { |
775 |
|
midi_key_info_t* pSelectedKey = &pSelectedChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
776 |
|
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
777 |
|
iuiLastStolenKey = iuiSelectedKey; |
778 |
|
pLastStolenChannel = pSelectedChannel; |
779 |
|
break; // selection succeeded |
780 |
|
} |
781 |
|
iChannelIndex = (iChannelIndex + 1) % engineChannels.size(); |
782 |
|
pSelectedChannel = engineChannels[iChannelIndex]; |
783 |
|
} |
784 |
|
} |
785 |
|
|
786 |
//FIXME: can be removed, just a sanity check for debugging |
//FIXME: can be removed, just a sanity check for debugging |
787 |
if (!itOldestVoice->IsActive()) dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); |
if (!itSelectedVoice->IsActive()) dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); |
788 |
|
|
789 |
// now kill the selected voice |
// now kill the selected voice |
790 |
itOldestVoice->Kill(itNoteOnEvent); |
itSelectedVoice->Kill(itNoteOnEvent); |
791 |
// remember which voice on which key we stole, so we can simply proceed for the next voice stealing |
|
792 |
pEngineChannel->itLastStolenVoice = itOldestVoice; |
// remember which voice we stole, so we can simply proceed for the next voice stealing |
793 |
pEngineChannel->iuiLastStolenKey = iuiOldestKey; |
itLastStolenVoice = itSelectedVoice; |
794 |
|
|
795 |
|
--VoiceTheftsLeft; |
796 |
} |
} |
797 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
798 |
} |
} |
913 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
914 |
|
|
915 |
// move event from the unsorted event list to the control change event list |
// move event from the unsorted event list to the control change event list |
916 |
itControlChangeEvent.moveToEndOf(pCCEvents); |
itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents); |
917 |
} |
} |
918 |
|
|
919 |
/** |
/** |
1051 |
} |
} |
1052 |
|
|
1053 |
String Engine::Version() { |
String Engine::Version() { |
1054 |
String s = "$Revision: 1.30 $"; |
String s = "$Revision: 1.31 $"; |
1055 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
1056 |
} |
} |
1057 |
|
|