39 |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
40 |
I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
41 |
RTList<R*>* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
RTList<R*>* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
42 |
|
InstrumentScript* pScript; ///< Instrument script to be executed for this instrument, or NULL if instrument does not have a script. |
43 |
}; |
}; |
44 |
|
|
45 |
template<class R> |
template<class R> |
85 |
} |
} |
86 |
|
|
87 |
virtual void DeleteRegionsInUse() { |
virtual void DeleteRegionsInUse() { |
88 |
|
RTList<R*>* previous = NULL; // prevent double free |
89 |
{ |
{ |
90 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
91 |
if (cmd.pRegionsInUse) { |
if (cmd.pRegionsInUse) { |
92 |
|
previous = cmd.pRegionsInUse; |
93 |
delete cmd.pRegionsInUse; |
delete cmd.pRegionsInUse; |
94 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
95 |
} |
} |
98 |
{ |
{ |
99 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
100 |
if (cmd.pRegionsInUse) { |
if (cmd.pRegionsInUse) { |
101 |
delete cmd.pRegionsInUse; |
if (cmd.pRegionsInUse != previous) |
102 |
|
delete cmd.pRegionsInUse; |
103 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
104 |
} |
} |
105 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
183 |
ResetInternal(); |
ResetInternal(); |
184 |
|
|
185 |
DeleteRegionsInUse(); |
DeleteRegionsInUse(); |
186 |
|
UnloadScriptInUse(); |
187 |
|
|
188 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
189 |
if (cmd.pInstrument) { |
if (cmd.pInstrument) { |
294 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
295 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
296 |
cmd.pInstrument = NULL; |
cmd.pInstrument = NULL; |
297 |
|
cmd.pScript = new InstrumentScript(this); |
298 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
299 |
} |
} |
300 |
{ |
{ |
301 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
302 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
303 |
cmd.pInstrument = NULL; |
cmd.pInstrument = NULL; |
304 |
|
cmd.pScript = new InstrumentScript(this); |
305 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
306 |
} |
} |
307 |
} |
} |
308 |
|
|
309 |
virtual ~EngineChannelBase() { } |
virtual ~EngineChannelBase() { |
310 |
|
InstrumentScript* previous = NULL; // prevent double free |
311 |
|
{ |
312 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
313 |
|
if (cmd.pScript) { |
314 |
|
previous = cmd.pScript; |
315 |
|
delete cmd.pScript; |
316 |
|
cmd.pScript = NULL; |
317 |
|
} |
318 |
|
} |
319 |
|
{ |
320 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
321 |
|
if (cmd.pScript) { |
322 |
|
if (previous != cmd.pScript) |
323 |
|
delete cmd.pScript; |
324 |
|
cmd.pScript = NULL; |
325 |
|
} |
326 |
|
} |
327 |
|
} |
328 |
|
|
329 |
typedef typename RTList<V>::Iterator RTListVoiceIterator; |
typedef typename RTList<V>::Iterator RTListVoiceIterator; |
330 |
|
|
377 |
} |
} |
378 |
|
|
379 |
/** |
/** |
380 |
|
* Unload the currently used and loaded real-time instrument script. |
381 |
|
* The source code of the script is retained, so that it can still |
382 |
|
* be reloaded. |
383 |
|
*/ |
384 |
|
void UnloadScriptInUse() { |
385 |
|
{ |
386 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
387 |
|
if (cmd.pScript) pScript->unload(); |
388 |
|
} |
389 |
|
{ |
390 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
391 |
|
if (cmd.pScript) pScript->unload(); |
392 |
|
} |
393 |
|
} |
394 |
|
|
395 |
|
/** |
396 |
|
* Load real-time instrument script and all its resources required |
397 |
|
* for the upcoming instrument change. |
398 |
|
* |
399 |
|
* @param text - source code of script |
400 |
|
*/ |
401 |
|
void LoadInstrumentScript(const String& text) { |
402 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
403 |
|
// load the new script |
404 |
|
cmd.pScript->load(text); |
405 |
|
} |
406 |
|
|
407 |
|
/** |
408 |
* Changes the instrument for an engine channel. |
* Changes the instrument for an engine channel. |
409 |
* |
* |
410 |
* @param pInstrument - new instrument |
* @param pInstrument - new instrument |