mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-18 20:56:28 +01:00
Similar hacks to framepos_minus_beats to handle -ve
positions as were appled to framepos_plus_beats. git-svn-id: svn://localhost/ardour2/branches/3.0@10984 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
32c4217994
commit
748b24009b
2 changed files with 22 additions and 3 deletions
|
|
@ -2024,6 +2024,15 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||||
|
|
||||||
for (i = metrics->begin(); i != metrics->end(); ++i) {
|
for (i = metrics->begin(); i != metrics->end(); ++i) {
|
||||||
|
|
||||||
|
/* This is a bit of a hack, but pos could be -ve, and if it is,
|
||||||
|
we consider the initial metric changes (at time 0) to actually
|
||||||
|
be in effect at pos.
|
||||||
|
*/
|
||||||
|
framepos_t f = (*i)->frame ();
|
||||||
|
if (pos < 0 && f == 0) {
|
||||||
|
f = pos;
|
||||||
|
}
|
||||||
|
|
||||||
if ((*i)->frame() > pos) {
|
if ((*i)->frame() > pos) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -2038,9 +2047,13 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool no_more_metrics = false;
|
||||||
|
|
||||||
/* Move i back to the metric before "pos" */
|
/* Move i back to the metric before "pos" */
|
||||||
if (i != metrics->begin ()) {
|
if (i != metrics->begin ()) {
|
||||||
--i;
|
--i;
|
||||||
|
} else {
|
||||||
|
no_more_metrics = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We now have:
|
/* We now have:
|
||||||
|
|
@ -2052,11 +2065,11 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||||
|
|
||||||
while (beats) {
|
while (beats) {
|
||||||
|
|
||||||
/* End of this section (looking backwards) */
|
/* Distance to the end of this section in frames */
|
||||||
framepos_t end = i == metrics->end() ? max_framepos : (*i)->frame ();
|
framecnt_t distance_frames = no_more_metrics ? max_framepos : (pos - (*i)->frame());
|
||||||
|
|
||||||
/* Distance to the end in beats */
|
/* Distance to the end in beats */
|
||||||
Evoral::MusicalTime distance_beats = (pos - end) / tempo->frames_per_beat (_frame_rate, *meter);
|
Evoral::MusicalTime distance_beats = distance_frames / tempo->frames_per_beat (_frame_rate, *meter);
|
||||||
|
|
||||||
/* Amount to subtract this time */
|
/* Amount to subtract this time */
|
||||||
double const sub = min (distance_beats, beats);
|
double const sub = min (distance_beats, beats);
|
||||||
|
|
@ -2112,6 +2125,8 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
no_more_metrics = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ FrameposMinusBeatsTest::singleTempoTest ()
|
||||||
/* Subtract 1 beat from beat 3 of the first bar */
|
/* Subtract 1 beat from beat 3 of the first bar */
|
||||||
framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, 1);
|
framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, 1);
|
||||||
CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 1));
|
CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 1));
|
||||||
|
|
||||||
|
/* Subtract 4 beats from 3 beats in, to go beyond zero */
|
||||||
|
r = map.framepos_minus_beats (frames_per_beat * 3, 4);
|
||||||
|
CPPUNIT_ASSERT_EQUAL (r, framepos_t (- frames_per_beat));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test adding things that overlap a tempo change */
|
/* Test adding things that overlap a tempo change */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue