From 1ecdc5c51565a570c8d95f35f8d6f71f4fb1f99a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 15 Dec 2021 14:58:03 -0700 Subject: [PATCH] triggerbox: try to avoid tempo that results in fractional bar cnts If minibpm's estimate of tempo implies that the clip has a duration measured in fractional bars, use the estimate as a starting point to get to a tempo that will lead to an integer number of bars (and quarters) --- libs/ardour/triggerbox.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 5b77675e2c..a5efbb9b82 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -826,6 +826,14 @@ AudioTrigger::determine_tempo () const double quarters = (seconds / 60.) * _apparent_tempo; _barcnt = quarters / metric.meter().divisions_per_bar(); + if ((_apparent_tempo != 0.) && (rint (_barcnt) != _barcnt)) { + /* fractional barcnt */ + int intquarters = floor (quarters); + double at = _apparent_tempo; + _apparent_tempo = intquarters / (seconds/60.); + DEBUG_TRACE (DEBUG::Triggers, string_compose ("adjusted barcnt of %1 and q = %2 to %3, old %4 new at = %5\n", _barcnt, quarters, intquarters, at, _apparent_tempo)); + } + /* use initial tempo in map (assumed for now to be the only one */ const samplecnt_t one_bar = tm->bbt_duration_at (timepos_t (AudioTime), BBT_Offset (1, 0, 0)).samples();