From d3f0e651998be01f75bb334e36a4329c9772af40 Mon Sep 17 00:00:00 2001 From: nick_m Date: Sat, 2 Apr 2016 03:23:51 +1100 Subject: Tempo ramps - tempo related tests pass, add ramp test. --- libs/ardour/test/framepos_minus_beats_test.cc | 8 +++-- libs/ardour/test/framepos_plus_beats_test.cc | 8 +++-- libs/ardour/test/framewalk_to_beats_test.cc | 8 +++-- libs/ardour/test/tempo_test.cc | 43 +++++++++++++++++++++++++++ libs/ardour/test/tempo_test.h | 2 ++ 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/libs/ardour/test/framepos_minus_beats_test.cc b/libs/ardour/test/framepos_minus_beats_test.cc index fd06f7de84..6982529bf6 100644 --- a/libs/ardour/test/framepos_minus_beats_test.cc +++ b/libs/ardour/test/framepos_minus_beats_test.cc @@ -57,6 +57,7 @@ FrameposMinusBeatsTest::doubleTempoTest () 120bpm 240bpm 0 beats 12 beats 0 frames 288e3 frames + 0 pulses 4 pulses | | | | | | 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 | @@ -65,7 +66,7 @@ FrameposMinusBeatsTest::doubleTempoTest () Tempo tempoA (120); map.add_tempo (tempoA, 0.0, TempoSection::Constant); Tempo tempoB (240); - map.add_tempo (tempoB, 12.0, TempoSection::Constant); + map.add_tempo (tempoB, 12.0 / tempoA.note_type(), TempoSection::Constant); /* Now some tests */ @@ -109,6 +110,7 @@ FrameposMinusBeatsTest::doubleTempoWithMeterTest () 120bpm 240bpm 0 beats 12 beats 0 frames 288e3 frames + 0 pulses 4 pulses | | | | | | 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 | @@ -117,9 +119,9 @@ FrameposMinusBeatsTest::doubleTempoWithMeterTest () Tempo tempoA (120); map.add_tempo (tempoA, 0.0, TempoSection::Constant); Tempo tempoB (240); - map.add_tempo (tempoB, 12.0, TempoSection::Constant); + map.add_tempo (tempoB, 12.0 / tempoA.note_type(), TempoSection::Constant); Meter meterB (3, 4); - map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0)); + map.add_meter (meterB, 12.0 / tempoA.note_type(), BBT_Time (4, 1, 0)); /* Now some tests */ diff --git a/libs/ardour/test/framepos_plus_beats_test.cc b/libs/ardour/test/framepos_plus_beats_test.cc index a2cc616c58..f31f73da20 100644 --- a/libs/ardour/test/framepos_plus_beats_test.cc +++ b/libs/ardour/test/framepos_plus_beats_test.cc @@ -56,6 +56,7 @@ FrameposPlusBeatsTest::doubleTempoTest () 120bpm 240bpm 0 beats 12 beats 0 frames 288e3 frames + 0 pulses 4 pulses | | | | | | 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 | @@ -64,7 +65,7 @@ FrameposPlusBeatsTest::doubleTempoTest () Tempo tempoA (120); map.add_tempo (tempoA, 0.0, TempoSection::Constant); Tempo tempoB (240); - map.add_tempo (tempoB, 12.0, TempoSection::Constant); + map.add_tempo (tempoB, 12.0 / tempoA.note_type(), TempoSection::Constant); /* Now some tests */ @@ -108,6 +109,7 @@ FrameposPlusBeatsTest::doubleTempoWithMeterTest () 120bpm 240bpm 0 beats 12 beats 0 frames 288e3 frames + 0 pulses 4 pulses | | | | | | 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 | @@ -116,9 +118,9 @@ FrameposPlusBeatsTest::doubleTempoWithMeterTest () Tempo tempoA (120); map.add_tempo (tempoA, 0.0, TempoSection::Constant); Tempo tempoB (240); - map.add_tempo (tempoB, 12.0, TempoSection::Constant); + map.add_tempo (tempoB, 12.0 / tempoA.note_type(), TempoSection::Constant); Meter meterB (3, 4); - map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0)); + map.add_meter (meterB, 12.0 / tempoA.note_type(), BBT_Time (4, 1, 0)); /* Now some tests */ diff --git a/libs/ardour/test/framewalk_to_beats_test.cc b/libs/ardour/test/framewalk_to_beats_test.cc index 9706375216..f895cfb1a4 100644 --- a/libs/ardour/test/framewalk_to_beats_test.cc +++ b/libs/ardour/test/framewalk_to_beats_test.cc @@ -63,6 +63,7 @@ FramewalkToBeatsTest::doubleTempoTest () 0 beats 12 beats 0 frames 288e3 frames 24e3 frames per beat 12e3 frames per beat + 0 pulses 4 pulses | | | | | 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 5.1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @@ -72,7 +73,7 @@ FramewalkToBeatsTest::doubleTempoTest () Tempo tempoA (120); map.add_tempo (tempoA, 0.0, TempoSection::Constant); Tempo tempoB (240); - map.add_tempo (tempoB, 12.0, TempoSection::Constant); + map.add_tempo (tempoB, 12.0 / tempoB.note_type(), TempoSection::Constant); /* Now some tests */ @@ -119,6 +120,7 @@ FramewalkToBeatsTest::tripleTempoTest () 120bpm 240bpm 160bpm 0 beats 4 beats 8 beats 0 frames 96e3 frames 144e3 frames + 0 pulses 1 pulse 2 pulses | | | | | | 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 | @@ -127,9 +129,9 @@ FramewalkToBeatsTest::tripleTempoTest () Tempo tempoA (120); map.add_tempo (tempoA, 0.0, TempoSection::Constant); Tempo tempoB (240); - map.add_tempo (tempoB, 4.0, TempoSection::Constant); + map.add_tempo (tempoB, 4.0 / tempoB.note_type(), TempoSection::Constant); Tempo tempoC (160); - map.add_tempo (tempoC, 8.0, TempoSection::Constant); + map.add_tempo (tempoC, 8.0 / tempoB.note_type(), TempoSection::Constant); /* Walk from 1|3 to 4|1 */ double r = map.framewalk_to_beats (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3)).to_double(); diff --git a/libs/ardour/test/tempo_test.cc b/libs/ardour/test/tempo_test.cc index aa425134ae..9a6229124f 100644 --- a/libs/ardour/test/tempo_test.cc +++ b/libs/ardour/test/tempo_test.cc @@ -29,6 +29,7 @@ TempoTest::recomputeMapTest () 120bpm 240bpm 0 beats 12 beats 0 frames 288e3 frames + 0 pulses 4 pulses | | | | | | 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 | @@ -48,3 +49,45 @@ TempoTest::recomputeMapTest () --i; CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), (*i)->frame ()); } + +void +TempoTest::rampTest () +{ + int const sampling_rate = 48000; + + TempoMap map (sampling_rate); + Meter meterA (4, 4); + Tempo tempoA (77.0, 4.0); + Tempo tempoB (217.0, 4.0); + map.add_tempo (tempoA, 0.0, TempoSection::Ramp); + map.add_tempo (tempoB, 100.0, TempoSection::Ramp); + map.add_meter (meterA, 0.0, BBT_Time (1, 1, 0)); + + /* + + 120bpm 240bpm + 0 beats 12 beats + 0 frames 288e3 frames + 0 pulses 4 pulses + | | | | | + | 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 | + + */ + + TempoSection* tA = 0; + TempoSection* tB; + list::iterator i; + + for (i = map._metrics.begin(); i != map._metrics.end(); ++i) { + if ((tB = dynamic_cast (*i)) != 0) { + if (tA) { + break; + } + tA = tB; + } + } + map.recompute_map (map._metrics); + + CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (tB->beats_per_minute() / tB->note_type(), 100.0, sampling_rate)); + CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (tB->pulse(), sampling_rate)); +} diff --git a/libs/ardour/test/tempo_test.h b/libs/ardour/test/tempo_test.h index 3252650b03..e2a6701228 100644 --- a/libs/ardour/test/tempo_test.h +++ b/libs/ardour/test/tempo_test.h @@ -6,6 +6,7 @@ class TempoTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE (TempoTest); CPPUNIT_TEST (recomputeMapTest); + CPPUNIT_TEST (rampTest); CPPUNIT_TEST_SUITE_END (); public: @@ -13,5 +14,6 @@ public: void tearDown () {} void recomputeMapTest (); + void rampTest (); }; -- cgit v1.2.3