abort if configuration fails
[ardour.git] / libs / ardour / port.cc
index 3252134ac3d48031153088f54d4cb3ab68eaf3bf..06169dd576634441afc378027c5df063ece1bd9f 100644 (file)
@@ -73,7 +73,7 @@ Port::Port (std::string const & n, DataType t, PortFlags f)
                cerr << "Failed to register port \"" << _name << "\", reason is unknown from here\n";
                throw failed_constructor ();
        }
-       
+
        PortDrop.connect_same_thread (drop_connection, boost::bind (&Port::drop, this));
 }
 
@@ -119,7 +119,7 @@ Port::connected () const
 {
        if (_port_handle) {
                return (port_engine.connected (_port_handle) != 0);
-       } 
+       }
        return false;
 }
 
@@ -127,14 +127,22 @@ int
 Port::disconnect_all ()
 {
        if (_port_handle) {
-               
+
+               std::vector<std::string> connections;
+               get_connections (connections);
+
                port_engine.disconnect_all (_port_handle);
                _connections.clear ();
-               
-               /* a cheaper, less hacky way to do boost::shared_from_this() ... 
+
+               /* a cheaper, less hacky way to do boost::shared_from_this() ...
                 */
                boost::shared_ptr<Port> pself = port_manager->get_port_by_name (name());
-               PostDisconnect (pself, boost::shared_ptr<Port>()); // emit signal
+               for (vector<string>::const_iterator c = connections.begin(); c != connections.end() && pself; ++c) {
+                       boost::shared_ptr<Port> pother = AudioEngine::instance()->get_port_by_name (*c);
+                       if (pother) {
+                               PostDisconnect (pself, pother); // emit signal
+                       }
+               }
        }
 
        return 0;
@@ -147,7 +155,7 @@ bool
 Port::connected_to (std::string const & o) const
 {
        if (!_port_handle) {
-               return false; 
+               return false;
        }
 
        if (!port_engine.available()) {
@@ -165,7 +173,11 @@ Port::get_connections (std::vector<std::string> & c) const
                return c.size();
        }
 
-       return port_engine.get_connections (_port_handle, c);
+       if (_port_handle) {
+               return port_engine.get_connections (_port_handle, c);
+       }
+
+       return 0;
 }
 
 int
@@ -213,7 +225,7 @@ Port::disconnect (std::string const & other)
                _connections.erase (other);
        }
 
-       /* a cheaper, less hacky way to do boost::shared_from_this() ... 
+       /* a cheaper, less hacky way to do boost::shared_from_this() ...
         */
        boost::shared_ptr<Port> pself = AudioEngine::instance()->get_port_by_name (name());
        boost::shared_ptr<Port> pother = AudioEngine::instance()->get_port_by_name (other);
@@ -223,7 +235,7 @@ Port::disconnect (std::string const & other)
                   a check on whether this may affect anything that we
                   need to know about.
                */
-               PostDisconnect (pself, pother); // emit signal 
+               PostDisconnect (pself, pother); // emit signal
        }
 
        return r;
@@ -361,7 +373,7 @@ Port::public_latency_range (bool /*playback*/) const
 
        if (_port_handle) {
                r = port_engine.get_latency_range (_port_handle, sends_output() ? true : false);
-               
+
                DEBUG_TRACE (DEBUG::Latency, string_compose (
                                     "GET PORT %1: %4 PUBLIC latency range %2 .. %3\n",
                                     name(), r.min, r.max,
@@ -516,7 +528,7 @@ Port::get_state () const
        }
 
        vector<string> c;
-       
+
        get_connections (c);
 
        for (vector<string>::const_iterator i = c.begin(); i != c.end(); ++i) {
@@ -550,7 +562,7 @@ Port::set_state (const XMLNode& node, int)
                if ((*c)->name() != X_("Connection")) {
                        continue;
                }
-               
+
                if ((prop = (*c)->property (X_("other"))) == 0) {
                        continue;
                }