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, 2006 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* 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 * |
29 |
|
|
30 |
#include "Engine.h" |
#include "Engine.h" |
31 |
|
|
|
#if defined(__APPLE__) |
|
|
# include <stdlib.h> |
|
|
#else |
|
|
# include <malloc.h> |
|
|
#endif |
|
|
|
|
32 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
33 |
|
|
34 |
InstrumentResourceManager Engine::instruments; |
InstrumentResourceManager Engine::instruments; |
108 |
} |
} |
109 |
pVoicePool->clear(); |
pVoicePool->clear(); |
110 |
|
|
|
pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected |
|
|
pBasicFilterParameters = NULL; |
|
|
pMainFilterParameters = NULL; |
|
|
|
|
111 |
ResetInternal(); |
ResetInternal(); |
112 |
ResetScaleTuning(); |
ResetScaleTuning(); |
113 |
} |
} |
129 |
delete pVoicePool; |
delete pVoicePool; |
130 |
} |
} |
131 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
|
if (pMainFilterParameters) delete[] pMainFilterParameters; |
|
|
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
|
|
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
|
132 |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
133 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
134 |
EngineFactory::Destroy(this); |
EngineFactory::Destroy(this); |
190 |
|
|
191 |
// delete all input events |
// delete all input events |
192 |
pEventQueue->init(); |
pEventQueue->init(); |
193 |
|
pSysexBuffer->init(); |
194 |
} |
} |
195 |
|
|
196 |
/** |
/** |
228 |
|
|
229 |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
230 |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; |
231 |
if (MaxFadeOutPos < 0) |
if (MaxFadeOutPos < 0) { |
232 |
throw LinuxSamplerException("CONFIG_EG_MIN_RELEASE_TIME too big for current audio fragment size / sampling rate!"); |
std::cerr << "gig::Engine: WARNING, CONFIG_EG_MIN_RELEASE_TIME " |
233 |
|
<< "too big for current audio fragment size & sampling rate! " |
234 |
|
<< "May lead to click sounds if voice stealing chimes in!\n" << std::flush; |
235 |
|
// force volume ramp downs at the beginning of each fragment |
236 |
|
MaxFadeOutPos = 0; |
237 |
|
// lower minimum release time |
238 |
|
const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate; |
239 |
|
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
240 |
|
iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate); |
241 |
|
} |
242 |
|
pVoicePool->clear(); |
243 |
|
} |
244 |
|
|
245 |
// (re)create disk thread |
// (re)create disk thread |
246 |
if (this->pDiskThread) { |
if (this->pDiskThread) { |
265 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
266 |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
267 |
|
|
|
// (re)allocate synthesis parameter matrix |
|
|
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
|
|
|
|
|
#if defined(__APPLE__) |
|
|
pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()); |
|
|
#else |
|
|
pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle())); |
|
|
#endif |
|
|
for (int dst = 1; dst < Event::destination_count; dst++) |
|
|
pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle(); |
|
|
|
|
|
// (re)allocate biquad filter parameter sequence |
|
|
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
|
|
if (pMainFilterParameters) delete[] pMainFilterParameters; |
|
|
pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()]; |
|
|
pMainFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()]; |
|
|
|
|
268 |
dmsg(1,("Starting disk thread...")); |
dmsg(1,("Starting disk thread...")); |
269 |
pDiskThread->StartThread(); |
pDiskThread->StartThread(); |
270 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
463 |
* this audio fragment cycle |
* this audio fragment cycle |
464 |
*/ |
*/ |
465 |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
466 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
467 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
468 |
|
#endif |
469 |
|
|
470 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
471 |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
472 |
while (iuiKey != end) { // iterate through all active keys |
while (iuiKey != end) { // iterate through all active keys |
505 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
506 |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
507 |
Pool<Voice>::Iterator itNewVoice = |
Pool<Voice>::Iterator itNewVoice = |
508 |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false); |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false); |
509 |
if (itNewVoice) { |
if (itNewVoice) { |
510 |
itNewVoice->Render(Samples); |
itNewVoice->Render(Samples); |
511 |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
595 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
596 |
*/ |
*/ |
597 |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
598 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
599 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
600 |
|
#endif |
601 |
|
|
602 |
const int key = itNoteOnEvent->Param.Note.Key; |
const int key = itNoteOnEvent->Param.Note.Key; |
603 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
604 |
|
|
605 |
|
// move note on event to the key's own event list |
606 |
|
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
607 |
|
|
608 |
|
// if Solo Mode then kill all already active voices |
609 |
|
if (pEngineChannel->SoloMode) { |
610 |
|
Pool<uint>::Iterator itYoungestKey = pEngineChannel->pActiveKeys->last(); |
611 |
|
if (itYoungestKey) { |
612 |
|
const int iYoungestKey = *itYoungestKey; |
613 |
|
const midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[iYoungestKey]; |
614 |
|
if (pOtherKey->Active) { |
615 |
|
// get final portamento position of currently active voice |
616 |
|
if (pEngineChannel->PortamentoMode) { |
617 |
|
RTList<Voice>::Iterator itVoice = pOtherKey->pActiveVoices->last(); |
618 |
|
if (itVoice) itVoice->UpdatePortamentoPos(itNoteOnEventOnKeyList); |
619 |
|
} |
620 |
|
// kill all voices on the (other) key |
621 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
622 |
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
623 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
624 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) |
625 |
|
itVoiceToBeKilled->Kill(itNoteOnEventOnKeyList); |
626 |
|
} |
627 |
|
} |
628 |
|
} |
629 |
|
// set this key as 'currently active solo key' |
630 |
|
pEngineChannel->SoloKey = key; |
631 |
|
} |
632 |
|
|
633 |
// Change key dimension value if key is in keyswitching area |
// Change key dimension value if key is in keyswitching area |
634 |
{ |
{ |
638 |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
639 |
} |
} |
640 |
|
|
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
|
|
|
|
641 |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
642 |
pKey->Velocity = itNoteOnEvent->Param.Note.Velocity; |
pKey->Velocity = itNoteOnEventOnKeyList->Param.Note.Velocity; |
643 |
pKey->NoteOnTime = FrameTime + itNoteOnEvent->FragmentPos(); // will be used to calculate note length |
pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length |
644 |
|
|
645 |
// cancel release process of voices on this key if needed |
// cancel release process of voices on this key if needed |
646 |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
647 |
RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend(); |
648 |
if (itCancelReleaseEvent) { |
if (itCancelReleaseEvent) { |
649 |
*itCancelReleaseEvent = *itNoteOnEvent; // copy event |
*itCancelReleaseEvent = *itNoteOnEventOnKeyList; // copy event |
650 |
itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type |
itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type |
651 |
} |
} |
652 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
653 |
} |
} |
654 |
|
|
|
// move note on event to the key's own event list |
|
|
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
|
|
|
|
655 |
// allocate and trigger new voice(s) for the key |
// allocate and trigger new voice(s) for the key |
656 |
{ |
{ |
657 |
// first, get total amount of required voices (dependant on amount of layers) |
// first, get total amount of required voices (dependant on amount of layers) |
660 |
int voicesRequired = pRegion->Layers; |
int voicesRequired = pRegion->Layers; |
661 |
// now launch the required amount of voices |
// now launch the required amount of voices |
662 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
663 |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true); |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true, true); |
664 |
} |
} |
665 |
} |
} |
666 |
|
|
668 |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
669 |
pKey->pEvents->free(itNoteOnEventOnKeyList); |
pKey->pEvents->free(itNoteOnEventOnKeyList); |
670 |
|
|
671 |
|
if (!pEngineChannel->SoloMode || pEngineChannel->PortamentoPos < 0.0f) pEngineChannel->PortamentoPos = (float) key; |
672 |
pKey->RoundRobinIndex++; |
pKey->RoundRobinIndex++; |
673 |
} |
} |
674 |
|
|
682 |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
683 |
*/ |
*/ |
684 |
void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
685 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key]; |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
686 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
687 |
|
#endif |
688 |
|
|
689 |
|
const int iKey = itNoteOffEvent->Param.Note.Key; |
690 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey]; |
691 |
pKey->KeyPressed = false; // the MIDI key was now released |
pKey->KeyPressed = false; // the MIDI key was now released |
692 |
|
|
693 |
// release voices on this key if needed |
// move event to the key's own event list |
694 |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
695 |
itNoteOffEvent->Type = Event::type_release; // transform event type |
|
696 |
|
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
697 |
|
|
698 |
|
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
699 |
|
if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P |
700 |
|
bool bOtherKeysPressed = false; |
701 |
|
if (iKey == pEngineChannel->SoloKey) { |
702 |
|
pEngineChannel->SoloKey = -1; |
703 |
|
// if there's still a key pressed down, respawn a voice (group) on the highest key |
704 |
|
for (int i = 127; i > 0; i--) { |
705 |
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[i]; |
706 |
|
if (pOtherKey->KeyPressed) { |
707 |
|
bOtherKeysPressed = true; |
708 |
|
// make the other key the new 'currently active solo key' |
709 |
|
pEngineChannel->SoloKey = i; |
710 |
|
// get final portamento position of currently active voice |
711 |
|
if (pEngineChannel->PortamentoMode) { |
712 |
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
713 |
|
if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList); |
714 |
|
} |
715 |
|
// create a pseudo note on event |
716 |
|
RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend(); |
717 |
|
if (itPseudoNoteOnEvent) { |
718 |
|
// copy event |
719 |
|
*itPseudoNoteOnEvent = *itNoteOffEventOnKeyList; |
720 |
|
// transform event to a note on event |
721 |
|
itPseudoNoteOnEvent->Type = Event::type_note_on; |
722 |
|
itPseudoNoteOnEvent->Param.Note.Key = i; |
723 |
|
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
724 |
|
// allocate and trigger new voice(s) for the other key |
725 |
|
{ |
726 |
|
// first, get total amount of required voices (dependant on amount of layers) |
727 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(i); |
728 |
|
if (pRegion) { |
729 |
|
int voicesRequired = pRegion->Layers; |
730 |
|
// now launch the required amount of voices |
731 |
|
for (int iLayer = 0; iLayer < voicesRequired; iLayer++) |
732 |
|
LaunchVoice(pEngineChannel, itPseudoNoteOnEvent, iLayer, false, true, false); |
733 |
|
} |
734 |
|
} |
735 |
|
// if neither a voice was spawned or postponed then remove note on event from key again |
736 |
|
if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued) |
737 |
|
pOtherKey->pEvents->free(itPseudoNoteOnEvent); |
738 |
|
|
739 |
|
} else dmsg(1,("Could not respawn voice, no free event left\n")); |
740 |
|
break; // done |
741 |
|
} |
742 |
|
} |
743 |
|
} |
744 |
|
if (bOtherKeysPressed) { |
745 |
|
if (pKey->Active) { // kill all voices on this key |
746 |
|
bShouldRelease = false; // no need to release, as we kill it here |
747 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pKey->pActiveVoices->first(); |
748 |
|
RTList<Voice>::Iterator end = pKey->pActiveVoices->end(); |
749 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
750 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) |
751 |
|
itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList); |
752 |
|
} |
753 |
|
} |
754 |
|
} else pEngineChannel->PortamentoPos = -1.0f; |
755 |
|
} |
756 |
|
|
757 |
// move event to the key's own event list |
// if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed |
758 |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
if (bShouldRelease) { |
759 |
|
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
760 |
|
|
761 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
762 |
if (pKey->ReleaseTrigger) { |
if (pKey->ReleaseTrigger) { |
770 |
|
|
771 |
// now launch the required amount of voices |
// now launch the required amount of voices |
772 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
773 |
LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
774 |
} |
} |
775 |
pKey->ReleaseTrigger = false; |
pKey->ReleaseTrigger = false; |
776 |
} |
} |
|
|
|
|
// if neither a voice was spawned or postponed then remove note off event from key again |
|
|
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
|
|
pKey->pEvents->free(itNoteOffEventOnKeyList); |
|
777 |
} |
} |
778 |
|
|
779 |
|
// if neither a voice was spawned or postponed on this key then remove note off event from key again |
780 |
|
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
781 |
|
pKey->pEvents->free(itNoteOffEventOnKeyList); |
782 |
} |
} |
783 |
|
|
784 |
/** |
/** |
785 |
* Moves pitchbend event from the general (input) event list to the pitch |
* Moves pitchbend event from the general (input) event list to the engine |
786 |
* event list. |
* channel's event list. It will actually processed later by the |
787 |
|
* respective voice. |
788 |
* |
* |
789 |
* @param pEngineChannel - engine channel on which this event occured on |
* @param pEngineChannel - engine channel on which this event occured on |
790 |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
791 |
*/ |
*/ |
792 |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
793 |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
|
itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]); |
|
794 |
} |
} |
795 |
|
|
796 |
/** |
/** |
807 |
* @param VoiceStealing - if voice stealing should be performed |
* @param VoiceStealing - if voice stealing should be performed |
808 |
* when there is no free voice |
* when there is no free voice |
809 |
* (optional, default = true) |
* (optional, default = true) |
810 |
|
* @param HandleKeyGroupConflicts - if voices should be killed due to a |
811 |
|
* key group conflict |
812 |
* @returns pointer to new voice or NULL if there was no free voice or |
* @returns pointer to new voice or NULL if there was no free voice or |
813 |
* if the voice wasn't triggered (for example when no region is |
* if the voice wasn't triggered (for example when no region is |
814 |
* defined for the given key). |
* defined for the given key). |
815 |
*/ |
*/ |
816 |
Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) { |
Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing, bool HandleKeyGroupConflicts) { |
817 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
int MIDIKey = itNoteOnEvent->Param.Note.Key; |
818 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[MIDIKey]; |
819 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(MIDIKey); |
820 |
|
|
821 |
|
// if nothing defined for this key |
822 |
|
if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do |
823 |
|
|
824 |
|
// only mark the first voice of a layered voice (group) to be in a |
825 |
|
// key group, so the layered voices won't kill each other |
826 |
|
int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0; |
827 |
|
|
828 |
|
// handle key group (a.k.a. exclusive group) conflicts |
829 |
|
if (HandleKeyGroupConflicts) { |
830 |
|
if (iKeyGroup) { // if this voice / key belongs to a key group |
831 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup]; |
832 |
|
if (*ppKeyGroup) { // if there's already an active key in that key group |
833 |
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup]; |
834 |
|
// kill all voices on the (other) key |
835 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
836 |
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
837 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
838 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) { |
839 |
|
itVoiceToBeKilled->Kill(itNoteOnEvent); |
840 |
|
--VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict |
841 |
|
} |
842 |
|
} |
843 |
|
} |
844 |
|
} |
845 |
|
} |
846 |
|
|
847 |
|
Voice::type_t VoiceType = Voice::type_normal; |
848 |
|
|
849 |
|
// get current dimension values to select the right dimension region |
850 |
|
//TODO: for stolen voices this dimension region selection block is processed twice, this should be changed |
851 |
|
//FIXME: controller values for selecting the dimension region here are currently not sample accurate |
852 |
|
uint DimValues[8] = { 0 }; |
853 |
|
for (int i = pRegion->Dimensions - 1; i >= 0; i--) { |
854 |
|
switch (pRegion->pDimensionDefinitions[i].dimension) { |
855 |
|
case ::gig::dimension_samplechannel: |
856 |
|
DimValues[i] = 0; //TODO: we currently ignore this dimension |
857 |
|
break; |
858 |
|
case ::gig::dimension_layer: |
859 |
|
DimValues[i] = iLayer; |
860 |
|
break; |
861 |
|
case ::gig::dimension_velocity: |
862 |
|
DimValues[i] = itNoteOnEvent->Param.Note.Velocity; |
863 |
|
break; |
864 |
|
case ::gig::dimension_channelaftertouch: |
865 |
|
DimValues[i] = 0; //TODO: we currently ignore this dimension |
866 |
|
break; |
867 |
|
case ::gig::dimension_releasetrigger: |
868 |
|
VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
869 |
|
DimValues[i] = (uint) ReleaseTriggerVoice; |
870 |
|
break; |
871 |
|
case ::gig::dimension_keyboard: |
872 |
|
DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension; |
873 |
|
break; |
874 |
|
case ::gig::dimension_roundrobin: |
875 |
|
DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on |
876 |
|
break; |
877 |
|
case ::gig::dimension_random: |
878 |
|
RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator |
879 |
|
DimValues[i] = (uint) RandomSeed >> (32 - pRegion->pDimensionDefinitions[i].bits); // highest bits are most random |
880 |
|
break; |
881 |
|
case ::gig::dimension_modwheel: |
882 |
|
DimValues[i] = pEngineChannel->ControllerTable[1]; |
883 |
|
break; |
884 |
|
case ::gig::dimension_breath: |
885 |
|
DimValues[i] = pEngineChannel->ControllerTable[2]; |
886 |
|
break; |
887 |
|
case ::gig::dimension_foot: |
888 |
|
DimValues[i] = pEngineChannel->ControllerTable[4]; |
889 |
|
break; |
890 |
|
case ::gig::dimension_portamentotime: |
891 |
|
DimValues[i] = pEngineChannel->ControllerTable[5]; |
892 |
|
break; |
893 |
|
case ::gig::dimension_effect1: |
894 |
|
DimValues[i] = pEngineChannel->ControllerTable[12]; |
895 |
|
break; |
896 |
|
case ::gig::dimension_effect2: |
897 |
|
DimValues[i] = pEngineChannel->ControllerTable[13]; |
898 |
|
break; |
899 |
|
case ::gig::dimension_genpurpose1: |
900 |
|
DimValues[i] = pEngineChannel->ControllerTable[16]; |
901 |
|
break; |
902 |
|
case ::gig::dimension_genpurpose2: |
903 |
|
DimValues[i] = pEngineChannel->ControllerTable[17]; |
904 |
|
break; |
905 |
|
case ::gig::dimension_genpurpose3: |
906 |
|
DimValues[i] = pEngineChannel->ControllerTable[18]; |
907 |
|
break; |
908 |
|
case ::gig::dimension_genpurpose4: |
909 |
|
DimValues[i] = pEngineChannel->ControllerTable[19]; |
910 |
|
break; |
911 |
|
case ::gig::dimension_sustainpedal: |
912 |
|
DimValues[i] = pEngineChannel->ControllerTable[64]; |
913 |
|
break; |
914 |
|
case ::gig::dimension_portamento: |
915 |
|
DimValues[i] = pEngineChannel->ControllerTable[65]; |
916 |
|
break; |
917 |
|
case ::gig::dimension_sostenutopedal: |
918 |
|
DimValues[i] = pEngineChannel->ControllerTable[66]; |
919 |
|
break; |
920 |
|
case ::gig::dimension_softpedal: |
921 |
|
DimValues[i] = pEngineChannel->ControllerTable[67]; |
922 |
|
break; |
923 |
|
case ::gig::dimension_genpurpose5: |
924 |
|
DimValues[i] = pEngineChannel->ControllerTable[80]; |
925 |
|
break; |
926 |
|
case ::gig::dimension_genpurpose6: |
927 |
|
DimValues[i] = pEngineChannel->ControllerTable[81]; |
928 |
|
break; |
929 |
|
case ::gig::dimension_genpurpose7: |
930 |
|
DimValues[i] = pEngineChannel->ControllerTable[82]; |
931 |
|
break; |
932 |
|
case ::gig::dimension_genpurpose8: |
933 |
|
DimValues[i] = pEngineChannel->ControllerTable[83]; |
934 |
|
break; |
935 |
|
case ::gig::dimension_effect1depth: |
936 |
|
DimValues[i] = pEngineChannel->ControllerTable[91]; |
937 |
|
break; |
938 |
|
case ::gig::dimension_effect2depth: |
939 |
|
DimValues[i] = pEngineChannel->ControllerTable[92]; |
940 |
|
break; |
941 |
|
case ::gig::dimension_effect3depth: |
942 |
|
DimValues[i] = pEngineChannel->ControllerTable[93]; |
943 |
|
break; |
944 |
|
case ::gig::dimension_effect4depth: |
945 |
|
DimValues[i] = pEngineChannel->ControllerTable[94]; |
946 |
|
break; |
947 |
|
case ::gig::dimension_effect5depth: |
948 |
|
DimValues[i] = pEngineChannel->ControllerTable[95]; |
949 |
|
break; |
950 |
|
case ::gig::dimension_none: |
951 |
|
std::cerr << "gig::Engine::LaunchVoice() Error: dimension=none\n" << std::flush; |
952 |
|
break; |
953 |
|
default: |
954 |
|
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
955 |
|
} |
956 |
|
} |
957 |
|
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
958 |
|
|
959 |
|
// no need to continue if sample is silent |
960 |
|
if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator(); |
961 |
|
|
962 |
// allocate a new voice for the key |
// allocate a new voice for the key |
963 |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
964 |
if (itNewVoice) { |
if (itNewVoice) { |
965 |
// launch the new voice |
// launch the new voice |
966 |
if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pEngineChannel->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) { |
if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pDimRgn, VoiceType, iKeyGroup) < 0) { |
967 |
dmsg(4,("Voice not triggered\n")); |
dmsg(4,("Voice not triggered\n")); |
968 |
pKey->pActiveVoices->free(itNewVoice); |
pKey->pActiveVoices->free(itNewVoice); |
969 |
} |
} |
970 |
else { // on success |
else { // on success |
971 |
--VoiceSpawnsLeft; |
--VoiceSpawnsLeft; |
|
uint** ppKeyGroup = NULL; |
|
|
if (itNewVoice->KeyGroup) { // if this voice / key belongs to a key group |
|
|
ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; |
|
|
if (*ppKeyGroup) { // if there's already an active key in that key group |
|
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup]; |
|
|
// kill all voices on the (other) key |
|
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
|
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
|
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
|
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) { |
|
|
itVoiceToBeKilled->Kill(itNoteOnEvent); |
|
|
--VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
972 |
if (!pKey->Active) { // mark as active key |
if (!pKey->Active) { // mark as active key |
973 |
pKey->Active = true; |
pKey->Active = true; |
974 |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
975 |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
976 |
} |
} |
977 |
if (itNewVoice->KeyGroup) { |
if (itNewVoice->KeyGroup) { |
978 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; |
979 |
*ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group |
*ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group |
980 |
} |
} |
981 |
if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) |
if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) |
1227 |
// update controller value in the engine channel's controller table |
// update controller value in the engine channel's controller table |
1228 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
1229 |
|
|
1230 |
// move event from the unsorted event list to the control change event list |
switch (itControlChangeEvent->Param.CC.Controller) { |
1231 |
Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents); |
case 5: { // portamento time |
1232 |
|
pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
1233 |
switch (itControlChangeEventOnCCList->Param.CC.Controller) { |
break; |
1234 |
|
} |
1235 |
case 7: { // volume |
case 7: { // volume |
1236 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1237 |
pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f; |
pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] * CONFIG_GLOBAL_ATTENUATION; |
1238 |
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
1239 |
break; |
break; |
1240 |
} |
} |
1241 |
case 10: { // panpot |
case 10: { // panpot |
1242 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1243 |
const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64; |
pEngineChannel->GlobalPanLeft = PanCurve[128 - itControlChangeEvent->Param.CC.Value]; |
1244 |
pEngineChannel->GlobalPanLeft = 1.0f - float(RTMath::Max(pan, 0)) / 63.0f; |
pEngineChannel->GlobalPanRight = PanCurve[itControlChangeEvent->Param.CC.Value]; |
|
pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f; |
|
1245 |
break; |
break; |
1246 |
} |
} |
1247 |
case 64: { // sustain |
case 64: { // sustain |
1248 |
if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) { |
1249 |
dmsg(4,("PEDAL DOWN\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n")); |
1250 |
pEngineChannel->SustainPedal = true; |
pEngineChannel->SustainPedal = true; |
1251 |
|
|
1252 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1253 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1254 |
|
#endif |
1255 |
|
|
1256 |
// cancel release process of voices if necessary |
// cancel release process of voices if necessary |
1257 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1258 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1260 |
if (!pKey->KeyPressed) { |
if (!pKey->KeyPressed) { |
1261 |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1262 |
if (itNewEvent) { |
if (itNewEvent) { |
1263 |
*itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list |
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1264 |
itNewEvent->Type = Event::type_cancel_release; // transform event type |
itNewEvent->Type = Event::type_cancel_release; // transform event type |
1265 |
} |
} |
1266 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
1267 |
} |
} |
1268 |
} |
} |
1269 |
} |
} |
1270 |
if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) { |
1271 |
dmsg(4,("PEDAL UP\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL UP\n")); |
1272 |
pEngineChannel->SustainPedal = false; |
pEngineChannel->SustainPedal = false; |
1273 |
|
|
1274 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1275 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1276 |
|
#endif |
1277 |
|
|
1278 |
// release voices if their respective key is not pressed |
// release voices if their respective key is not pressed |
1279 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1280 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1281 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
1282 |
if (!pKey->KeyPressed) { |
if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) { |
1283 |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1284 |
if (itNewEvent) { |
if (itNewEvent) { |
1285 |
*itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list |
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1286 |
|
itNewEvent->Type = Event::type_release; // transform event type |
1287 |
|
} |
1288 |
|
else dmsg(1,("Event pool emtpy!\n")); |
1289 |
|
} |
1290 |
|
} |
1291 |
|
} |
1292 |
|
break; |
1293 |
|
} |
1294 |
|
case 65: { // portamento on / off |
1295 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1296 |
|
pEngineChannel->PortamentoMode = itControlChangeEvent->Param.CC.Value >= 64; |
1297 |
|
break; |
1298 |
|
} |
1299 |
|
case 66: { // sostenuto |
1300 |
|
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) { |
1301 |
|
dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n")); |
1302 |
|
pEngineChannel->SostenutoPedal = true; |
1303 |
|
|
1304 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1305 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1306 |
|
#endif |
1307 |
|
|
1308 |
|
SostenutoKeyCount = 0; |
1309 |
|
// Remeber the pressed keys |
1310 |
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1311 |
|
for (; iuiKey; ++iuiKey) { |
1312 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
1313 |
|
if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey; |
1314 |
|
} |
1315 |
|
} |
1316 |
|
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) { |
1317 |
|
dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n")); |
1318 |
|
pEngineChannel->SostenutoPedal = false; |
1319 |
|
|
1320 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1321 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1322 |
|
#endif |
1323 |
|
|
1324 |
|
// release voices if the damper pedal is up and their respective key is not pressed |
1325 |
|
for (int i = 0; i < SostenutoKeyCount; i++) { |
1326 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]]; |
1327 |
|
if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) { |
1328 |
|
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1329 |
|
if (itNewEvent) { |
1330 |
|
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1331 |
itNewEvent->Type = Event::type_release; // transform event type |
itNewEvent->Type = Event::type_release; // transform event type |
1332 |
} |
} |
1333 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
1341 |
// Channel Mode Messages |
// Channel Mode Messages |
1342 |
|
|
1343 |
case 120: { // all sound off |
case 120: { // all sound off |
1344 |
KillAllVoices(pEngineChannel, itControlChangeEventOnCCList); |
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1345 |
break; |
break; |
1346 |
} |
} |
1347 |
case 121: { // reset all controllers |
case 121: { // reset all controllers |
1349 |
break; |
break; |
1350 |
} |
} |
1351 |
case 123: { // all notes off |
case 123: { // all notes off |
1352 |
ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList); |
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
1353 |
|
break; |
1354 |
|
} |
1355 |
|
case 126: { // mono mode on |
1356 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1357 |
|
pEngineChannel->SoloMode = true; |
1358 |
|
break; |
1359 |
|
} |
1360 |
|
case 127: { // poly mode on |
1361 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1362 |
|
pEngineChannel->SoloMode = false; |
1363 |
break; |
break; |
1364 |
} |
} |
1365 |
} |
} |
1503 |
} |
} |
1504 |
|
|
1505 |
/** |
/** |
1506 |
* Initialize the parameter sequence for the modulation destination given by |
* Determines whether the specified voice should be released. |
1507 |
* by 'dst' with the constant value given by val. |
* |
1508 |
*/ |
* @param pEngineChannel - The engine channel on which the voice should be checked |
1509 |
void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) { |
* @param Key - The key number |
1510 |
int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle(); |
* @returns true if the specified should be released, false otherwise. |
1511 |
float* m = &pSynthesisParameters[dst][0]; |
*/ |
1512 |
for (int i = 0; i < maxsamples; i += 4) { |
bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) { |
1513 |
m[i] = val; |
if (pEngineChannel->SustainPedal) return false; |
1514 |
m[i+1] = val; |
|
1515 |
m[i+2] = val; |
if (pEngineChannel->SostenutoPedal) { |
1516 |
m[i+3] = val; |
for (int i = 0; i < SostenutoKeyCount; i++) |
1517 |
|
if (Key == SostenutoKeys[i]) return false; |
1518 |
} |
} |
1519 |
|
|
1520 |
|
return true; |
1521 |
} |
} |
1522 |
|
|
1523 |
uint Engine::VoiceCount() { |
uint Engine::VoiceCount() { |
1557 |
} |
} |
1558 |
|
|
1559 |
String Engine::Version() { |
String Engine::Version() { |
1560 |
String s = "$Revision: 1.45 $"; |
String s = "$Revision: 1.59 $"; |
1561 |
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 |
1562 |
} |
} |
1563 |
|
|
1564 |
|
// static constant initializers |
1565 |
|
const float* Engine::VolumeCurve(InitVolumeCurve()); |
1566 |
|
const float* Engine::PanCurve(InitPanCurve()); |
1567 |
|
const float* Engine::CrossfadeCurve(InitCrossfadeCurve()); |
1568 |
|
|
1569 |
|
float* Engine::InitVolumeCurve() { |
1570 |
|
// line-segment approximation |
1571 |
|
const float segments[] = { |
1572 |
|
0, 0, 2, 0.0046, 16, 0.016, 31, 0.051, 45, 0.115, 54.5, 0.2, |
1573 |
|
64.5, 0.39, 74, 0.74, 92, 1.03, 114, 1.94, 119.2, 2.2, 127, 2.2 |
1574 |
|
}; |
1575 |
|
return InitCurve(segments); |
1576 |
|
} |
1577 |
|
|
1578 |
|
float* Engine::InitPanCurve() { |
1579 |
|
// line-segment approximation |
1580 |
|
const float segments[] = { |
1581 |
|
0, 0, 1, 0, |
1582 |
|
2, 0.05, 31.5, 0.7, 51, 0.851, 74.5, 1.12, |
1583 |
|
127, 1.41, 128, 1.41 |
1584 |
|
}; |
1585 |
|
return InitCurve(segments, 129); |
1586 |
|
} |
1587 |
|
|
1588 |
|
float* Engine::InitCrossfadeCurve() { |
1589 |
|
// line-segment approximation |
1590 |
|
const float segments[] = { |
1591 |
|
0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1 |
1592 |
|
}; |
1593 |
|
return InitCurve(segments); |
1594 |
|
} |
1595 |
|
|
1596 |
|
float* Engine::InitCurve(const float* segments, int size) { |
1597 |
|
float* y = new float[size]; |
1598 |
|
for (int x = 0 ; x < size ; x++) { |
1599 |
|
if (x > segments[2]) segments += 2; |
1600 |
|
y[x] = segments[1] + (x - segments[0]) * |
1601 |
|
(segments[3] - segments[1]) / (segments[2] - segments[0]); |
1602 |
|
} |
1603 |
|
return y; |
1604 |
|
} |
1605 |
|
|
1606 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |