diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-11-18 14:40:46 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-11-18 14:40:46 +0000 |
commit | 0f313672f59f7a00314400f82fc012e56df8d095 (patch) | |
tree | 4accf9839b6910402b175bdda17c78957cab2f45 /libs/ardour/tempo.cc | |
parent | 51bdbf692593b22fed05878843c6754ec41745cf (diff) |
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
Diffstat (limited to 'libs/ardour/tempo.cc')
-rw-r--r-- | libs/ardour/tempo.cc | 36 |
1 files 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; |