+/** Port destructor */
+Port::~Port ()
+{
+ jack_port_unregister (_engine->jack (), _jack_port);
+}
+
+/** @return true if this port is connected to anything */
+bool
+Port::connected () const
+{
+ return (jack_port_connected (_jack_port) != 0);
+}
+
+int
+Port::disconnect_all ()
+{
+ jack_port_disconnect (_engine->jack(), _jack_port);
+ _connections.clear ();
+
+ return 0;
+}
+
+/** @param o Port name
+ * @return true if this port is connected to o, otherwise false.
+ */
+bool
+Port::connected_to (std::string const & o) const
+{
+ return jack_port_connected_to (_jack_port, _engine->make_port_name_non_relative(o).c_str ());
+}
+
+/** @param o Filled in with port full names of ports that we are connected to */
+int
+Port::get_connections (std::vector<std::string> & c) const
+{
+ int n = 0;
+
+ const char** jc = jack_port_get_connections (_jack_port);
+ if (jc) {
+ for (int i = 0; jc[i]; ++i) {
+ c.push_back (jc[i]);
+ ++n;
+ }
+ free (jc);
+ }
+
+ return n;
+}
+
+int
+Port::connect (std::string const & other)
+{
+ /* caller must hold process lock */
+
+ std::string const other_shrt = _engine->make_port_name_non_relative (other);
+ std::string const this_shrt = _engine->make_port_name_non_relative (_name);
+
+ int r = 0;
+
+ if (sends_output ()) {
+ r = jack_connect (_engine->jack (), this_shrt.c_str (), other_shrt.c_str ());
+ } else {
+ r = jack_connect (_engine->jack (), other_shrt.c_str (), this_shrt.c_str());
+ }
+
+ if (r == 0) {
+ _connections.insert (other);
+ }
+
+ return r;
+}
+
+int
+Port::disconnect (std::string const & other)
+{
+ /* caller must hold process lock */
+
+ std::string const other_shrt = _engine->make_port_name_non_relative (other);
+ std::string const this_shrt = _engine->make_port_name_non_relative (_name);
+
+ int r = 0;
+
+ if (sends_output ()) {
+ r = jack_disconnect (_engine->jack (), this_shrt.c_str (), other_shrt.c_str ());
+ } else {
+ r = jack_disconnect (_engine->jack (), other_shrt.c_str (), this_shrt.c_str ());
+ }
+
+ if (r == 0) {
+ _connections.erase (other);
+ }
+
+return r;
+}
+
+
+bool
+Port::connected_to (Port* o) const
+{
+ return connected_to (o->name ());
+}
+
+int
+Port::connect (Port* o)
+{
+ return connect (o->name ());
+}
+
+int
+Port::disconnect (Port* o)
+{
+ return disconnect (o->name ());
+}
+
+void
+Port::set_engine (AudioEngine* e)
+{
+ _engine = e;
+}
+
+void
+Port::ensure_monitor_input (bool yn)
+{
+ jack_port_ensure_monitor (_jack_port, yn);
+}
+
+bool
+Port::monitoring_input () const
+{
+ return jack_port_monitoring_input (_jack_port);