From 0199a4e561554cff534d57592e1bf7d3517977b0 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 5 Oct 2021 16:01:52 -0600 Subject: [PATCH] triggerbox: basic stretch test using assumption that slot holds s 4 bar region --- libs/ardour/ardour/triggerbox.h | 4 ++-- libs/ardour/triggerbox.cc | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index dc30f79e3e..3033366b48 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -77,7 +77,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { virtual void set_start (timepos_t const &) = 0; virtual void set_end (timepos_t const &) = 0; /* this accepts timepos_t because the origin is assumed to be the start */ - virtual void set_length (timepos_t const &) = 0; + virtual void set_length (timecnt_t const &) = 0; virtual double position_as_fraction() const = 0; @@ -206,7 +206,7 @@ class LIBARDOUR_API AudioTrigger : public Trigger { void set_legato_offset (timepos_t const &); timepos_t current_pos() const; /* this accepts timepos_t because the origin is assumed to be the start */ - void set_length (timepos_t const &); + void set_length (timecnt_t const &); timepos_t start_offset () const { return timepos_t (_start_offset); } /* offset from start of data */ timepos_t end() const; /* offset from start of data */ timepos_t current_length() const; /* offset from start of data */ diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index f27ecdb05c..9b68501d9b 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -483,7 +483,7 @@ AudioTrigger::set_start (timepos_t const & s) void AudioTrigger::set_end (timepos_t const & e) { - set_length (timepos_t (e.samples() - _start_offset)); + set_length (timecnt_t (e.samples() - _start_offset, timepos_t (_start_offset))); } void @@ -505,7 +505,7 @@ AudioTrigger::end() const } void -AudioTrigger::set_length (timepos_t const & newlen) +AudioTrigger::set_length (timecnt_t const & newlen) { using namespace RubberBand; using namespace Temporal; @@ -520,7 +520,7 @@ AudioTrigger::set_length (timepos_t const & newlen) load_data (ar); - if (newlen == timepos_t (_region->length_samples())) { + if (newlen == _region->length()) { /* no stretch required */ return; } @@ -540,6 +540,7 @@ AudioTrigger::set_length (timepos_t const & newlen) if (newlen.time_domain() == AudioTime) { new_ratio = (double) newlen.samples() / data_length; + cerr << "gonna stretch, ratio is " << new_ratio << endl; } else { /* XXX what to use for position ??? */ timecnt_t l (newlen, timepos_t (AudioTime)); @@ -547,6 +548,8 @@ AudioTrigger::set_length (timepos_t const & newlen) new_ratio = (double) dur.samples() / data_length; } + + stretcher.setTimeRatio (new_ratio); const samplecnt_t expected_length = ceil (data_length * new_ratio) + 16; /* extra space for safety */ @@ -685,6 +688,8 @@ AudioTrigger::natural_length() const int AudioTrigger::set_region (boost::shared_ptr r) { + using namespace Temporal; + boost::shared_ptr ar = boost::dynamic_pointer_cast (r); if (!ar) { @@ -695,7 +700,10 @@ AudioTrigger::set_region (boost::shared_ptr r) /* this will load data, but won't stretch it for now */ - set_length (timepos_t::from_superclock (r->length ().magnitude())); + TempoMap::SharedPtr tm (TempoMap::use()); + timecnt_t two_bars = tm->bbt_duration_at (timepos_t (AudioTime), BBT_Offset (4, 0, 0)); + + set_length (two_bars); PropertyChanged (ARDOUR::Properties::name);