From e2729c12a89e25cec7247ef92077f125d2909484 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 17 Jan 2012 03:00:32 +0000 Subject: [PATCH] fix bug with tempo computation where passed in positions or offsets are negative git-svn-id: svn://localhost/ardour2/branches/3.0@11252 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/tempo.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 8b59b06de6..23310db4ff 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -2006,6 +2006,7 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const const TempoSection* tempo; const TempoSection* t; double frames_per_beat; + framepos_t effective_pos = max (pos, (framepos_t) 0); meter = &first_meter (); tempo = &first_tempo (); @@ -2017,7 +2018,7 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const for (i = metrics.begin(); i != metrics.end(); ++i) { - if ((*i)->frame() > pos) { + if ((*i)->frame() > effective_pos) { break; } @@ -2138,8 +2139,9 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const { Glib::RWLock::ReaderLock lm (lock); Metrics::const_iterator next_tempo; - const TempoSection* tempo; - + const TempoSection* tempo = 0; + framepos_t effective_pos = max (pos, (framepos_t) 0); + /* Find the relevant initial tempo metric */ for (next_tempo = metrics.begin(); next_tempo != metrics.end(); ++next_tempo) { @@ -2148,7 +2150,7 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const if ((t = dynamic_cast(*next_tempo)) != 0) { - if ((*next_tempo)->frame() > pos) { + if ((*next_tempo)->frame() > effective_pos) { break; } @@ -2162,6 +2164,8 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const next_tempo -> the next tempo after "pos", possibly metrics.end() */ + assert (tempo); + Evoral::MusicalTime beats = 0; while (distance) { @@ -2178,6 +2182,7 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const /* Update */ pos += sub; distance -= sub; + assert (tempo); beats += sub / tempo->frames_per_beat (_frame_rate); /* Move on if there's anything to move to */ @@ -2199,6 +2204,7 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const } } } + assert (tempo); } return beats; -- 2.30.2