forward part the backend part of the generic MIDI control fixes from mb2/a2
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 17 Oct 2012 14:36:40 +0000 (14:36 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 17 Oct 2012 14:36:40 +0000 (14:36 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@13297 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/control_protocol_manager.h
libs/ardour/control_protocol_manager.cc
libs/ardour/session_state.cc
libs/surfaces/generic_midi/generic_midi_control_protocol.cc

index 80c966876341b54589b1a759690e8a8cec9aca3b..94fd0df2b47cc6cf2dee8d4cea3c11a9a9ecf9da 100644 (file)
@@ -72,11 +72,11 @@ class ControlProtocolManager : public PBD::Stateful, public ARDOUR::SessionHandl
 
        static const std::string state_node_name;
 
-       void set_protocol_states (const XMLNode&);
-
        int set_state (const XMLNode&, int version);
        XMLNode& get_state (void);
 
+        sigc::signal<void,ControlProtocolInfo*> ProtocolStatusChange;
+
   private:
        ControlProtocolManager ();
        static ControlProtocolManager* _instance;
index 8611447a93592a33397fdda846e1ced9e5397ff2..64876b1d5f0316779df2781f5b5d4530c507f88c 100644 (file)
@@ -139,6 +139,8 @@ ControlProtocolManager::instantiate (ControlProtocolInfo& cpi)
 
        control_protocols.push_back (cpi.protocol);
 
+       ProtocolStatusChange (&cpi);
+
        return cpi.protocol;
 }
 
@@ -173,6 +175,9 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi)
        delete cpi.state;
        cpi.state = 0;
        dlclose (cpi.descriptor->module);
+
+       ProtocolStatusChange (&cpi);
+
        return 0;
 }
 
@@ -326,30 +331,43 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/)
        for (citer = clist.begin(); citer != clist.end(); ++citer) {
                if ((*citer)->name() == X_("Protocol")) {
 
-                       prop = (*citer)->property (X_("active"));
-
-                       if (prop && string_is_affirmative (prop->value())) {
-                               if ((prop = (*citer)->property (X_("name"))) != 0) {
-                                       ControlProtocolInfo* cpi = cpi_by_name (prop->value());
-
-                                       if (cpi) {
-
-                                               if (cpi->state) {
-                                                       delete cpi->state;
-                                               }
+                       if ((prop = (*citer)->property (X_("active"))) == 0) {
+                               continue;
+                       }
 
-                                               cpi->state = new XMLNode (**citer);
+                       bool active = string_is_affirmative (prop->value());
+                       
+                       if ((prop = (*citer)->property (X_("name"))) == 0) {
+                               continue;
+                       }
 
-                                               if (_session) {
-                                                       instantiate (*cpi);
-                                               } else {
-                                                       cpi->requested = true;
-                                               }
+                       ControlProtocolInfo* cpi = cpi_by_name (prop->value());
+                       
+                       if (cpi) {
+                               
+                               if (!(*citer)->children().empty()) {
+                                       cpi->state = new XMLNode (*((*citer)->children().front ()));
+                               } else {
+                                       cpi->state = 0;
+                               }
+                               
+                               if (active) {
+                                       if (_session) {
+                                               instantiate (*cpi);
+                                       } else {
+                                               cpi->requested = true;
+                                       }
+                               } else {
+                                       if (_session) {
+                                               teardown (*cpi);
+                                       } else {
+                                               cpi->requested = false;
                                        }
                                }
                        }
                }
        }
+
        return 0;
 }
 
@@ -382,36 +400,6 @@ ControlProtocolManager::get_state ()
        return *root;
 }
 
-void
-ControlProtocolManager::set_protocol_states (const XMLNode& node)
-{
-       XMLNodeList nlist;
-       XMLNodeConstIterator niter;
-       XMLProperty* prop;
-
-       nlist = node.children();
-
-       for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-
-               XMLNode* child = (*niter);
-
-               if ((prop = child->property ("name")) == 0) {
-                       error << _("control protocol XML node has no name property. Ignored.") << endmsg;
-                       continue;
-               }
-
-               ControlProtocolInfo* cpi = cpi_by_name (prop->value());
-
-               if (!cpi) {
-                       warning << string_compose (_("control protocol \"%1\" is not known. Ignored"), prop->value()) << endmsg;
-                       continue;
-               }
-
-               /* copy the node so that ownership is clear */
-
-               cpi->state = new XMLNode (*child);
-       }
-}
 
 ControlProtocolManager&
 ControlProtocolManager::instance ()
index 950f3a1ecbd67bfd54d8762d9c923c81dceefbdb..51f6f1352c321cc9e83bbaa5b9a07076938d79d6 100644 (file)
@@ -1386,8 +1386,8 @@ Session::set_state (const XMLNode& node, int version)
                }
        }
 
-       if ((child = find_named_node (node, "ControlProtocols")) != 0) {
-               ControlProtocolManager::instance().set_protocol_states (*child);
+       if ((child = find_named_node (node, ControlProtocolManager::state_node_name)) != 0) {
+               ControlProtocolManager::instance().set_state (*child, version);
        }
 
        update_have_rec_enabled_track ();
index e23e8725ae290e149dd994b0b01a43a9df72ca6c..8039e552e9eaa5bf52a8ffaaf51a1a1729748ac3 100644 (file)
@@ -539,13 +539,11 @@ GenericMidiControlProtocol::set_state (const XMLNode& node, int version)
                Glib::Threads::Mutex::Lock lm2 (controllables_lock);
                controllables.clear ();
                nlist = node.children(); // "Controls"
-               
+
                if (nlist.empty()) {
                        return 0;
                }
-               
-               nlist = nlist.front()->children ();
-               
+
                for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                        
                        if ((prop = (*niter)->property ("id")) != 0) {