Remove unused methods, add tests to ensure meter divisors don't mess with Beats.

- TempoMap::framepos_minus_beats() was only used by its test,
	  so don't build the test.
This commit is contained in:
nick_m 2016-10-02 03:55:18 +11:00
parent bb3312c3bb
commit af289cab62
8 changed files with 128 additions and 64 deletions

View file

@ -56,8 +56,8 @@ class LIBARDOUR_API Tempo {
Tempo (double bpm, double type=4.0) // defaulting to quarter note
: _beats_per_minute (bpm), _note_type(type) {}
/* ..or more aptly 'pulse divisions per minute'.
Nothing to do with actual beats, which are defined by the meter and tempo.
/*
quarter note beats as distinct from a beat derived from meter and pulse.
*/
double beats_per_minute () const { return _beats_per_minute; }
void set_beats_per_minute (double bpm) { _beats_per_minute = bpm; }
@ -401,7 +401,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
that align with the grid formed by tempo and meter sections.
They SHOULD NOT be used to determine the position of events
whose location is canonically defined in beats.
whose location is canonically defined in Evoral::Beats.
*/
double beat_at_frame (const framecnt_t& frame) const;
@ -436,21 +436,19 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
/* TEMPO-SENSITIVE FUNCTIONS
These next 4 functions will all take tempo in account and should be
These next 2 functions will all take tempo in account and should be
used to determine position (and in the last case, distance in beats)
when tempo matters but meter does not.
They SHOULD be used to determine the position of events
whose location is canonically defined in beats.
whose location is canonically defined in Evoral::Beats.
*/
framepos_t framepos_plus_bbt (framepos_t pos, Timecode::BBT_Time b) const;
framepos_t framepos_plus_beats (framepos_t, Evoral::Beats) const;
framepos_t framepos_plus_qn (framepos_t, Evoral::Beats) const;
framepos_t framepos_minus_beats (framepos_t, Evoral::Beats) const;
Evoral::Beats framewalk_to_beats (framepos_t pos, framecnt_t distance) const;
Evoral::Beats framewalk_to_qn (framepos_t pos, framecnt_t distance) const;
framepos_t framepos_plus_bbt (framepos_t pos, Timecode::BBT_Time b) const;
double quarter_note_at_frame (const framepos_t frame);
double quarter_note_at_frame_rt (const framepos_t frame);
framepos_t frame_at_quarter_note (const double quarter_note);

View file

@ -4075,17 +4075,10 @@ TempoMap::remove_time (framepos_t where, framecnt_t amount)
return moved;
}
/** Add some (fractional) beats to a session frame position, and return the result in frames.
/** Add some (fractional) Beats to a session frame position, and return the result in frames.
* pos can be -ve, if required.
*/
framepos_t
TempoMap::framepos_plus_beats (framepos_t frame, Evoral::Beats beats) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return frame_at_beat_locked (_metrics, beat_at_frame_locked (_metrics, frame) + beats.to_double());
}
framepos_t
TempoMap::framepos_plus_qn (framepos_t frame, Evoral::Beats quarter_note) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
@ -4093,16 +4086,6 @@ TempoMap::framepos_plus_qn (framepos_t frame, Evoral::Beats quarter_note) const
return frame_at_quarter_note_locked (_metrics, quarter_note_at_frame_locked (_metrics, frame) + quarter_note.to_double());
}
/** Subtract some (fractional) beats from a frame position, and return the result in frames */
framepos_t
TempoMap::framepos_minus_beats (framepos_t pos, Evoral::Beats beats) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return frame_at_beat_locked (_metrics, beat_at_frame_locked (_metrics, pos) - beats.to_double());
}
/** Add the BBT interval op to pos and return the result */
framepos_t
TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const
{
@ -4130,14 +4113,6 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const
/** Count the number of beats that are equivalent to distance when going forward,
starting at pos.
*/
Evoral::Beats
TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
return Evoral::Beats (beat_at_frame_locked (_metrics, pos + distance) - beat_at_frame_locked (_metrics, pos));
}
Evoral::Beats
TempoMap::framewalk_to_qn (framepos_t pos, framecnt_t distance) const
{
@ -4145,6 +4120,7 @@ TempoMap::framewalk_to_qn (framepos_t pos, framecnt_t distance) const
return Evoral::Beats (quarter_note_at_frame_locked (_metrics, pos + distance) - quarter_note_at_frame_locked (_metrics, pos));
}
struct bbtcmp {
bool operator() (const BBT_Time& a, const BBT_Time& b) {
return a < b;

View file

@ -26,11 +26,11 @@ FrameposMinusBeatsTest::singleTempoTest ()
map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
/* Subtract 1 beat from beat 3 of the first bar */
framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, Beats(1));
framepos_t r = map.framepos_minus_qn (frames_per_beat * 2, Beats(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, Beats(4));
r = map.framepos_minus_qn (frames_per_beat * 3, Beats(4));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (- frames_per_beat));
}
@ -71,15 +71,15 @@ FrameposMinusBeatsTest::doubleTempoTest ()
/* Now some tests */
/* Subtract 1 beat from 1|2 */
framepos_t r = map.framepos_minus_beats (24e3, Beats(1));
framepos_t r = map.framepos_minus_qn (24e3, Beats(1));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
/* Subtract 2 beats from 4|2 (over the tempo change) */
r = map.framepos_minus_beats (288e3 + 12e3, Beats(2));
r = map.framepos_minus_qn (288e3 + 12e3, Beats(2));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
/* Subtract 2.5 beats from 4|2 (over the tempo change) */
r = map.framepos_minus_beats (288e3 + 12e3, Beats(2.5));
r = map.framepos_minus_qn (288e3 + 12e3, Beats(2.5));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));
}
@ -126,15 +126,15 @@ FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
/* Now some tests */
/* Subtract 1 beat from 1|2 */
framepos_t r = map.framepos_minus_beats (24e3, Beats(1));
framepos_t r = map.framepos_minus_qn (24e3, Beats(1));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
/* Subtract 2 beats from 4|2 (over the tempo change) */
r = map.framepos_minus_beats (288e3 + 12e3, Beats(2));
r = map.framepos_minus_qn (288e3 + 12e3, Beats(2));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
/* Subtract 2.5 beats from 4|2 (over the tempo change) */
r = map.framepos_minus_beats (288e3 + 12e3, Beats(2.5));
r = map.framepos_minus_qn (288e3 + 12e3, Beats(2.5));
CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));
}

View file

@ -25,11 +25,11 @@ FrameposPlusBeatsTest::singleTempoTest ()
map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
/* Add 1 beat to beat 3 of the first bar */
framepos_t r = map.framepos_plus_beats (frames_per_beat * 2, Evoral::Beats(1));
framepos_t r = map.framepos_plus_qn (frames_per_beat * 2, Evoral::Beats(1));
CPPUNIT_ASSERT_EQUAL (framepos_t (frames_per_beat * 3), r);
/* Add 4 beats to a -ve frame of 1 beat before zero */
r = map.framepos_plus_beats (-frames_per_beat * 1, Evoral::Beats(4));
r = map.framepos_plus_qn (-frames_per_beat * 1, Evoral::Beats(4));
CPPUNIT_ASSERT_EQUAL (framepos_t (frames_per_beat * 3), r);
}
@ -70,15 +70,15 @@ FrameposPlusBeatsTest::doubleTempoTest ()
/* Now some tests */
/* Add 1 beat to 1|2 */
framepos_t r = map.framepos_plus_beats (24e3, Evoral::Beats(1));
framepos_t r = map.framepos_plus_qn (24e3, Evoral::Beats(1));
CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
/* Add 2 beats to 3|4 (over the tempo change) */
r = map.framepos_plus_beats (264e3, Evoral::Beats(2));
r = map.framepos_plus_qn (264e3, Evoral::Beats(2));
CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
/* Add 2.5 beats to 3|3|960 (over the tempo change) */
r = map.framepos_plus_beats (264e3 - 12e3, Evoral::Beats(2.5));
r = map.framepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
}
@ -119,21 +119,77 @@ FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
Tempo tempoB (240);
map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
Meter meterB (3, 4);
Meter meterB (3, 8);
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), 0, MusicTime);
/* Now some tests */
/* Add 1 beat to 1|2 */
framepos_t r = map.framepos_plus_beats (24e3, Evoral::Beats(1));
framepos_t r = map.framepos_plus_qn (24e3, Evoral::Beats(1));
CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
/* Add 2 beats to 3|4 (over the tempo change) */
r = map.framepos_plus_beats (264e3, Evoral::Beats(2));
r = map.framepos_plus_qn (264e3, Evoral::Beats(2));
CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
/* Add 2.5 beats to 3|3|960 (over the tempo change) */
r = map.framepos_plus_beats (264e3 - 12e3, Evoral::Beats(2.5));
r = map.framepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
}
/* Same as doubleTempoWithMeterTest () except use odd meter divisors
(which shouldn't affect anything, since we are just dealing with
beats)
*/
void
FrameposPlusBeatsTest::doubleTempoWithComplexMeterTest ()
{
int const sampling_rate = 48000;
TempoMap map (sampling_rate);
Meter meterA (3, 4);
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
/*
120bpm at bar 1, 240bpm at bar 4
120bpm = 24e3 samples per beat
240bpm = 12e3 samples per beat
*/
/*
120bpm 5/8 240bpm
0 beats 9 quarter note beats 12 quarter note beats
9 meter-based beat 15 meter-based beat
0 frames 288e3 frames
0 pulses | 3 pulses
| | | | |
| 1.1 1.2 1.3 | 2.1 2.2 2.3 | 3.1 3.2 3.3 |4.14.24.34.44.5|5.15.2^5.35.45.5|
|
4|1|0
*/
Tempo tempoA (120);
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
Tempo tempoB (240, 4.0);
map.add_tempo (tempoB, 12.0 / 4.0, 0, TempoSection::Constant, MusicTime);
Meter meterB (5, 8);
map.add_meter (meterB, 9.0, BBT_Time (4, 1, 0), 0, MusicTime);
/* Now some tests */
/* Add 1 beat to 1|2 */
framepos_t r = map.framepos_plus_qn (24e3, Evoral::Beats(1));
CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
/* Add 2 beats to 5|1 (over the tempo change) */
r = map.framepos_plus_qn (264e3, Evoral::Beats(2));
CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
/* Add 2.5 beats to 4|5 (over the tempo change) */
r = map.framepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
}

View file

@ -8,6 +8,7 @@ class FrameposPlusBeatsTest : public CppUnit::TestFixture
CPPUNIT_TEST (singleTempoTest);
CPPUNIT_TEST (doubleTempoTest);
CPPUNIT_TEST (doubleTempoWithMeterTest);
CPPUNIT_TEST (doubleTempoWithComplexMeterTest);
CPPUNIT_TEST_SUITE_END ();
public:
@ -17,5 +18,6 @@ public:
void singleTempoTest ();
void doubleTempoTest ();
void doubleTempoWithMeterTest ();
void doubleTempoWithComplexMeterTest ();
};

View file

@ -24,19 +24,19 @@ FramewalkToBeatsTest::singleTempoTest ()
map.replace_tempo (map.tempo_section_at_frame (0), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
/* Walk 1 beats-worth of frames from beat 3 */
double r = map.framewalk_to_beats (frames_per_beat * 2, frames_per_beat * 1).to_double();
double r = map.framewalk_to_qn (frames_per_beat * 2, frames_per_beat * 1).to_double();
CPPUNIT_ASSERT_EQUAL (1.0, r);
/* Walk 6 beats-worth of frames from beat 4 */
r = map.framewalk_to_beats (frames_per_beat * 3, frames_per_beat * 6).to_double();
r = map.framewalk_to_qn (frames_per_beat * 3, frames_per_beat * 6).to_double();
CPPUNIT_ASSERT_EQUAL (6.0, r);
/* Walk 1.5 beats-worth of frames from beat 3 */
r = map.framewalk_to_beats (frames_per_beat * 2, frames_per_beat * 1.5).to_double();
r = map.framewalk_to_qn (frames_per_beat * 2, frames_per_beat * 1.5).to_double();
CPPUNIT_ASSERT_EQUAL (1.5, r);
/* Walk 1.5 beats-worth of frames from beat 2.5 */
r = map.framewalk_to_beats (frames_per_beat * 2.5, frames_per_beat * 1.5).to_double();
r = map.framewalk_to_qn (frames_per_beat * 2.5, frames_per_beat * 1.5).to_double();
CPPUNIT_ASSERT_EQUAL (1.5, r);
}
@ -78,22 +78,22 @@ FramewalkToBeatsTest::doubleTempoTest ()
/* Now some tests */
/* Walk 1 beat from 1|2 */
double r = map.framewalk_to_beats (24e3, 24e3).to_double();
double r = map.framewalk_to_qn (24e3, 24e3).to_double();
CPPUNIT_ASSERT_EQUAL (1.0, r);
/* Walk 2 beats from 3|3 to 4|1 (over the tempo change) */
r = map.framewalk_to_beats (240e3, (24e3 + 24e3)).to_double();
r = map.framewalk_to_qn (240e3, (24e3 + 24e3)).to_double();
CPPUNIT_ASSERT_EQUAL (2.0, r);
/* Walk 2.5 beats from 3|3.5 to 4.2 (over the tempo change) */
r = map.framewalk_to_beats (264e3 - 12e3, (24e3 + 12e3 + 12e3)).to_double();
r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3)).to_double();
CPPUNIT_ASSERT_EQUAL (2.5, r);
/* Walk 3 beats from 3|4.5 to 4|3.5 (over the tempo change) */
r = map.framewalk_to_beats (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 6e3)).to_double();
r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 6e3)).to_double();
CPPUNIT_ASSERT_EQUAL (3.0, r);
/* Walk 3.5 beats from 3|4.5 to 4.4 (over the tempo change) */
r = map.framewalk_to_beats (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 12e3)).to_double();
r = map.framewalk_to_qn (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 12e3)).to_double();
CPPUNIT_ASSERT_EQUAL (3.5, r);
}
@ -134,6 +134,38 @@ FramewalkToBeatsTest::tripleTempoTest ()
map.add_tempo (tempoC, 8.0 / tempoB.note_type(), 0, TempoSection::Constant, MusicTime);
/* Walk from 1|3 to 4|1 */
double r = map.framewalk_to_beats (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3)).to_double();
double r = map.framewalk_to_qn (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3)).to_double();
CPPUNIT_ASSERT_EQUAL (10.0, r);
}
void
FramewalkToBeatsTest::singleTempoMeterTest ()
{
int const sampling_rate = 48000;
int const bpm = 120;
double const frames_per_beat = (60 / double (bpm)) * double (sampling_rate);
TempoMap map (sampling_rate);
Tempo tempo (bpm);
Meter meter (7, 8);
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
map.replace_tempo (map.tempo_section_at_frame (0), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
/* Walk 1 qn beats-worth of frames from beat 3 */
double r = map.framewalk_to_qn (frames_per_beat * 2, frames_per_beat * 1).to_double();
CPPUNIT_ASSERT_EQUAL (1.0, r);
/* Walk 6 qn beats-worth of frames from beat 4 */
r = map.framewalk_to_qn (frames_per_beat * 3, frames_per_beat * 6).to_double();
CPPUNIT_ASSERT_EQUAL (6.0, r);
/* Walk 1.5 qn beats-worth of frames from beat 3 */
r = map.framewalk_to_qn (frames_per_beat * 2, frames_per_beat * 1.5).to_double();
CPPUNIT_ASSERT_EQUAL (1.5, r);
/* Walk 1.5 qn beats-worth of frames from beat 2.5 */
r = map.framewalk_to_qn (frames_per_beat * 2.5, frames_per_beat * 1.5).to_double();
CPPUNIT_ASSERT_EQUAL (1.5, r);
}

View file

@ -8,6 +8,7 @@ class FramewalkToBeatsTest : public CppUnit::TestFixture
CPPUNIT_TEST (singleTempoTest);
CPPUNIT_TEST (doubleTempoTest);
CPPUNIT_TEST (tripleTempoTest);
CPPUNIT_TEST (singleTempoMeterTest);
CPPUNIT_TEST_SUITE_END ();
public:
@ -17,5 +18,6 @@ public:
void singleTempoTest ();
void doubleTempoTest ();
void tripleTempoTest ();
void singleTempoMeterTest ();
};

View file

@ -520,7 +520,6 @@ def build(bld):
create_ardour_test_program(bld, obj.includes, 'resampled_source', 'test_resampled_source', ['test/resampled_source_test.cc'])
create_ardour_test_program(bld, obj.includes, 'framewalk_to_beats', 'test_framewalk_to_beats', ['test/framewalk_to_beats_test.cc'])
create_ardour_test_program(bld, obj.includes, 'framepos_plus_beats', 'test_framepos_plus_beats', ['test/framepos_plus_beats_test.cc'])
create_ardour_test_program(bld, obj.includes, 'framepos_minus_beats', 'test_framepos_minus_beats', ['test/framepos_minus_beats_test.cc'])
create_ardour_test_program(bld, obj.includes, 'playlist_equivalent_regions', 'test_playlist_equivalent_regions', ['test/playlist_equivalent_regions_test.cc'])
create_ardour_test_program(bld, obj.includes, 'playlist_layering', 'test_playlist_layering', ['test/playlist_layering_test.cc'])
create_ardour_test_program(bld, obj.includes, 'plugins_test', 'test_plugins', ['test/plugins_test.cc'])
@ -542,7 +541,6 @@ def build(bld):
test/resampled_source_test.cc
test/framewalk_to_beats_test.cc
test/framepos_plus_beats_test.cc
test/framepos_minus_beats_test.cc
test/playlist_equivalent_regions_test.cc
test/playlist_layering_test.cc
test/plugins_test.cc