11 |
#define LS_INSTRUMENT_SCRIPT_VM_H |
#define LS_INSTRUMENT_SCRIPT_VM_H |
12 |
|
|
13 |
#include "../../common/global.h" |
#include "../../common/global.h" |
14 |
|
#include "../../common/ConstCapacityArray.h" |
15 |
#include "../../scriptvm/ScriptVM.h" |
#include "../../scriptvm/ScriptVM.h" |
16 |
#include "Event.h" |
#include "Event.h" |
17 |
#include "../../common/Pool.h" |
#include "../../common/Pool.h" |
18 |
#include "InstrumentScriptVMFunctions.h" |
#include "InstrumentScriptVMFunctions.h" |
19 |
|
|
20 |
|
#define INSTR_SCRIPT_EVENT_GROUPS 28 |
21 |
|
|
22 |
namespace LinuxSampler { |
namespace LinuxSampler { |
23 |
|
|
24 |
class AbstractEngineChannel; |
class AbstractEngineChannel; |
25 |
|
class InstrumentScript; |
26 |
|
|
27 |
|
/** @brief List of Event IDs. |
28 |
|
* |
29 |
|
* Used for built-in script functions: |
30 |
|
* by_marks(), set_event_mark(), delete_event_mark() |
31 |
|
*/ |
32 |
|
class EventGroup : protected ConstCapacityArray<int> { |
33 |
|
public: |
34 |
|
EventGroup() : ConstCapacityArray<int>(CONFIG_MAX_EVENTS_PER_FRAGMENT), m_script(NULL) {} |
35 |
|
void insert(int eventID); |
36 |
|
void erase(int eventID); |
37 |
|
void setScript(InstrumentScript* pScript) { m_script = pScript; } |
38 |
|
inline int size() const { return ConstCapacityArray<int>::size(); } |
39 |
|
inline int& operator[](uint index) { return ConstCapacityArray<int>::operator[](index); } |
40 |
|
inline const int& operator[](uint index) const { return ConstCapacityArray<int>::operator[](index); } |
41 |
|
protected: |
42 |
|
InstrumentScript* m_script; |
43 |
|
}; |
44 |
|
|
45 |
/** @brief Real-time instrument script VM representation. |
/** @brief Real-time instrument script VM representation. |
46 |
* |
* |
47 |
* Holds the VM representation of all event handlers of the currently loaded |
* Holds the VM representation of all event handlers of the currently loaded |
48 |
* script, ready to be executed by the sampler engine. |
* script, ready to be executed by the sampler engine. |
49 |
|
* |
50 |
|
* Even thought scripts (or to be more specific their event handler objects) |
51 |
|
* are shared between sampler engine channels, the InstrumentScript struct |
52 |
|
* instances though are not shared. Each sampler engine channel has its own |
53 |
|
* instance of a InstrumentScript struct. That's important, because this |
54 |
|
* struct also holds engine channel local informations, for example the |
55 |
|
* events that occured on the respective engine channel. |
56 |
*/ |
*/ |
57 |
struct InstrumentScript { |
struct InstrumentScript { |
58 |
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! |
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! |
61 |
VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler. |
VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler. |
62 |
VMEventHandler* handlerRelease; ///< VM representation of script's MIDI note off 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. |
63 |
VMEventHandler* handlerController; ///< VM representation of script's MIDI controller 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. |
64 |
Pool<ScriptEvent>* 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. |
Pool<ScriptEvent>* 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 (@see pKeyEvents). |
65 |
|
RTList<ScriptEvent>* pKeyEvents[128]; ///< Stores previously finished executed "note on" script events for the respective active note/key as long as the key/note is active. This is however only done if there is a "note" script event handler and a "release" script event handler defined in the script and both handlers use (reference) polyphonic variables. If that is not the case, then this list is not used at all. So the purpose of pKeyEvents is only to implement preserving/passing polyphonic variable data from "on note .. end on" script block to the respective "on release .. end on" script block. |
66 |
AbstractEngineChannel* pEngineChannel; |
AbstractEngineChannel* pEngineChannel; |
67 |
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. |
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. |
68 |
|
EventGroup eventGroups[INSTR_SCRIPT_EVENT_GROUPS]; ///< Used for built-in script functions: by_event_marks(), set_event_mark(), delete_event_mark(). |
69 |
|
|
70 |
InstrumentScript(AbstractEngineChannel* pEngineChannel) { |
InstrumentScript(AbstractEngineChannel* pEngineChannel); |
71 |
parserContext = NULL; |
~InstrumentScript(); |
|
bHasValidScript = false; |
|
|
handlerInit = NULL; |
|
|
handlerNote = NULL; |
|
|
handlerRelease = NULL; |
|
|
handlerController = NULL; |
|
|
pEvents = NULL; |
|
|
this->pEngineChannel = pEngineChannel; |
|
|
} |
|
|
|
|
|
~InstrumentScript() { |
|
|
resetAll(); |
|
|
} |
|
72 |
|
|
73 |
void load(const String& text); |
void load(const String& text); |
74 |
void unload(); |
void unload(); |
112 |
InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; |
InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; |
113 |
InstrumentScriptVMFunction_ignore_controller m_fnIgnoreController; |
InstrumentScriptVMFunction_ignore_controller m_fnIgnoreController; |
114 |
InstrumentScriptVMFunction_note_off m_fnNoteOff; |
InstrumentScriptVMFunction_note_off m_fnNoteOff; |
115 |
|
InstrumentScriptVMFunction_set_event_mark m_fnSetEventMark; |
116 |
|
InstrumentScriptVMFunction_delete_event_mark m_fnDeleteEventMark; |
117 |
|
InstrumentScriptVMFunction_by_marks m_fnByMarks; |
118 |
|
|
119 |
friend class InstrumentScriptVMFunction_play_note; |
friend class InstrumentScriptVMFunction_play_note; |
120 |
friend class InstrumentScriptVMFunction_set_controller; |
friend class InstrumentScriptVMFunction_set_controller; |
121 |
friend class InstrumentScriptVMFunction_ignore_event; |
friend class InstrumentScriptVMFunction_ignore_event; |
122 |
friend class InstrumentScriptVMFunction_ignore_controller; |
friend class InstrumentScriptVMFunction_ignore_controller; |
123 |
friend class InstrumentScriptVMFunction_note_off; |
friend class InstrumentScriptVMFunction_note_off; |
124 |
|
friend class InstrumentScriptVMFunction_set_event_mark; |
125 |
|
friend class InstrumentScriptVMFunction_delete_event_mark; |
126 |
|
friend class InstrumentScriptVMFunction_by_marks; |
127 |
}; |
}; |
128 |
|
|
129 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |