11 |
#include "../AbstractEngineChannel.h" |
#include "../AbstractEngineChannel.h" |
12 |
#include "../../common/global_private.h" |
#include "../../common/global_private.h" |
13 |
#include "AbstractInstrumentManager.h" |
#include "AbstractInstrumentManager.h" |
14 |
|
#include "MidiKeyboardManager.h" |
15 |
|
|
16 |
namespace LinuxSampler { |
namespace LinuxSampler { |
17 |
|
|
33 |
|
|
34 |
// hand back old script reference and VM execution contexts |
// hand back old script reference and VM execution contexts |
35 |
// (if not done already) |
// (if not done already) |
36 |
reset(); |
unload(); |
37 |
|
|
38 |
|
code = text; |
39 |
|
|
40 |
AbstractInstrumentManager* pManager = |
AbstractInstrumentManager* pManager = |
41 |
dynamic_cast<AbstractInstrumentManager*>(pEngineChannel->pEngine->GetInstrumentManager()); |
dynamic_cast<AbstractInstrumentManager*>(pEngineChannel->pEngine->GetInstrumentManager()); |
87 |
* is used to share equivalent scripts among multiple sampler channels, and |
* is used to share equivalent scripts among multiple sampler channels, and |
88 |
* to deallocate the parsed script once not used on any engine channel |
* to deallocate the parsed script once not used on any engine channel |
89 |
* anymore. |
* anymore. |
90 |
|
* |
91 |
|
* Calling thid method will however not clear the @c code member variable. |
92 |
|
* Thus, the script can be parsed again afterwards. |
93 |
*/ |
*/ |
94 |
void InstrumentScript::reset() { |
void InstrumentScript::unload() { |
95 |
if (parserContext) |
if (parserContext) |
96 |
dmsg(1,("Unloading current instrument script.")); |
dmsg(1,("Unloading current instrument script.\n")); |
97 |
|
|
98 |
// free allocated VM execution contexts |
// free allocated VM execution contexts |
99 |
if (pEvents) { |
if (pEvents) { |
125 |
bHasValidScript = false; |
bHasValidScript = false; |
126 |
} |
} |
127 |
|
|
128 |
|
/** |
129 |
|
* Same as unload(), but this one also empties the @c code member variable |
130 |
|
* to an empty string. |
131 |
|
*/ |
132 |
|
void InstrumentScript::resetAll() { |
133 |
|
unload(); |
134 |
|
code.clear(); |
135 |
|
} |
136 |
|
|
137 |
/////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////// |
138 |
// class 'InstrumentScriptVM' |
// class 'InstrumentScriptVM' |
139 |
|
|
146 |
m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id); |
m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id); |
147 |
m_EVENT_NOTE = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Key); |
m_EVENT_NOTE = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Key); |
148 |
m_EVENT_VELOCITY = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Velocity); |
m_EVENT_VELOCITY = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Velocity); |
149 |
|
m_KEY_DOWN.size = 128; |
150 |
} |
} |
151 |
|
|
152 |
VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { |
VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { |
156 |
// prepare built-in script variables for script execution |
// prepare built-in script variables for script execution |
157 |
m_event = event; |
m_event = event; |
158 |
m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; |
m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; |
159 |
|
m_KEY_DOWN.data = &pEngineChannel->GetMidiKeyboardManager()->KeyDown[0]; |
160 |
|
|
161 |
// if script is in start condition, then do mandatory MIDI event |
// if script is in start condition, then do mandatory MIDI event |
162 |
// preprocessing tasks, which essentially means updating i.e. controller |
// preprocessing tasks, which essentially means updating i.e. controller |
212 |
|
|
213 |
// now add own built-in variables |
// now add own built-in variables |
214 |
m["%CC"] = &m_CC; |
m["%CC"] = &m_CC; |
215 |
//m["%KEY_DOWN"] = &m_KEY_DOWN; |
m["%KEY_DOWN"] = &m_KEY_DOWN; |
216 |
//m["%POLY_AT"] = &m_POLY_AT; |
//m["%POLY_AT"] = &m_POLY_AT; |
217 |
|
|
218 |
return m; |
return m; |