519 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
520 |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
521 |
Pool<Voice>::Iterator itNewVoice = |
Pool<Voice>::Iterator itNewVoice = |
522 |
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); |
523 |
if (itNewVoice) { |
if (itNewVoice) { |
524 |
itNewVoice->Render(Samples); |
itNewVoice->Render(Samples); |
525 |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
647 |
int voicesRequired = pRegion->Layers; |
int voicesRequired = pRegion->Layers; |
648 |
// now launch the required amount of voices |
// now launch the required amount of voices |
649 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
650 |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true); |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true, true); |
651 |
} |
} |
652 |
} |
} |
653 |
|
|
691 |
|
|
692 |
// now launch the required amount of voices |
// now launch the required amount of voices |
693 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
694 |
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 |
695 |
} |
} |
696 |
pKey->ReleaseTrigger = false; |
pKey->ReleaseTrigger = false; |
697 |
} |
} |
728 |
* @param VoiceStealing - if voice stealing should be performed |
* @param VoiceStealing - if voice stealing should be performed |
729 |
* when there is no free voice |
* when there is no free voice |
730 |
* (optional, default = true) |
* (optional, default = true) |
731 |
|
* @param HandleKeyGroupConflicts - if voices should be killed due to a |
732 |
|
* key group conflict |
733 |
* @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 |
734 |
* if the voice wasn't triggered (for example when no region is |
* if the voice wasn't triggered (for example when no region is |
735 |
* defined for the given key). |
* defined for the given key). |
736 |
*/ |
*/ |
737 |
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) { |
738 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
739 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key); |
740 |
|
|
741 |
|
// if nothing defined for this key |
742 |
|
if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do |
743 |
|
|
744 |
|
// handle key group (a.k.a. exclusive group) conflicts |
745 |
|
if (HandleKeyGroupConflicts) { |
746 |
|
// only mark the first voice of a layered voice (group) to be in a |
747 |
|
// key group, so the layered voices won't kill each other |
748 |
|
int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0; |
749 |
|
if (iKeyGroup) { // if this voice / key belongs to a key group |
750 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup]; |
751 |
|
if (*ppKeyGroup) { // if there's already an active key in that key group |
752 |
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup]; |
753 |
|
// kill all voices on the (other) key |
754 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
755 |
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
756 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
757 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) { |
758 |
|
itVoiceToBeKilled->Kill(itNoteOnEvent); |
759 |
|
--VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict |
760 |
|
} |
761 |
|
} |
762 |
|
} |
763 |
|
} |
764 |
|
} |
765 |
|
|
766 |
// allocate a new voice for the key |
// allocate a new voice for the key |
767 |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
773 |
} |
} |
774 |
else { // on success |
else { // on success |
775 |
--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 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
776 |
if (!pKey->Active) { // mark as active key |
if (!pKey->Active) { // mark as active key |
777 |
pKey->Active = true; |
pKey->Active = true; |
778 |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
779 |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
780 |
} |
} |
781 |
if (itNewVoice->KeyGroup) { |
if (itNewVoice->KeyGroup) { |
782 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; |
783 |
*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 |
784 |
} |
} |
785 |
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) |
1295 |
} |
} |
1296 |
|
|
1297 |
String Engine::Version() { |
String Engine::Version() { |
1298 |
String s = "$Revision: 1.45 $"; |
String s = "$Revision: 1.46 $"; |
1299 |
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 |
1300 |
} |
} |
1301 |
|
|