379 |
} |
} |
380 |
pVoicePool->clear(); |
pVoicePool->clear(); |
381 |
|
|
382 |
// (re)create event generator |
// update event generator |
383 |
if (pEventGenerator) delete pEventGenerator; |
pEventGenerator->SetSampleRate(pAudioOut->SampleRate()); |
|
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
|
384 |
|
|
385 |
dmsg(1,("Starting disk thread...")); |
dmsg(1,("Starting disk thread...")); |
386 |
pDiskThread->StartThread(); |
pDiskThread->StartThread(); |
675 |
* @param pNoteOnEvent - event which caused this |
* @param pNoteOnEvent - event which caused this |
676 |
* @returns new note's unique ID (or zero on error) |
* @returns new note's unique ID (or zero on error) |
677 |
*/ |
*/ |
678 |
note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) OVERRIDE { |
note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE { |
679 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
680 |
Pool< Note<V> >* pNotePool = GetNotePool(); |
Pool< Note<V> >* pNotePool = GetNotePool(); |
681 |
|
|
690 |
const note_id_t newNoteID = pNotePool->getID(itNewNote); |
const note_id_t newNoteID = pNotePool->getID(itNewNote); |
691 |
|
|
692 |
// remember the engine's time when this note was triggered exactly |
// remember the engine's time when this note was triggered exactly |
693 |
itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime(); |
itNewNote->triggerSchedTime = itNoteOnEvent->SchedTime(); |
694 |
|
|
695 |
// usually the new note (and its subsequent voices) will be |
// usually the new note (and its subsequent voices) will be |
696 |
// allocated on the key provided by the event's note number, |
// allocated on the key provided by the event's note number, |
698 |
// note, but rather a child note, then this new note will be |
// note, but rather a child note, then this new note will be |
699 |
// allocated on the parent note's key instead in order to |
// allocated on the parent note's key instead in order to |
700 |
// release the child note simultaniously with its parent note |
// release the child note simultaniously with its parent note |
701 |
itNewNote->hostKey = pNoteOnEvent->Param.Note.Key; |
itNewNote->hostKey = itNoteOnEvent->Param.Note.Key; |
702 |
|
|
703 |
// in case this new note was requested to be a child note, |
// in case this new note was requested to be a child note, |
704 |
// then retrieve its parent note and link them with each other |
// then retrieve its parent note and link them with each other |
705 |
const note_id_t parentNoteID = pNoteOnEvent->Param.Note.ParentNoteID; |
const note_id_t parentNoteID = itNoteOnEvent->Param.Note.ParentNoteID; |
706 |
if (parentNoteID) { |
if (parentNoteID) { |
707 |
NoteIterator itParentNote = pNotePool->fromID(parentNoteID); |
NoteIterator itParentNote = pNotePool->fromID(parentNoteID); |
708 |
if (itParentNote) { |
if (itParentNote) { |
730 |
dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey)); |
dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey)); |
731 |
|
|
732 |
// copy event which caused this note |
// copy event which caused this note |
733 |
itNewNote->cause = *pNoteOnEvent; |
itNewNote->cause = *itNoteOnEvent; |
734 |
itNewNote->eventID = pEventPool->getID(pNoteOnEvent); |
itNewNote->eventID = pEventPool->getID(itNoteOnEvent); |
735 |
|
if (!itNewNote->eventID) { |
736 |
|
dmsg(0,("Engine: No valid event ID resolved for note. This is a bug!!!\n")); |
737 |
|
} |
738 |
|
|
739 |
// move new note to its host key |
// move new note to its host key |
740 |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey]; |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey]; |
741 |
itNewNote.moveToEndOf(pKey->pActiveNotes); |
itNewNote.moveToEndOf(pKey->pActiveNotes); |
742 |
|
|
743 |
// 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 |
744 |
pNoteOnEvent->Param.Note.ID = newNoteID; |
itNoteOnEvent->Param.Note.ID = newNoteID; |
745 |
|
|
746 |
return newNoteID; // success |
return newNoteID; // success |
747 |
} |
} |
983 |
// script event object |
// script event object |
984 |
RTList<ScriptEvent>::Iterator itScriptEvent = |
RTList<ScriptEvent>::Iterator itScriptEvent = |
985 |
pChannel->pScript->pEvents->allocAppend(); |
pChannel->pScript->pEvents->allocAppend(); |
986 |
|
// if event handler uses polyphonic variables, reset them |
987 |
|
// to zero values before starting to execute the handler |
988 |
|
if (pEventHandler->isPolyphonic()) |
989 |
|
itScriptEvent->execCtx->resetPolyphonicData(); |
990 |
ProcessScriptEvent( |
ProcessScriptEvent( |
991 |
pChannel, itEvent, pEventHandler, itScriptEvent |
pChannel, itEvent, pEventHandler, itScriptEvent |
992 |
); |
); |
1019 |
|
|
1020 |
// initialize/reset other members |
// initialize/reset other members |
1021 |
itScriptEvent->cause = *itEvent; |
itScriptEvent->cause = *itEvent; |
1022 |
|
itScriptEvent->scheduleTime = itEvent->SchedTime(); |
1023 |
itScriptEvent->currentHandler = 0; |
itScriptEvent->currentHandler = 0; |
1024 |
itScriptEvent->executionSlices = 0; |
itScriptEvent->executionSlices = 0; |
1025 |
itScriptEvent->ignoreAllWaitCalls = false; |
itScriptEvent->ignoreAllWaitCalls = false; |
1295 |
RTList<ScriptEvent>::Iterator itScriptEvent = |
RTList<ScriptEvent>::Iterator itScriptEvent = |
1296 |
pEngineChannel->pScript->pEvents->allocAppend(); |
pEngineChannel->pScript->pEvents->allocAppend(); |
1297 |
|
|
1298 |
|
itScriptEvent->cause = pEventGenerator->CreateEvent(0); |
1299 |
|
itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing |
1300 |
itScriptEvent->cause.pEngineChannel = pEngineChannel; |
itScriptEvent->cause.pEngineChannel = pEngineChannel; |
1301 |
|
itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort(); |
1302 |
itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit; |
itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit; |
1303 |
itScriptEvent->handlers[1] = NULL; |
itScriptEvent->handlers[1] = NULL; |
1304 |
itScriptEvent->currentHandler = 0; |
itScriptEvent->currentHandler = 0; |
1306 |
itScriptEvent->ignoreAllWaitCalls = false; |
itScriptEvent->ignoreAllWaitCalls = false; |
1307 |
itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; |
itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; |
1308 |
|
|
1309 |
/*VMExecStatus_t res = */ pScriptVM->exec( |
VMExecStatus_t res; |
1310 |
pEngineChannel->pScript->parserContext, &*itScriptEvent |
size_t instructionsCount = 0; |
1311 |
); |
const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction) |
1312 |
|
bool bWarningShown = false; |
1313 |
|
do { |
1314 |
|
res = pScriptVM->exec( |
1315 |
|
pEngineChannel->pScript->parserContext, &*itScriptEvent |
1316 |
|
); |
1317 |
|
instructionsCount += itScriptEvent->execCtx->instructionsPerformed(); |
1318 |
|
if (instructionsCount > maxInstructions && !bWarningShown) { |
1319 |
|
bWarningShown = true; |
1320 |
|
dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n")); |
1321 |
|
} |
1322 |
|
} while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR)); |
1323 |
|
|
1324 |
pEngineChannel->pScript->pEvents->free(itScriptEvent); |
pEngineChannel->pScript->pEvents->free(itScriptEvent); |
1325 |
} |
} |
1380 |
// usually there should already be a new Note object |
// usually there should already be a new Note object |
1381 |
NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID); |
NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID); |
1382 |
if (!itNote) { // should not happen, but just to be sure ... |
if (!itNote) { // should not happen, but just to be sure ... |
1383 |
const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent); |
const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent); |
1384 |
if (!noteID) { |
if (!noteID) { |
1385 |
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")); |
1386 |
continue; |
continue; |
1857 |
itPseudoNoteOnEvent->Param.Note.Key = i; |
itPseudoNoteOnEvent->Param.Note.Key = i; |
1858 |
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
1859 |
// assign a new note to this note-on event |
// assign a new note to this note-on event |
1860 |
if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) { |
if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) { |
1861 |
// allocate and trigger new voice(s) for the other key |
// allocate and trigger new voice(s) for the other key |
1862 |
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
1863 |
} |
} |
1944 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
1945 |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
1946 |
// assign a new note to this release event |
// assign a new note to this release event |
1947 |
if (LaunchNewNote(pChannel, &*itEvent)) { |
if (LaunchNewNote(pChannel, itEvent)) { |
1948 |
// allocate and trigger new release voice(s) |
// allocate and trigger new release voice(s) |
1949 |
TriggerReleaseVoices(pChannel, itEvent); |
TriggerReleaseVoices(pChannel, itEvent); |
1950 |
} |
} |
2007 |
case Event::synth_param_volume_time: |
case Event::synth_param_volume_time: |
2008 |
pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2009 |
break; |
break; |
2010 |
|
case Event::synth_param_volume_curve: |
2011 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2012 |
|
pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2013 |
|
break; |
2014 |
case Event::synth_param_pitch: |
case Event::synth_param_pitch: |
2015 |
if (relative) |
if (relative) |
2016 |
pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta; |
2021 |
case Event::synth_param_pitch_time: |
case Event::synth_param_pitch_time: |
2022 |
pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2023 |
break; |
break; |
2024 |
|
case Event::synth_param_pitch_curve: |
2025 |
|
itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2026 |
|
pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue; |
2027 |
|
break; |
2028 |
case Event::synth_param_pan: |
case Event::synth_param_pan: |
2029 |
if (relative) { |
if (relative) { |
2030 |
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); |