240 |
|
|
241 |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
242 |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; |
243 |
if (MaxFadeOutPos < 0) |
if (MaxFadeOutPos < 0) { |
244 |
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 " |
245 |
|
<< "too big for current audio fragment size & sampling rate! " |
246 |
|
<< "May lead to click sounds if voice stealing chimes in!\n" << std::flush; |
247 |
|
// force volume ramp downs at the beginning of each fragment |
248 |
|
MaxFadeOutPos = 0; |
249 |
|
// lower minimum release time |
250 |
|
const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate; |
251 |
|
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
252 |
|
iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate); |
253 |
|
} |
254 |
|
pVoicePool->clear(); |
255 |
|
} |
256 |
|
|
257 |
// (re)create disk thread |
// (re)create disk thread |
258 |
if (this->pDiskThread) { |
if (this->pDiskThread) { |
371 |
// 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) |
372 |
pEventGenerator->UpdateFragmentTime(Samples); |
pEventGenerator->UpdateFragmentTime(Samples); |
373 |
|
|
374 |
|
// We only allow a maximum of CONFIG_MAX_VOICES voices to be spawned |
375 |
|
// in each audio fragment. All subsequent request for spawning new |
376 |
|
// voices in the same audio fragment will be ignored. |
377 |
|
VoiceSpawnsLeft = CONFIG_MAX_VOICES; |
378 |
|
|
379 |
// 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 |
380 |
// (these are usually just SysEx messages) |
// (these are usually just SysEx messages) |
381 |
ImportEvents(Samples); |
ImportEvents(Samples); |
394 |
} |
} |
395 |
} |
} |
396 |
|
|
|
// We only allow a maximum of CONFIG_MAX_VOICES voices to be stolen |
|
|
// in each audio fragment. All subsequent request for spawning new |
|
|
// voices in the same audio fragment will be ignored. |
|
|
VoiceTheftsLeft = CONFIG_MAX_VOICES; |
|
|
|
|
397 |
// reset internal voice counter (just for statistic of active voices) |
// reset internal voice counter (just for statistic of active voices) |
398 |
ActiveVoiceCountTemp = 0; |
ActiveVoiceCountTemp = 0; |
399 |
|
|
|
|
|
400 |
// handle events on all engine channels |
// handle events on all engine channels |
401 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
402 |
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
492 |
* this audio fragment cycle |
* this audio fragment cycle |
493 |
*/ |
*/ |
494 |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
495 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
496 |
|
|
497 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
498 |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
499 |
while (iuiKey != end) { // iterate through all active keys |
while (iuiKey != end) { // iterate through all active keys |
532 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
533 |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
534 |
Pool<Voice>::Iterator itNewVoice = |
Pool<Voice>::Iterator itNewVoice = |
535 |
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); |
536 |
if (itNewVoice) { |
if (itNewVoice) { |
537 |
itNewVoice->Render(Samples); |
itNewVoice->Render(Samples); |
538 |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
622 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
623 |
*/ |
*/ |
624 |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
625 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
626 |
|
|
627 |
const int key = itNoteOnEvent->Param.Note.Key; |
const int key = itNoteOnEvent->Param.Note.Key; |
628 |
|
|
661 |
int voicesRequired = pRegion->Layers; |
int voicesRequired = pRegion->Layers; |
662 |
// now launch the required amount of voices |
// now launch the required amount of voices |
663 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
664 |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true); |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true, true); |
665 |
} |
} |
666 |
} |
} |
667 |
|
|
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 (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
686 |
|
|
687 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key]; |
688 |
pKey->KeyPressed = false; // the MIDI key was now released |
pKey->KeyPressed = false; // the MIDI key was now released |
689 |
|
|
690 |
// release voices on this key if needed |
// release voices on this key if needed |
706 |
|
|
707 |
// now launch the required amount of voices |
// now launch the required amount of voices |
708 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
709 |
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 |
710 |
} |
} |
711 |
pKey->ReleaseTrigger = false; |
pKey->ReleaseTrigger = false; |
712 |
} |
} |
743 |
* @param VoiceStealing - if voice stealing should be performed |
* @param VoiceStealing - if voice stealing should be performed |
744 |
* when there is no free voice |
* when there is no free voice |
745 |
* (optional, default = true) |
* (optional, default = true) |
746 |
|
* @param HandleKeyGroupConflicts - if voices should be killed due to a |
747 |
|
* key group conflict |
748 |
* @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 |
749 |
* if the voice wasn't triggered (for example when no region is |
* if the voice wasn't triggered (for example when no region is |
750 |
* defined for the given key). |
* defined for the given key). |
751 |
*/ |
*/ |
752 |
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) { |
753 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
int MIDIKey = itNoteOnEvent->Param.Note.Key; |
754 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[MIDIKey]; |
755 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(MIDIKey); |
756 |
|
|
757 |
|
// if nothing defined for this key |
758 |
|
if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do |
759 |
|
|
760 |
|
// only mark the first voice of a layered voice (group) to be in a |
761 |
|
// key group, so the layered voices won't kill each other |
762 |
|
int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0; |
763 |
|
|
764 |
|
// handle key group (a.k.a. exclusive group) conflicts |
765 |
|
if (HandleKeyGroupConflicts) { |
766 |
|
if (iKeyGroup) { // if this voice / key belongs to a key group |
767 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup]; |
768 |
|
if (*ppKeyGroup) { // if there's already an active key in that key group |
769 |
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup]; |
770 |
|
// kill all voices on the (other) key |
771 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
772 |
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
773 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
774 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) { |
775 |
|
itVoiceToBeKilled->Kill(itNoteOnEvent); |
776 |
|
--VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict |
777 |
|
} |
778 |
|
} |
779 |
|
} |
780 |
|
} |
781 |
|
} |
782 |
|
|
783 |
|
Voice::type_t VoiceType = Voice::type_normal; |
784 |
|
|
785 |
|
// get current dimension values to select the right dimension region |
786 |
|
//TODO: for stolen voices this dimension region selection block is processed twice, this should be changed |
787 |
|
//FIXME: controller values for selecting the dimension region here are currently not sample accurate |
788 |
|
uint DimValues[8] = { 0 }; |
789 |
|
for (int i = pRegion->Dimensions - 1; i >= 0; i--) { |
790 |
|
switch (pRegion->pDimensionDefinitions[i].dimension) { |
791 |
|
case ::gig::dimension_samplechannel: |
792 |
|
DimValues[i] = 0; //TODO: we currently ignore this dimension |
793 |
|
break; |
794 |
|
case ::gig::dimension_layer: |
795 |
|
DimValues[i] = iLayer; |
796 |
|
break; |
797 |
|
case ::gig::dimension_velocity: |
798 |
|
DimValues[i] = itNoteOnEvent->Param.Note.Velocity; |
799 |
|
break; |
800 |
|
case ::gig::dimension_channelaftertouch: |
801 |
|
DimValues[i] = 0; //TODO: we currently ignore this dimension |
802 |
|
break; |
803 |
|
case ::gig::dimension_releasetrigger: |
804 |
|
VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
805 |
|
DimValues[i] = (uint) ReleaseTriggerVoice; |
806 |
|
break; |
807 |
|
case ::gig::dimension_keyboard: |
808 |
|
DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension; |
809 |
|
break; |
810 |
|
case ::gig::dimension_roundrobin: |
811 |
|
DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on |
812 |
|
break; |
813 |
|
case ::gig::dimension_random: |
814 |
|
RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator |
815 |
|
DimValues[i] = (uint) RandomSeed >> (32 - pRegion->pDimensionDefinitions[i].bits); // highest bits are most random |
816 |
|
break; |
817 |
|
case ::gig::dimension_modwheel: |
818 |
|
DimValues[i] = pEngineChannel->ControllerTable[1]; |
819 |
|
break; |
820 |
|
case ::gig::dimension_breath: |
821 |
|
DimValues[i] = pEngineChannel->ControllerTable[2]; |
822 |
|
break; |
823 |
|
case ::gig::dimension_foot: |
824 |
|
DimValues[i] = pEngineChannel->ControllerTable[4]; |
825 |
|
break; |
826 |
|
case ::gig::dimension_portamentotime: |
827 |
|
DimValues[i] = pEngineChannel->ControllerTable[5]; |
828 |
|
break; |
829 |
|
case ::gig::dimension_effect1: |
830 |
|
DimValues[i] = pEngineChannel->ControllerTable[12]; |
831 |
|
break; |
832 |
|
case ::gig::dimension_effect2: |
833 |
|
DimValues[i] = pEngineChannel->ControllerTable[13]; |
834 |
|
break; |
835 |
|
case ::gig::dimension_genpurpose1: |
836 |
|
DimValues[i] = pEngineChannel->ControllerTable[16]; |
837 |
|
break; |
838 |
|
case ::gig::dimension_genpurpose2: |
839 |
|
DimValues[i] = pEngineChannel->ControllerTable[17]; |
840 |
|
break; |
841 |
|
case ::gig::dimension_genpurpose3: |
842 |
|
DimValues[i] = pEngineChannel->ControllerTable[18]; |
843 |
|
break; |
844 |
|
case ::gig::dimension_genpurpose4: |
845 |
|
DimValues[i] = pEngineChannel->ControllerTable[19]; |
846 |
|
break; |
847 |
|
case ::gig::dimension_sustainpedal: |
848 |
|
DimValues[i] = pEngineChannel->ControllerTable[64]; |
849 |
|
break; |
850 |
|
case ::gig::dimension_portamento: |
851 |
|
DimValues[i] = pEngineChannel->ControllerTable[65]; |
852 |
|
break; |
853 |
|
case ::gig::dimension_sostenutopedal: |
854 |
|
DimValues[i] = pEngineChannel->ControllerTable[66]; |
855 |
|
break; |
856 |
|
case ::gig::dimension_softpedal: |
857 |
|
DimValues[i] = pEngineChannel->ControllerTable[67]; |
858 |
|
break; |
859 |
|
case ::gig::dimension_genpurpose5: |
860 |
|
DimValues[i] = pEngineChannel->ControllerTable[80]; |
861 |
|
break; |
862 |
|
case ::gig::dimension_genpurpose6: |
863 |
|
DimValues[i] = pEngineChannel->ControllerTable[81]; |
864 |
|
break; |
865 |
|
case ::gig::dimension_genpurpose7: |
866 |
|
DimValues[i] = pEngineChannel->ControllerTable[82]; |
867 |
|
break; |
868 |
|
case ::gig::dimension_genpurpose8: |
869 |
|
DimValues[i] = pEngineChannel->ControllerTable[83]; |
870 |
|
break; |
871 |
|
case ::gig::dimension_effect1depth: |
872 |
|
DimValues[i] = pEngineChannel->ControllerTable[91]; |
873 |
|
break; |
874 |
|
case ::gig::dimension_effect2depth: |
875 |
|
DimValues[i] = pEngineChannel->ControllerTable[92]; |
876 |
|
break; |
877 |
|
case ::gig::dimension_effect3depth: |
878 |
|
DimValues[i] = pEngineChannel->ControllerTable[93]; |
879 |
|
break; |
880 |
|
case ::gig::dimension_effect4depth: |
881 |
|
DimValues[i] = pEngineChannel->ControllerTable[94]; |
882 |
|
break; |
883 |
|
case ::gig::dimension_effect5depth: |
884 |
|
DimValues[i] = pEngineChannel->ControllerTable[95]; |
885 |
|
break; |
886 |
|
case ::gig::dimension_none: |
887 |
|
std::cerr << "gig::Engine::LaunchVoice() Error: dimension=none\n" << std::flush; |
888 |
|
break; |
889 |
|
default: |
890 |
|
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
891 |
|
} |
892 |
|
} |
893 |
|
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
894 |
|
|
895 |
|
// no need to continue if sample is silent |
896 |
|
if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator(); |
897 |
|
|
898 |
// allocate a new voice for the key |
// allocate a new voice for the key |
899 |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
900 |
if (itNewVoice) { |
if (itNewVoice) { |
901 |
// launch the new voice |
// launch the new voice |
902 |
if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pEngineChannel->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) { |
if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pDimRgn, VoiceType, iKeyGroup) < 0) { |
903 |
dmsg(4,("Voice not triggered\n")); |
dmsg(4,("Voice not triggered\n")); |
904 |
pKey->pActiveVoices->free(itNewVoice); |
pKey->pActiveVoices->free(itNewVoice); |
905 |
} |
} |
906 |
else { // on success |
else { // on success |
907 |
uint** ppKeyGroup = NULL; |
--VoiceSpawnsLeft; |
|
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); |
|
|
} |
|
|
} |
|
|
} |
|
908 |
if (!pKey->Active) { // mark as active key |
if (!pKey->Active) { // mark as active key |
909 |
pKey->Active = true; |
pKey->Active = true; |
910 |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
911 |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
912 |
} |
} |
913 |
if (itNewVoice->KeyGroup) { |
if (itNewVoice->KeyGroup) { |
914 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; |
915 |
*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 |
916 |
} |
} |
917 |
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) |
948 |
* @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing |
* @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing |
949 |
*/ |
*/ |
950 |
int Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
int Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
951 |
if (!VoiceTheftsLeft) { |
if (VoiceSpawnsLeft <= 0) { |
952 |
dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n")); |
dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n")); |
953 |
return -1; |
return -1; |
954 |
} |
} |
967 |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
968 |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
969 |
// proceed iterating if voice was created in this fragment cycle |
// proceed iterating if voice was created in this fragment cycle |
970 |
while (itSelectedVoice && !itSelectedVoice->hasRendered()) ++itSelectedVoice; |
while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice; |
971 |
// if we haven't found a voice then proceed with algorithm 'oldestkey' |
// if we haven't found a voice then proceed with algorithm 'oldestkey' |
972 |
if (itSelectedVoice && itSelectedVoice->hasRendered()) break; |
if (itSelectedVoice && itSelectedVoice->IsStealable()) break; |
973 |
} // no break - intentional ! |
} // no break - intentional ! |
974 |
|
|
975 |
// try to pick the oldest voice on the oldest active key |
// try to pick the oldest voice on the oldest active key |
981 |
itSelectedVoice = this->itLastStolenVoice; |
itSelectedVoice = this->itLastStolenVoice; |
982 |
do { |
do { |
983 |
++itSelectedVoice; |
++itSelectedVoice; |
984 |
} while (itSelectedVoice && !itSelectedVoice->hasRendered()); // proceed iterating if voice was created in this fragment cycle |
} while (itSelectedVoice && !itSelectedVoice->IsStealable()); // proceed iterating if voice was created in this fragment cycle |
985 |
// found a "stealable" voice ? |
// found a "stealable" voice ? |
986 |
if (itSelectedVoice && itSelectedVoice->hasRendered()) { |
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
987 |
// remember which voice we stole, so we can simply proceed on next voice stealing |
// remember which voice we stole, so we can simply proceed on next voice stealing |
988 |
this->itLastStolenVoice = itSelectedVoice; |
this->itLastStolenVoice = itSelectedVoice; |
989 |
break; // selection succeeded |
break; // selection succeeded |
995 |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
996 |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
997 |
// proceed iterating if voice was created in this fragment cycle |
// proceed iterating if voice was created in this fragment cycle |
998 |
while (itSelectedVoice && !itSelectedVoice->hasRendered()) ++itSelectedVoice; |
while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice; |
999 |
// found a "stealable" voice ? |
// found a "stealable" voice ? |
1000 |
if (itSelectedVoice && itSelectedVoice->hasRendered()) { |
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1001 |
// remember which voice on which key we stole, so we can simply proceed on next voice stealing |
// remember which voice on which key we stole, so we can simply proceed on next voice stealing |
1002 |
this->iuiLastStolenKey = iuiSelectedKey; |
this->iuiLastStolenKey = iuiSelectedKey; |
1003 |
this->itLastStolenVoice = itSelectedVoice; |
this->itLastStolenVoice = itSelectedVoice; |
1019 |
// if we couldn't steal a voice from the same engine channel then |
// if we couldn't steal a voice from the same engine channel then |
1020 |
// steal oldest voice on the oldest key from any other engine channel |
// steal oldest voice on the oldest key from any other engine channel |
1021 |
// (the smaller engine channel number, the higher priority) |
// (the smaller engine channel number, the higher priority) |
1022 |
if (!itSelectedVoice || !itSelectedVoice->hasRendered()) { |
if (!itSelectedVoice || !itSelectedVoice->IsStealable()) { |
1023 |
EngineChannel* pSelectedChannel; |
EngineChannel* pSelectedChannel; |
1024 |
int iChannelIndex; |
int iChannelIndex; |
1025 |
// select engine channel |
// select engine channel |
1030 |
iChannelIndex = (pEngineChannel->iEngineIndexSelf + 1) % engineChannels.size(); |
iChannelIndex = (pEngineChannel->iEngineIndexSelf + 1) % engineChannels.size(); |
1031 |
pSelectedChannel = engineChannels[iChannelIndex]; |
pSelectedChannel = engineChannels[iChannelIndex]; |
1032 |
} |
} |
1033 |
// iterate through engine channels |
|
1034 |
while (true) { |
// if we already stole in this fragment, try to proceed on same key |
1035 |
// if we already stole in this fragment, try to proceed on same key |
if (this->itLastStolenVoiceGlobally) { |
1036 |
if (this->itLastStolenVoiceGlobally) { |
itSelectedVoice = this->itLastStolenVoiceGlobally; |
1037 |
itSelectedVoice = this->itLastStolenVoiceGlobally; |
do { |
1038 |
do { |
++itSelectedVoice; |
1039 |
++itSelectedVoice; |
} while (itSelectedVoice && !itSelectedVoice->IsStealable()); // proceed iterating if voice was created in this fragment cycle |
1040 |
} while (itSelectedVoice && !itSelectedVoice->hasRendered()); // proceed iterating if voice was created in this fragment cycle |
} |
1041 |
// break if selection succeeded |
|
1042 |
if (itSelectedVoice && itSelectedVoice->hasRendered()) { |
#if CONFIG_DEVMODE |
1043 |
// remember which voice we stole, so we can simply proceed on next voice stealing |
EngineChannel* pBegin = pSelectedChannel; // to detect endless loop |
1044 |
this->itLastStolenVoiceGlobally = itSelectedVoice; |
#endif // CONFIG_DEVMODE |
1045 |
break; // selection succeeded |
|
1046 |
} |
// did we find a 'stealable' voice? |
1047 |
} |
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1048 |
|
// remember which voice we stole, so we can simply proceed on next voice stealing |
1049 |
|
this->itLastStolenVoiceGlobally = itSelectedVoice; |
1050 |
|
} else while (true) { // iterate through engine channels |
1051 |
// get (next) oldest key |
// get (next) oldest key |
1052 |
RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKey) ? ++this->iuiLastStolenKey : pSelectedChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKeyGlobally) ? ++this->iuiLastStolenKeyGlobally : pSelectedChannel->pActiveKeys->first(); |
1053 |
|
this->iuiLastStolenKeyGlobally = RTList<uint>::Iterator(); // to prevent endless loop (see line above) |
1054 |
while (iuiSelectedKey) { |
while (iuiSelectedKey) { |
1055 |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
midi_key_info_t* pSelectedKey = &pSelectedChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
1056 |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
1057 |
// proceed iterating if voice was created in this fragment cycle |
// proceed iterating if voice was created in this fragment cycle |
1058 |
while (itSelectedVoice && !itSelectedVoice->hasRendered()) ++itSelectedVoice; |
while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice; |
1059 |
// found a "stealable" voice ? |
// found a "stealable" voice ? |
1060 |
if (itSelectedVoice && itSelectedVoice->hasRendered()) { |
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1061 |
// remember which voice on which key on which engine channel we stole, so we can simply proceed on next voice stealing |
// remember which voice on which key on which engine channel we stole, so we can simply proceed on next voice stealing |
1062 |
this->iuiLastStolenKeyGlobally = iuiSelectedKey; |
this->iuiLastStolenKeyGlobally = iuiSelectedKey; |
1063 |
this->itLastStolenVoiceGlobally = itSelectedVoice; |
this->itLastStolenVoiceGlobally = itSelectedVoice; |
1064 |
this->pLastStolenChannel = pSelectedChannel; |
this->pLastStolenChannel = pSelectedChannel; |
1065 |
break; // selection succeeded |
goto stealable_voice_found; // selection succeeded |
1066 |
} |
} |
1067 |
++iuiSelectedKey; // get next key on current engine channel |
++iuiSelectedKey; // get next key on current engine channel |
1068 |
} |
} |
1069 |
// get next engine channel |
// get next engine channel |
1070 |
iChannelIndex = (iChannelIndex + 1) % engineChannels.size(); |
iChannelIndex = (iChannelIndex + 1) % engineChannels.size(); |
1071 |
pSelectedChannel = engineChannels[iChannelIndex]; |
pSelectedChannel = engineChannels[iChannelIndex]; |
1072 |
|
|
1073 |
|
#if CONFIG_DEVMODE |
1074 |
|
if (pSelectedChannel == pBegin) { |
1075 |
|
dmsg(1,("FATAL ERROR: voice stealing endless loop!\n")); |
1076 |
|
dmsg(1,("VoiceSpawnsLeft=%d.\n", VoiceSpawnsLeft)); |
1077 |
|
dmsg(1,("Exiting.\n")); |
1078 |
|
exit(-1); |
1079 |
|
} |
1080 |
|
#endif // CONFIG_DEVMODE |
1081 |
} |
} |
1082 |
} |
} |
1083 |
|
|
1084 |
|
// jump point if a 'stealable' voice was found |
1085 |
|
stealable_voice_found: |
1086 |
|
|
1087 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
1088 |
if (!itSelectedVoice->IsActive()) { |
if (!itSelectedVoice->IsActive()) { |
1089 |
dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); |
dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); |
1094 |
// now kill the selected voice |
// now kill the selected voice |
1095 |
itSelectedVoice->Kill(itNoteOnEvent); |
itSelectedVoice->Kill(itNoteOnEvent); |
1096 |
|
|
1097 |
--VoiceTheftsLeft; |
--VoiceSpawnsLeft; |
1098 |
|
|
1099 |
return 0; // success |
return 0; // success |
1100 |
} |
} |
1185 |
dmsg(4,("PEDAL DOWN\n")); |
dmsg(4,("PEDAL DOWN\n")); |
1186 |
pEngineChannel->SustainPedal = true; |
pEngineChannel->SustainPedal = true; |
1187 |
|
|
1188 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1189 |
|
|
1190 |
// cancel release process of voices if necessary |
// cancel release process of voices if necessary |
1191 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1192 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1205 |
dmsg(4,("PEDAL UP\n")); |
dmsg(4,("PEDAL UP\n")); |
1206 |
pEngineChannel->SustainPedal = false; |
pEngineChannel->SustainPedal = false; |
1207 |
|
|
1208 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1209 |
|
|
1210 |
// release voices if their respective key is not pressed |
// release voices if their respective key is not pressed |
1211 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1212 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1374 |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
1375 |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
1376 |
itVoice->Kill(itKillEvent); |
itVoice->Kill(itKillEvent); |
1377 |
|
--VoiceSpawnsLeft; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead |
1378 |
} |
} |
1379 |
} |
} |
1380 |
} |
} |
1431 |
} |
} |
1432 |
|
|
1433 |
String Engine::Version() { |
String Engine::Version() { |
1434 |
String s = "$Revision: 1.43 $"; |
String s = "$Revision: 1.50 $"; |
1435 |
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 |
1436 |
} |
} |
1437 |
|
|