Add option to limit automatable control parmaters
[ardour.git] / libs / ardour / control_protocol_manager.cc
index bd5b7e72a6dd28fd978a9ab5777ab900293ad74d..048ff3f7d5dac16bc7fca17fbe7ea96dad430610 100644 (file)
@@ -266,6 +266,7 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi, bool lock_required)
        cpi.descriptor->destroy (cpi.descriptor, cpi.protocol);
 
        if (lock_required) {
+               /* the lock is required when the protocol is torn down by a user from the GUI. */
                Glib::Threads::RWLock::WriterLock lm (protocols_lock);
                list<ControlProtocol*>::iterator p = find (control_protocols.begin(), control_protocols.end(), cpi.protocol);
                if (p != control_protocols.end()) {
@@ -284,14 +285,6 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi, bool lock_required)
 
        cpi.protocol = 0;
 
-       if (lock_required) {
-               /* the lock is only required when the protocol is torn down from the GUI.
-                * If a user disables a protocol, we take this as indicator to forget the
-                * state.
-                */
-               delete cpi.state;
-               cpi.state = 0;
-       }
        delete (Glib::Module*) cpi.descriptor->module;
        /* cpi->descriptor is now inaccessible since dlclose() or equivalent
         * has been performed, and the descriptor is (or could be) a static
@@ -459,7 +452,7 @@ ControlProtocolManager::cpi_by_name (string name)
 }
 
 int
-ControlProtocolManager::set_state (const XMLNode& node, int /*version*/)
+ControlProtocolManager::set_state (const XMLNode& node, int session_specific_state /* here: not version */)
 {
        XMLNodeList clist;
        XMLNodeConstIterator citer;
@@ -483,11 +476,14 @@ 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;
                                        cpi->state = new XMLNode (**citer);
+                                       cpi->state->set_property (X_("session-state"), session_specific_state ? true : false);
                                        if (_session) {
                                                instantiate (*cpi);
                                        } else {
@@ -497,6 +493,7 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/)
                                        if (!cpi->state) {
                                                cpi->state = new XMLNode (**citer);
                                                cpi->state->set_property (X_("active"), false);
+                                               cpi->state->set_property (X_("session-state"), session_specific_state ? true : false);
                                        }
                                        cpi->requested = false;
                                        if (_session) {
@@ -523,6 +520,8 @@ ControlProtocolManager::get_state ()
                if ((*i)->protocol) {
                        XMLNode& child_state ((*i)->protocol->get_state());
                        child_state.set_property (X_("active"), true);
+                       delete ((*i)->state);
+                       (*i)->state = new XMLNode (child_state);
                        root->add_child_nocopy (child_state);
                } else if ((*i)->state) {
                        XMLNode* child_state = new XMLNode (*(*i)->state);