1 |
/* |
/* |
2 |
* Copyright (c) 2014-2016 Christian Schoenebeck |
* Copyright (c) 2014-2017 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
16 |
#include "Event.h" |
#include "Event.h" |
17 |
#include "../../common/Pool.h" |
#include "../../common/Pool.h" |
18 |
#include "InstrumentScriptVMFunctions.h" |
#include "InstrumentScriptVMFunctions.h" |
19 |
|
#include "InstrumentScriptVMDynVars.h" |
20 |
|
|
21 |
/** |
/** |
22 |
* Amount of bits on the left hand side of all pool_element_id_t numbers (i.e. |
* Amount of bits on the left hand side of all pool_element_id_t numbers (i.e. |
30 |
#define INSTR_SCRIPT_EVENT_ID_RESERVED_BITS 1 |
#define INSTR_SCRIPT_EVENT_ID_RESERVED_BITS 1 |
31 |
|
|
32 |
/** |
/** |
33 |
* Used to mark IDs (in script scope) to actually be a note ID. |
* Used by InstrScriptIDType_T to initialize its constants at compile time. |
34 |
|
* |
35 |
|
* This macro is already ready to initialize additional members for |
36 |
|
* InstrScriptIDType_T (that is more than the currently two enum constants). |
37 |
|
* Just keep in mind that you also have to increase |
38 |
|
* INSTR_SCRIPT_EVENT_ID_RESERVED_BITS when you add more! |
39 |
|
* |
40 |
|
* @param x - sequential consecutive number (starting with zero) |
41 |
|
*/ |
42 |
|
#define INSTR_SCRIPT_ID_TYPE_FLAG(x) \ |
43 |
|
(x << (sizeof(pool_element_id_t) * 8 - INSTR_SCRIPT_EVENT_ID_RESERVED_BITS)) |
44 |
|
|
45 |
|
/** |
46 |
|
* These flags are used to distinguish the individual ID Types in script scope |
47 |
|
* from each other. They are added as most left bit(s) to each ID in script |
48 |
|
* scope. |
49 |
*/ |
*/ |
50 |
#define INSTR_SCRIPT_NOTE_ID_FLAG (1 << (sizeof(pool_element_id_t) * 8 - 1)) |
enum InstrScriptIDType_T { |
51 |
|
/** |
52 |
|
* Used to mark IDs (in script scope) to actually be a MIDI event ID. |
53 |
|
*/ |
54 |
|
INSTR_SCRIPT_EVENT_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(0), |
55 |
|
|
56 |
|
/** |
57 |
|
* Used to mark IDs (in script scope) to actually be a note ID. |
58 |
|
*/ |
59 |
|
INSTR_SCRIPT_NOTE_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(1), |
60 |
|
}; |
61 |
|
|
62 |
#define INSTR_SCRIPT_EVENT_GROUPS 28 |
#define INSTR_SCRIPT_EVENT_GROUPS 28 |
63 |
|
|
67 |
namespace LinuxSampler { |
namespace LinuxSampler { |
68 |
|
|
69 |
class AbstractEngineChannel; |
class AbstractEngineChannel; |
70 |
class InstrumentScript; |
struct InstrumentScript; |
71 |
|
|
72 |
/** @brief Convert IDs between script scope and engine internal scope. |
/** @brief Convert IDs between script scope and engine internal scope. |
73 |
* |
* |
82 |
* event_id_t (engine internal scope) -> int (script scope) |
* event_id_t (engine internal scope) -> int (script scope) |
83 |
* note_id_t (engine internal scope) -> int (script scope) |
* note_id_t (engine internal scope) -> int (script scope) |
84 |
* @endcode |
* @endcode |
85 |
* This is required because engine internally notes and regular events are |
* This is required because engine internally i.e. notes and regular events |
86 |
* using their own, separate ID generating pool, and their ID number set |
* are using their own, separate ID generating pool, and their ID number |
87 |
* may thus overlap. |
* set may thus overlap and historically there were built-in script |
88 |
|
* functions in KSP which allow to pass both regular MIDI event IDs, as well |
89 |
|
* as Note IDs. So we must be able to distinguish between them in our |
90 |
|
* built-in script function implementations. |
91 |
* |
* |
92 |
* @see INSTR_SCRIPT_EVENT_ID_RESERVED_BITS |
* @see INSTR_SCRIPT_EVENT_ID_RESERVED_BITS |
93 |
*/ |
*/ |
108 |
* internal scope. |
* internal scope. |
109 |
*/ |
*/ |
110 |
inline static ScriptID fromEventID(event_id_t id) { |
inline static ScriptID fromEventID(event_id_t id) { |
111 |
return ScriptID(id); |
return ScriptID(INSTR_SCRIPT_EVENT_ID_FLAG | id); |
112 |
} |
} |
113 |
|
|
114 |
/** |
/** |
243 |
std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE; |
std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE; |
244 |
std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE; |
std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE; |
245 |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
246 |
|
std::map<String,VMDynVar*> builtInDynamicVariables() OVERRIDE; |
247 |
protected: |
protected: |
248 |
ScriptEvent* m_event; ///< The event currently executed by exec(). |
ScriptEvent* m_event; ///< The event currently executed by exec(). |
249 |
|
|
250 |
// buil-in script variables |
// built-in script variables |
251 |
VMInt8Array m_CC; |
VMInt8Array m_CC; |
252 |
VMInt8RelPtr m_CC_NUM; |
VMInt8RelPtr m_CC_NUM; |
253 |
VMIntRelPtr m_EVENT_ID; |
VMIntRelPtr m_EVENT_ID; |
256 |
VMInt8Array m_KEY_DOWN; |
VMInt8Array m_KEY_DOWN; |
257 |
//VMIntArray m_POLY_AT; //TODO: ... |
//VMIntArray m_POLY_AT; //TODO: ... |
258 |
//int m_POLY_AT_NUM; //TODO: ... |
//int m_POLY_AT_NUM; //TODO: ... |
259 |
|
VMIntRelPtr m_NI_CALLBACK_TYPE; |
260 |
|
VMIntRelPtr m_NKSP_IGNORE_WAIT; |
261 |
|
|
262 |
// buil-in script functions |
// built-in script functions |
263 |
InstrumentScriptVMFunction_play_note m_fnPlayNote; |
InstrumentScriptVMFunction_play_note m_fnPlayNote; |
264 |
InstrumentScriptVMFunction_set_controller m_fnSetController; |
InstrumentScriptVMFunction_set_controller m_fnSetController; |
265 |
InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; |
InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; |
273 |
InstrumentScriptVMFunction_change_pan m_fnChangePan; |
InstrumentScriptVMFunction_change_pan m_fnChangePan; |
274 |
InstrumentScriptVMFunction_change_cutoff m_fnChangeCutoff; |
InstrumentScriptVMFunction_change_cutoff m_fnChangeCutoff; |
275 |
InstrumentScriptVMFunction_change_reso m_fnChangeReso; |
InstrumentScriptVMFunction_change_reso m_fnChangeReso; |
276 |
|
InstrumentScriptVMFunction_change_attack m_fnChangeAttack; |
277 |
|
InstrumentScriptVMFunction_change_decay m_fnChangeDecay; |
278 |
|
InstrumentScriptVMFunction_change_release m_fnChangeRelease; |
279 |
InstrumentScriptVMFunction_event_status m_fnEventStatus; |
InstrumentScriptVMFunction_event_status m_fnEventStatus; |
280 |
|
InstrumentScriptVMFunction_wait m_fnWait2; |
281 |
|
InstrumentScriptVMFunction_stop_wait m_fnStopWait; |
282 |
|
InstrumentScriptVMDynVar_ENGINE_UPTIME m_varEngineUptime; |
283 |
|
InstrumentScriptVMDynVar_NI_CALLBACK_ID m_varCallbackID; |
284 |
|
InstrumentScriptVMDynVar_ALL_EVENTS m_varAllEvents; |
285 |
|
|
286 |
friend class InstrumentScriptVMFunction_play_note; |
friend class InstrumentScriptVMFunction_play_note; |
287 |
friend class InstrumentScriptVMFunction_set_controller; |
friend class InstrumentScriptVMFunction_set_controller; |
296 |
friend class InstrumentScriptVMFunction_change_pan; |
friend class InstrumentScriptVMFunction_change_pan; |
297 |
friend class InstrumentScriptVMFunction_change_cutoff; |
friend class InstrumentScriptVMFunction_change_cutoff; |
298 |
friend class InstrumentScriptVMFunction_change_reso; |
friend class InstrumentScriptVMFunction_change_reso; |
299 |
|
friend class InstrumentScriptVMFunction_change_attack; |
300 |
|
friend class InstrumentScriptVMFunction_change_decay; |
301 |
|
friend class InstrumentScriptVMFunction_change_release; |
302 |
friend class InstrumentScriptVMFunction_event_status; |
friend class InstrumentScriptVMFunction_event_status; |
303 |
|
friend class InstrumentScriptVMFunction_wait; |
304 |
|
friend class InstrumentScriptVMFunction_stop_wait; |
305 |
|
friend class InstrumentScriptVMDynVar_ENGINE_UPTIME; |
306 |
|
friend class InstrumentScriptVMDynVar_NI_CALLBACK_ID; |
307 |
|
friend class InstrumentScriptVMDynVar_ALL_EVENTS; |
308 |
}; |
}; |
309 |
|
|
310 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |