on session-load: skip output-change-handler until IOs are restored
[ardour.git] / libs / ardour / port.cc
index e9a3c09a100027e33f52549988d2dc88bc34143f..3473b73617a84226bb442a1bc421bc717fc1ce57 100644 (file)
 #include "libardour-config.h"
 #endif
 
-#include <stdexcept>
-
 #include <jack/weakjack.h> // so that we can test for new functions at runtime
 
-#include "pbd/error.h"
 #include "pbd/compose.h"
+#include "pbd/error.h"
+#include "pbd/failed_constructor.h"
 
+#include "ardour/audioengine.h"
 #include "ardour/debug.h"
 #include "ardour/port.h"
-#include "ardour/audioengine.h"
-#include "pbd/failed_constructor.h"
 
 #include "i18n.h"
 
@@ -40,6 +38,7 @@ using namespace ARDOUR;
 using namespace PBD;
 
 PBD::Signal2<void,boost::shared_ptr<Port>, boost::shared_ptr<Port> > Port::PostDisconnect;
+PBD::Signal0<void> Port::PortDrop;
 
 AudioEngine* Port::_engine = 0;
 bool         Port::_connecting_blocked = false;
@@ -73,13 +72,24 @@ Port::Port (std::string const & n, DataType t, Flags f)
                cerr << "Failed to register JACK port \"" << _name << "\", reason is unknown from here\n";
                throw failed_constructor ();
        }
+
+       PortDrop.connect_same_thread (drop_connection, boost::bind (&Port::drop, this));
 }
 
 /** Port destructor */
 Port::~Port ()
 {
-       if (_engine->jack ()) {
-               jack_port_unregister (_engine->jack (), _jack_port);
+       drop ();
+}
+
+void
+Port::drop ()
+{
+       if (_jack_port) {
+               if (_engine->jack ()) {
+                       jack_port_unregister (_engine->jack (), _jack_port);
+               }
+               _jack_port = 0;
        }
 }