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 * |
600 |
#endif |
#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) |
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 |
|
|
686 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
687 |
#endif |
#endif |
688 |
|
|
689 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key]; |
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 && ShouldReleaseVoice(pEngineChannel, itNoteOffEvent->Param.Note.Key)) { |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
|
itNoteOffEvent->Type = Event::type_release; // transform event type |
|
695 |
|
|
696 |
// move event to the key's own event list |
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
697 |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
|
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 |
|
// 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 |
|
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) { |
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 |
/** |
/** |
1228 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
1229 |
|
|
1230 |
switch (itControlChangeEvent->Param.CC.Controller) { |
switch (itControlChangeEvent->Param.CC.Controller) { |
1231 |
|
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 |
|
break; |
1234 |
|
} |
1235 |
case 7: { // volume |
case 7: { // volume |
1236 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1237 |
pEngineChannel->GlobalVolume = (float) itControlChangeEvent->Param.CC.Value / 127.0f * CONFIG_GLOBAL_ATTENUATION; |
pEngineChannel->GlobalVolume = (float) itControlChangeEvent->Param.CC.Value / 127.0f * CONFIG_GLOBAL_ATTENUATION; |
1292 |
} |
} |
1293 |
break; |
break; |
1294 |
} |
} |
1295 |
|
case 65: { // portamento on / off |
1296 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1297 |
|
pEngineChannel->PortamentoMode = itControlChangeEvent->Param.CC.Value >= 64; |
1298 |
|
break; |
1299 |
|
} |
1300 |
case 66: { // sostenuto |
case 66: { // sostenuto |
1301 |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) { |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) { |
1302 |
dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n")); |
dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n")); |
1353 |
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
1354 |
break; |
break; |
1355 |
} |
} |
1356 |
|
case 126: { // mono mode on |
1357 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1358 |
|
pEngineChannel->SoloMode = true; |
1359 |
|
break; |
1360 |
|
} |
1361 |
|
case 127: { // poly mode on |
1362 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1363 |
|
pEngineChannel->SoloMode = false; |
1364 |
|
break; |
1365 |
|
} |
1366 |
} |
} |
1367 |
} |
} |
1368 |
|
|
1558 |
} |
} |
1559 |
|
|
1560 |
String Engine::Version() { |
String Engine::Version() { |
1561 |
String s = "$Revision: 1.56 $"; |
String s = "$Revision: 1.57 $"; |
1562 |
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 |
1563 |
} |
} |
1564 |
|
|