From 1e3100efbc7fd9c9bfd5a9ef78334bf8e42ca03c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 8 May 2025 22:01:05 +0200 Subject: [PATCH] Stretch gain envelope and region-FX automation with region --- libs/ardour/rb_effect.cc | 27 ++++++++++++++++++--------- libs/ardour/st_stretch.cc | 26 +++++++++++++++++--------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/libs/ardour/rb_effect.cc b/libs/ardour/rb_effect.cc index e82ed01ddf..048bbbce2f 100644 --- a/libs/ardour/rb_effect.cc +++ b/libs/ardour/rb_effect.cc @@ -32,6 +32,7 @@ #include "ardour/audioregion.h" #include "ardour/audiosource.h" #include "ardour/pitch.h" +#include "ardour/region_fx_plugin.h" #include "ardour/session.h" #include "ardour/stretch.h" #include "ardour/types.h" @@ -345,6 +346,23 @@ RBEffect::run (std::shared_ptr r, Progress* progress) ret = finish (region, nsrcs, new_name); } + + /* apply automation scaling before calling set_length, which trims automation */ + if (ret == 0 && !tsr.time_fraction.is_unity()) { + for (auto& r : results) { + std::shared_ptr ar = std::dynamic_pointer_cast (r); + assert (ar); + ar->envelope ()->x_scale (tsr.time_fraction); + ar->foreach_plugin ([&](std::weak_ptr wfx) + { + shared_ptr rfx = wfx.lock (); + if (rfx) { + rfx->x_scale_automation (tsr.time_fraction); + } + }); + } + } + /* now reset ancestral data for each new region */ for (vector >::iterator x = results.begin (); x != results.end (); ++x) { @@ -360,15 +378,6 @@ RBEffect::run (std::shared_ptr r, Progress* progress) (*x)->set_whole_file (true); } - /* stretch region gain envelope */ - /* XXX: assuming we've only processed one input region into one result here */ - - if (ret == 0 && !tsr.time_fraction.is_unity()) { - std::shared_ptr result = std::dynamic_pointer_cast (results.front ()); - assert (result); - result->envelope ()->x_scale (tsr.time_fraction); - } - out: if (buffers) { diff --git a/libs/ardour/st_stretch.cc b/libs/ardour/st_stretch.cc index ab37198e0a..97f5044ad6 100644 --- a/libs/ardour/st_stretch.cc +++ b/libs/ardour/st_stretch.cc @@ -27,6 +27,7 @@ #include "ardour/types.h" #include "ardour/stretch.h" #include "ardour/audiofilesource.h" +#include "ardour/region_fx_plugin.h" #include "ardour/session.h" #include "ardour/audioregion.h" @@ -289,6 +290,22 @@ STStretch::run (std::shared_ptr r, Progress* progress) ret = finish (region, nsrcs, new_name); } + /* apply automation scaling before calling set_length, which trims automation */ + if (ret == 0 && !tsr.time_fraction.is_unity()) { + for (auto& r : results) { + std::shared_ptr ar = std::dynamic_pointer_cast (r); + assert (ar); + ar->envelope ()->x_scale (tsr.time_fraction); + ar->foreach_plugin ([&](std::weak_ptr wfx) + { + shared_ptr rfx = wfx.lock (); + if (rfx) { + rfx->x_scale_automation (tsr.time_fraction); + } + }); + } + } + /* now reset ancestral data for each new region */ for (vector >::iterator x = results.begin (); x != results.end (); ++x) { @@ -304,15 +321,6 @@ STStretch::run (std::shared_ptr r, Progress* progress) (*x)->set_whole_file (true); } - /* stretch region gain envelope */ - /* XXX: assuming we've only processed one input region into one result here */ - - if (ret == 0 && tsr.time_fraction != 1) { - std::shared_ptr result = std::dynamic_pointer_cast (results.front ()); - assert (result); - result->envelope ()->x_scale (tsr.time_fraction); - } - out: if (buffers) {