--- linuxsampler/trunk/src/engines/common/InstrumentScriptVM.cpp 2014/06/09 19:20:37 2611 +++ linuxsampler/trunk/src/engines/common/InstrumentScriptVM.cpp 2014/06/10 17:22:48 2614 @@ -11,6 +11,7 @@ #include "../AbstractEngineChannel.h" #include "../../common/global_private.h" #include "AbstractInstrumentManager.h" +#include "MidiKeyboardManager.h" namespace LinuxSampler { @@ -32,7 +33,9 @@ // hand back old script reference and VM execution contexts // (if not done already) - reset(); + unload(); + + code = text; AbstractInstrumentManager* pManager = dynamic_cast(pEngineChannel->pEngine->GetInstrumentManager()); @@ -84,10 +87,13 @@ * is used to share equivalent scripts among multiple sampler channels, and * to deallocate the parsed script once not used on any engine channel * anymore. + * + * Calling this method will however not clear the @c code member variable. + * Thus, the script can be parsed again afterwards. */ - void InstrumentScript::reset() { + void InstrumentScript::unload() { if (parserContext) - dmsg(1,("Unloading current instrument script.")); + dmsg(1,("Unloading current instrument script.\n")); // free allocated VM execution contexts if (pEvents) { @@ -119,6 +125,15 @@ bHasValidScript = false; } + /** + * Same as unload(), but this one also empties the @c code member variable + * to an empty string. + */ + void InstrumentScript::resetAll() { + unload(); + code.clear(); + } + /////////////////////////////////////////////////////////////////////// // class 'InstrumentScriptVM' @@ -131,6 +146,7 @@ m_EVENT_ID = DECLARE_VMINT(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; } VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { @@ -140,6 +156,7 @@ // prepare built-in script variables for script execution m_event = event; m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; + m_KEY_DOWN.data = &pEngineChannel->GetMidiKeyboardManager()->KeyDown[0]; // if script is in start condition, then do mandatory MIDI event // preprocessing tasks, which essentially means updating i.e. controller @@ -195,7 +212,7 @@ // now add own built-in variables m["%CC"] = &m_CC; - //m["%KEY_DOWN"] = &m_KEY_DOWN; + m["%KEY_DOWN"] = &m_KEY_DOWN; //m["%POLY_AT"] = &m_POLY_AT; return m;