From fbb8a562fdbd1975aad4cf0c80cf86d730a16a2d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 4 Jan 2021 21:56:06 -0700 Subject: [PATCH] libtemporal: fix implementation of TempoMetric::bbt_at() to deal with cases where the beats value is not in quarter notes e.g. 7/8 time --- libs/temporal/tempo.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index d346a6836e..244e1f0b27 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -572,9 +572,18 @@ TempoMetric::bbt_at (superclock_t sc) const DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("qn @ %1 = %2, meter @ %3\n", sc, _tempo->quarters_at_superclock (sc), _meter->beats())); const Beats dq = _tempo->quarters_at_superclock (sc) - _meter->beats(); - const BBT_Offset bbt_offset (0, dq.get_beats(), dq.get_ticks()); - DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("BBT offset from meter: %1\n", bbt_offset)); + /* dq is delta in quarters (beats). Convert to delta in note types of + the current meter, which we'll call "grid" + */ + + const int64_t note_value_count = int_div_round (dq.get_beats() * _meter->note_value(), 4); + + /* now construct a BBT_Offset using the count in grid units */ + + const BBT_Offset bbt_offset (0, note_value_count, dq.get_ticks()); + + DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("BBT offset from meter @ %1: %2\n", _meter->bbt(), bbt_offset)); return _meter->bbt_add (_meter->bbt(), bbt_offset); }