From 44a2ef90981fd77c8a453bad239217e6204ca106 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 17 Oct 2023 05:46:44 +0200 Subject: [PATCH] Fix duplicate Port flush_buffer calls (#9481) Since 62fc1d3c2e, Delivery buffers were flushed twice. Once by copy_to_outputs() and again later by Delivery::flush_buffers. This resulted in duplicate events during export (see 576840c09ee, MIDI buffers are not cleared after flush to allow export processing to grab the data from the port-buffers). The workaround in 62fc1d3c2e is only relevant for ClickIO, other Deliveries (Send is a Delivery) are explicitly flushed by Route::flush_processor_buffers_locked. --- libs/ardour/ardour/io.h | 1 + libs/ardour/delivery.cc | 10 ++-------- libs/ardour/io.cc | 6 +++++- libs/ardour/io_plug.cc | 4 +--- libs/ardour/session_click.cc | 1 + 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libs/ardour/ardour/io.h b/libs/ardour/ardour/io.h index 5d4d916832..8ebf4e78a0 100644 --- a/libs/ardour/ardour/io.h +++ b/libs/ardour/ardour/io.h @@ -193,6 +193,7 @@ public: void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset); void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, samplecnt_t offset); + void flush_buffers (pframes_t nframes); /* AudioTrack::deprecated_use_diskstream_connections() needs these */ diff --git a/libs/ardour/delivery.cc b/libs/ardour/delivery.cc index e94551df50..0586b57a1f 100644 --- a/libs/ardour/delivery.cc +++ b/libs/ardour/delivery.cc @@ -534,16 +534,10 @@ void Delivery::flush_buffers (samplecnt_t nframes) { /* io_lock, not taken: function must be called from Session::process() calltree */ - - if (!_output) { + if (_output) { + _output->flush_buffers (nframes); return; } - - PortSet& ports (_output->ports()); - - for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) { - i->flush_buffers (nframes); - } } void diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 07682f28e1..720376404e 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -1688,9 +1688,13 @@ IO::copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, samplecn port_buffer.read_from (*prev, nframes, offset); ++o; } +} +void +IO::flush_buffers (pframes_t nframes) +{ /* when port is both externally and internally connected, - * make data directly available to downstream internal ports */ + * make data available to downstream internal ports */ for (auto const& p : _ports) { p->flush_buffers (nframes); } diff --git a/libs/ardour/io_plug.cc b/libs/ardour/io_plug.cc index 14e32b03d4..1fccf87b3a 100644 --- a/libs/ardour/io_plug.cc +++ b/libs/ardour/io_plug.cc @@ -495,9 +495,7 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples) } } } - for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) { - i->flush_buffers (n_samples); - } + _output->flush_buffers (n_samples);; const samplecnt_t l = effective_latency (); if (_plugin_signal_latency != l) { diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 089c3e61b8..9a64916191 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -251,6 +251,7 @@ Session::run_click (samplepos_t start, samplepos_t nframes) _click_gain->run (bufs, 0, 0, 1.0, nframes, false); _click_io->copy_to_outputs (bufs, DataType::AUDIO, nframes, 0); + _click_io->flush_buffers (nframes); } void