From 66488e1174ad5dbdc724c82418c4bf32f00b1eb9 Mon Sep 17 00:00:00 2001 From: nick_m Date: Tue, 22 Nov 2016 00:29:53 +1100 Subject: [PATCH] TempoMap::bbt_duration_at() handles an audio-locked meter. - fixes some odd results when scrolling down/up over the BBT clock display. --- libs/ardour/tempo.cc | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 0f3766b03c..65299587fe 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -3495,6 +3495,7 @@ TempoMap::bbt_duration_at (framepos_t pos, const BBT_Time& bbt, int dir) BBT_Time pos_bbt = bbt_at_minute_locked (_metrics, minute_at_frame (pos)); const framecnt_t offset = frame_at_minute (minute_at_bbt_locked (_metrics, pos_bbt)); + const double divisions = meter_section_at_minute_locked (_metrics, minute_at_frame (pos)).divisions_per_bar(); if (dir > 0) { @@ -3511,26 +3512,48 @@ TempoMap::bbt_duration_at (framepos_t pos, const BBT_Time& bbt, int dir) pos_bbt.bars += 1; pos_bbt.beats -= divisions; } + const framecnt_t music_origin = frame_at_minute (minute_at_bbt_locked (_metrics, BBT_Time (1, 1, 0))); + const framecnt_t pos_bbt_frame = frame_at_minute (minute_at_bbt_locked (_metrics, pos_bbt)); - return frame_at_minute (minute_at_bbt_locked (_metrics, pos_bbt)) - offset; + if (pos < music_origin) { + + return pos_bbt_frame - pos; + } else { + + return pos_bbt_frame - offset; + } } else { - pos_bbt.bars -= bbt.bars; + + if (pos_bbt.bars <= bbt.bars) { + pos_bbt.bars = 1; + } else { + pos_bbt.bars -= bbt.bars; + } if (pos_bbt.ticks < bbt.ticks) { - if (pos_bbt.beats == 1) { - pos_bbt.bars--; - pos_bbt.beats = divisions; + if (pos_bbt.bars > 1) { + if (pos_bbt.beats == 1) { + pos_bbt.bars--; + pos_bbt.beats = divisions; + } else { + pos_bbt.beats--; + } + pos_bbt.ticks = BBT_Time::ticks_per_beat - (bbt.ticks - pos_bbt.ticks); } else { - pos_bbt.beats--; + pos_bbt.beats = 1; + pos_bbt.ticks = 0; } - pos_bbt.ticks = BBT_Time::ticks_per_beat - (bbt.ticks - pos_bbt.ticks); } else { pos_bbt.ticks -= bbt.ticks; } if (pos_bbt.beats <= bbt.beats) { - pos_bbt.bars--; - pos_bbt.beats = divisions - (bbt.beats - pos_bbt.beats); + if (pos_bbt.bars > 1) { + pos_bbt.bars--; + pos_bbt.beats = divisions - (bbt.beats - pos_bbt.beats); + } else { + pos_bbt.beats = 1; + } } else { pos_bbt.beats -= bbt.beats; }