TempoMap::bbt_duration_at() handles an audio-locked meter.
authornick_m <mainsbridge@gmail.com>
Mon, 21 Nov 2016 13:29:53 +0000 (00:29 +1100)
committernick_m <mainsbridge@gmail.com>
Mon, 21 Nov 2016 13:29:53 +0000 (00:29 +1100)
- fixes some odd results when scrolling down/up over the BBT clock display.

libs/ardour/tempo.cc

index 0f3766b03c88b27c87f2a344010d1eecd4eb3377..65299587fe0958d4170abc8bdeb6bf262e0a89f6 100644 (file)
@@ -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));
+
+               if (pos < music_origin) {
+
+                       return pos_bbt_frame - pos;
+               } else {
 
-               return frame_at_minute (minute_at_bbt_locked (_metrics, pos_bbt)) - offset;
+                       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;
                }