Fix session-archive edge-cases, prepare uncompressed archives
[ardour.git] / libs / ardour / port.cc
index 61313f371cb965004063b33e65b2e965dbcd10d6..81290aa021187d3a4d7b62ee51e9f46223a43edb 100644 (file)
@@ -30,7 +30,7 @@
 #include "ardour/port.h"
 #include "ardour/port_engine.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -56,7 +56,7 @@ Port::Port (std::string const & n, DataType t, PortFlags f)
        : _port_buffer_offset (0)
        , _name (n)
        , _flags (f)
-        , _last_monitor (false)
+       , _last_monitor (false)
 {
        _private_playback_latency.min = 0;
        _private_playback_latency.max = 0;
@@ -70,10 +70,14 @@ Port::Port (std::string const & n, DataType t, PortFlags f)
 
        assert (_name.find_first_of (':') == std::string::npos);
 
-       if ((_port_handle = port_engine.register_port (_name, t, _flags)) == 0) {
+       if (!port_engine.available ()) {
+               DEBUG_TRACE (DEBUG::Ports, string_compose ("port-engine n/a postpone registering %1\n", name()));
+               _port_handle = 0; // created during ::reestablish() later
+       } else if ((_port_handle = port_engine.register_port (_name, t, _flags)) == 0) {
                cerr << "Failed to register port \"" << _name << "\", reason is unknown from here\n";
                throw failed_constructor ();
        }
+       DEBUG_TRACE (DEBUG::Ports, string_compose ("registed port %1 handle %2\n", name(), _port_handle));
 
        PortDrop.connect_same_thread (drop_connection, boost::bind (&Port::drop, this));
        PortSignalDrop.connect_same_thread (drop_connection, boost::bind (&Port::signal_drop, this));
@@ -505,6 +509,8 @@ Port::reestablish ()
                return -1;
        }
 
+       DEBUG_TRACE (DEBUG::Ports, string_compose ("Port::reestablish %1 handle %2\n", name(), _port_handle));
+
        reset ();
 
        port_manager->PortConnectedOrDisconnected.connect_same_thread (engine_connection,
@@ -563,12 +569,12 @@ Port::get_state () const
 {
        XMLNode* root = new XMLNode (state_node_name);
 
-       root->add_property (X_("name"), AudioEngine::instance()->make_port_name_relative (name()));
+       root->set_property (X_("name"), AudioEngine::instance()->make_port_name_relative (name()));
 
        if (receives_input()) {
-               root->add_property (X_("direction"), X_("input"));
+               root->set_property (X_("direction"), X_("input"));
        } else {
-               root->add_property (X_("direction"), X_("output"));
+               root->set_property (X_("direction"), X_("output"));
        }
 
        vector<string> c;
@@ -577,7 +583,7 @@ Port::get_state () const
 
        for (vector<string>::const_iterator i = c.begin(); i != c.end(); ++i) {
                XMLNode* child = new XMLNode (X_("Connection"));
-               child->add_property (X_("other"), *i);
+               child->set_property (X_("other"), *i);
                root->add_child_nocopy (*child);
        }
 
@@ -587,14 +593,13 @@ Port::get_state () const
 int
 Port::set_state (const XMLNode& node, int)
 {
-       XMLProperty const * prop;
-
        if (node.name() != state_node_name) {
                return -1;
        }
 
-       if ((prop = node.property (X_("name"))) != 0) {
-               set_name (prop->value());
+       std::string str;
+       if (node.get_property (X_("name"), str)) {
+               set_name (str);
        }
 
        const XMLNodeList& children (node.children());
@@ -607,11 +612,11 @@ Port::set_state (const XMLNode& node, int)
                        continue;
                }
 
-               if ((prop = (*c)->property (X_("other"))) == 0) {
+               if (!(*c)->get_property (X_("other"), str)) {
                        continue;
                }
 
-               _connections.insert (prop->value());
+               _connections.insert (str);
        }
 
        return 0;