1 |
/* |
/* |
2 |
* Copyright (c) 2014 - 2020 Christian Schoenebeck |
* Copyright (c) 2014 - 2021 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
42 |
if (!pEngine->EventByID(eventID)) firstDead = i; |
if (!pEngine->EventByID(eventID)) firstDead = i; |
43 |
} |
} |
44 |
} |
} |
45 |
|
if (firstDead >= 0) |
46 |
|
remove(firstDead, size() - firstDead); |
47 |
|
|
48 |
append(eventID); |
append(eventID); |
49 |
} |
} |
90 |
* channels. |
* channels. |
91 |
* |
* |
92 |
* @param text - source code of script |
* @param text - source code of script |
93 |
|
* @param patchVars - 'patch' variables being overridden by instrument |
94 |
*/ |
*/ |
95 |
void InstrumentScript::load(const String& text) { |
void InstrumentScript::load(const String& text, |
96 |
|
const std::map<String,String>& patchVars) |
97 |
|
{ |
98 |
dmsg(1,("Loading real-time instrument script ... ")); |
dmsg(1,("Loading real-time instrument script ... ")); |
99 |
|
|
100 |
// hand back old script reference and VM execution contexts |
// hand back old script reference and VM execution contexts |
107 |
dynamic_cast<AbstractInstrumentManager*>(pEngineChannel->pEngine->GetInstrumentManager()); |
dynamic_cast<AbstractInstrumentManager*>(pEngineChannel->pEngine->GetInstrumentManager()); |
108 |
|
|
109 |
// get new script reference |
// get new script reference |
110 |
parserContext = pManager->scripts.Borrow(text, pEngineChannel); |
parserContext = pManager->scripts.Borrow( |
111 |
|
{ .code = text, .patchVars = patchVars }, pEngineChannel |
112 |
|
); |
113 |
if (!parserContext->errors().empty()) { |
if (!parserContext->errors().empty()) { |
114 |
std::vector<ParserIssue> errors = parserContext->errors(); |
std::vector<ParserIssue> errors = parserContext->errors(); |
115 |
std::cerr << "[ScriptVM] Could not load instrument script, there were " |
std::cerr << "[ScriptVM] Could not load instrument script, there were " |
146 |
RTList<ScriptEvent>::Iterator it = pEvents->allocAppend(); |
RTList<ScriptEvent>::Iterator it = pEvents->allocAppend(); |
147 |
it->reset(); |
it->reset(); |
148 |
} |
} |
|
pEvents->clear(); |
|
149 |
} |
} |
150 |
|
pEvents->clear(); // outside of upper block, as loop below must always start from cleared list |
151 |
|
|
152 |
// create new VM execution contexts for new script |
// create new VM execution contexts for new script |
153 |
while (!pEvents->poolIsEmpty()) { |
while (!pEvents->poolIsEmpty()) { |
186 |
pEvents->clear(); |
pEvents->clear(); |
187 |
while (!pEvents->poolIsEmpty()) { |
while (!pEvents->poolIsEmpty()) { |
188 |
RTList<ScriptEvent>::Iterator it = pEvents->allocAppend(); |
RTList<ScriptEvent>::Iterator it = pEvents->allocAppend(); |
189 |
|
if (!it) break; |
190 |
if (it->execCtx) { |
if (it->execCtx) { |
191 |
// free VM execution context object |
// free VM execution context object |
192 |
delete it->execCtx; |
delete it->execCtx; |
193 |
it->execCtx = NULL; |
it->execCtx = NULL; |
194 |
// free C array of handler pointers |
// free C array of handler pointers |
195 |
delete [] it->handlers; |
delete [] it->handlers; |
196 |
|
it->handlers = NULL; |
197 |
} |
} |
198 |
} |
} |
199 |
pEvents->clear(); |
pEvents->clear(); |
246 |
|
|
247 |
InstrumentScriptVM::InstrumentScriptVM() : |
InstrumentScriptVM::InstrumentScriptVM() : |
248 |
m_event(NULL), m_fnPlayNote(this), m_fnSetController(this), |
m_event(NULL), m_fnPlayNote(this), m_fnSetController(this), |
249 |
|
m_fnSetRpn(this), m_fnSetNrpn(this), |
250 |
m_fnIgnoreEvent(this), m_fnIgnoreController(this), m_fnNoteOff(this), |
m_fnIgnoreEvent(this), m_fnIgnoreController(this), m_fnNoteOff(this), |
251 |
m_fnSetEventMark(this), m_fnDeleteEventMark(this), m_fnByMarks(this), |
m_fnSetEventMark(this), m_fnDeleteEventMark(this), m_fnByMarks(this), |
252 |
m_fnChangeVol(this), m_fnChangeVolTime(this), |
m_fnChangeVol(this), m_fnChangeVolTime(this), |
414 |
// built-in script functions of this class |
// built-in script functions of this class |
415 |
if (name == "play_note") return &m_fnPlayNote; |
if (name == "play_note") return &m_fnPlayNote; |
416 |
else if (name == "set_controller") return &m_fnSetController; |
else if (name == "set_controller") return &m_fnSetController; |
417 |
|
else if (name == "set_rpn") return &m_fnSetRpn; |
418 |
|
else if (name == "set_nrpn") return &m_fnSetNrpn; |
419 |
else if (name == "ignore_event") return &m_fnIgnoreEvent; |
else if (name == "ignore_event") return &m_fnIgnoreEvent; |
420 |
else if (name == "ignore_controller") return &m_fnIgnoreController; |
else if (name == "ignore_controller") return &m_fnIgnoreController; |
421 |
else if (name == "note_off") return &m_fnNoteOff; |
else if (name == "note_off") return &m_fnNoteOff; |