--- linuxsampler/trunk/src/engines/common/InstrumentScriptVM.h 2016/05/03 14:00:16 2902 +++ linuxsampler/trunk/src/engines/common/InstrumentScriptVM.h 2016/07/16 11:24:39 2953 @@ -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,12 +30,40 @@ #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_NOTE_ID_FLAG (1 << (sizeof(pool_element_id_t) * 8 - 1)) +#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. + */ +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 +#define EVENT_STATUS_INACTIVE 0 +#define EVENT_STATUS_NOTE_QUEUE 1 + namespace LinuxSampler { class AbstractEngineChannel; @@ -53,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 */ @@ -76,7 +108,7 @@ * internal scope. */ inline static ScriptID fromEventID(event_id_t id) { - return ScriptID(id); + return ScriptID(INSTR_SCRIPT_EVENT_ID_FLAG | id); } /** @@ -211,6 +243,7 @@ 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(). @@ -223,6 +256,8 @@ 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 InstrumentScriptVMFunction_play_note m_fnPlayNote; @@ -233,6 +268,19 @@ InstrumentScriptVMFunction_set_event_mark m_fnSetEventMark; InstrumentScriptVMFunction_delete_event_mark m_fnDeleteEventMark; InstrumentScriptVMFunction_by_marks m_fnByMarks; + InstrumentScriptVMFunction_change_vol m_fnChangeVol; + InstrumentScriptVMFunction_change_tune m_fnChangeTune; + 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; friend class InstrumentScriptVMFunction_play_note; friend class InstrumentScriptVMFunction_set_controller; @@ -242,6 +290,19 @@ friend class InstrumentScriptVMFunction_set_event_mark; friend class InstrumentScriptVMFunction_delete_event_mark; friend class InstrumentScriptVMFunction_by_marks; + friend class InstrumentScriptVMFunction_change_vol; + friend class InstrumentScriptVMFunction_change_tune; + 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; }; } // namespace LinuxSampler