676 |
* @param pNoteOnEvent - event which caused this |
* @param pNoteOnEvent - event which caused this |
677 |
* @returns new note's unique ID (or zero on error) |
* @returns new note's unique ID (or zero on error) |
678 |
*/ |
*/ |
679 |
note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) OVERRIDE { |
note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE { |
680 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
681 |
Pool< Note<V> >* pNotePool = GetNotePool(); |
Pool< Note<V> >* pNotePool = GetNotePool(); |
682 |
|
|
691 |
const note_id_t newNoteID = pNotePool->getID(itNewNote); |
const note_id_t newNoteID = pNotePool->getID(itNewNote); |
692 |
|
|
693 |
// remember the engine's time when this note was triggered exactly |
// remember the engine's time when this note was triggered exactly |
694 |
itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime(); |
itNewNote->triggerSchedTime = itNoteOnEvent->SchedTime(); |
695 |
|
|
696 |
// usually the new note (and its subsequent voices) will be |
// usually the new note (and its subsequent voices) will be |
697 |
// allocated on the key provided by the event's note number, |
// allocated on the key provided by the event's note number, |
699 |
// note, but rather a child note, then this new note will be |
// note, but rather a child note, then this new note will be |
700 |
// allocated on the parent note's key instead in order to |
// allocated on the parent note's key instead in order to |
701 |
// release the child note simultaniously with its parent note |
// release the child note simultaniously with its parent note |
702 |
itNewNote->hostKey = pNoteOnEvent->Param.Note.Key; |
itNewNote->hostKey = itNoteOnEvent->Param.Note.Key; |
703 |
|
|
704 |
// in case this new note was requested to be a child note, |
// in case this new note was requested to be a child note, |
705 |
// then retrieve its parent note and link them with each other |
// then retrieve its parent note and link them with each other |
706 |
const note_id_t parentNoteID = pNoteOnEvent->Param.Note.ParentNoteID; |
const note_id_t parentNoteID = itNoteOnEvent->Param.Note.ParentNoteID; |
707 |
if (parentNoteID) { |
if (parentNoteID) { |
708 |
NoteIterator itParentNote = pNotePool->fromID(parentNoteID); |
NoteIterator itParentNote = pNotePool->fromID(parentNoteID); |
709 |
if (itParentNote) { |
if (itParentNote) { |
731 |
dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey)); |
dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey)); |
732 |
|
|
733 |
// copy event which caused this note |
// copy event which caused this note |
734 |
itNewNote->cause = *pNoteOnEvent; |
itNewNote->cause = *itNoteOnEvent; |
735 |
itNewNote->eventID = pEventPool->getID(pNoteOnEvent); |
itNewNote->eventID = pEventPool->getID(itNoteOnEvent); |
736 |
|
if (!itNewNote->eventID) { |
737 |
|
dmsg(0,("Engine: No valid event ID resolved for note. This is a bug!!!\n")); |
738 |
|
} |
739 |
|
|
740 |
// move new note to its host key |
// move new note to its host key |
741 |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey]; |
MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey]; |
742 |
itNewNote.moveToEndOf(pKey->pActiveNotes); |
itNewNote.moveToEndOf(pKey->pActiveNotes); |
743 |
|
|
744 |
// 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 |
745 |
pNoteOnEvent->Param.Note.ID = newNoteID; |
itNoteOnEvent->Param.Note.ID = newNoteID; |
746 |
|
|
747 |
return newNoteID; // success |
return newNoteID; // success |
748 |
} |
} |
812 |
case Event::type_release_note: |
case Event::type_release_note: |
813 |
case Event::type_play_note: |
case Event::type_play_note: |
814 |
case Event::type_stop_note: |
case Event::type_stop_note: |
815 |
|
case Event::type_kill_note: |
816 |
case Event::type_note_synth_param: |
case Event::type_note_synth_param: |
817 |
break; // noop |
break; // noop |
818 |
} |
} |
885 |
dmsg(5,("Engine: Stop Note received\n")); |
dmsg(5,("Engine: Stop Note received\n")); |
886 |
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent); |
887 |
break; |
break; |
888 |
|
case Event::type_kill_note: |
889 |
|
dmsg(5,("Engine: Kill Note received\n")); |
890 |
|
ProcessKillNote((EngineChannel*)itEvent->pEngineChannel, itEvent); |
891 |
|
break; |
892 |
case Event::type_control_change: |
case Event::type_control_change: |
893 |
dmsg(5,("Engine: MIDI CC received\n")); |
dmsg(5,("Engine: MIDI CC received\n")); |
894 |
ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent); |
ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent); |
984 |
// script event object |
// script event object |
985 |
RTList<ScriptEvent>::Iterator itScriptEvent = |
RTList<ScriptEvent>::Iterator itScriptEvent = |
986 |
pChannel->pScript->pEvents->allocAppend(); |
pChannel->pScript->pEvents->allocAppend(); |
987 |
|
// if event handler uses polyphonic variables, reset them |
988 |
|
// to zero values before starting to execute the handler |
989 |
|
if (pEventHandler->isPolyphonic()) |
990 |
|
itScriptEvent->execCtx->resetPolyphonicData(); |
991 |
ProcessScriptEvent( |
ProcessScriptEvent( |
992 |
pChannel, itEvent, pEventHandler, itScriptEvent |
pChannel, itEvent, pEventHandler, itScriptEvent |
993 |
); |
); |
1020 |
|
|
1021 |
// initialize/reset other members |
// initialize/reset other members |
1022 |
itScriptEvent->cause = *itEvent; |
itScriptEvent->cause = *itEvent; |
1023 |
|
itScriptEvent->scheduleTime = itEvent->SchedTime(); |
1024 |
itScriptEvent->currentHandler = 0; |
itScriptEvent->currentHandler = 0; |
1025 |
itScriptEvent->executionSlices = 0; |
itScriptEvent->executionSlices = 0; |
1026 |
itScriptEvent->ignoreAllWaitCalls = false; |
itScriptEvent->ignoreAllWaitCalls = false; |
1367 |
// usually there should already be a new Note object |
// usually there should already be a new Note object |
1368 |
NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID); |
NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID); |
1369 |
if (!itNote) { // should not happen, but just to be sure ... |
if (!itNote) { // should not happen, but just to be sure ... |
1370 |
const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent); |
const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent); |
1371 |
if (!noteID) { |
if (!noteID) { |
1372 |
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")); |
1373 |
continue; |
continue; |
1844 |
itPseudoNoteOnEvent->Param.Note.Key = i; |
itPseudoNoteOnEvent->Param.Note.Key = i; |
1845 |
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
1846 |
// assign a new note to this note-on event |
// assign a new note to this note-on event |
1847 |
if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) { |
if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) { |
1848 |
// allocate and trigger new voice(s) for the other key |
// allocate and trigger new voice(s) for the other key |
1849 |
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false); |
1850 |
} |
} |
1931 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
1932 |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
if (pKey->ReleaseTrigger && pChannel->pInstrument) { |
1933 |
// assign a new note to this release event |
// assign a new note to this release event |
1934 |
if (LaunchNewNote(pChannel, &*itEvent)) { |
if (LaunchNewNote(pChannel, itEvent)) { |
1935 |
// allocate and trigger new release voice(s) |
// allocate and trigger new release voice(s) |
1936 |
TriggerReleaseVoices(pChannel, itEvent); |
TriggerReleaseVoices(pChannel, itEvent); |
1937 |
} |
} |
1940 |
} |
} |
1941 |
|
|
1942 |
/** |
/** |
1943 |
|
* Called on "kill note" events, which currently only happens on |
1944 |
|
* built-in real-time instrument script function fade_out(). This |
1945 |
|
* method only fulfills one task: moving the even to the Note's own |
1946 |
|
* event list so that its voices can process the kill event sample |
1947 |
|
* accurately. |
1948 |
|
*/ |
1949 |
|
void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) { |
1950 |
|
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1951 |
|
|
1952 |
|
NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID ); |
1953 |
|
if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return; |
1954 |
|
|
1955 |
|
// move note kill event to its MIDI key |
1956 |
|
MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey]; |
1957 |
|
itEvent.moveToEndOf(pKey->pEvents); |
1958 |
|
} |
1959 |
|
|
1960 |
|
/** |
1961 |
* Called on note synthesis parameter change events. These are |
* Called on note synthesis parameter change events. These are |
1962 |
* internal events caused by calling built-in real-time instrument |
* internal events caused by calling built-in real-time instrument |
1963 |
* script functions like change_vol(), change_pitch(), etc. |
* script functions like change_vol(), change_tune(), etc. |
1964 |
* |
* |
1965 |
* This method performs two tasks: |
* This method performs two tasks: |
1966 |
* |
* |
1991 |
pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta; |
1992 |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume; |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume; |
1993 |
break; |
break; |
1994 |
|
case Event::synth_param_volume_time: |
1995 |
|
pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
1996 |
|
break; |
1997 |
case Event::synth_param_pitch: |
case Event::synth_param_pitch: |
1998 |
if (relative) |
if (relative) |
1999 |
pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta; |
2001 |
pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta; |
2002 |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch; |
itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch; |
2003 |
break; |
break; |
2004 |
|
case Event::synth_param_pitch_time: |
2005 |
|
pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2006 |
|
break; |
2007 |
case Event::synth_param_pan: |
case Event::synth_param_pan: |
2008 |
if (relative) { |
if (relative) { |
2009 |
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); |