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 |
|
|
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 |
// remember the engine's time when this note was triggered exactly |
710 |
itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime(); |
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, |
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 |
902 |
dmsg(5,("Engine: Stop Note received\n")); |
dmsg(5,("Engine: Stop Note received\n")); |
903 |
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
904 |
break; |
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); |
926 |
dmsg(5,("Engine: Note Synth Param received\n")); |
dmsg(5,("Engine: Note Synth Param received\n")); |
927 |
ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent); |
ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent); |
928 |
break; |
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; |
itScriptEvent->ignoreAllWaitCalls = false; |
1044 |
itScriptEvent->handlerType = pEventHandler->eventHandlerType(); |
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 |
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; |
itScriptEvent->currentHandler = 0; |
1333 |
itScriptEvent->executionSlices = 0; |
itScriptEvent->executionSlices = 0; |
1334 |
itScriptEvent->ignoreAllWaitCalls = false; |
itScriptEvent->ignoreAllWaitCalls = false; |
1335 |
itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; |
itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; |
1336 |
|
itScriptEvent->parentHandlerID = 0; |
1337 |
VMExecStatus_t res = pScriptVM->exec( |
itScriptEvent->childHandlerID[0] = 0; |
1338 |
pEngineChannel->pScript->parserContext, &*itScriptEvent |
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) |
1690 |
* @param pEngineChannel - engine channel on which this event occurred on |
* @param pEngineChannel - engine channel on which this event occurred on |
1691 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
1692 |
*/ |
*/ |
1693 |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE { |
1694 |
EngineChannelBase<V, R, I>* pChannel = |
EngineChannelBase<V, R, I>* pChannel = |
1695 |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1696 |
|
|
1821 |
* @param pEngineChannel - engine channel on which this event occurred on |
* @param pEngineChannel - engine channel on which this event occurred on |
1822 |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
1823 |
*/ |
*/ |
1824 |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE { |
1825 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1826 |
|
|
1827 |
const int iKey = itNoteOffEvent->Param.Note.Key; |
const int iKey = itNoteOffEvent->Param.Note.Key; |
1890 |
itPseudoNoteOnEvent->Param.Note.Key = i; |
itPseudoNoteOnEvent->Param.Note.Key = i; |
1891 |
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
1892 |
// assign a new note to this note-on event |
// assign a new note to this note-on event |
1893 |
if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) { |
if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) { |
1894 |
// allocate and trigger new voice(s) for the other key |
// allocate and trigger new voice(s) for the other key |
1895 |
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
1896 |
} |
} |
1977 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
1978 |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
1979 |
// assign a new note to this release event |
// assign a new note to this release event |
1980 |
if (LaunchNewNote(pChannel, &*itEvent)) { |
if (LaunchNewNote(pChannel, itEvent)) { |
1981 |
// allocate and trigger new release voice(s) |
// allocate and trigger new release voice(s) |
1982 |
TriggerReleaseVoices(pChannel, itEvent); |
TriggerReleaseVoices(pChannel, itEvent); |
1983 |
} |
} |
1986 |
} |
} |
1987 |
|
|
1988 |
/** |
/** |
1989 |
|
* Called on "kill note" events, which currently only happens on |
1990 |
|
* built-in real-time instrument script function fade_out(). This |
1991 |
|
* method only fulfills one task: moving the even to the Note's own |
1992 |
|
* event list so that its voices can process the kill event sample |
1993 |
|
* accurately. |
1994 |
|
*/ |
1995 |
|
void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) { |
1996 |
|
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1997 |
|
|
1998 |
|
NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID ); |
1999 |
|
if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return; |
2000 |
|
|
2001 |
|
// move note kill event to its MIDI key |
2002 |
|
MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey]; |
2003 |
|
itEvent.moveToEndOf(pKey->pEvents); |
2004 |
|
} |
2005 |
|
|
2006 |
|
/** |
2007 |
* Called on note synthesis parameter change events. These are |
* Called on note synthesis parameter change events. These are |
2008 |
* internal events caused by calling built-in real-time instrument |
* internal events caused by calling built-in real-time instrument |
2009 |
* script functions like change_vol(), change_pitch(), etc. |
* script functions like change_vol(), change_tune(), etc. |
2010 |
* |
* |
2011 |
* This method performs two tasks: |
* This method performs two tasks: |
2012 |
* |
* |
2037 |
pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta; |
2038 |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume; |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume; |
2039 |
break; |
break; |
2040 |
|
case Event::synth_param_volume_time: |
2041 |
|
pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2042 |
|
break; |
2043 |
|
case Event::synth_param_volume_curve: |
2044 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2045 |
|
pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2046 |
|
break; |
2047 |
case Event::synth_param_pitch: |
case Event::synth_param_pitch: |
2048 |
if (relative) |
if (relative) |
2049 |
pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta; |
2051 |
pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta; |
2052 |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch; |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch; |
2053 |
break; |
break; |
2054 |
|
case Event::synth_param_pitch_time: |
2055 |
|
pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2056 |
|
break; |
2057 |
|
case Event::synth_param_pitch_curve: |
2058 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2059 |
|
pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2060 |
|
break; |
2061 |
case Event::synth_param_pan: |
case Event::synth_param_pan: |
2062 |
if (relative) { |
if (relative) { |
2063 |
pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources); |
pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources); |
2067 |
} |
} |
2068 |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pan; |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pan; |
2069 |
break; |
break; |
2070 |
|
case Event::synth_param_pan_time: |
2071 |
|
pNote->Override.PanTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2072 |
|
break; |
2073 |
|
case Event::synth_param_pan_curve: |
2074 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2075 |
|
pNote->Override.PanCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2076 |
|
break; |
2077 |
case Event::synth_param_cutoff: |
case Event::synth_param_cutoff: |
2078 |
pNote->Override.Cutoff = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Cutoff = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2079 |
break; |
break; |
2086 |
case Event::synth_param_decay: |
case Event::synth_param_decay: |
2087 |
pNote->Override.Decay = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Decay = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2088 |
break; |
break; |
2089 |
|
case Event::synth_param_sustain: |
2090 |
|
pNote->Override.Sustain = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2091 |
|
break; |
2092 |
case Event::synth_param_release: |
case Event::synth_param_release: |
2093 |
pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2094 |
break; |
break; |
2095 |
|
case Event::synth_param_amp_lfo_depth: |
2096 |
|
pNote->Override.AmpLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2097 |
|
break; |
2098 |
|
case Event::synth_param_amp_lfo_freq: |
2099 |
|
pNote->Override.AmpLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2100 |
|
break; |
2101 |
|
case Event::synth_param_pitch_lfo_depth: |
2102 |
|
pNote->Override.PitchLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2103 |
|
break; |
2104 |
|
case Event::synth_param_pitch_lfo_freq: |
2105 |
|
pNote->Override.PitchLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2106 |
|
break; |
2107 |
} |
} |
2108 |
|
|
2109 |
// move note parameter event to its MIDI key |
// move note parameter event to its MIDI key |
2115 |
* 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 |
2116 |
* control and status variables. This method is protected by a mutex. |
* control and status variables. This method is protected by a mutex. |
2117 |
*/ |
*/ |
2118 |
virtual void ResetInternal() { |
virtual void ResetInternal() OVERRIDE { |
2119 |
LockGuard lock(ResetInternalMutex); |
LockGuard lock(ResetInternalMutex); |
2120 |
|
|
2121 |
// make sure that the engine does not get any sysex messages |
// make sure that the engine does not get any sysex messages |
2174 |
* @param pEngineChannel - engine channel on which all voices should be killed |
* @param pEngineChannel - engine channel on which all voices should be killed |
2175 |
* @param itKillEvent - event which caused this killing of all voices |
* @param itKillEvent - event which caused this killing of all voices |
2176 |
*/ |
*/ |
2177 |
virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) { |
virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE { |
2178 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
2179 |
int count = pChannel->KillAllVoices(itKillEvent); |
int count = pChannel->KillAllVoices(itKillEvent); |
2180 |
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 |
2209 |
bool HandleKeyGroupConflicts |
bool HandleKeyGroupConflicts |
2210 |
) = 0; |
) = 0; |
2211 |
|
|
2212 |
virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; } |
virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; } |
2213 |
|
|
2214 |
int InitNewVoice ( |
int InitNewVoice ( |
2215 |
EngineChannelBase<V, R, I>* pChannel, |
EngineChannelBase<V, R, I>* pChannel, |
2232 |
} |
} |
2233 |
else { // on success |
else { // on success |
2234 |
--VoiceSpawnsLeft; |
--VoiceSpawnsLeft; |
2235 |
if (!pKey->Active) { // mark as active key |
|
2236 |
pKey->Active = true; |
// should actually be superfluous now, since this is |
2237 |
pKey->itSelf = pChannel->pActiveKeys->allocAppend(); |
// already done in LaunchNewNote() |
2238 |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
pChannel->markKeyAsActive(pKey); |
2239 |
} |
|
2240 |
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) |
2241 |
return 0; // success |
return 0; // success |
2242 |
} |
} |