Delivery::run() now offsets data delivered to MIDI ports by the global port offset
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 13 Sep 2016 18:40:02 +0000 (13:40 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 13 Sep 2016 19:11:29 +0000 (14:11 -0500)
if the output is then re-used, MIDI data is readjusted to not use the global port offset

libs/ardour/delivery.cc

index 9f5051704f6343012643614e435dddda09299a01..bc49c9be69bc126248e4100762cccaed58fc21d7 100644 (file)
@@ -307,23 +307,41 @@ Delivery::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, do
 
        } else {
 
-               // Do a 1:1 copy of data to output ports
+               /* Do a 1:1 copy of data to output ports
+
+                  Audio is handled separately because we use 0 for the offset,
+                  since the port offset is only used for timestamped events
+                  (i.e. MIDI).
+               */
 
-               // audio is handled separately because we use 0 for the offset
-               // XXX how does this interact with Port::increment_global_port_buffer_offset ?
                if (bufs.count().n_audio() > 0) {
                        _output->copy_to_outputs (bufs, DataType::AUDIO, nframes, 0);
                }
 
                for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                        if (*t != DataType::AUDIO && bufs.count().get(*t) > 0) {
-                               _output->copy_to_outputs (bufs, *t, nframes, ports.port(0)->port_offset());
+                               _output->copy_to_outputs (bufs, *t, nframes, Port::port_offset());
                        }
                }
        }
 
        if (result_required) {
-               bufs.read_from (output_buffers (), nframes);
+
+               /* "bufs" are internal, meaning they should never reflect
+                  split-cycle offsets. So shift events back in time from where
+                  they were for the external buffers associated with Ports.
+               */
+
+               BufferSet& outs (output_buffers());
+
+               for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+
+                       uint32_t n = 0;
+
+                       for (BufferSet::iterator b = bufs.begin (*t); b != bufs.end (*t); ++b) {
+                               b->read_from (outs.get (*t, n++), nframes, (*t == DataType::AUDIO ? 0 : -Port::port_offset()));
+                       }
+               }
        }
 
 out: