60 |
typedef typename RTList<R*>::Iterator RTListRegionIterator; |
typedef typename RTList<R*>::Iterator RTListRegionIterator; |
61 |
typedef typename MidiKeyboardManager<V>::MidiKey MidiKey; |
typedef typename MidiKeyboardManager<V>::MidiKey MidiKey; |
62 |
|
|
63 |
|
virtual MidiKeyboardManagerBase* GetMidiKeyboardManager() OVERRIDE { |
64 |
|
return this; |
65 |
|
} |
66 |
|
|
67 |
virtual void HandBack(I* Instrument) { |
virtual void HandBack(I* Instrument) { |
68 |
ResourceManager<InstrumentManager::instrument_id_t, I>* mgr = |
ResourceManager<InstrumentManager::instrument_id_t, I>* mgr = |
69 |
dynamic_cast<ResourceManager<InstrumentManager::instrument_id_t, I>*>(pEngine->GetInstrumentManager()); |
dynamic_cast<ResourceManager<InstrumentManager::instrument_id_t, I>*>(pEngine->GetInstrumentManager()); |
89 |
} |
} |
90 |
|
|
91 |
virtual void DeleteRegionsInUse() { |
virtual void DeleteRegionsInUse() { |
92 |
|
RTList<R*>* previous = NULL; // prevent double free |
93 |
{ |
{ |
94 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
95 |
if (cmd.pRegionsInUse) { |
if (cmd.pRegionsInUse) { |
96 |
|
previous = cmd.pRegionsInUse; |
97 |
delete cmd.pRegionsInUse; |
delete cmd.pRegionsInUse; |
98 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
99 |
} |
} |
102 |
{ |
{ |
103 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
104 |
if (cmd.pRegionsInUse) { |
if (cmd.pRegionsInUse) { |
105 |
delete cmd.pRegionsInUse; |
if (cmd.pRegionsInUse != previous) |
106 |
|
delete cmd.pRegionsInUse; |
107 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
108 |
} |
} |
109 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
187 |
ResetInternal(); |
ResetInternal(); |
188 |
|
|
189 |
DeleteRegionsInUse(); |
DeleteRegionsInUse(); |
190 |
|
UnloadScriptInUse(); |
191 |
|
|
192 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
193 |
if (cmd.pInstrument) { |
if (cmd.pInstrument) { |
311 |
} |
} |
312 |
|
|
313 |
virtual ~EngineChannelBase() { |
virtual ~EngineChannelBase() { |
314 |
|
InstrumentScript* previous = NULL; // prevent double free |
315 |
{ |
{ |
316 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
317 |
if (cmd.pScript) delete cmd.pScript; |
if (cmd.pScript) { |
318 |
|
previous = cmd.pScript; |
319 |
|
delete cmd.pScript; |
320 |
|
cmd.pScript = NULL; |
321 |
|
} |
322 |
} |
} |
323 |
{ |
{ |
324 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
325 |
if (cmd.pScript) delete cmd.pScript; |
if (cmd.pScript) { |
326 |
|
if (previous != cmd.pScript) |
327 |
|
delete cmd.pScript; |
328 |
|
cmd.pScript = NULL; |
329 |
|
} |
330 |
} |
} |
331 |
} |
} |
332 |
|
|
381 |
} |
} |
382 |
|
|
383 |
/** |
/** |
384 |
|
* Unload the currently used and loaded real-time instrument script. |
385 |
|
* The source code of the script is retained, so that it can still |
386 |
|
* be reloaded. |
387 |
|
*/ |
388 |
|
void UnloadScriptInUse() { |
389 |
|
{ |
390 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
391 |
|
if (cmd.pScript) cmd.pScript->unload(); |
392 |
|
} |
393 |
|
{ |
394 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
395 |
|
if (cmd.pScript) cmd.pScript->unload(); |
396 |
|
} |
397 |
|
InstrumentChangeCommand.SwitchConfig(); // switch back to original one |
398 |
|
} |
399 |
|
|
400 |
|
/** |
401 |
* Load real-time instrument script and all its resources required |
* Load real-time instrument script and all its resources required |
402 |
* for the upcoming instrument change. |
* for the upcoming instrument change. |
403 |
* |
* |
405 |
*/ |
*/ |
406 |
void LoadInstrumentScript(const String& text) { |
void LoadInstrumentScript(const String& text) { |
407 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
|
// unload *PRE*-previous script |
|
|
cmd.pScript->reset(); //TODO: previous script should be freed as soon as the EngineBase switched the instrument, right now 2 scripts are kept in memory all the time, even though the old one is not used anymore |
|
408 |
// load the new script |
// load the new script |
409 |
cmd.pScript->load(text); |
cmd.pScript->load(text); |
410 |
} |
} |