--- linuxsampler/trunk/src/engines/common/InstrumentScriptVM.cpp 2016/07/09 14:38:33 2931 +++ linuxsampler/trunk/src/engines/common/InstrumentScriptVM.cpp 2017/05/19 14:23:12 3188 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 - 2016 Christian Schoenebeck + * Copyright (c) 2014 - 2017 Christian Schoenebeck * * http://www.linuxsampler.org * @@ -7,6 +7,7 @@ * See README file for details. */ +#include "../../common/global_private.h" #include "InstrumentScriptVM.h" #include "../AbstractEngineChannel.h" #include "../../common/global_private.h" @@ -125,6 +126,13 @@ pEvents = new Pool(CONFIG_MAX_EVENTS_PER_FRAGMENT); for (int i = 0; i < 128; ++i) pKeyEvents[i] = new RTList(pEvents); + // reset RTAVLNode's tree node member variables after nodes are allocated + // (since we can't use a constructor right now, we do that initialization here) + while (!pEvents->poolIsEmpty()) { + RTList::Iterator it = pEvents->allocAppend(); + it->reset(); + } + pEvents->clear(); } // create new VM execution contexts for new script @@ -222,14 +230,24 @@ m_event(NULL), m_fnPlayNote(this), m_fnSetController(this), m_fnIgnoreEvent(this), m_fnIgnoreController(this), m_fnNoteOff(this), m_fnSetEventMark(this), m_fnDeleteEventMark(this), m_fnByMarks(this), - m_fnChangeVol(this), m_fnChangeTune(this), m_fnChangePan(this) + m_fnChangeVol(this), m_fnChangeVolTime(this), + m_fnChangeTune(this), m_fnChangeTuneTime(this), m_fnChangePan(this), + m_fnChangeCutoff(this), m_fnChangeReso(this), m_fnChangeAttack(this), + m_fnChangeDecay(this), m_fnChangeRelease(this), + m_fnChangeAmpLFODepth(this), m_fnChangeAmpLFOFreq(this), + m_fnChangePitchLFODepth(this), m_fnChangePitchLFOFreq(this), + m_fnEventStatus(this), m_fnWait2(this), m_fnStopWait(this), + m_fnFadeIn(this), m_fnFadeOut(this), + m_varEngineUptime(this), m_varCallbackID(this), m_varAllEvents(this) { m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable); m_CC_NUM = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.CC.Controller); - m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id); + m_EVENT_ID = DECLARE_VMINT_READONLY(m_event, class ScriptEvent, id); m_EVENT_NOTE = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Key); m_EVENT_VELOCITY = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Velocity); m_KEY_DOWN.size = 128; + m_NI_CALLBACK_TYPE = DECLARE_VMINT_READONLY(m_event, class ScriptEvent, handlerType); + m_NKSP_IGNORE_WAIT = DECLARE_VMINT(m_event, class ScriptEvent, ignoreAllWaitCalls); } VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { @@ -259,6 +277,8 @@ pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] = event->cause.Param.Pitch.Pitch; break; + default: + ; // noop } } @@ -276,7 +296,7 @@ } std::map InstrumentScriptVM::builtInIntVariables() { - // first get buil-in integer variables of derived VM class + // first get built-in integer variables of derived VM class std::map m = ScriptVM::builtInIntVariables(); // now add own built-in variables @@ -285,12 +305,14 @@ m["$EVENT_NOTE"] = &m_EVENT_NOTE; m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY; // m["$POLY_AT_NUM"] = &m_POLY_AT_NUM; + m["$NI_CALLBACK_TYPE"] = &m_NI_CALLBACK_TYPE; + m["$NKSP_IGNORE_WAIT"] = &m_NKSP_IGNORE_WAIT; return m; } std::map InstrumentScriptVM::builtInIntArrayVariables() { - // first get buil-in integer array variables of derived VM class + // first get built-in integer array variables of derived VM class std::map m = ScriptVM::builtInIntArrayVariables(); // now add own built-in variables @@ -302,9 +324,11 @@ } std::map InstrumentScriptVM::builtInConstIntVariables() { - // first get buil-in integer variables of derived VM class + // first get built-in integer variables of derived VM class std::map m = ScriptVM::builtInConstIntVariables(); + m["$EVENT_STATUS_INACTIVE"] = EVENT_STATUS_INACTIVE; + m["$EVENT_STATUS_NOTE_QUEUE"] = EVENT_STATUS_NOTE_QUEUE; m["$VCC_MONO_AT"] = CTRL_TABLE_IDX_AFTERTOUCH; m["$VCC_PITCH_BEND"] = CTRL_TABLE_IDX_PITCHBEND; for (int i = 0; i < INSTR_SCRIPT_EVENT_GROUPS; ++i) { @@ -314,6 +338,17 @@ return m; } + std::map InstrumentScriptVM::builtInDynamicVariables() { + // first get built-in dynamic variables of derived VM class + std::map m = ScriptVM::builtInDynamicVariables(); + + m["%ALL_EVENTS"] = &m_varAllEvents; + m["$ENGINE_UPTIME"] = &m_varEngineUptime; + m["$NI_CALLBACK_ID"] = &m_varCallbackID; + + return m; + } + VMFunction* InstrumentScriptVM::functionByName(const String& name) { // built-in script functions of this class if (name == "play_note") return &m_fnPlayNote; @@ -325,8 +360,24 @@ else if (name == "delete_event_mark") return &m_fnDeleteEventMark; else if (name == "by_marks") return &m_fnByMarks; else if (name == "change_vol") return &m_fnChangeVol; + else if (name == "change_vol_time") return &m_fnChangeVolTime; else if (name == "change_tune") return &m_fnChangeTune; + else if (name == "change_tune_time") return &m_fnChangeTuneTime; else if (name == "change_pan") return &m_fnChangePan; + else if (name == "change_cutoff") return &m_fnChangeCutoff; + else if (name == "change_reso") return &m_fnChangeReso; + else if (name == "change_attack") return &m_fnChangeAttack; + else if (name == "change_decay") return &m_fnChangeDecay; + else if (name == "change_release") return &m_fnChangeRelease; + else if (name == "change_amp_lfo_depth") return &m_fnChangeAmpLFODepth; + else if (name == "change_amp_lfo_freq") return &m_fnChangeAmpLFOFreq; + else if (name == "change_pitch_lfo_depth") return &m_fnChangePitchLFODepth; + else if (name == "change_pitch_lfo_freq") return &m_fnChangePitchLFOFreq; + else if (name == "fade_in") return &m_fnFadeIn; + else if (name == "fade_out") return &m_fnFadeOut; + else if (name == "event_status") return &m_fnEventStatus; + else if (name == "wait") return &m_fnWait2; // override wait() core implementation + else if (name == "stop_wait") return &m_fnStopWait; // built-in script functions of derived VM class return ScriptVM::functionByName(name);