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-2008 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
8 |
* Copyright (C) 2012-2016 Christian Schoenebeck and Andreas Persson * |
* Copyright (C) 2012-2017 Christian Schoenebeck and Andreas Persson * |
9 |
* * |
* * |
10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
11 |
* 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 * |
58 |
typedef typename RTList<RR*>::Iterator RootRegionIterator; |
typedef typename RTList<RR*>::Iterator RootRegionIterator; |
59 |
typedef typename MidiKeyboardManager<V>::MidiKey MidiKey; |
typedef typename MidiKeyboardManager<V>::MidiKey MidiKey; |
60 |
|
|
61 |
EngineBase() : SuspendedRegions(128), noteIDPool(GLOBAL_MAX_NOTES) { |
EngineBase() : noteIDPool(GLOBAL_MAX_NOTES), SuspendedRegions(128) { |
62 |
pDiskThread = NULL; |
pDiskThread = NULL; |
63 |
pNotePool = new Pool< Note<V> >(GLOBAL_MAX_NOTES); |
pNotePool = new Pool< Note<V> >(GLOBAL_MAX_NOTES); |
64 |
pNotePool->setPoolElementIDsReservedBits(INSTR_SCRIPT_EVENT_ID_RESERVED_BITS); |
pNotePool->setPoolElementIDsReservedBits(INSTR_SCRIPT_EVENT_ID_RESERVED_BITS); |
163 |
dmsg(5,("Engine: Sysex received\n")); |
dmsg(5,("Engine: Sysex received\n")); |
164 |
ProcessSysex(itEvent); |
ProcessSysex(itEvent); |
165 |
break; |
break; |
166 |
|
default: ; // noop |
167 |
} |
} |
168 |
} |
} |
169 |
} |
} |
202 |
PostProcess(engineChannels[i]); |
PostProcess(engineChannels[i]); |
203 |
} |
} |
204 |
|
|
205 |
|
// Just for debugging: dump the amount of free Note objects to |
206 |
|
// the terminal (note due to the static variables being used, |
207 |
|
// this is currently just intended for debugging with only one |
208 |
|
// engine channel). |
209 |
|
#if (CONFIG_DEBUG_LEVEL >= 3) |
210 |
|
{ |
211 |
|
static int slice = 0; |
212 |
|
static int noteCount = -1; |
213 |
|
if (slice++ % 10 == 0) { |
214 |
|
int n = pNotePool->countFreeElements(); |
215 |
|
if (n != noteCount) { |
216 |
|
noteCount = n; |
217 |
|
dmsg(1,("[%d] free Note objects count = %d\n", slice / 10, n)); |
218 |
|
} |
219 |
|
} |
220 |
|
} |
221 |
|
#endif |
222 |
|
|
223 |
// empty the engine's event list for the next audio fragment |
// empty the engine's event list for the next audio fragment |
224 |
ClearEventLists(); |
ClearEventLists(); |
396 |
} |
} |
397 |
pVoicePool->clear(); |
pVoicePool->clear(); |
398 |
|
|
399 |
// (re)create event generator |
// update event generator |
400 |
if (pEventGenerator) delete pEventGenerator; |
pEventGenerator->SetSampleRate(pAudioOut->SampleRate()); |
|
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
|
401 |
|
|
402 |
dmsg(1,("Starting disk thread...")); |
dmsg(1,("Starting disk thread...")); |
403 |
pDiskThread->StartThread(); |
pDiskThread->StartThread(); |
613 |
} |
} |
614 |
|
|
615 |
// implementation of abstract method derived from class 'LinuxSampler::RegionPools' |
// implementation of abstract method derived from class 'LinuxSampler::RegionPools' |
616 |
virtual Pool<R*>* GetRegionPool(int index) { |
virtual Pool<R*>* GetRegionPool(int index) OVERRIDE { |
617 |
if (index < 0 || index > 1) throw Exception("Index out of bounds"); |
if (index < 0 || index > 1) throw Exception("Index out of bounds"); |
618 |
return pRegionPool[index]; |
return pRegionPool[index]; |
619 |
} |
} |
621 |
// implementation of abstract methods derived from class 'LinuxSampler::NotePool' |
// implementation of abstract methods derived from class 'LinuxSampler::NotePool' |
622 |
virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; } |
virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; } |
623 |
virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; } |
virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; } |
624 |
virtual Pool<note_id_t>* GetNodeIDPool() OVERRIDE { return ¬eIDPool; } |
virtual Pool<note_id_t>* GetNoteIDPool() OVERRIDE { return ¬eIDPool; } |
625 |
|
|
626 |
D* GetDiskThread() { return pDiskThread; } |
D* GetDiskThread() { return pDiskThread; } |
627 |
|
|
692 |
* @param pNoteOnEvent - event which caused this |
* @param pNoteOnEvent - event which caused this |
693 |
* @returns new note's unique ID (or zero on error) |
* @returns new note's unique ID (or zero on error) |
694 |
*/ |
*/ |
695 |
note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) OVERRIDE { |
note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE { |
696 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
697 |
Pool< Note<V> >* pNotePool = GetNotePool(); |
Pool< Note<V> >* pNotePool = GetNotePool(); |
698 |
|
|
706 |
NoteIterator itNewNote = pNotePool->allocAppend(); |
NoteIterator itNewNote = pNotePool->allocAppend(); |
707 |
const note_id_t newNoteID = pNotePool->getID(itNewNote); |
const note_id_t newNoteID = pNotePool->getID(itNewNote); |
708 |
|
|
709 |
|
// remember the engine's time when this note was triggered exactly |
710 |
|
itNewNote->triggerSchedTime = itNoteOnEvent->SchedTime(); |
711 |
|
|
712 |
// usually the new note (and its subsequent voices) will be |
// usually the new note (and its subsequent voices) will be |
713 |
// allocated on the key provided by the event's note number, |
// allocated on the key provided by the event's note number, |
714 |
// however if this new note is requested not to be a regular |
// however if this new note is requested not to be a regular |
715 |
// note, but rather a child note, then this new note will be |
// note, but rather a child note, then this new note will be |
716 |
// allocated on the parent note's key instead in order to |
// allocated on the parent note's key instead in order to |
717 |
// release the child note simultaniously with its parent note |
// release the child note simultaniously with its parent note |
718 |
itNewNote->hostKey = pNoteOnEvent->Param.Note.Key; |
itNewNote->hostKey = itNoteOnEvent->Param.Note.Key; |
719 |
|
|
720 |
// in case this new note was requested to be a child note, |
// in case this new note was requested to be a child note, |
721 |
// then retrieve its parent note and link them with each other |
// then retrieve its parent note and link them with each other |
722 |
const note_id_t parentNoteID = pNoteOnEvent->Param.Note.ParentNoteID; |
const note_id_t parentNoteID = itNoteOnEvent->Param.Note.ParentNoteID; |
723 |
if (parentNoteID) { |
if (parentNoteID) { |
724 |
NoteIterator itParentNote = pNotePool->fromID(parentNoteID); |
NoteIterator itParentNote = pNotePool->fromID(parentNoteID); |
725 |
if (itParentNote) { |
if (itParentNote) { |
747 |
dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey)); |
dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey)); |
748 |
|
|
749 |
// copy event which caused this note |
// copy event which caused this note |
750 |
itNewNote->cause = *pNoteOnEvent; |
itNewNote->cause = *itNoteOnEvent; |
751 |
itNewNote->eventID = pEventPool->getID(pNoteOnEvent); |
itNewNote->eventID = pEventPool->getID(itNoteOnEvent); |
752 |
|
if (!itNewNote->eventID) { |
753 |
|
dmsg(0,("Engine: No valid event ID resolved for note. This is a bug!!!\n")); |
754 |
|
} |
755 |
|
|
756 |
// move new note to its host key |
// move new note to its host key |
757 |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey]; |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey]; |
758 |
itNewNote.moveToEndOf(pKey->pActiveNotes); |
itNewNote.moveToEndOf(pKey->pActiveNotes); |
759 |
|
pChannel->markKeyAsActive(pKey); |
760 |
|
|
761 |
// assign unique note ID of this new note to the original note on event |
// assign unique note ID of this new note to the original note on event |
762 |
pNoteOnEvent->Param.Note.ID = newNoteID; |
itNoteOnEvent->Param.Note.ID = newNoteID; |
763 |
|
|
764 |
return newNoteID; // success |
return newNoteID; // success |
765 |
} |
} |
819 |
case Event::type_note_pressure: |
case Event::type_note_pressure: |
820 |
//TODO: ... |
//TODO: ... |
821 |
break; |
break; |
822 |
|
|
823 |
|
case Event::type_sysex: |
824 |
|
//TODO: ... |
825 |
|
break; |
826 |
|
|
827 |
|
case Event::type_cancel_release_key: |
828 |
|
case Event::type_release_key: |
829 |
|
case Event::type_release_note: |
830 |
|
case Event::type_play_note: |
831 |
|
case Event::type_stop_note: |
832 |
|
case Event::type_kill_note: |
833 |
|
case Event::type_note_synth_param: |
834 |
|
break; // noop |
835 |
} |
} |
836 |
|
|
837 |
// see HACK comment above |
// see HACK comment above |
890 |
dmsg(5,("Engine: Note on received\n")); |
dmsg(5,("Engine: Note on received\n")); |
891 |
ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent); |
ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent); |
892 |
break; |
break; |
893 |
|
case Event::type_play_note: |
894 |
|
dmsg(5,("Engine: Play Note received\n")); |
895 |
|
ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent); |
896 |
|
break; |
897 |
case Event::type_note_off: |
case Event::type_note_off: |
898 |
dmsg(5,("Engine: Note off received\n")); |
dmsg(5,("Engine: Note off received\n")); |
899 |
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
900 |
break; |
break; |
901 |
|
case Event::type_stop_note: |
902 |
|
dmsg(5,("Engine: Stop Note received\n")); |
903 |
|
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
904 |
|
break; |
905 |
|
case Event::type_kill_note: |
906 |
|
dmsg(5,("Engine: Kill Note received\n")); |
907 |
|
ProcessKillNote((EngineChannel*)itEvent->pEngineChannel, itEvent); |
908 |
|
break; |
909 |
case Event::type_control_change: |
case Event::type_control_change: |
910 |
dmsg(5,("Engine: MIDI CC received\n")); |
dmsg(5,("Engine: MIDI CC received\n")); |
911 |
ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent); |
ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent); |
922 |
dmsg(5,("Engine: Pitchbend received\n")); |
dmsg(5,("Engine: Pitchbend received\n")); |
923 |
ProcessPitchbend(static_cast<AbstractEngineChannel*>(itEvent->pEngineChannel), itEvent); |
ProcessPitchbend(static_cast<AbstractEngineChannel*>(itEvent->pEngineChannel), itEvent); |
924 |
break; |
break; |
925 |
|
case Event::type_note_synth_param: |
926 |
|
dmsg(5,("Engine: Note Synth Param received\n")); |
927 |
|
ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent); |
928 |
|
break; |
929 |
|
case Event::type_sysex: |
930 |
|
break; // TODO ... |
931 |
|
|
932 |
|
case Event::type_cancel_release_key: |
933 |
|
case Event::type_release_key: |
934 |
|
case Event::type_release_note: |
935 |
|
break; // noop |
936 |
} |
} |
937 |
} |
} |
938 |
} |
} |
1001 |
// script event object |
// script event object |
1002 |
RTList<ScriptEvent>::Iterator itScriptEvent = |
RTList<ScriptEvent>::Iterator itScriptEvent = |
1003 |
pChannel->pScript->pEvents->allocAppend(); |
pChannel->pScript->pEvents->allocAppend(); |
1004 |
|
// if event handler uses polyphonic variables, reset them |
1005 |
|
// to zero values before starting to execute the handler |
1006 |
|
if (pEventHandler->isPolyphonic()) |
1007 |
|
itScriptEvent->execCtx->resetPolyphonicData(); |
1008 |
ProcessScriptEvent( |
ProcessScriptEvent( |
1009 |
pChannel, itEvent, pEventHandler, itScriptEvent |
pChannel, itEvent, pEventHandler, itScriptEvent |
1010 |
); |
); |
1037 |
|
|
1038 |
// initialize/reset other members |
// initialize/reset other members |
1039 |
itScriptEvent->cause = *itEvent; |
itScriptEvent->cause = *itEvent; |
1040 |
|
itScriptEvent->scheduleTime = itEvent->SchedTime(); |
1041 |
itScriptEvent->currentHandler = 0; |
itScriptEvent->currentHandler = 0; |
1042 |
itScriptEvent->executionSlices = 0; |
itScriptEvent->executionSlices = 0; |
1043 |
|
itScriptEvent->ignoreAllWaitCalls = false; |
1044 |
|
itScriptEvent->handlerType = pEventHandler->eventHandlerType(); |
1045 |
|
itScriptEvent->parentHandlerID = 0; |
1046 |
|
itScriptEvent->childHandlerID[0] = 0; |
1047 |
|
itScriptEvent->autoAbortByParent = false; |
1048 |
|
itScriptEvent->forkIndex = 0; |
1049 |
// this is the native representation of the $EVENT_ID script variable |
// this is the native representation of the $EVENT_ID script variable |
1050 |
itScriptEvent->id = |
itScriptEvent->id = |
1051 |
(itEvent->Type == Event::type_note_on) |
(itEvent->Type == Event::type_note_on) |
1158 |
* @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 |
1159 |
*/ |
*/ |
1160 |
int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
1161 |
|
dmsg(3,("StealVoice()\n")); |
1162 |
if (VoiceSpawnsLeft <= 0) { |
if (VoiceSpawnsLeft <= 0) { |
1163 |
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")); |
1164 |
return -1; |
return -1; |
1183 |
int iChannelIndex; |
int iChannelIndex; |
1184 |
VoiceIterator itSelectedVoice; |
VoiceIterator itSelectedVoice; |
1185 |
|
|
1186 |
|
#if CONFIG_DEVMODE |
1187 |
|
EngineChannel* pBegin = NULL; // to detect endless loop |
1188 |
|
#endif |
1189 |
|
|
1190 |
// select engine channel |
// select engine channel |
1191 |
if (pLastStolenChannel) { |
if (pLastStolenChannel) { |
1192 |
pSelectedChannel = pLastStolenChannel; |
pSelectedChannel = pLastStolenChannel; |
1229 |
} |
} |
1230 |
|
|
1231 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
1232 |
EngineChannel* pBegin = pSelectedChannel; // to detect endless loop |
pBegin = pSelectedChannel; // to detect endless loop |
1233 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
1234 |
|
|
1235 |
while (true) { // iterate through engine channels |
while (true) { // iterate through engine channels |
1318 |
// the script's "init" event handler is only executed |
// the script's "init" event handler is only executed |
1319 |
// once (when the script is loaded or reloaded) |
// once (when the script is loaded or reloaded) |
1320 |
if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) { |
if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) { |
1321 |
|
dmsg(5,("Engine: exec handlerInit %p\n", pEngineChannel->pScript->handlerInit)); |
1322 |
RTList<ScriptEvent>::Iterator itScriptEvent = |
RTList<ScriptEvent>::Iterator itScriptEvent = |
1323 |
pEngineChannel->pScript->pEvents->allocAppend(); |
pEngineChannel->pScript->pEvents->allocAppend(); |
1324 |
|
|
1325 |
|
itScriptEvent->cause = pEventGenerator->CreateEvent(0); |
1326 |
|
itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing |
1327 |
itScriptEvent->cause.pEngineChannel = pEngineChannel; |
itScriptEvent->cause.pEngineChannel = pEngineChannel; |
1328 |
|
itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort(); |
1329 |
|
itScriptEvent->id = 0; |
1330 |
itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit; |
itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit; |
1331 |
itScriptEvent->handlers[1] = NULL; |
itScriptEvent->handlers[1] = NULL; |
1332 |
|
itScriptEvent->currentHandler = 0; |
1333 |
VMExecStatus_t res = pScriptVM->exec( |
itScriptEvent->executionSlices = 0; |
1334 |
pEngineChannel->pScript->parserContext, &*itScriptEvent |
itScriptEvent->ignoreAllWaitCalls = false; |
1335 |
); |
itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; |
1336 |
|
itScriptEvent->parentHandlerID = 0; |
1337 |
|
itScriptEvent->childHandlerID[0] = 0; |
1338 |
|
itScriptEvent->autoAbortByParent = false; |
1339 |
|
itScriptEvent->forkIndex = 0; |
1340 |
|
|
1341 |
|
VMExecStatus_t res; |
1342 |
|
size_t instructionsCount = 0; |
1343 |
|
const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction) |
1344 |
|
bool bWarningShown = false; |
1345 |
|
do { |
1346 |
|
res = pScriptVM->exec( |
1347 |
|
pEngineChannel->pScript->parserContext, &*itScriptEvent |
1348 |
|
); |
1349 |
|
instructionsCount += itScriptEvent->execCtx->instructionsPerformed(); |
1350 |
|
if (instructionsCount > maxInstructions && !bWarningShown) { |
1351 |
|
bWarningShown = true; |
1352 |
|
dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n")); |
1353 |
|
} |
1354 |
|
} while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR)); |
1355 |
|
|
1356 |
pEngineChannel->pScript->pEvents->free(itScriptEvent); |
pEngineChannel->pScript->pEvents->free(itScriptEvent); |
1357 |
} |
} |
1412 |
// usually there should already be a new Note object |
// usually there should already be a new Note object |
1413 |
NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID); |
NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID); |
1414 |
if (!itNote) { // should not happen, but just to be sure ... |
if (!itNote) { // should not happen, but just to be sure ... |
1415 |
const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent); |
dmsg(2,("Engine: No Note object for stolen voice!\n")); |
1416 |
|
const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent); |
1417 |
if (!noteID) { |
if (!noteID) { |
1418 |
dmsg(1,("Engine: Voice stealing failed; No Note object and Note pool empty!\n")); |
dmsg(1,("Engine: Voice stealing failed; No Note object and Note pool empty!\n")); |
1419 |
continue; |
continue; |
1457 |
void PostProcess(EngineChannel* pEngineChannel) { |
void PostProcess(EngineChannel* pEngineChannel) { |
1458 |
EngineChannelBase<V, R, I>* pChannel = |
EngineChannelBase<V, R, I>* pChannel = |
1459 |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1460 |
pChannel->FreeAllInactiveKyes(); |
pChannel->FreeAllInactiveKeys(); |
1461 |
|
|
1462 |
// empty the engine channel's own event lists |
// empty the engine channel's own event lists |
1463 |
// (only events of the current audio fragment cycle) |
// (only events of the current audio fragment cycle) |
1484 |
pChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
pChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
1485 |
break; |
break; |
1486 |
} |
} |
1487 |
case 6: { // data entry (currently only used for RPN and NRPN controllers) |
case 6: { // data entry (MSB) |
1488 |
//dmsg(1,("DATA ENTRY %d\n", itControlChangeEvent->Param.CC.Value)); |
//dmsg(1,("DATA ENTRY MSB %d\n", itControlChangeEvent->Param.CC.Value)); |
1489 |
if (pChannel->GetMidiRpnController() >= 0) { // RPN controller number was sent previously ... |
|
1490 |
dmsg(4,("Guess it's an RPN ...\n")); |
// look-ahead: if next MIDI event is data entry LSB, |
1491 |
if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones |
// then skip this event here for now (to avoid double |
1492 |
int transpose = (int) itControlChangeEvent->Param.CC.Value - 64; |
// handling of what's supposed to be one RPN/NRPN event) |
1493 |
// limit to +- two octaves for now |
if (isNextEventCCNr(itControlChangeEvent, 38)) |
1494 |
transpose = RTMath::Min(transpose, 24); |
break; |
1495 |
transpose = RTMath::Max(transpose, -24); |
|
1496 |
pChannel->GlobalTranspose = transpose; |
if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ... |
1497 |
// workaround, so we won't have hanging notes |
int ch = itControlChangeEvent->Param.CC.Channel; |
1498 |
pChannel->ReleaseAllVoices(itControlChangeEvent); |
int param = pChannel->GetMidiRpnParameter(); |
1499 |
} |
int value = itControlChangeEvent->Param.CC.Value << 7; |
1500 |
// to prevent other MIDI CC #6 messages to be misenterpreted as RPN controller data |
|
1501 |
pChannel->ResetMidiRpnController(); |
// transform event type: CC event -> RPN event |
1502 |
} else if (pChannel->GetMidiNrpnController() >= 0) { // NRPN controller number was sent previously ... |
itControlChangeEvent->Type = Event::type_rpn; |
1503 |
dmsg(4,("Guess it's an NRPN ...\n")); |
itControlChangeEvent->Param.RPN.Channel = ch; |
1504 |
const int NrpnCtrlMSB = pChannel->GetMidiNrpnController() >> 8; |
itControlChangeEvent->Param.RPN.Parameter = param; |
1505 |
const int NrpnCtrlLSB = pChannel->GetMidiNrpnController() & 0xff; |
itControlChangeEvent->Param.RPN.Value = value; |
1506 |
dmsg(4,("NRPN MSB=%d LSB=%d Data=%d\n", NrpnCtrlMSB, NrpnCtrlLSB, itControlChangeEvent->Param.CC.Value)); |
|
1507 |
switch (NrpnCtrlMSB) { |
// do the actual RPN event processing |
1508 |
case 0x1a: { // volume level of note (Roland GS NRPN) |
ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent); |
1509 |
const uint note = NrpnCtrlLSB; |
|
1510 |
const uint vol = itControlChangeEvent->Param.CC.Value; |
// to prevent other data entry messages to be misenterpreted as RPN value |
1511 |
dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol)); |
pChannel->ResetMidiRpnParameter(); |
1512 |
if (note < 128 && vol < 128) |
} else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ... |
1513 |
pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol]; |
int ch = itControlChangeEvent->Param.CC.Channel; |
1514 |
break; |
int param = pChannel->GetMidiNrpnParameter(); |
1515 |
} |
int value = itControlChangeEvent->Param.CC.Value << 7; |
1516 |
case 0x1c: { // panpot of note (Roland GS NRPN) |
|
1517 |
const uint note = NrpnCtrlLSB; |
// transform event type: CC event -> NRPN event |
1518 |
const uint pan = itControlChangeEvent->Param.CC.Value; |
itControlChangeEvent->Type = Event::type_nrpn; |
1519 |
dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan)); |
itControlChangeEvent->Param.RPN.Channel = ch; |
1520 |
if (note < 128 && pan < 128) { |
itControlChangeEvent->Param.RPN.Parameter = param; |
1521 |
pChannel->pMIDIKeyInfo[note].PanLeft = PanCurve[128 - pan]; |
itControlChangeEvent->Param.RPN.Value = value; |
1522 |
pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan]; |
|
1523 |
} |
// do the actual NRPN event processing |
1524 |
break; |
ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent); |
1525 |
} |
|
1526 |
case 0x1d: { // reverb send of note (Roland GS NRPN) |
// to prevent other data entry messages to be misenterpreted as NRPN value |
1527 |
const uint note = NrpnCtrlLSB; |
pChannel->ResetMidiNrpnParameter(); |
|
const float reverb = float(itControlChangeEvent->Param.CC.Value) / 127.0f; |
|
|
dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb)); |
|
|
if (note < 128) |
|
|
pChannel->pMIDIKeyInfo[note].ReverbSend = reverb; |
|
|
break; |
|
|
} |
|
|
case 0x1e: { // chorus send of note (Roland GS NRPN) |
|
|
const uint note = NrpnCtrlLSB; |
|
|
const float chorus = float(itControlChangeEvent->Param.CC.Value) / 127.0f; |
|
|
dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus)); |
|
|
if (note < 128) |
|
|
pChannel->pMIDIKeyInfo[note].ChorusSend = chorus; |
|
|
break; |
|
|
} |
|
|
} |
|
|
// to prevent other MIDI CC #6 messages to be misenterpreted as NRPN controller data |
|
|
pChannel->ResetMidiNrpnController(); |
|
1528 |
} |
} |
1529 |
break; |
break; |
1530 |
} |
} |
1539 |
pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value; |
pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value; |
1540 |
break; |
break; |
1541 |
} |
} |
1542 |
|
case 38: { // data entry (LSB) |
1543 |
|
//dmsg(1,("DATA ENTRY LSB %d\n", itControlChangeEvent->Param.CC.Value)); |
1544 |
|
int value = 0; |
1545 |
|
|
1546 |
|
// look-back: if previous MIDI event was data entry MSB, |
1547 |
|
// then obtain that value for the MSB value portion |
1548 |
|
if (isPrevEventCCNr(itControlChangeEvent, 6)) |
1549 |
|
value = prevEventOf(itControlChangeEvent)->Param.CC.Value << 7; |
1550 |
|
|
1551 |
|
if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ... |
1552 |
|
int ch = itControlChangeEvent->Param.CC.Channel; |
1553 |
|
int param = pChannel->GetMidiRpnParameter(); |
1554 |
|
value |= itControlChangeEvent->Param.CC.Value; |
1555 |
|
|
1556 |
|
// transform event type: CC event -> RPN event |
1557 |
|
itControlChangeEvent->Type = Event::type_rpn; |
1558 |
|
itControlChangeEvent->Param.RPN.Channel = ch; |
1559 |
|
itControlChangeEvent->Param.RPN.Parameter = param; |
1560 |
|
itControlChangeEvent->Param.RPN.Value = value; |
1561 |
|
|
1562 |
|
// do the actual RPN event processing |
1563 |
|
ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent); |
1564 |
|
|
1565 |
|
// to prevent other data entry messages to be misenterpreted as RPN value |
1566 |
|
pChannel->ResetMidiRpnParameter(); |
1567 |
|
} else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ... |
1568 |
|
int ch = itControlChangeEvent->Param.CC.Channel; |
1569 |
|
int param = pChannel->GetMidiNrpnParameter(); |
1570 |
|
value |= itControlChangeEvent->Param.CC.Value; |
1571 |
|
|
1572 |
|
// transform event type: CC event -> NRPN event |
1573 |
|
itControlChangeEvent->Type = Event::type_nrpn; |
1574 |
|
itControlChangeEvent->Param.RPN.Channel = ch; |
1575 |
|
itControlChangeEvent->Param.RPN.Parameter = param; |
1576 |
|
itControlChangeEvent->Param.RPN.Value = value; |
1577 |
|
|
1578 |
|
// do the actual NRPN event processing |
1579 |
|
ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent); |
1580 |
|
|
1581 |
|
// to prevent other data entry messages to be misenterpreted as NRPN value |
1582 |
|
pChannel->ResetMidiNrpnParameter(); |
1583 |
|
} |
1584 |
|
break; |
1585 |
|
} |
1586 |
case 64: { // sustain |
case 64: { // sustain |
1587 |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) { |
1588 |
dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n")); |
1656 |
} |
} |
1657 |
break; |
break; |
1658 |
} |
} |
1659 |
case 98: { // NRPN controller LSB |
case 98: { // NRPN parameter LSB |
1660 |
dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value)); |
dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value)); |
1661 |
pEngineChannel->SetMidiNrpnControllerLsb(itControlChangeEvent->Param.CC.Value); |
pEngineChannel->SetMidiNrpnParameterLsb(itControlChangeEvent->Param.CC.Value); |
1662 |
break; |
break; |
1663 |
} |
} |
1664 |
case 99: { // NRPN controller MSB |
case 99: { // NRPN parameter MSB |
1665 |
dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value)); |
dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value)); |
1666 |
pEngineChannel->SetMidiNrpnControllerMsb(itControlChangeEvent->Param.CC.Value); |
pEngineChannel->SetMidiNrpnParameterMsb(itControlChangeEvent->Param.CC.Value); |
1667 |
break; |
break; |
1668 |
} |
} |
1669 |
case 100: { // RPN controller LSB |
case 100: { // RPN parameter LSB |
1670 |
dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value)); |
dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value)); |
1671 |
pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value); |
pEngineChannel->SetMidiRpnParameterLsb(itControlChangeEvent->Param.CC.Value); |
1672 |
break; |
break; |
1673 |
} |
} |
1674 |
case 101: { // RPN controller MSB |
case 101: { // RPN parameter MSB |
1675 |
dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value)); |
dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value)); |
1676 |
pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value); |
pEngineChannel->SetMidiRpnParameterMsb(itControlChangeEvent->Param.CC.Value); |
1677 |
break; |
break; |
1678 |
} |
} |
1679 |
|
|
1709 |
} |
} |
1710 |
} |
} |
1711 |
|
|
1712 |
|
/** |
1713 |
|
* Process MIDI RPN events with hard coded behavior. |
1714 |
|
* |
1715 |
|
* @param pEngineChannel - engine channel on which the MIDI RPN |
1716 |
|
* event was received |
1717 |
|
* @param itRpnEvent - the actual MIDI RPN event |
1718 |
|
*/ |
1719 |
|
void ProcessHardcodedRpn(EngineChannel* pEngineChannel, |
1720 |
|
Pool<Event>::Iterator& itRpnEvent) |
1721 |
|
{ |
1722 |
|
EngineChannelBase<V, R, I>* pChannel = |
1723 |
|
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1724 |
|
|
1725 |
|
if (itRpnEvent->Param.RPN.Parameter == 2) { // coarse tuning in half tones |
1726 |
|
int transpose = (int) itRpnEvent->Param.RPN.ValueMSB() - 64; |
1727 |
|
// limit to +- two octaves for now |
1728 |
|
transpose = RTMath::Min(transpose, 24); |
1729 |
|
transpose = RTMath::Max(transpose, -24); |
1730 |
|
pChannel->GlobalTranspose = transpose; |
1731 |
|
// workaround, so we won't have hanging notes |
1732 |
|
pChannel->ReleaseAllVoices(itRpnEvent); |
1733 |
|
} |
1734 |
|
} |
1735 |
|
|
1736 |
|
/** |
1737 |
|
* Process MIDI NRPN events with hard coded behavior. |
1738 |
|
* |
1739 |
|
* @param pEngineChannel - engine channel on which the MIDI NRPN |
1740 |
|
* event was received |
1741 |
|
* @param itRpnEvent - the actual MIDI NRPN event |
1742 |
|
*/ |
1743 |
|
void ProcessHardcodedNrpn(EngineChannel* pEngineChannel, |
1744 |
|
Pool<Event>::Iterator& itNrpnEvent) |
1745 |
|
{ |
1746 |
|
EngineChannelBase<V, R, I>* pChannel = |
1747 |
|
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1748 |
|
|
1749 |
|
switch (itNrpnEvent->Param.NRPN.ParameterMSB()) { |
1750 |
|
case 0x1a: { // volume level of note (Roland GS NRPN) |
1751 |
|
const uint note = itNrpnEvent->Param.NRPN.ParameterLSB(); |
1752 |
|
const uint vol = itNrpnEvent->Param.NRPN.ValueMSB(); |
1753 |
|
dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol)); |
1754 |
|
if (note < 128 && vol < 128) |
1755 |
|
pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol]; |
1756 |
|
break; |
1757 |
|
} |
1758 |
|
case 0x1c: { // panpot of note (Roland GS NRPN) |
1759 |
|
const uint note = itNrpnEvent->Param.NRPN.ParameterLSB(); |
1760 |
|
const uint pan = itNrpnEvent->Param.NRPN.ValueMSB(); |
1761 |
|
dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan)); |
1762 |
|
if (note < 128 && pan < 128) { |
1763 |
|
pChannel->pMIDIKeyInfo[note].PanLeft = PanCurve[128 - pan]; |
1764 |
|
pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan]; |
1765 |
|
} |
1766 |
|
break; |
1767 |
|
} |
1768 |
|
case 0x1d: { // reverb send of note (Roland GS NRPN) |
1769 |
|
const uint note = itNrpnEvent->Param.NRPN.ParameterLSB(); |
1770 |
|
const float reverb = float(itNrpnEvent->Param.NRPN.Value) / 16383.f; |
1771 |
|
dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb)); |
1772 |
|
if (note < 128) |
1773 |
|
pChannel->pMIDIKeyInfo[note].ReverbSend = reverb; |
1774 |
|
break; |
1775 |
|
} |
1776 |
|
case 0x1e: { // chorus send of note (Roland GS NRPN) |
1777 |
|
const uint note = itNrpnEvent->Param.NRPN.ParameterLSB(); |
1778 |
|
const float chorus = float(itNrpnEvent->Param.NRPN.Value) / 16383.f; |
1779 |
|
dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus)); |
1780 |
|
if (note < 128) |
1781 |
|
pChannel->pMIDIKeyInfo[note].ChorusSend = chorus; |
1782 |
|
break; |
1783 |
|
} |
1784 |
|
} |
1785 |
|
} |
1786 |
|
|
1787 |
virtual D* CreateDiskThread() = 0; |
virtual D* CreateDiskThread() = 0; |
1788 |
|
|
1789 |
/** |
/** |
1792 |
* @param pEngineChannel - engine channel on which this event occurred on |
* @param pEngineChannel - engine channel on which this event occurred on |
1793 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
1794 |
*/ |
*/ |
1795 |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE { |
1796 |
EngineChannelBase<V, R, I>* pChannel = |
EngineChannelBase<V, R, I>* pChannel = |
1797 |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1798 |
|
|
1802 |
|
|
1803 |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[key]; |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[key]; |
1804 |
|
|
1805 |
pChannel->listeners.PreProcessNoteOn(key, vel); |
// There are real MIDI note-on events (Event::type_note_on) and |
1806 |
|
// programmatically spawned notes (Event::type_play_note). We have |
1807 |
|
// to distinguish between them, since certain processing below |
1808 |
|
// must only be done on real MIDI note-on events (i.e. for |
1809 |
|
// correctly updating which MIDI keys are currently pressed down). |
1810 |
|
const bool isRealMIDINoteOnEvent = itNoteOnEvent->Type == Event::type_note_on; |
1811 |
|
|
1812 |
|
if (isRealMIDINoteOnEvent) |
1813 |
|
pChannel->listeners.PreProcessNoteOn(key, vel); |
1814 |
|
|
1815 |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1816 |
if (pEngineChannel->GetMute()) { // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) { // skip if sampler channel is muted |
1817 |
pChannel->listeners.PostProcessNoteOn(key, vel); |
if (isRealMIDINoteOnEvent) |
1818 |
|
pChannel->listeners.PostProcessNoteOn(key, vel); |
1819 |
return; |
return; |
1820 |
} |
} |
1821 |
#endif |
#endif |
1822 |
|
|
1823 |
if (!pChannel->pInstrument) { |
if (!pChannel->pInstrument) { |
1824 |
pChannel->listeners.PostProcessNoteOn(key, vel); |
if (isRealMIDINoteOnEvent) |
1825 |
|
pChannel->listeners.PostProcessNoteOn(key, vel); |
1826 |
return; // ignore if no instrument loaded |
return; // ignore if no instrument loaded |
1827 |
} |
} |
1828 |
|
|
1830 |
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
1831 |
|
|
1832 |
// if Solo Mode then kill all already active voices |
// if Solo Mode then kill all already active voices |
1833 |
if (pChannel->SoloMode) { |
if (pChannel->SoloMode && isRealMIDINoteOnEvent) { |
1834 |
Pool<uint>::Iterator itYoungestKey = pChannel->pActiveKeys->last(); |
Pool<uint>::Iterator itYoungestKey = pChannel->pActiveKeys->last(); |
1835 |
if (itYoungestKey) { |
if (itYoungestKey) { |
1836 |
const int iYoungestKey = *itYoungestKey; |
const int iYoungestKey = *itYoungestKey; |
1859 |
pChannel->SoloKey = key; |
pChannel->SoloKey = key; |
1860 |
} |
} |
1861 |
|
|
1862 |
pChannel->ProcessKeySwitchChange(key); |
if (isRealMIDINoteOnEvent) { |
1863 |
|
pChannel->ProcessKeySwitchChange(key); |
1864 |
|
|
1865 |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
1866 |
pChannel->KeyDown[key] = true; // just used as built-in %KEY_DOWN script variable |
pChannel->KeyDown[key] = true; // just used as built-in %KEY_DOWN script variable |
1867 |
pKey->Velocity = itNoteOnEventOnKeyList->Param.Note.Velocity; |
pKey->Velocity = itNoteOnEventOnKeyList->Param.Note.Velocity; |
1868 |
pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length |
pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length |
1869 |
|
} |
1870 |
|
|
1871 |
// cancel release process of voices on this key if needed |
// cancel release process of voices on this key if needed |
1872 |
if (pKey->Active && !pChannel->SustainPedal) { |
if (pKey->Active && !pChannel->SustainPedal && isRealMIDINoteOnEvent) { |
1873 |
RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend(); |
1874 |
if (itCancelReleaseEvent) { |
if (itCancelReleaseEvent) { |
1875 |
*itCancelReleaseEvent = *itNoteOnEventOnKeyList; // copy event |
*itCancelReleaseEvent = *itNoteOnEventOnKeyList; // copy event |
1876 |
itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type |
itCancelReleaseEvent->Type = Event::type_cancel_release_key; // transform event type |
1877 |
} |
} |
1878 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
1879 |
} |
} |
1884 |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
1885 |
pKey->pEvents->free(itNoteOnEventOnKeyList); |
pKey->pEvents->free(itNoteOnEventOnKeyList); |
1886 |
|
|
1887 |
if (!pChannel->SoloMode || pChannel->PortamentoPos < 0.0f) pChannel->PortamentoPos = (float) key; |
if (isRealMIDINoteOnEvent && (!pChannel->SoloMode || pChannel->PortamentoPos < 0.0f)) |
1888 |
|
pChannel->PortamentoPos = (float) key; |
1889 |
|
|
1890 |
|
//NOTE: Hmm, I guess its a matter of taste whether round robin should be advanced only on real MIDI note-on events, isn't it? |
1891 |
if (pKey->pRoundRobinIndex) { |
if (pKey->pRoundRobinIndex) { |
1892 |
(*pKey->pRoundRobinIndex)++; // counter specific for the key or region |
(*pKey->pRoundRobinIndex)++; // counter specific for the key or region |
1893 |
pChannel->RoundRobinIndex++; // common counter for the channel |
pChannel->RoundRobinIndex++; // common counter for the channel |
1894 |
} |
} |
1895 |
pChannel->listeners.PostProcessNoteOn(key, vel); |
|
1896 |
|
if (isRealMIDINoteOnEvent) |
1897 |
|
pChannel->listeners.PostProcessNoteOn(key, vel); |
1898 |
} |
} |
1899 |
|
|
1900 |
/** |
/** |
1923 |
* @param pEngineChannel - engine channel on which this event occurred on |
* @param pEngineChannel - engine channel on which this event occurred on |
1924 |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
1925 |
*/ |
*/ |
1926 |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE { |
1927 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1928 |
|
|
1929 |
const int iKey = itNoteOffEvent->Param.Note.Key; |
const int iKey = itNoteOffEvent->Param.Note.Key; |
1932 |
|
|
1933 |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[iKey]; |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[iKey]; |
1934 |
|
|
1935 |
pChannel->listeners.PreProcessNoteOff(iKey, vel); |
// There are real MIDI note-off events (Event::type_note_off) and |
1936 |
|
// programmatically spawned notes (Event::type_stop_note). We have |
1937 |
|
// to distinguish between them, since certain processing below |
1938 |
|
// must only be done on real MIDI note-off events (i.e. for |
1939 |
|
// correctly updating which MIDI keys are currently pressed down), |
1940 |
|
// plus a stop-note event just releases voices of one particular |
1941 |
|
// note, whereas a note-off event releases all voices on a |
1942 |
|
// particular MIDI key instead. |
1943 |
|
const bool isRealMIDINoteOffEvent = itNoteOffEvent->Type == Event::type_note_off; |
1944 |
|
|
1945 |
|
if (isRealMIDINoteOffEvent) |
1946 |
|
pChannel->listeners.PreProcessNoteOff(iKey, vel); |
1947 |
|
|
1948 |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1949 |
if (pEngineChannel->GetMute()) { // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) { // skip if sampler channel is muted |
1950 |
pChannel->listeners.PostProcessNoteOff(iKey, vel); |
if (isRealMIDINoteOffEvent) |
1951 |
|
pChannel->listeners.PostProcessNoteOff(iKey, vel); |
1952 |
return; |
return; |
1953 |
} |
} |
1954 |
#endif |
#endif |
1955 |
|
|
1956 |
pKey->KeyPressed = false; // the MIDI key was now released |
if (isRealMIDINoteOffEvent) { |
1957 |
pChannel->KeyDown[iKey] = false; // just used as built-in %KEY_DOWN script variable |
pKey->KeyPressed = false; // the MIDI key was now released |
1958 |
|
pChannel->KeyDown[iKey] = false; // just used as built-in %KEY_DOWN script variable |
1959 |
|
} |
1960 |
|
|
1961 |
// move event to the key's own event list |
// move event to the key's own event list |
1962 |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
1963 |
|
|
1964 |
bool bShouldRelease = pKey->Active && pChannel->ShouldReleaseVoice(itNoteOffEventOnKeyList->Param.Note.Key); |
if (isRealMIDINoteOffEvent) { |
1965 |
|
bool bShouldRelease = pKey->Active && pChannel->ShouldReleaseVoice(itNoteOffEventOnKeyList->Param.Note.Key); |
1966 |
|
|
1967 |
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
1968 |
if (pChannel->SoloMode && pChannel->pInstrument) { //TODO: this feels like too much code just for handling solo mode :P |
if (pChannel->SoloMode && pChannel->pInstrument) { //TODO: this feels like too much code just for handling solo mode :P |
1969 |
bool bOtherKeysPressed = false; |
bool bOtherKeysPressed = false; |
1970 |
if (iKey == pChannel->SoloKey) { |
if (iKey == pChannel->SoloKey) { |
1971 |
pChannel->SoloKey = -1; |
pChannel->SoloKey = -1; |
1972 |
// if there's still a key pressed down, respawn a voice (group) on the highest key |
// if there's still a key pressed down, respawn a voice (group) on the highest key |
1973 |
for (int i = 127; i > 0; i--) { |
for (int i = 127; i > 0; i--) { |
1974 |
MidiKey* pOtherKey = &pChannel->pMIDIKeyInfo[i]; |
MidiKey* pOtherKey = &pChannel->pMIDIKeyInfo[i]; |
1975 |
if (pOtherKey->KeyPressed) { |
if (pOtherKey->KeyPressed) { |
1976 |
bOtherKeysPressed = true; |
bOtherKeysPressed = true; |
1977 |
// make the other key the new 'currently active solo key' |
// make the other key the new 'currently active solo key' |
1978 |
pChannel->SoloKey = i; |
pChannel->SoloKey = i; |
1979 |
// get final portamento position of currently active voice |
// get final portamento position of currently active voice |
1980 |
if (pChannel->PortamentoMode) { |
if (pChannel->PortamentoMode) { |
1981 |
NoteIterator itNote = pKey->pActiveNotes->first(); |
NoteIterator itNote = pKey->pActiveNotes->first(); |
1982 |
VoiceIterator itVoice = itNote->pActiveVoices->first(); |
VoiceIterator itVoice = itNote->pActiveVoices->first(); |
1983 |
if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList); |
if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList); |
|
} |
|
|
// create a pseudo note on event |
|
|
RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend(); |
|
|
if (itPseudoNoteOnEvent) { |
|
|
// copy event |
|
|
*itPseudoNoteOnEvent = *itNoteOffEventOnKeyList; |
|
|
// transform event to a note on event |
|
|
itPseudoNoteOnEvent->Type = Event::type_note_on; |
|
|
itPseudoNoteOnEvent->Param.Note.Key = i; |
|
|
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
|
|
// assign a new note to this note-on event |
|
|
if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) { |
|
|
// allocate and trigger new voice(s) for the other key |
|
|
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
|
1984 |
} |
} |
1985 |
// if neither a voice was spawned or postponed then remove note on event from key again |
// create a pseudo note on event |
1986 |
if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued) |
RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend(); |
1987 |
pOtherKey->pEvents->free(itPseudoNoteOnEvent); |
if (itPseudoNoteOnEvent) { |
1988 |
|
// copy event |
1989 |
|
*itPseudoNoteOnEvent = *itNoteOffEventOnKeyList; |
1990 |
|
// transform event to a note on event |
1991 |
|
itPseudoNoteOnEvent->Type = Event::type_note_on; //FIXME: should probably use Event::type_play_note instead (to avoid i.e. hanging notes) |
1992 |
|
itPseudoNoteOnEvent->Param.Note.Key = i; |
1993 |
|
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
1994 |
|
// assign a new note to this note-on event |
1995 |
|
if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) { |
1996 |
|
// allocate and trigger new voice(s) for the other key |
1997 |
|
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
1998 |
|
} |
1999 |
|
// if neither a voice was spawned or postponed then remove note on event from key again |
2000 |
|
if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued) |
2001 |
|
pOtherKey->pEvents->free(itPseudoNoteOnEvent); |
2002 |
|
|
2003 |
} else dmsg(1,("Could not respawn voice, no free event left\n")); |
} else dmsg(1,("Could not respawn voice, no free event left\n")); |
2004 |
break; // done |
break; // done |
2005 |
|
} |
2006 |
} |
} |
2007 |
} |
} |
2008 |
} |
if (bOtherKeysPressed) { |
2009 |
if (bOtherKeysPressed) { |
if (pKey->Active) { // kill all voices on this key |
2010 |
if (pKey->Active) { // kill all voices on this key |
bShouldRelease = false; // no need to release, as we kill it here |
2011 |
bShouldRelease = false; // no need to release, as we kill it here |
for (NoteIterator itNote = pKey->pActiveNotes->first(); itNote; ++itNote) { |
2012 |
for (NoteIterator itNote = pKey->pActiveNotes->first(); itNote; ++itNote) { |
VoiceIterator itVoiceToBeKilled = itNote->pActiveVoices->first(); |
2013 |
VoiceIterator itVoiceToBeKilled = itNote->pActiveVoices->first(); |
VoiceIterator end = itNote->pActiveVoices->end(); |
2014 |
VoiceIterator end = itNote->pActiveVoices->end(); |
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
2015 |
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
if (!(itVoiceToBeKilled->Type & Voice::type_release_trigger)) |
2016 |
if (!(itVoiceToBeKilled->Type & Voice::type_release_trigger)) |
itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList); |
2017 |
itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList); |
} |
2018 |
} |
} |
2019 |
} |
} |
2020 |
} |
} else pChannel->PortamentoPos = -1.0f; |
2021 |
} else pChannel->PortamentoPos = -1.0f; |
} |
|
} |
|
|
|
|
|
// if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed |
|
|
if (bShouldRelease) { |
|
|
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
|
2022 |
|
|
2023 |
// spawn release triggered voice(s) if needed |
// if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed |
2024 |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
if (bShouldRelease) { |
2025 |
// assign a new note to this release event |
itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type |
2026 |
if (LaunchNewNote(pChannel, &*itNoteOffEventOnKeyList)) { |
// spawn release triggered voice(s) if needed |
2027 |
// allocate and trigger new release voice(s) |
if (pKey->ReleaseTrigger & release_trigger_noteoff) |
2028 |
TriggerReleaseVoices(pChannel, itNoteOffEventOnKeyList); |
ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey); |
2029 |
} |
} |
2030 |
pKey->ReleaseTrigger = false; |
} else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) { |
2031 |
|
// This programmatically caused event is caused by a call to |
2032 |
|
// the built-in instrument script function note_off(). In |
2033 |
|
// contrast to a real MIDI note-off event the stop-note |
2034 |
|
// event just intends to release voices of one particular note. |
2035 |
|
NoteBase* pNote = pChannel->pEngine->NoteByID( itNoteOffEventOnKeyList->Param.Note.ID ); |
2036 |
|
if (pNote) { // the requested note is still alive ... |
2037 |
|
itNoteOffEventOnKeyList->Type = Event::type_release_note; // transform event type |
2038 |
|
} else { // note is dead and gone .. |
2039 |
|
pKey->pEvents->free(itNoteOffEventOnKeyList); // remove stop-note event from key again |
2040 |
|
return; // prevent event to be removed a 2nd time below |
2041 |
} |
} |
2042 |
} |
} |
2043 |
|
|
2045 |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
2046 |
pKey->pEvents->free(itNoteOffEventOnKeyList); |
pKey->pEvents->free(itNoteOffEventOnKeyList); |
2047 |
|
|
2048 |
pChannel->listeners.PostProcessNoteOff(iKey, vel); |
if (isRealMIDINoteOffEvent) |
2049 |
|
pChannel->listeners.PostProcessNoteOff(iKey, vel); |
2050 |
|
} |
2051 |
|
|
2052 |
|
/** |
2053 |
|
* Called on sustain pedal up events to check and if required, |
2054 |
|
* launch release trigger voices on the respective active key. |
2055 |
|
* |
2056 |
|
* @param pEngineChannel - engine channel on which this event occurred on |
2057 |
|
* @param itEvent - release trigger event (contains note number) |
2058 |
|
*/ |
2059 |
|
virtual void ProcessReleaseTriggerBySustain(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE { |
2060 |
|
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
2061 |
|
|
2062 |
|
const int iKey = itEvent->Param.Note.Key; |
2063 |
|
if (iKey < 0 || iKey > 127) return; // ignore event, key outside allowed key range |
2064 |
|
|
2065 |
|
MidiKey* pKey = &pChannel->pMIDIKeyInfo[iKey]; |
2066 |
|
|
2067 |
|
ProcessReleaseTrigger(pChannel, itEvent, pKey); |
2068 |
|
} |
2069 |
|
|
2070 |
|
/** |
2071 |
|
* Called on note-off and sustain pedal up events to check and if |
2072 |
|
* required, launch release trigger voices on the respective active |
2073 |
|
* key. |
2074 |
|
* |
2075 |
|
* @param pEngineChannel - engine channel on which this event occurred on |
2076 |
|
* @param itEvent - note off event / release trigger event |
2077 |
|
* @param pKey - key on which the release trigger voices shall be spawned |
2078 |
|
*/ |
2079 |
|
inline void ProcessReleaseTrigger(EngineChannelBase<V, R, I>* pChannel, RTList<Event>::Iterator& itEvent, MidiKey* pKey) { |
2080 |
|
// spawn release triggered voice(s) if needed |
2081 |
|
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
2082 |
|
// assign a new note to this release event |
2083 |
|
if (LaunchNewNote(pChannel, itEvent)) { |
2084 |
|
// allocate and trigger new release voice(s) |
2085 |
|
TriggerReleaseVoices(pChannel, itEvent); |
2086 |
|
} |
2087 |
|
pKey->ReleaseTrigger = release_trigger_none; |
2088 |
|
} |
2089 |
|
} |
2090 |
|
|
2091 |
|
/** |
2092 |
|
* Called on "kill note" events, which currently only happens on |
2093 |
|
* built-in real-time instrument script function fade_out(). This |
2094 |
|
* method only fulfills one task: moving the even to the Note's own |
2095 |
|
* event list so that its voices can process the kill event sample |
2096 |
|
* accurately. |
2097 |
|
*/ |
2098 |
|
void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) { |
2099 |
|
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
2100 |
|
|
2101 |
|
NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID ); |
2102 |
|
if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return; |
2103 |
|
|
2104 |
|
// move note kill event to its MIDI key |
2105 |
|
MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey]; |
2106 |
|
itEvent.moveToEndOf(pKey->pEvents); |
2107 |
|
} |
2108 |
|
|
2109 |
|
/** |
2110 |
|
* Called on note synthesis parameter change events. These are |
2111 |
|
* internal events caused by calling built-in real-time instrument |
2112 |
|
* script functions like change_vol(), change_tune(), etc. |
2113 |
|
* |
2114 |
|
* This method performs two tasks: |
2115 |
|
* |
2116 |
|
* - It converts the event's relative values changes (Deltas) to |
2117 |
|
* the respective final new synthesis parameter value (AbsValue), |
2118 |
|
* for that particular moment of the event that is. |
2119 |
|
* |
2120 |
|
* - It moves the individual events to the Note's own event list |
2121 |
|
* (or actually to the event list of the MIDI key), so that |
2122 |
|
* voices can process those events sample accurately. |
2123 |
|
* |
2124 |
|
* @param pEngineChannel - engine channel on which this event occurred on |
2125 |
|
* @param itEvent - note synthesis parameter change event |
2126 |
|
*/ |
2127 |
|
virtual void ProcessNoteSynthParam(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) { |
2128 |
|
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
2129 |
|
|
2130 |
|
NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID ); |
2131 |
|
if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return; |
2132 |
|
|
2133 |
|
switch (itEvent->Param.NoteSynthParam.Type) { |
2134 |
|
case Event::synth_param_volume: |
2135 |
|
pNote->apply(itEvent, &NoteBase::_Override::Volume); |
2136 |
|
break; |
2137 |
|
case Event::synth_param_volume_time: |
2138 |
|
pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2139 |
|
break; |
2140 |
|
case Event::synth_param_volume_curve: |
2141 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2142 |
|
pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2143 |
|
break; |
2144 |
|
case Event::synth_param_pitch: |
2145 |
|
pNote->apply(itEvent, &NoteBase::_Override::Pitch); |
2146 |
|
break; |
2147 |
|
case Event::synth_param_pitch_time: |
2148 |
|
pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2149 |
|
break; |
2150 |
|
case Event::synth_param_pitch_curve: |
2151 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2152 |
|
pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2153 |
|
break; |
2154 |
|
case Event::synth_param_pan: |
2155 |
|
pNote->apply(itEvent, &NoteBase::_Override::Pan); |
2156 |
|
break; |
2157 |
|
case Event::synth_param_pan_time: |
2158 |
|
pNote->Override.PanTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2159 |
|
break; |
2160 |
|
case Event::synth_param_pan_curve: |
2161 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2162 |
|
pNote->Override.PanCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2163 |
|
break; |
2164 |
|
case Event::synth_param_cutoff: |
2165 |
|
pNote->apply(itEvent, &NoteBase::_Override::Cutoff); |
2166 |
|
break; |
2167 |
|
case Event::synth_param_resonance: |
2168 |
|
pNote->apply(itEvent, &NoteBase::_Override::Resonance); |
2169 |
|
break; |
2170 |
|
case Event::synth_param_attack: |
2171 |
|
pNote->apply(itEvent, &NoteBase::_Override::Attack); |
2172 |
|
break; |
2173 |
|
case Event::synth_param_decay: |
2174 |
|
pNote->apply(itEvent, &NoteBase::_Override::Decay); |
2175 |
|
break; |
2176 |
|
case Event::synth_param_sustain: |
2177 |
|
pNote->apply(itEvent, &NoteBase::_Override::Sustain); |
2178 |
|
break; |
2179 |
|
case Event::synth_param_release: |
2180 |
|
pNote->apply(itEvent, &NoteBase::_Override::Release); |
2181 |
|
break; |
2182 |
|
|
2183 |
|
case Event::synth_param_cutoff_attack: |
2184 |
|
pNote->apply(itEvent, &NoteBase::_Override::CutoffAttack); |
2185 |
|
break; |
2186 |
|
case Event::synth_param_cutoff_decay: |
2187 |
|
pNote->apply(itEvent, &NoteBase::_Override::CutoffDecay); |
2188 |
|
break; |
2189 |
|
case Event::synth_param_cutoff_sustain: |
2190 |
|
pNote->apply(itEvent, &NoteBase::_Override::CutoffSustain); |
2191 |
|
break; |
2192 |
|
case Event::synth_param_cutoff_release: |
2193 |
|
pNote->apply(itEvent, &NoteBase::_Override::CutoffRelease); |
2194 |
|
break; |
2195 |
|
|
2196 |
|
case Event::synth_param_amp_lfo_depth: |
2197 |
|
pNote->apply(itEvent, &NoteBase::_Override::AmpLFODepth); |
2198 |
|
break; |
2199 |
|
case Event::synth_param_amp_lfo_freq: |
2200 |
|
pNote->apply(itEvent, &NoteBase::_Override::AmpLFOFreq); |
2201 |
|
break; |
2202 |
|
case Event::synth_param_cutoff_lfo_depth: |
2203 |
|
pNote->apply(itEvent, &NoteBase::_Override::CutoffLFODepth); |
2204 |
|
break; |
2205 |
|
case Event::synth_param_cutoff_lfo_freq: |
2206 |
|
pNote->apply(itEvent, &NoteBase::_Override::CutoffLFOFreq); |
2207 |
|
break; |
2208 |
|
case Event::synth_param_pitch_lfo_depth: |
2209 |
|
pNote->apply(itEvent, &NoteBase::_Override::PitchLFODepth); |
2210 |
|
break; |
2211 |
|
case Event::synth_param_pitch_lfo_freq: |
2212 |
|
pNote->apply(itEvent, &NoteBase::_Override::PitchLFOFreq); |
2213 |
|
break; |
2214 |
|
} |
2215 |
|
|
2216 |
|
// move note parameter event to its MIDI key |
2217 |
|
MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey]; |
2218 |
|
itEvent.moveToEndOf(pKey->pEvents); |
2219 |
} |
} |
2220 |
|
|
2221 |
/** |
/** |
2222 |
* Reset all voices and disk thread and clear input event queue and all |
* Reset all voices and disk thread and clear input event queue and all |
2223 |
* control and status variables. This method is protected by a mutex. |
* control and status variables. This method is protected by a mutex. |
2224 |
*/ |
*/ |
2225 |
virtual void ResetInternal() { |
virtual void ResetInternal() OVERRIDE { |
2226 |
LockGuard lock(ResetInternalMutex); |
LockGuard lock(ResetInternalMutex); |
2227 |
|
|
2228 |
// make sure that the engine does not get any sysex messages |
// make sure that the engine does not get any sysex messages |
2281 |
* @param pEngineChannel - engine channel on which all voices should be killed |
* @param pEngineChannel - engine channel on which all voices should be killed |
2282 |
* @param itKillEvent - event which caused this killing of all voices |
* @param itKillEvent - event which caused this killing of all voices |
2283 |
*/ |
*/ |
2284 |
virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) { |
virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE { |
2285 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
2286 |
int count = pChannel->KillAllVoices(itKillEvent); |
int count = pChannel->KillAllVoices(itKillEvent); |
2287 |
VoiceSpawnsLeft -= count; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead |
VoiceSpawnsLeft -= count; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead |
2316 |
bool HandleKeyGroupConflicts |
bool HandleKeyGroupConflicts |
2317 |
) = 0; |
) = 0; |
2318 |
|
|
2319 |
virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; } |
virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; } |
2320 |
|
|
2321 |
int InitNewVoice ( |
int InitNewVoice ( |
2322 |
EngineChannelBase<V, R, I>* pChannel, |
EngineChannelBase<V, R, I>* pChannel, |
2339 |
} |
} |
2340 |
else { // on success |
else { // on success |
2341 |
--VoiceSpawnsLeft; |
--VoiceSpawnsLeft; |
2342 |
if (!pKey->Active) { // mark as active key |
|
2343 |
pKey->Active = true; |
// should actually be superfluous now, since this is |
2344 |
pKey->itSelf = pChannel->pActiveKeys->allocAppend(); |
// already done in LaunchNewNote() |
2345 |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
pChannel->markKeyAsActive(pKey); |
2346 |
} |
|
2347 |
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) |
2348 |
|
pKey->ReleaseTrigger |= itNewVoice->GetReleaseTriggerFlags(); // mark key for the need of release triggered voice(s) |
2349 |
return 0; // success |
return 0; // success |
2350 |
} |
} |
2351 |
} |
} |