continue the saga of Rewrite The XML Node So That It Can Be Used To Set Another Objec...
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 16 Mar 2012 22:36:06 +0000 (22:36 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 16 Mar 2012 22:36:06 +0000 (22:36 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11717 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/io.h
libs/ardour/io.cc
libs/ardour/io_processor.cc

index 88706ecea11c30c49873a954b803fdfd6b09fbce..2451611b1b6b3a39611e49168f111ffd683c498e 100644 (file)
@@ -144,6 +144,7 @@ class IO : public SessionObject, public Latent
        XMLNode& get_state (void);
        int set_state (const XMLNode&, int version);
        int set_state_2X (const XMLNode&, int, bool);
+       static void prepare_for_reset (XMLNode&, const std::string&);
 
        class BoolCombiner {
        public:
index 3805d7ac837eac14f16c13e876471e9643b6e49a..93ab043308d1c4b89ddef72a1eae82de25c7e5f0 100644 (file)
@@ -614,6 +614,8 @@ IO::set_state (const XMLNode& node, int version)
                return -1;
        }
 
+       cerr << "IO::set state, connecting legal ? " << connecting_legal << endl;
+
        if (connecting_legal) {
 
                if (make_connections (node, version, false)) {
@@ -956,6 +958,44 @@ IO::make_connections (const XMLNode& node, int version, bool in)
        return 0;
 }
 
+void
+IO::prepare_for_reset (XMLNode& node, const std::string& name)
+{
+       /* reset name */
+       node.add_property ("name", name);
+
+       /* now find connections and reset the name of the port
+          in one so that when we re-use it it will match
+          the name of the thing we're applying it to.
+       */
+
+       XMLProperty* prop;
+       XMLNodeList children = node.children();
+
+       for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
+
+               if ((*i)->name() == "Port") {
+                       
+                       prop = (*i)->property (X_("name"));
+                       
+                       if (prop) {
+                               string new_name;
+                               string old = prop->value();
+                               string::size_type slash = old.find ('/');
+
+                               if (slash != string::npos) {
+                                       /* port name is of form: <IO-name>/<port-name> */
+                                       
+                                       new_name = name;
+                                       new_name += old.substr (old.find ('/'));
+                                       
+                                       prop->set_value (new_name);
+                               }
+                       }
+               }
+       }
+}
+
 
 int
 IO::make_connections_2X (const XMLNode& node, int /*version*/, bool in)
index e1d1461bcdbbde71856e077e17a0f262fafe08e1..d5e0f3e0eb7b2ec432666b02b54dbb56ff30b641 100644 (file)
@@ -318,6 +318,6 @@ IOProcessor::prepare_for_reset (XMLNode &state, const std::string& name)
        XMLNode* io_node = state.child (IO::state_node_name.c_str());
 
        if (io_node) {
-               io_node->add_property ("name", name);
+               IO::prepare_for_reset (*io_node, name);
        }
 }