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 |
} |
} |
597 |
} |
} |
598 |
|
|
599 |
// implementation of abstract method derived from class 'LinuxSampler::RegionPools' |
// implementation of abstract method derived from class 'LinuxSampler::RegionPools' |
600 |
virtual Pool<R*>* GetRegionPool(int index) { |
virtual Pool<R*>* GetRegionPool(int index) OVERRIDE { |
601 |
if (index < 0 || index > 1) throw Exception("Index out of bounds"); |
if (index < 0 || index > 1) throw Exception("Index out of bounds"); |
602 |
return pRegionPool[index]; |
return pRegionPool[index]; |
603 |
} |
} |
605 |
// implementation of abstract methods derived from class 'LinuxSampler::NotePool' |
// implementation of abstract methods derived from class 'LinuxSampler::NotePool' |
606 |
virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; } |
virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; } |
607 |
virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; } |
virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; } |
608 |
virtual Pool<note_id_t>* GetNodeIDPool() OVERRIDE { return ¬eIDPool; } |
virtual Pool<note_id_t>* GetNoteIDPool() OVERRIDE { return ¬eIDPool; } |
609 |
|
|
610 |
D* GetDiskThread() { return pDiskThread; } |
D* GetDiskThread() { return pDiskThread; } |
611 |
|
|
690 |
NoteIterator itNewNote = pNotePool->allocAppend(); |
NoteIterator itNewNote = pNotePool->allocAppend(); |
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 |
694 |
|
itNewNote->triggerSchedTime = pNoteOnEvent->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, |
698 |
// however if this new note is requested not to be a regular |
// however if this new note is requested not to be a regular |
799 |
case Event::type_note_pressure: |
case Event::type_note_pressure: |
800 |
//TODO: ... |
//TODO: ... |
801 |
break; |
break; |
802 |
|
|
803 |
|
case Event::type_sysex: |
804 |
|
//TODO: ... |
805 |
|
break; |
806 |
|
|
807 |
|
case Event::type_cancel_release_key: |
808 |
|
case Event::type_release_key: |
809 |
|
case Event::type_release_note: |
810 |
|
case Event::type_play_note: |
811 |
|
case Event::type_stop_note: |
812 |
|
case Event::type_note_synth_param: |
813 |
|
break; // noop |
814 |
} |
} |
815 |
|
|
816 |
// see HACK comment above |
// see HACK comment above |
901 |
dmsg(5,("Engine: Note Synth Param received\n")); |
dmsg(5,("Engine: Note Synth Param received\n")); |
902 |
ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent); |
ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent); |
903 |
break; |
break; |
904 |
|
case Event::type_sysex: |
905 |
|
break; // TODO ... |
906 |
|
|
907 |
|
case Event::type_cancel_release_key: |
908 |
|
case Event::type_release_key: |
909 |
|
case Event::type_release_note: |
910 |
|
break; // noop |
911 |
} |
} |
912 |
} |
} |
913 |
} |
} |
1279 |
// the script's "init" event handler is only executed |
// the script's "init" event handler is only executed |
1280 |
// once (when the script is loaded or reloaded) |
// once (when the script is loaded or reloaded) |
1281 |
if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) { |
if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) { |
1282 |
|
dmsg(5,("Engine: exec handlerInit %p\n", pEngineChannel->pScript->handlerInit)); |
1283 |
RTList<ScriptEvent>::Iterator itScriptEvent = |
RTList<ScriptEvent>::Iterator itScriptEvent = |
1284 |
pEngineChannel->pScript->pEvents->allocAppend(); |
pEngineChannel->pScript->pEvents->allocAppend(); |
1285 |
|
|
1286 |
itScriptEvent->cause.pEngineChannel = pEngineChannel; |
itScriptEvent->cause.pEngineChannel = pEngineChannel; |
1287 |
itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit; |
itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit; |
1288 |
itScriptEvent->handlers[1] = NULL; |
itScriptEvent->handlers[1] = NULL; |
1289 |
|
itScriptEvent->currentHandler = 0; |
1290 |
|
itScriptEvent->executionSlices = 0; |
1291 |
|
itScriptEvent->ignoreAllWaitCalls = false; |
1292 |
|
itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; |
1293 |
|
|
1294 |
VMExecStatus_t res = pScriptVM->exec( |
/*VMExecStatus_t res = */ pScriptVM->exec( |
1295 |
pEngineChannel->pScript->parserContext, &*itScriptEvent |
pEngineChannel->pScript->parserContext, &*itScriptEvent |
1296 |
); |
); |
1297 |
|
|
1631 |
* @param pEngineChannel - engine channel on which this event occurred on |
* @param pEngineChannel - engine channel on which this event occurred on |
1632 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
1633 |
*/ |
*/ |
1634 |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE { |
1635 |
EngineChannelBase<V, R, I>* pChannel = |
EngineChannelBase<V, R, I>* pChannel = |
1636 |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1637 |
|
|
1762 |
* @param pEngineChannel - engine channel on which this event occurred on |
* @param pEngineChannel - engine channel on which this event occurred on |
1763 |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
1764 |
*/ |
*/ |
1765 |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE { |
1766 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
1767 |
|
|
1768 |
const int iKey = itNoteOffEvent->Param.Note.Key; |
const int iKey = itNoteOffEvent->Param.Note.Key; |
1991 |
case Event::synth_param_release: |
case Event::synth_param_release: |
1992 |
pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
1993 |
break; |
break; |
1994 |
|
case Event::synth_param_amp_lfo_depth: |
1995 |
|
pNote->Override.AmpLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
1996 |
|
break; |
1997 |
|
case Event::synth_param_amp_lfo_freq: |
1998 |
|
pNote->Override.AmpLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
1999 |
|
break; |
2000 |
|
case Event::synth_param_pitch_lfo_depth: |
2001 |
|
pNote->Override.PitchLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2002 |
|
break; |
2003 |
|
case Event::synth_param_pitch_lfo_freq: |
2004 |
|
pNote->Override.PitchLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta; |
2005 |
|
break; |
2006 |
} |
} |
2007 |
|
|
2008 |
// move note parameter event to its MIDI key |
// move note parameter event to its MIDI key |
2014 |
* 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 |
2015 |
* control and status variables. This method is protected by a mutex. |
* control and status variables. This method is protected by a mutex. |
2016 |
*/ |
*/ |
2017 |
virtual void ResetInternal() { |
virtual void ResetInternal() OVERRIDE { |
2018 |
LockGuard lock(ResetInternalMutex); |
LockGuard lock(ResetInternalMutex); |
2019 |
|
|
2020 |
// make sure that the engine does not get any sysex messages |
// make sure that the engine does not get any sysex messages |
2073 |
* @param pEngineChannel - engine channel on which all voices should be killed |
* @param pEngineChannel - engine channel on which all voices should be killed |
2074 |
* @param itKillEvent - event which caused this killing of all voices |
* @param itKillEvent - event which caused this killing of all voices |
2075 |
*/ |
*/ |
2076 |
virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) { |
virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE { |
2077 |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel); |
2078 |
int count = pChannel->KillAllVoices(itKillEvent); |
int count = pChannel->KillAllVoices(itKillEvent); |
2079 |
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 |
2108 |
bool HandleKeyGroupConflicts |
bool HandleKeyGroupConflicts |
2109 |
) = 0; |
) = 0; |
2110 |
|
|
2111 |
virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; } |
virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; } |
2112 |
|
|
2113 |
int InitNewVoice ( |
int InitNewVoice ( |
2114 |
EngineChannelBase<V, R, I>* pChannel, |
EngineChannelBase<V, R, I>* pChannel, |