From 34e12a5d78e2a89f0909a730387181caf409dde3 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 11 Jan 2023 00:25:07 +0100 Subject: [PATCH] Fix grid when tempo marker is not on a mod_bar/beat_div Previously the current iterator bbt was moved to p->bbt(). From then on, no grid line is reached if the point p is not on a bar and mod_bar != 0 or the point is not on an expected beat_div. e.g. when using bbt += mod_bar, and a tempo-change is at 5|2|0. iterations continues 6|2|0 7|2|0 is_bar() is always false and no more grid-lines were added. Rather than trying bbt = round-up-to-next-grid-mod-div and then finding the metric for that position, this approach only does the latter using the already incremented BBT position. --- libs/temporal/tempo.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 8d428b221c..d98ffbf28b 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -2107,11 +2107,14 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u if (reset) { - /* reset our sense of "now" to be wherever the point is */ + /* bbt is position for the next grid-line. + * It is already increameted above depending on mod_bar and beat_div + * and must not be changed here. + * + * Skip metrics until p->bbt() is at or after up to next grid mod div. + */ - start = p->sclock(); - bbt = p->bbt(); - beats = p->beats(); + assert (p->bbt() <= bbt); /* If we just arrived at a point (indicated by bbt == * p->bbt()), use all points at the same location to @@ -2122,7 +2125,7 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u bool rebuild_metric = false; - while (p->bbt() == bbt) { + while (p != _points.end() && p->bbt() <= bbt) { TempoPoint const * tpp; MeterPoint const * mpp; @@ -2147,6 +2150,8 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u DEBUG_TRACE (DEBUG::Grid, string_compose ("second| with start = %1 aka %2 rebuilt metric from points, now %3\n", start, bbt, metric)); } + /* this is potentially ambiguous */ + start = metric.superclock_at (bbt); } /* Update the quarter-note time value to match the BBT and