diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-01-06 20:29:41 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-01-06 20:29:41 +0000 |
commit | 28df3238c224c4c9a5dd855b1c4219d44969f5d2 (patch) | |
tree | 07a364e387a4ec1065efe608af5a6bac2501452e /libs | |
parent | bfca00efd29d49af5b5a5b95d84d1a21beb602a0 (diff) |
fix frame/beat walking to pass unit tests
git-svn-id: svn://localhost/ardour2/branches/3.0@11176 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/tempo.cc | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 096bcd8a67..b00fffb3e0 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -1884,6 +1884,10 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const } } + DEBUG_TRACE (DEBUG::TempoMath, string_compose ("frame %1 minus %2 beats, start with tempo = %3 @ %4 prev at beg? %5\n", + pos, beats, *((Tempo*)tempo), tempo->frame(), + prev_tempo == metrics.rend())); + /* We now have: tempo -> the Tempo for "pos" @@ -1893,7 +1897,7 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const while (beats) { /* Distance to the start of this section in frames */ - framecnt_t distance_frames = ((prev_tempo == metrics.rend()) ? max_framepos : (pos - (*prev_tempo)->frame())); + framecnt_t distance_frames = (pos - tempo->frame()); /* Distance to the start in beats */ Evoral::MusicalTime distance_beats = distance_frames / tempo->frames_per_beat (_frame_rate); @@ -1901,17 +1905,26 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const /* Amount to subtract this time */ double const sub = min (distance_beats, beats); + DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tdistance to %1 = %2 (%3 beats)\n", + tempo->frame(), distance_frames, distance_beats)); /* Update */ beats -= sub; pos -= sub * tempo->frames_per_beat (_frame_rate); + DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnow at %1, %2 beats left, prev at end ? %3\n", pos, beats, + (prev_tempo == metrics.rend()))); + /* step backwards to prior TempoSection */ if (prev_tempo != metrics.rend()) { tempo = dynamic_cast<const TempoSection*>(*prev_tempo); + DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n", + *((Tempo*)tempo), tempo->frame(), + tempo->frames_per_beat (_frame_rate))); + while (prev_tempo != metrics.rend ()) { ++prev_tempo; @@ -1920,6 +1933,9 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const break; } } + } else { + pos -= llrint (beats * tempo->frames_per_beat (_frame_rate)); + beats = 0; } } @@ -2112,16 +2128,23 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const beats += sub / tempo->frames_per_beat (_frame_rate); /* Move on if there's anything to move to */ - while (next_tempo != metrics.end ()) { - const TempoSection* t; - - ++next_tempo; - if (next_tempo != metrics.end() && (t = dynamic_cast<const TempoSection*>(*next_tempo)) != 0) { - tempo = t; - break; + if (next_tempo != metrics.end()) { + + tempo = dynamic_cast<const TempoSection*>(*next_tempo); + + DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n", + *((Tempo*)tempo), tempo->frame(), + tempo->frames_per_beat (_frame_rate))); + + while (next_tempo != metrics.end ()) { + + ++next_tempo; + + if (next_tempo != metrics.end() && dynamic_cast<const TempoSection*>(*next_tempo)) { + break; + } } - } } |