X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fcontrol_protocol_manager.cc;h=c2929a396870a5dc1ba660812f70f97f51570832;hb=8c04457be14673385287def048c387b3953fa8e8;hp=ba32ab8b70803c4b017ae1835aa0171846911214;hpb=44cec185162661586169126d5f482bc7a89fb3a5;p=ardour.git diff --git a/libs/ardour/control_protocol_manager.cc b/libs/ardour/control_protocol_manager.cc index ba32ab8b70..c2929a3968 100644 --- a/libs/ardour/control_protocol_manager.cc +++ b/libs/ardour/control_protocol_manager.cc @@ -32,7 +32,8 @@ #include "ardour/control_protocol_manager.h" #include "ardour/search_paths.h" - +#include "ardour/selection.h" +#include "ardour/session.h" using namespace ARDOUR; using namespace std; @@ -42,7 +43,7 @@ using namespace PBD; ControlProtocolManager* ControlProtocolManager::_instance = 0; const string ControlProtocolManager::state_node_name = X_("ControlProtocols"); - +PBD::Signal1 ControlProtocolManager::StripableSelectionChanged; ControlProtocolInfo::~ControlProtocolInfo () { @@ -65,7 +66,7 @@ ControlProtocolManager::ControlProtocolManager () ControlProtocolManager::~ControlProtocolManager() { - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::WriterLock lm (protocols_lock); for (list::iterator i = control_protocols.begin(); i != control_protocols.end(); ++i) { delete (*i); @@ -75,6 +76,7 @@ ControlProtocolManager::~ControlProtocolManager() for (list::iterator p = control_protocol_info.begin(); p != control_protocol_info.end(); ++p) { + (*p)->protocol = 0; // protocol was already destroyed above. delete (*p); } @@ -86,8 +88,12 @@ ControlProtocolManager::set_session (Session* s) { SessionHandlePtr::set_session (s); - if (_session) { - Glib::Threads::Mutex::Lock lm (protocols_lock); + if (!_session) { + return; + } + + { + Glib::Threads::RWLock::ReaderLock lm (protocols_lock); for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { if ((*i)->requested || (*i)->mandatory) { @@ -95,6 +101,21 @@ ControlProtocolManager::set_session (Session* s) } } } + + CoreSelection::StripableAutomationControls sac; + _session->selection().get_stripables (sac); + + if (!sac.empty()) { + StripableNotificationListPtr v (new StripableNotificationList); + for (CoreSelection::StripableAutomationControls::iterator i = sac.begin(); i != sac.end(); ++i) { + if ((*i).stripable) { + v->push_back (boost::weak_ptr ((*i).stripable)); + } + } + if (!v->empty()) { + StripableSelectionChanged (v); /* EMIT SIGNAL */ + } + } } int @@ -158,7 +179,7 @@ ControlProtocolManager::drop_protocols () * before the process cycle stops and ports vanish. */ - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::WriterLock lm (protocols_lock); for (list::iterator p = control_protocols.begin(); p != control_protocols.end(); ++p) { delete *p; @@ -245,7 +266,7 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi, bool lock_required) cpi.descriptor->destroy (cpi.descriptor, cpi.protocol); if (lock_required) { - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::WriterLock lm (protocols_lock); list::iterator p = find (control_protocols.begin(), control_protocols.end(), cpi.protocol); if (p != control_protocols.end()) { control_protocols.erase (p); @@ -290,7 +311,7 @@ ControlProtocolManager::load_mandatory_protocols () return; } - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::ReaderLock lm (protocols_lock); for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { if ((*i)->mandatory && ((*i)->protocol == 0)) { @@ -443,7 +464,7 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/) XMLNodeList clist; XMLNodeConstIterator citer; - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::WriterLock lm (protocols_lock); clist = node.children(); @@ -462,7 +483,9 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/) ControlProtocolInfo* cpi = cpi_by_name (name); if (cpi) { +#ifndef NDEBUG std::cerr << "protocol " << name << " active ? " << active << std::endl; +#endif if (active) { delete cpi->state; @@ -495,7 +518,7 @@ XMLNode& ControlProtocolManager::get_state () { XMLNode* root = new XMLNode (state_node_name); - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::ReaderLock lm (protocols_lock); for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { @@ -533,7 +556,7 @@ ControlProtocolManager::instance () void ControlProtocolManager::midi_connectivity_established () { - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::ReaderLock lm (protocols_lock); for (list::iterator p = control_protocols.begin(); p != control_protocols.end(); ++p) { (*p)->midi_connectivity_established (); @@ -543,7 +566,7 @@ ControlProtocolManager::midi_connectivity_established () void ControlProtocolManager::register_request_buffer_factories () { - Glib::Threads::Mutex::Lock lm (protocols_lock); + Glib::Threads::RWLock::ReaderLock lm (protocols_lock); for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { @@ -557,3 +580,26 @@ ControlProtocolManager::register_request_buffer_factories () } } } + +void +ControlProtocolManager::stripable_selection_changed (StripableNotificationListPtr sp) +{ + /* this sets up the (static) data structures owned by ControlProtocol + that are "shared" across all control protocols. + */ + + DEBUG_TRACE (DEBUG::Selection, string_compose ("Surface manager: selection changed, now %1 stripables\n", sp ? sp->size() : -1)); + StripableSelectionChanged (sp); /* EMIT SIGNAL */ + + /* now give each protocol the chance to respond to the selection change + */ + + { + Glib::Threads::RWLock::ReaderLock lm (protocols_lock); + + for (list::iterator p = control_protocols.begin(); p != control_protocols.end(); ++p) { + DEBUG_TRACE (DEBUG::Selection, string_compose ("selection change notification for surface \"%1\"\n", (*p)->name())); + (*p)->stripable_selection_changed (); + } + } +}