X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fcontrol_protocol_manager.cc;h=afb322f41b926eb0d0bbb40529dc3d94e4f9f252;hb=0938a42440cc82ce8d0cb064840c258c863714ab;hp=724d60c389614108c1ab699bd454947c674512f0;hpb=bc56eb8bd73c7b456b646ba0cc627d449baa37f2;p=ardour.git diff --git a/libs/ardour/control_protocol_manager.cc b/libs/ardour/control_protocol_manager.cc index 724d60c389..afb322f41b 100644 --- a/libs/ardour/control_protocol_manager.cc +++ b/libs/ardour/control_protocol_manager.cc @@ -39,7 +39,6 @@ ControlProtocolManager* ControlProtocolManager::_instance = 0; const string ControlProtocolManager::state_node_name = X_("ControlProtocols"); ControlProtocolManager::ControlProtocolManager () - : _session (0) { } @@ -63,36 +62,42 @@ ControlProtocolManager::~ControlProtocolManager() } void -ControlProtocolManager::set_session (Session& s) +ControlProtocolManager::set_session (Session* s) { - _session = &s; - _session->GoingAway.connect (mem_fun (*this, &ControlProtocolManager::drop_session)); + SessionHandlePtr::set_session (s); - for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { - if ((*i)->requested || (*i)->mandatory) { - instantiate (**i); - (*i)->requested = false; + if (_session) { + Glib::Mutex::Lock lm (protocols_lock); - if ((*i)->protocol && (*i)->state) { - (*i)->protocol->set_state (*(*i)->state, Stateful::loading_state_version); + for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { + if ((*i)->requested || (*i)->mandatory) { + instantiate (**i); + (*i)->requested = false; + + if ((*i)->protocol && (*i)->state) { + (*i)->protocol->set_state (*(*i)->state, Stateful::loading_state_version); + } } } } } void -ControlProtocolManager::drop_session () +ControlProtocolManager::session_going_away() { - _session = 0; + SessionHandlePtr::session_going_away (); { Glib::Mutex::Lock lm (protocols_lock); + for (list::iterator p = control_protocols.begin(); p != control_protocols.end(); ++p) { delete *p; } + control_protocols.clear (); for (list::iterator p = control_protocol_info.begin(); p != control_protocol_info.end(); ++p) { + // mark existing protocols as requested // otherwise the ControlProtocol instances are not recreated in set_session if ((*p)->protocol) { (*p)->requested = true; @@ -105,6 +110,8 @@ ControlProtocolManager::drop_session () ControlProtocol* ControlProtocolManager::instantiate (ControlProtocolInfo& cpi) { + /* CALLER MUST HOLD LOCK */ + if (_session == 0) { return 0; } @@ -121,7 +128,6 @@ ControlProtocolManager::instantiate (ControlProtocolInfo& cpi) return 0; } - Glib::Mutex::Lock lm (protocols_lock); control_protocols.push_back (cpi.protocol); return cpi.protocol; @@ -152,13 +158,6 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi) } else { cerr << "Programming error: ControlProtocolManager::teardown() called for " << cpi.name << ", but it was not found in control_protocols" << endl; } - - list::iterator p2 = find (control_protocol_info.begin(), control_protocol_info.end(), &cpi); - if (p2 != control_protocol_info.end()) { - control_protocol_info.erase (p2); - } else { - cerr << "Programming error: ControlProtocolManager::teardown() called for " << cpi.name << ", but it was not found in control_protocol_info" << endl; - } } cpi.protocol = 0; @@ -173,6 +172,8 @@ ControlProtocolManager::load_mandatory_protocols () return; } + Glib::Mutex::Lock lm (protocols_lock); + for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { if ((*i)->mandatory && ((*i)->protocol == 0)) { info << string_compose (_("Instantiating mandatory control protocol %1"), (*i)->name) << endmsg; @@ -209,12 +210,12 @@ ControlProtocolManager::control_protocol_discover (string path) if ((descriptor = get_descriptor (path)) != 0) { - ControlProtocolInfo* cpi = new ControlProtocolInfo (); - if (!descriptor->probe (descriptor)) { info << string_compose (_("Control protocol %1 not usable"), descriptor->name) << endmsg; } else { + ControlProtocolInfo* cpi = new ControlProtocolInfo (); + cpi->descriptor = descriptor; cpi->name = descriptor->name; cpi->path = path; @@ -269,7 +270,7 @@ ControlProtocolManager::get_descriptor (string path) } void -ControlProtocolManager::foreach_known_protocol (sigc::slot method) +ControlProtocolManager::foreach_known_protocol (boost::function method) { for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { method (*i); @@ -294,6 +295,8 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/) XMLNodeConstIterator citer; XMLProperty* prop; + Glib::Mutex::Lock lm (protocols_lock); + clist = node.children(); for (citer = clist.begin(); citer != clist.end(); ++citer) { @@ -325,7 +328,7 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/) } XMLNode& -ControlProtocolManager::get_state (void) +ControlProtocolManager::get_state () { XMLNode* root = new XMLNode (state_node_name); Glib::Mutex::Lock lm (protocols_lock); @@ -339,12 +342,10 @@ ControlProtocolManager::get_state (void) child->add_property (X_("active"), "yes"); // should we update (*i)->state here? probably. root->add_child_nocopy (*child); - } - else if ((*i)->state) { + } else if ((*i)->state) { // keep ownership clear root->add_child_copy (*(*i)->state); - } - else { + } else { child = new XMLNode (X_("Protocol")); child->add_property (X_("name"), (*i)->name); child->add_property (X_("active"), "no");