From c996d3775209f3696e123ba7e81a7566b111a515 Mon Sep 17 00:00:00 2001 From: Giso Grimm Date: Sun, 5 May 2024 20:32:34 +0200 Subject: [PATCH] correct /runscript implementation to either append or cancel --- libtascar/include/osc_helper.h | 1 + libtascar/src/osc_helper.cc | 13 ++++++++-- libtascar/src/session.cc | 46 +++++++++++++++++----------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/libtascar/include/osc_helper.h b/libtascar/include/osc_helper.h index 25ae0c00..16fc6613 100644 --- a/libtascar/include/osc_helper.h +++ b/libtascar/include/osc_helper.h @@ -291,6 +291,7 @@ namespace TASCAR { void read_script_async(const std::vector& filenames); std::string scriptpath = ""; std::string scriptext = ""; + bool scriptcancel = false; /** @brief Dispatch all messages from the time interval tstart (included) to tend (excluded). diff --git a/libtascar/src/osc_helper.cc b/libtascar/src/osc_helper.cc index 6c654256..a97316ce 100644 --- a/libtascar/src/osc_helper.cc +++ b/libtascar/src/osc_helper.cc @@ -1140,19 +1140,29 @@ void osc_server_t::scriptthread_fun() std::vector scripts; { std::unique_lock lock{mtxscriptnames}; - cond_var_script.wait(lock); + bool needtowait = true; + if(nextscripts.size() > 0) { + needtowait = false; + } + if(needtowait) { + cond_var_script.wait(lock); + } scripts = nextscripts; nextscripts.clear(); lock.unlock(); } if(runscriptthread && scripts.size()) { + cancelscript = false; read_script(scripts); + cancelscript = false; } } } void osc_server_t::read_script_async(const std::vector& filenames) { + if(scriptcancel) + cancelscript = true; { std::lock_guard lk{mtxscriptnames}; nextscripts = filenames; @@ -1198,7 +1208,6 @@ void osc_server_t::generate_osc_documentation_files() { // auto vmap = get_variable_map(); for(const auto& owner : owned_vars) { - DEBUG(owner.first); std::vector fullpath; bool first = true; size_t kmax = fullpath.size(); diff --git a/libtascar/src/session.cc b/libtascar/src/session.cc index 9f83629f..9f9a69cb 100644 --- a/libtascar/src/session.cc +++ b/libtascar/src/session.cc @@ -490,27 +490,30 @@ void TASCAR::session_t::read_xml() GET_ATTRIBUTE(scriptext, "", "Extension appended to OSC script names"); GET_ATTRIBUTE(initoscscript, "", "OSC scripts to run when session is loaded."); + GET_ATTRIBUTE_BOOL(scriptcancel, + "Cancel current OSC script when a new one is loaded " + "(true), or append (false)."); } catch(...) { if(lock_vars()) { std::vector lmodules(modules); modules.clear(); - for(std::vector::iterator it = lmodules.begin(); - it != lmodules.end(); ++it) - if((*it)->is_prepared()) - (*it)->release(); - for(std::vector::iterator it = lmodules.begin(); - it != lmodules.end(); ++it) - delete(*it); - for(std::vector::iterator it = scenes.begin(); - it != scenes.end(); ++it) - delete(*it); - for(std::vector::iterator it = ranges.begin(); - it != ranges.end(); ++it) - delete(*it); - for(std::vector::iterator it = connections.begin(); - it != connections.end(); ++it) - delete(*it); + // release all prepared modules: + for(auto& mod : lmodules) + if(mod->is_prepared()) + mod->release(); + // delete loaded modules: + for(auto& mod : lmodules) + delete mod; + // delete scenes: + for(auto& scene : scenes) + delete scene; + // delete ranges: + for(auto& range : ranges) + delete range; + // delete connections: + for(auto& con : connections) + delete con; unlock_vars(); } throw; @@ -573,10 +576,8 @@ TASCAR::session_t::~session_t() std::vector TASCAR::session_t::get_render_output_ports() const { std::vector ports; - for(std::vector::const_iterator it = - scenes.begin(); - it != scenes.end(); ++it) { - std::vector pports((*it)->get_output_ports()); + for(auto& scene : scenes) { + std::vector pports = scene->get_output_ports(); ports.insert(ports.end(), pports.begin(), pports.end()); } return ports; @@ -788,9 +789,8 @@ int TASCAR::session_t::process(jack_nframes_t, const std::vector&, void TASCAR::session_t::stop() { started_ = false; - for(std::vector::iterator ipl = scenes.begin(); - ipl != scenes.end(); ++ipl) - (*ipl)->stop(); + for(auto& scene : scenes) + scene->stop(); } void TASCAR::session_t::run(bool& b_quit, bool use_stdin)