Skip to content

Commit

Permalink
correct /runscript implementation to either append or cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed May 5, 2024
1 parent 02ca8dd commit c996d37
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions libtascar/include/osc_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ namespace TASCAR {
void read_script_async(const std::vector<std::string>& filenames);
std::string scriptpath = "";
std::string scriptext = "";
bool scriptcancel = false;
/**
@brief Dispatch all messages from the time interval tstart (included) to
tend (excluded).
Expand Down
13 changes: 11 additions & 2 deletions libtascar/src/osc_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1140,19 +1140,29 @@ void osc_server_t::scriptthread_fun()
std::vector<std::string> scripts;
{
std::unique_lock<std::mutex> 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<std::string>& filenames)
{
if(scriptcancel)
cancelscript = true;
{
std::lock_guard<std::mutex> lk{mtxscriptnames};
nextscripts = filenames;
Expand Down Expand Up @@ -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<std::string> fullpath;
bool first = true;
size_t kmax = fullpath.size();
Expand Down
46 changes: 23 additions & 23 deletions libtascar/src/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TASCAR::module_t*> lmodules(modules);
modules.clear();
for(std::vector<TASCAR::module_t*>::iterator it = lmodules.begin();
it != lmodules.end(); ++it)
if((*it)->is_prepared())
(*it)->release();
for(std::vector<TASCAR::module_t*>::iterator it = lmodules.begin();
it != lmodules.end(); ++it)
delete(*it);
for(std::vector<TASCAR::scene_render_rt_t*>::iterator it = scenes.begin();
it != scenes.end(); ++it)
delete(*it);
for(std::vector<TASCAR::range_t*>::iterator it = ranges.begin();
it != ranges.end(); ++it)
delete(*it);
for(std::vector<TASCAR::connection_t*>::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;
Expand Down Expand Up @@ -573,10 +576,8 @@ TASCAR::session_t::~session_t()
std::vector<std::string> TASCAR::session_t::get_render_output_ports() const
{
std::vector<std::string> ports;
for(std::vector<TASCAR::scene_render_rt_t*>::const_iterator it =
scenes.begin();
it != scenes.end(); ++it) {
std::vector<std::string> pports((*it)->get_output_ports());
for(auto& scene : scenes) {
std::vector<std::string> pports = scene->get_output_ports();
ports.insert(ports.end(), pports.begin(), pports.end());
}
return ports;
Expand Down Expand Up @@ -788,9 +789,8 @@ int TASCAR::session_t::process(jack_nframes_t, const std::vector<float*>&,
void TASCAR::session_t::stop()
{
started_ = false;
for(std::vector<TASCAR::scene_render_rt_t*>::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)
Expand Down

0 comments on commit c996d37

Please sign in to comment.