Improve import status messages slightly.
[ardour.git] / libs / ardour / io.cc
index a5d4e639e34e4bf5391c70d277d209c2bbf7b207..0d7446e8523a2757bcbfb285a4a600eb5353d690 100644 (file)
@@ -83,7 +83,6 @@ IO::IO (Session& s, const string& name, Direction dir, DataType default_type)
        _active = true;
        pending_state_node = 0;
        setup_bundles ();
-       cerr << "+++ IO created with name = " << _name << endl;
 }
 
 IO::IO (Session& s, const XMLNode& node, DataType dt)
@@ -95,9 +94,7 @@ IO::IO (Session& s, const XMLNode& node, DataType dt)
        pending_state_node = 0;
 
        set_state (node);
-
        setup_bundles ();
-       cerr << "+++ IO created from XML with name = " << _name << endl;
 }
 
 IO::~IO ()
@@ -263,7 +260,7 @@ IO::remove_port (Port* port, void* src)
                PortCountChanged (n_ports()); /* EMIT SIGNAL */
        }
 
-       if (change == ConfigurationChanged) {
+       if (change & ConfigurationChanged) {
                setup_bundles ();
        }
 
@@ -357,7 +354,7 @@ IO::disconnect (void* src)
 }
 
 bool
-IO::ensure_ports_locked (ChanCount count, bool clear, void* src)
+IO::ensure_ports_locked (ChanCount count, bool clear, void* /*src*/)
 {
        Port* port = 0;
        bool  changed    = false;
@@ -429,11 +426,7 @@ IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src)
 {
        bool changed = false;
 
-       cerr << "Ensure that IO " << _name << '/' << (_direction == Input ? "input" : "output") 
-            << " has " << count << endl;
-
        if (count == n_ports() && !clear) {
-               cerr << "\talready has " << n_ports() << endl;
                return 0;
        }
 
@@ -451,8 +444,6 @@ IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src)
                _session.set_dirty ();
        }
 
-       cerr << "\t@" << this << "  established with " << n_ports() << endl;
-       
        return 0;
 }
 
@@ -469,7 +460,7 @@ IO::get_state (void)
 }
 
 XMLNode&
-IO::state (bool full_state)
+IO::state (bool /*full_state*/)
 {
        XMLNode* node = new XMLNode (state_node_name);
        char buf[64];
@@ -495,8 +486,9 @@ IO::state (bool full_state)
                
                vector<string> connections;
 
-               XMLNode* pnode = new XMLNode (X_("port"));
+               XMLNode* pnode = new XMLNode (X_("Port"));
                pnode->add_property (X_("type"), i->type().to_string());
+               pnode->add_property (X_("name"), i->name());
 
                if (i->get_connections (connections)) {
 
@@ -509,7 +501,10 @@ IO::state (bool full_state)
                                   client name is different.
                                */
                                
-                               pnode->add_property (X_("connection"), _session.engine().make_port_name_relative (*ci));
+                               XMLNode* cnode = new XMLNode (X_("Connection"));
+
+                               cnode->add_property (X_("other"), _session.engine().make_port_name_relative (*ci));
+                               pnode->add_child_nocopy (*cnode);
                        }       
                }
                
@@ -552,10 +547,6 @@ IO::set_state (const XMLNode& node)
                _direction = (Direction) string_2_enum (prop->value(), _direction);
        }
 
-       if (!connecting_legal) {
-               pending_state_node = new XMLNode (node);
-       } 
-
        if (create_ports (node)) {
                return -1;
        }
@@ -567,7 +558,8 @@ IO::set_state (const XMLNode& node)
                }
 
        } else {
-               
+
+               pending_state_node = new XMLNode (node);
                connection_legal_c = ConnectingLegal.connect (mem_fun (*this, &IO::connecting_became_legal));
        }
 
@@ -716,7 +708,7 @@ IO::get_port_counts (const XMLNode& node, ChanCount& n, boost::shared_ptr<Bundle
                        }
                }
 
-               if ((*iter)->name() == X_("port")) {
+               if ((*iter)->name() == X_("Port")) {
                        prop = (*iter)->property (X_("type"));
 
                        if (!prop) {
@@ -743,8 +735,6 @@ IO::create_ports (const XMLNode& node)
        
        get_port_counts (node, n, c);
        
-       cerr << _name << " got " << n << " from XML node" << endl;
-
        if (ensure_ports (n, true, true, this)) {
                error << string_compose(_("%1: cannot create I/O ports"), _name) << endmsg;
                return -1;
@@ -760,22 +750,6 @@ IO::make_connections (const XMLNode& node)
 {
        const XMLProperty* prop;
 
-       if ((prop = node.property ("connection")) != 0) {
-               boost::shared_ptr<Bundle> c = find_possible_bundle (prop->value());
-               
-               if (!c) {
-                       return -1;
-               }
-
-               if (n_ports().get(c->type()) == c->nchannels() && c->ports_are_outputs()) {
-                       connect_ports_to_bundle (c, this);
-               }
-
-               return 0;
-       } 
-
-       uint32_t n = 0;
-
        for (XMLNodeConstIterator i = node.children().begin(); i != node.children().end(); ++i) {
 
                if ((*i)->name() == "Bundle") {
@@ -790,11 +764,33 @@ IO::make_connections (const XMLNode& node)
                        return 0;
                }
 
-               if ((*i)->name() == "port") {
-                       Port* p = nth (n++);
-                       XMLProperty* prop = (*i)->property ("connection");
-                       if (p && prop) {
-                               p->connect (prop->value());
+               if ((*i)->name() == "Port") {
+
+                       prop = (*i)->property (X_("name"));
+
+                       if (!prop) {
+                               continue;
+                       }
+                       
+                       Port* p = port_by_name (prop->value());
+
+                       if (p) {
+                               for (XMLNodeConstIterator c = (*i)->children().begin(); c != (*i)->children().end(); ++c) {     
+
+                                       XMLNode* cnode = (*c);
+                                       
+                                       if (cnode->name() != X_("Connection")) {
+                                               continue;
+                                       }
+                                       
+                                       if ((prop = cnode->property (X_("other"))) == 0) {
+                                               continue;
+                                       }
+                                       
+                                       if (prop) {
+                                               p->connect (prop->value());
+                                       }
+                               }
                        }
                }
        }
@@ -903,19 +899,12 @@ IO::parse_gain_string (const string& str, vector<string>& ports)
 bool
 IO::set_name (const string& requested_name)
 {
-       if (requested_name == _name) {
+       string name = requested_name;
+
+       if (name == _name) {
                return true;
        }
        
-       string name;
-       Route *rt;
-       if ( (rt = dynamic_cast<Route *>(this))) {
-               name = Route::ensure_track_or_route_name(requested_name, _session);
-       } else {
-               name = requested_name;
-       }
-
-
        /* replace all colons in the name. i wish we didn't have to do this */
 
        if (replace_all (name, ":", "-")) {
@@ -928,7 +917,7 @@ IO::set_name (const string& requested_name)
                i->set_name (current_name);
        }
 
-       bool const r = SessionObject::set_name(name);
+       bool const r = SessionObject::set_name (name);
 
        setup_bundles ();
 
@@ -1050,7 +1039,7 @@ IO::enable_connecting ()
 }
 
 void
-IO::bundle_changed (Bundle::Change c)
+IO::bundle_changed (Bundle::Change /*c*/)
 {
        //XXX
 //     connect_input_ports_to_bundle (_input_bundle, this);
@@ -1266,6 +1255,18 @@ IO::set_name_in_state (XMLNode& node, const string& new_name)
 bool
 IO::connected_to (boost::shared_ptr<const IO> other) const
 {
+       if (!other) {
+               /* do we have any connections at all? */
+
+               for (PortSet::const_iterator p = _ports.begin(); p != _ports.end(); ++p) {
+                       if (p->connected()) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
        assert (_direction != other->direction());
 
        uint32_t i, j;
@@ -1291,7 +1292,7 @@ IO::process_input (boost::shared_ptr<Processor> proc, sframes_t start_frame, sfr
        /* don't read the data into new buffers - just use the port buffers directly */
 
        bufs.attach_buffers (_ports, nframes, 0);
-       proc->run_in_place (bufs, start_frame, end_frame, nframes);
+       proc->run (bufs, start_frame, end_frame, nframes);
 }
 
 void
@@ -1347,3 +1348,20 @@ IO::copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_
                ++o;
        }
 }
+
+Port*
+IO::port_by_name (const std::string& str) const
+{
+       /* to be called only from ::set_state() - no locking */
+
+       for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) {
+
+               const Port& p(*i);
+
+               if (p.name() == str) {
+                       return const_cast<Port*>(&p);
+               }
+       }
+
+       return 0;
+}