/[svn]/linuxsampler/trunk/src/engines/EngineChannelBase.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/EngineChannelBase.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2611 by schoenebeck, Mon Jun 9 19:20:37 2014 UTC revision 2612 by schoenebeck, Tue Jun 10 13:32:16 2014 UTC
# Line 85  namespace LinuxSampler { Line 85  namespace LinuxSampler {
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                      }                      }
# Line 96  namespace LinuxSampler { Line 98  namespace LinuxSampler {
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;
# Line 180  namespace LinuxSampler { Line 183  namespace LinuxSampler {
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) {
# Line 303  namespace LinuxSampler { Line 307  namespace LinuxSampler {
307              }              }
308    
309              virtual ~EngineChannelBase() {              virtual ~EngineChannelBase() {
310                    InstrumentScript* previous = NULL; // prevent double free
311                  {                  {
312                      InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate();                      InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate();
313                      if (cmd.pScript) delete cmd.pScript;                      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();                      InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig();
321                      if (cmd.pScript) delete cmd.pScript;                      if (cmd.pScript) {
322                            if (previous != cmd.pScript)
323                                delete cmd.pScript;
324                            cmd.pScript = NULL;
325                        }
326                  }                  }
327              }              }
328    
# Line 364  namespace LinuxSampler { Line 377  namespace LinuxSampler {
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               * Load real-time instrument script and all its resources required
397               * for the upcoming instrument change.               * for the upcoming instrument change.
398               *               *
# Line 371  namespace LinuxSampler { Line 400  namespace LinuxSampler {
400               */               */
401              void LoadInstrumentScript(const String& text) {              void LoadInstrumentScript(const String& text) {
402                  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  
403                  // load the new script                  // load the new script
404                  cmd.pScript->load(text);                  cmd.pScript->load(text);
405              }              }

Legend:
Removed from v.2611  
changed lines
  Added in v.2612

  ViewVC Help
Powered by ViewVC