1 |
schoenebeck |
2594 |
/* |
2 |
|
|
* Copyright (c) 2014 Christian Schoenebeck |
3 |
|
|
* |
4 |
|
|
* http://www.linuxsampler.org |
5 |
|
|
* |
6 |
|
|
* This file is part of LinuxSampler and released under the same terms. |
7 |
|
|
* See README file for details. |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#ifndef LS_INSTRUMENT_SCRIPT_VM_H |
11 |
|
|
#define LS_INSTRUMENT_SCRIPT_VM_H |
12 |
|
|
|
13 |
|
|
#include "../../common/global.h" |
14 |
|
|
#include "../../scriptvm/ScriptVM.h" |
15 |
|
|
#include "Event.h" |
16 |
schoenebeck |
2611 |
#include "../../common/Pool.h" |
17 |
schoenebeck |
2596 |
#include "InstrumentScriptVMFunctions.h" |
18 |
schoenebeck |
2594 |
|
19 |
|
|
namespace LinuxSampler { |
20 |
|
|
|
21 |
schoenebeck |
2611 |
class AbstractEngineChannel; |
22 |
|
|
|
23 |
|
|
/** @brief Real-time instrument script VM representation. |
24 |
|
|
* |
25 |
|
|
* Holds the VM representation of all event handlers of the currently loaded |
26 |
|
|
* script, ready to be executed by the sampler engine. |
27 |
|
|
*/ |
28 |
|
|
struct InstrumentScript { |
29 |
|
|
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! |
30 |
|
|
bool bHasValidScript; ///< True in case there is a valid script currently loaded, false if script processing shall be skipped. |
31 |
|
|
VMEventHandler* handlerInit; ///< VM representation of script's initilization callback or NULL if current script did not define such an init handler. |
32 |
|
|
VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler. |
33 |
|
|
VMEventHandler* handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler. |
34 |
|
|
VMEventHandler* handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler. |
35 |
|
|
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. |
36 |
|
|
AbstractEngineChannel* pEngineChannel; |
37 |
|
|
|
38 |
|
|
InstrumentScript(AbstractEngineChannel* pEngineChannel) { |
39 |
|
|
parserContext = NULL; |
40 |
|
|
bHasValidScript = false; |
41 |
|
|
handlerInit = NULL; |
42 |
|
|
handlerNote = NULL; |
43 |
|
|
handlerRelease = NULL; |
44 |
|
|
handlerController = NULL; |
45 |
|
|
pEvents = NULL; |
46 |
|
|
this->pEngineChannel = pEngineChannel; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
~InstrumentScript() { |
50 |
|
|
reset(); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
void load(const String& text); |
54 |
|
|
void reset(); |
55 |
|
|
}; |
56 |
|
|
|
57 |
schoenebeck |
2594 |
/** @brief Real-time instrument script virtual machine. |
58 |
|
|
* |
59 |
|
|
* Extends the core ScriptVM implementation with MIDI specific built-in |
60 |
|
|
* script functions and MIDI specific built-in script variables required |
61 |
|
|
* for MIDI processing by instrument script for all sampler engine |
62 |
|
|
* implementations (sampler formats) of this sampler. |
63 |
|
|
* |
64 |
|
|
* Note that this class is currently re-entrant safe, but @b not thread |
65 |
|
|
* safe! See also comments of base class ScriptVM regarding this issue. |
66 |
|
|
*/ |
67 |
|
|
class InstrumentScriptVM : public ScriptVM { |
68 |
|
|
public: |
69 |
|
|
InstrumentScriptVM(); |
70 |
|
|
VMExecStatus_t exec(VMParserContext* parserCtx, ScriptEvent* event); |
71 |
schoenebeck |
2596 |
VMFunction* functionByName(const String& name) OVERRIDE; |
72 |
schoenebeck |
2594 |
std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE; |
73 |
|
|
std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE; |
74 |
|
|
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
75 |
|
|
protected: |
76 |
|
|
ScriptEvent* m_event; ///< The event currently executed by exec(). |
77 |
|
|
|
78 |
|
|
// buil-in script variables |
79 |
|
|
VMInt8Array m_CC; |
80 |
|
|
VMInt8RelPtr m_CC_NUM; |
81 |
schoenebeck |
2598 |
VMIntRelPtr m_EVENT_ID; |
82 |
schoenebeck |
2594 |
VMInt8RelPtr m_EVENT_NOTE; |
83 |
|
|
VMInt8RelPtr m_EVENT_VELOCITY; |
84 |
|
|
//VMIntArray m_KEY_DOWN; //TODO: ... |
85 |
|
|
//VMIntArray m_POLY_AT; //TODO: ... |
86 |
|
|
//int m_POLY_AT_NUM; //TODO: ... |
87 |
schoenebeck |
2596 |
|
88 |
|
|
// buil-in script functions |
89 |
|
|
InstrumentScriptVMFunction_play_note m_fnPlayNote; |
90 |
schoenebeck |
2600 |
InstrumentScriptVMFunction_set_controller m_fnSetController; |
91 |
|
|
InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent; |
92 |
|
|
InstrumentScriptVMFunction_ignore_controller m_fnIgnoreController; |
93 |
schoenebeck |
2596 |
|
94 |
|
|
friend class InstrumentScriptVMFunction_play_note; |
95 |
schoenebeck |
2600 |
friend class InstrumentScriptVMFunction_set_controller; |
96 |
schoenebeck |
2598 |
friend class InstrumentScriptVMFunction_ignore_event; |
97 |
|
|
friend class InstrumentScriptVMFunction_ignore_controller; |
98 |
schoenebeck |
2594 |
}; |
99 |
|
|
|
100 |
|
|
} // namespace LinuxSampler |
101 |
|
|
|
102 |
|
|
#endif // LS_INSTRUMENT_SCRIPT_VM_H |