fix all manner of things relating to io connections, setting capture alignment, and...
[ardour.git] / libs / ardour / io.cc
index c29ee51a5849b995165d067c23204a3c5884a23c..27f8ca819dcdca6889dc87082c364681545ad3c4 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "ardour/audioengine.h"
 #include "ardour/buffer.h"
+#include "ardour/debug.h"
 #include "ardour/io.h"
 #include "ardour/route.h"
 #include "ardour/port.h"
@@ -95,6 +96,18 @@ IO::~IO ()
        }
 }
 
+void 
+IO::increment_port_buffer_offset (pframes_t offset)
+{
+       /* io_lock, not taken: function must be called from Session::process() calltree */
+
+        if (_direction == Output) {
+                for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
+                        i->increment_port_buffer_offset (offset);
+                }
+        }
+}
+
 void
 IO::silence (framecnt_t nframes)
 {
@@ -162,7 +175,7 @@ IO::disconnect (Port* our_port, string other_port, void* src)
        if (other_port.length() == 0 || our_port == 0) {
                return 0;
        }
-        
+
         {
                 Glib::Mutex::Lock lm (io_lock);
                 
@@ -189,7 +202,6 @@ IO::disconnect (Port* our_port, string other_port, void* src)
        return 0;
 }
 
-/** Caller must hold process lock */
 int
 IO::connect (Port* our_port, string other_port, void* src)
 {
@@ -212,7 +224,6 @@ IO::connect (Port* our_port, string other_port, void* src)
                        return -1;
                }
        }
-
        changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */
        _session.set_dirty ();
        return 0;
@@ -448,6 +459,7 @@ IO::ensure_ports (ChanCount count, bool clear, void* src)
                change.after = _ports.count ();
                change.type = IOChange::ConfigurationChanged;
                this->changed (change, src); /* EMIT SIGNAL */
+               _buffers.attach_buffers (_ports);
                setup_bundle ();
                _session.set_dirty ();
        }
@@ -899,7 +911,7 @@ IO::make_connections (const XMLNode& node, int version, bool in)
                                        }
                                         
                                        if (prop) {
-                                               p->connect (prop->value());
+                                                connect (p, prop->value(), this);
                                        }
                                }
                        } 
@@ -1132,16 +1144,6 @@ IO::set_name (const string& requested_name)
        return r;
 }
 
-void
-IO::set_port_latency (framecnt_t nframes)
-{
-       Glib::Mutex::Lock lm (io_lock);
-
-       for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
-               i->set_latency (nframes);
-       }
-}
-
 framecnt_t
 IO::latency () const
 {
@@ -1153,24 +1155,17 @@ IO::latency () const
        /* io lock not taken - must be protected by other means */
 
        for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) {
-               if ((latency = i->total_latency ()) > max_latency) {
+               if ((latency = i->private_latency_range (_direction == Output).max) > max_latency) {
                        max_latency = latency;
                }
        }
 
+        DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: max %4 latency from %2 ports = %3\n", 
+                                                     name(), _ports.num_ports(), max_latency,
+                                                     ((_direction == Output) ? "PLAYBACK" : "CAPTURE")));
        return max_latency;
 }
 
-void
-IO::update_port_total_latencies ()
-{
-       /* io_lock, not taken: function must be called from Session::process() calltree */
-
-       for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
-               _session.engine().update_total_latency (*i);
-       }
-}
-
 int
 IO::connect_ports_to_bundle (boost::shared_ptr<Bundle> c, void* src)
 {
@@ -1523,12 +1518,10 @@ IO::connected_to (boost::shared_ptr<const IO> other) const
 void
 IO::process_input (boost::shared_ptr<Processor> proc, framepos_t start_frame, framepos_t end_frame, pframes_t nframes)
 {
-       BufferSet bufs;
-
        /* don't read the data into new buffers - just use the port buffers directly */
 
-       bufs.attach_buffers (_ports, nframes, 0);
-       proc->run (bufs, start_frame, end_frame, nframes, true);
+       _buffers.get_jack_port_addresses (_ports, nframes);
+       proc->run (_buffers, start_frame, end_frame, nframes, true);
 }
 
 void
@@ -1613,3 +1606,10 @@ IO::physically_connected () const
 
         return false;
 }
+
+bool
+IO::has_port (Port* p) const
+{
+       Glib::Mutex::Lock lm (io_lock);
+       return _ports.contains (p);
+}