--- linuxsampler/trunk/src/engines/common/InstrumentScriptVM.h 2016/07/10 14:24:13 2935 +++ linuxsampler/trunk/src/engines/common/InstrumentScriptVM.h 2017/01/09 18:39:35 3082 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016 Christian Schoenebeck + * Copyright (c) 2014-2017 Christian Schoenebeck * * http://www.linuxsampler.org * @@ -16,6 +16,7 @@ #include "Event.h" #include "../../common/Pool.h" #include "InstrumentScriptVMFunctions.h" +#include "InstrumentScriptVMDynVars.h" /** * Amount of bits on the left hand side of all pool_element_id_t numbers (i.e. @@ -29,9 +30,34 @@ #define INSTR_SCRIPT_EVENT_ID_RESERVED_BITS 1 /** - * Used to mark IDs (in script scope) to actually be a note ID. + * Used by InstrScriptIDType_T to initialize its constants at compile time. + * + * This macro is already ready to initialize additional members for + * InstrScriptIDType_T (that is more than the currently two enum constants). + * Just keep in mind that you also have to increase + * INSTR_SCRIPT_EVENT_ID_RESERVED_BITS when you add more! + * + * @param x - sequential consecutive number (starting with zero) + */ +#define INSTR_SCRIPT_ID_TYPE_FLAG(x) \ + (x << (sizeof(pool_element_id_t) * 8 - INSTR_SCRIPT_EVENT_ID_RESERVED_BITS)) + +/** + * These flags are used to distinguish the individual ID Types in script scope + * from each other. They are added as most left bit(s) to each ID in script + * scope. */ -#define INSTR_SCRIPT_NOTE_ID_FLAG (1 << (sizeof(pool_element_id_t) * 8 - 1)) +enum InstrScriptIDType_T { + /** + * Used to mark IDs (in script scope) to actually be a MIDI event ID. + */ + INSTR_SCRIPT_EVENT_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(0), + + /** + * Used to mark IDs (in script scope) to actually be a note ID. + */ + INSTR_SCRIPT_NOTE_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(1), +}; #define INSTR_SCRIPT_EVENT_GROUPS 28 @@ -41,7 +67,7 @@ namespace LinuxSampler { class AbstractEngineChannel; - class InstrumentScript; + struct InstrumentScript; /** @brief Convert IDs between script scope and engine internal scope. * @@ -56,9 +82,12 @@ * event_id_t (engine internal scope) -> int (script scope) * note_id_t (engine internal scope) -> int (script scope) * @endcode - * This is required because engine internally notes and regular events are - * using their own, separate ID generating pool, and their ID number set - * may thus overlap. + * This is required because engine internally i.e. notes and regular events + * are using their own, separate ID generating pool, and their ID number + * set may thus overlap and historically there were built-in script + * functions in KSP which allow to pass both regular MIDI event IDs, as well + * as Note IDs. So we must be able to distinguish between them in our + * built-in script function implementations. * * @see INSTR_SCRIPT_EVENT_ID_RESERVED_BITS */ @@ -79,7 +108,7 @@ * internal scope. */ inline static ScriptID fromEventID(event_id_t id) { - return ScriptID(id); + return ScriptID(INSTR_SCRIPT_EVENT_ID_FLAG | id); } /** @@ -214,10 +243,11 @@ std::map builtInIntVariables() OVERRIDE; std::map builtInIntArrayVariables() OVERRIDE; std::map builtInConstIntVariables() OVERRIDE; + std::map builtInDynamicVariables() OVERRIDE; protected: ScriptEvent* m_event; ///< The event currently executed by exec(). - // buil-in script variables + // built-in script variables VMInt8Array m_CC; VMInt8RelPtr m_CC_NUM; VMIntRelPtr m_EVENT_ID; @@ -226,8 +256,10 @@ VMInt8Array m_KEY_DOWN; //VMIntArray m_POLY_AT; //TODO: ... //int m_POLY_AT_NUM; //TODO: ... + VMIntRelPtr m_NI_CALLBACK_TYPE; + VMIntRelPtr m_NKSP_IGNORE_WAIT; - // buil-in script functions + // built-in script functions InstrumentScriptVMFunction_play_note m_fnPlayNote; InstrumentScriptVMFunction_set_controller m_fnSetController; InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; @@ -241,7 +273,15 @@ InstrumentScriptVMFunction_change_pan m_fnChangePan; InstrumentScriptVMFunction_change_cutoff m_fnChangeCutoff; InstrumentScriptVMFunction_change_reso m_fnChangeReso; + InstrumentScriptVMFunction_change_attack m_fnChangeAttack; + InstrumentScriptVMFunction_change_decay m_fnChangeDecay; + InstrumentScriptVMFunction_change_release m_fnChangeRelease; InstrumentScriptVMFunction_event_status m_fnEventStatus; + InstrumentScriptVMFunction_wait m_fnWait2; + InstrumentScriptVMFunction_stop_wait m_fnStopWait; + InstrumentScriptVMDynVar_ENGINE_UPTIME m_varEngineUptime; + InstrumentScriptVMDynVar_NI_CALLBACK_ID m_varCallbackID; + InstrumentScriptVMDynVar_ALL_EVENTS m_varAllEvents; friend class InstrumentScriptVMFunction_play_note; friend class InstrumentScriptVMFunction_set_controller; @@ -256,7 +296,15 @@ friend class InstrumentScriptVMFunction_change_pan; friend class InstrumentScriptVMFunction_change_cutoff; friend class InstrumentScriptVMFunction_change_reso; + friend class InstrumentScriptVMFunction_change_attack; + friend class InstrumentScriptVMFunction_change_decay; + friend class InstrumentScriptVMFunction_change_release; friend class InstrumentScriptVMFunction_event_status; + friend class InstrumentScriptVMFunction_wait; + friend class InstrumentScriptVMFunction_stop_wait; + friend class InstrumentScriptVMDynVar_ENGINE_UPTIME; + friend class InstrumentScriptVMDynVar_NI_CALLBACK_ID; + friend class InstrumentScriptVMDynVar_ALL_EVENTS; }; } // namespace LinuxSampler