From 0f313672f59f7a00314400f82fc012e56df8d095 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 18 Nov 2009 14:40:46 +0000 Subject: [PATCH] use a simpler (and likely correct) round-to-nearest-bar implementation git-svn-id: svn://localhost/ardour2/branches/3.0@6119 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/tempo.cc | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index f1248b11aa..5616c489ff 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -1235,25 +1235,25 @@ TempoMap::round_to_type (nframes64_t frame, int dir, BBTPointType type) /* "true" rounding */ - /* round to nearest beat */ - if (bbt.ticks >= (Meter::ticks_per_beat/2)) { - try { - bbt = bbt_add (bbt, one_beat, metric); - } - catch (...) { - return frame; - } - } + float midbar_beats; + float midbar_ticks; - /* round to nearest bar */ - if (bbt.beats >= metric.meter().beats_per_bar()/2) { - try { - bbt = bbt_add (bbt, one_bar, metric); - } - catch (...) { - return frame; - } - } + midbar_beats = metric.meter().beats_per_bar() / 2; + midbar_ticks = Meter::ticks_per_beat * fmod (midbar_beats, 1.0f); + midbar_beats = floor (midbar_beats); + + BBT_Time midbar (bbt.bars, lrintf (midbar_beats), lrintf (midbar_ticks)); + + if (bbt < midbar) { + /* round down */ + bbt.beats = 1; + bbt.ticks = 0; + } else { + /* round up */ + bbt.bars++; + bbt.beats = 1; + bbt.ticks = 0; + } } /* force beats & ticks to their values at the start of a bar */ bbt.beats = 1;