--- linuxsampler/trunk/src/engines/common/InstrumentScriptVM.h 2014/06/06 12:38:54 2598 +++ linuxsampler/trunk/src/engines/common/InstrumentScriptVM.h 2014/06/10 13:32:16 2612 @@ -13,10 +13,49 @@ #include "../../common/global.h" #include "../../scriptvm/ScriptVM.h" #include "Event.h" +#include "../../common/Pool.h" #include "InstrumentScriptVMFunctions.h" namespace LinuxSampler { + class AbstractEngineChannel; + + /** @brief Real-time instrument script VM representation. + * + * Holds the VM representation of all event handlers of the currently loaded + * script, ready to be executed by the sampler engine. + */ + struct InstrumentScript { + VMParserContext* parserContext; ///< VM represenation of the currently loaded script or NULL if not script was loaded. Note that it is also not NULL if parser errors occurred! + bool bHasValidScript; ///< True in case there is a valid script currently loaded, false if script processing shall be skipped. + VMEventHandler* handlerInit; ///< VM representation of script's initilization callback or NULL if current script did not define such an init handler. + VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler. + VMEventHandler* handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler. + VMEventHandler* handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler. + Pool* pEvents; ///< Pool of all available script execution instances. ScriptEvents available to be allocated from the Pool are currently unused / not executiong, whereas the ScriptEvents allocated on the list are currently suspended / have not finished execution yet. + AbstractEngineChannel* pEngineChannel; + String code; ///< Source code of the instrument script. Used in case the sampler engine is changed, in that case a new ScriptVM object is created for the engine and VMParserContext object for this script needs to be recreated as well. Thus the script is then parsed again by passing the source code to recreate the parser context. + + InstrumentScript(AbstractEngineChannel* pEngineChannel) { + parserContext = NULL; + bHasValidScript = false; + handlerInit = NULL; + handlerNote = NULL; + handlerRelease = NULL; + handlerController = NULL; + pEvents = NULL; + this->pEngineChannel = pEngineChannel; + } + + ~InstrumentScript() { + resetAll(); + } + + void load(const String& text); + void unload(); + void resetAll(); + }; + /** @brief Real-time instrument script virtual machine. * * Extends the core ScriptVM implementation with MIDI specific built-in @@ -50,10 +89,12 @@ // buil-in script functions InstrumentScriptVMFunction_play_note m_fnPlayNote; - InstrumentScriptVMFunction_play_note m_fnIgnoreEvent; - InstrumentScriptVMFunction_play_note m_fnIgnoreController; + InstrumentScriptVMFunction_set_controller m_fnSetController; + InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; + InstrumentScriptVMFunction_ignore_controller m_fnIgnoreController; friend class InstrumentScriptVMFunction_play_note; + friend class InstrumentScriptVMFunction_set_controller; friend class InstrumentScriptVMFunction_ignore_event; friend class InstrumentScriptVMFunction_ignore_controller; };