--- linuxsampler/trunk/src/engines/EngineChannelBase.h 2013/03/07 19:23:24 2434 +++ linuxsampler/trunk/src/engines/EngineChannelBase.h 2014/06/09 19:20:37 2611 @@ -39,6 +39,7 @@ bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. RTList* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. + InstrumentScript* pScript; ///< Instrument script to be executed for this instrument, or NULL if instrument does not have a script. }; template @@ -289,17 +290,28 @@ InstrumentChangeCmd& cmd = InstrumentChangeCommand.GetConfigForUpdate(); cmd.pRegionsInUse = NULL; cmd.pInstrument = NULL; + cmd.pScript = new InstrumentScript(this); cmd.bChangeInstrument = false; } { InstrumentChangeCmd& cmd = InstrumentChangeCommand.SwitchConfig(); cmd.pRegionsInUse = NULL; cmd.pInstrument = NULL; + cmd.pScript = new InstrumentScript(this); cmd.bChangeInstrument = false; } } - virtual ~EngineChannelBase() { } + virtual ~EngineChannelBase() { + { + InstrumentChangeCmd& cmd = InstrumentChangeCommand.GetConfigForUpdate(); + if (cmd.pScript) delete cmd.pScript; + } + { + InstrumentChangeCmd& cmd = InstrumentChangeCommand.SwitchConfig(); + if (cmd.pScript) delete cmd.pScript; + } + } typedef typename RTList::Iterator RTListVoiceIterator; @@ -352,6 +364,20 @@ } /** + * Load real-time instrument script and all its resources required + * for the upcoming instrument change. + * + * @param text - source code of script + */ + void LoadInstrumentScript(const String& text) { + InstrumentChangeCmd& 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 + // load the new script + cmd.pScript->load(text); + } + + /** * Changes the instrument for an engine channel. * * @param pInstrument - new instrument