From 21f682164e8c4d7d0c1361a62e63c9ab09bc079f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 9 Dec 2019 18:23:17 +0100 Subject: [PATCH] Fix automation alignment for latent plugins This also solves bi-stable automation for plugins where latency can change due to automation. e.g. cycle 1: run (t): automation (t) = on: -> increase latency cycle 2: run (t-latency): automation (t-latency) = off -> decrease latency repeat. --- libs/ardour/route.cc | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index a06d4fd3d6..3bc66f1a30 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -513,6 +513,24 @@ Route::process_output_buffers (BufferSet& bufs, pspeed = 0; } + /* Note: plugin latency may change. The plugin does inform the session via + * processor_latency_changed(). But the session may not yet have gotten around to + * update the actual worste-case and update this track's _signal_latency. + * So there can be cases where adding up all latencies may not equal _signal_latency. + * + * Also running a plugin may change the plugin's latency, so we need to + * add the latency first. Otherwise this can lead to bistable case + * in case of automation playback. e.g. + * + * cycle 1: run (t): automation (t) = on: -> increase latency + * cycle 2: run (t-latency): automation (t-latency) = off -> decrease latency + * reapeat. + */ + + if ((*i)->active ()) { + latency += (*i)->effective_latency (); + } + if (speed < 0) { (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back()); } else { @@ -521,16 +539,6 @@ Route::process_output_buffers (BufferSet& bufs, bufs.set_count ((*i)->output_streams()); - /* Note: plugin latency may change. While the plugin does inform the session via - * processor_latency_changed(). But the session may not yet have gotten around to - * update the actual worste-case and update this track's _signal_latency. - * - * So there can be cases where adding up all latencies may not equal _signal_latency. - */ - if ((*i)->active ()) { - latency += (*i)->effective_latency (); - } - if (re_inject_oob_data) { write_out_of_band_data (bufs, nframes); }