diff options
author | Carl Hetherington <carl@carlh.net> | 2011-12-11 14:50:36 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-12-11 14:50:36 +0000 |
commit | 1bbe08af1a44f46c13873b762decc7629274929d (patch) | |
tree | c7516ca9e7bdce095a906002f354e8e04dfa94bf /libs/ardour/test | |
parent | ed360080d0e7a4505eb3e90f3f9946754f0c779b (diff) |
Keep track of MIDI region's start positions in beats, to
match the source, so that starts are not corrupted when
tempos change (#4494).
git-svn-id: svn://localhost/ardour2/branches/3.0@10976 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/test')
-rw-r--r-- | libs/ardour/test/framepos_minus_beats_test.cc | 134 | ||||
-rw-r--r-- | libs/ardour/test/framepos_minus_beats_test.h | 21 | ||||
-rw-r--r-- | libs/ardour/test/framepos_plus_beats_test.cc | 4 | ||||
-rw-r--r-- | libs/ardour/test/framewalk_to_beats_test.cc | 10 |
4 files changed, 164 insertions, 5 deletions
diff --git a/libs/ardour/test/framepos_minus_beats_test.cc b/libs/ardour/test/framepos_minus_beats_test.cc new file mode 100644 index 0000000000..f80f57d969 --- /dev/null +++ b/libs/ardour/test/framepos_minus_beats_test.cc @@ -0,0 +1,134 @@ +#include "framepos_minus_beats_test.h" +#include "ardour/tempo.h" +#include "timecode/bbt_time.h" + +CPPUNIT_TEST_SUITE_REGISTRATION (FrameposMinusBeatsTest); + +using namespace std; +using namespace ARDOUR; +using namespace Timecode; + +/* Basic tests with no tempo / meter changes */ +void +FrameposMinusBeatsTest::singleTempoTest () +{ + 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 (4, 4); + + map.add_meter (meter, BBT_Time (1, 1, 0)); + map.add_tempo (tempo, BBT_Time (1, 1, 0)); + + /* Subtract 1 beat from beat 3 of the first bar */ + framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, 1); + CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 1)); +} + +/* Test adding things that overlap a tempo change */ +void +FrameposMinusBeatsTest::doubleTempoTest () +{ + int const sampling_rate = 48000; + + TempoMap map (sampling_rate); + Meter meter (4, 4); + map.add_meter (meter, BBT_Time (1, 1, 0)); + + /* + 120bpm at bar 1, 240bpm at bar 4 + + 120bpm = 24e3 samples per beat + 240bpm = 12e3 samples per beat + */ + + + /* + + 120bpm 240bpm + 0 beats 12 beats + 0 frames 288e3 frames + | | | | | + | 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 4.4 | + + */ + + Tempo tempoA (120); + map.add_tempo (tempoA, BBT_Time (1, 1, 0)); + Tempo tempoB (240); + map.add_tempo (tempoB, BBT_Time (4, 1, 0)); + + /* Now some tests */ + + /* Subtract 1 beat from 1|2 */ + framepos_t r = map.framepos_minus_beats (24e3, 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, 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, 2.5); + CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3)); +} + +/* Same as doubleTempoTest () except put a meter change at the same time as the + tempo change (which shouldn't affect anything, since we are just dealing with + beats) +*/ + +void +FrameposMinusBeatsTest::doubleTempoWithMeterTest () +{ + int const sampling_rate = 48000; + + TempoMap map (sampling_rate); + Meter meterA (4, 4); + map.add_meter (meterA, BBT_Time (1, 1, 0)); + + /* + 120bpm at bar 1, 240bpm at bar 4 + + 120bpm = 24e3 samples per beat + 240bpm = 12e3 samples per beat + */ + + + /* + + 120bpm 240bpm + 0 beats 12 beats + 0 frames 288e3 frames + | | | | | + | 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 | + + */ + + Tempo tempoA (120); + map.add_tempo (tempoA, BBT_Time (1, 1, 0)); + Tempo tempoB (240); + map.add_tempo (tempoB, BBT_Time (4, 1, 0)); + Meter meterB (3, 4); + map.add_meter (meterB, BBT_Time (4, 1, 0)); + + /* Now some tests */ + + /* Subtract 1 beat from 1|2 */ + framepos_t r = map.framepos_minus_beats (24e3, 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, 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, 2.5); + CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3)); +} + + diff --git a/libs/ardour/test/framepos_minus_beats_test.h b/libs/ardour/test/framepos_minus_beats_test.h new file mode 100644 index 0000000000..648ef71918 --- /dev/null +++ b/libs/ardour/test/framepos_minus_beats_test.h @@ -0,0 +1,21 @@ +#include <sigc++/sigc++.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +class FrameposMinusBeatsTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE (FrameposMinusBeatsTest); + CPPUNIT_TEST (singleTempoTest); + CPPUNIT_TEST (doubleTempoTest); + CPPUNIT_TEST (doubleTempoWithMeterTest); + CPPUNIT_TEST_SUITE_END (); + +public: + void setUp () {} + void tearDown () {} + + void singleTempoTest (); + void doubleTempoTest (); + void doubleTempoWithMeterTest (); +}; + diff --git a/libs/ardour/test/framepos_plus_beats_test.cc b/libs/ardour/test/framepos_plus_beats_test.cc index 19aa7f29c6..882b6b5721 100644 --- a/libs/ardour/test/framepos_plus_beats_test.cc +++ b/libs/ardour/test/framepos_plus_beats_test.cc @@ -27,6 +27,10 @@ FrameposPlusBeatsTest::singleTempoTest () /* Add 1 beat to beat 3 of the first bar */ framepos_t r = map.framepos_plus_beats (frames_per_beat * 2, 1); CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 3)); + + /* Add 4 beats to a -ve frame of 1 beat before zero */ + r = map.framepos_plus_beats (-frames_per_beat * 1, 4); + CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 3)); } /* Test adding things that overlap a tempo change */ diff --git a/libs/ardour/test/framewalk_to_beats_test.cc b/libs/ardour/test/framewalk_to_beats_test.cc index 7e50aedcb5..2b2a5a782c 100644 --- a/libs/ardour/test/framewalk_to_beats_test.cc +++ b/libs/ardour/test/framewalk_to_beats_test.cc @@ -74,23 +74,23 @@ FramewalkToBeatsTest::doubleTempoTest () /* Now some tests */ - /* Walk 1 beat from 1.2 */ + /* Walk 1 beat from 1|2 */ double r = map.framewalk_to_beats (24e3, 24e3); CPPUNIT_ASSERT_EQUAL (r, 1.0); - /* Walk 2 beats from 3.3 to 4.1 (over the tempo change) */ + /* Walk 2 beats from 3|3 to 4|1 (over the tempo change) */ r = map.framewalk_to_beats (264e3, (24e3 + 12e3)); CPPUNIT_ASSERT_EQUAL (r, 2.0); - /* Walk 2.5 beats from 3.3-and-a-half to 4.2 (over the tempo change) */ + /* 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)); CPPUNIT_ASSERT_EQUAL (r, 2.5); - /* Walk 3 beats from 3.4-and-a-half to 4.3-and-a-half (over the tempo change) */ + /* 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)); CPPUNIT_ASSERT_EQUAL (r, 3.0); - /* Walk 3.5 beats from 3.4-and-a-half to 4.4 (over the tempo change) */ + /* 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)); CPPUNIT_ASSERT_EQUAL (r, 3.5); } |