From d824e696c0322ebc8e14320f9ef1d713ea9d9404 Mon Sep 17 00:00:00 2001 From: nick_m Date: Thu, 13 Oct 2016 14:14:27 +1100 Subject: Fix ramp test, add tempoAtPulseTest. --- libs/ardour/test/tempo_test.cc | 68 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) (limited to 'libs/ardour/test/tempo_test.cc') diff --git a/libs/ardour/test/tempo_test.cc b/libs/ardour/test/tempo_test.cc index 04bf071cac..ae75896855 100644 --- a/libs/ardour/test/tempo_test.cc +++ b/libs/ardour/test/tempo_test.cc @@ -65,7 +65,7 @@ TempoTest::rampTest () /* - 77bpm / note typeA 217bpm / note type B + 77bpm 217bpm 0 frames 60 * sample rate frames | | | | | | *| @@ -96,14 +96,76 @@ TempoTest::rampTest () } map.recompute_map (map._metrics); - CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (tB->beats_per_minute() / tB->note_type(), 300.0, sampling_rate)); + CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (tB->beats_per_minute(), 300.0, sampling_rate)); CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (tB->pulse(), sampling_rate)); /* self-check tempo at pulse @ 125 bpm. */ - CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0 / 4.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0 / 4.0, 0, sampling_rate)), 0.00000000000000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0, sampling_rate)), 0.00000000000000001); /* self-check frame at pulse 20 seconds in. */ const framepos_t target = 20 * sampling_rate; const framepos_t result = tA->frame_at_pulse (tA->pulse_at_frame (target, sampling_rate), sampling_rate); CPPUNIT_ASSERT_EQUAL (target, result); } + + +void +TempoTest::tempoAtPulseTest () +{ + int const sampling_rate = 48000; + + TempoMap map (sampling_rate); + Meter meterA (4, 8); + Tempo tempoA (80.0, 8.0); + Tempo tempoB (160.0, 3.0); + Tempo tempoC (123.0, 4.0); + + map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime); + map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime); + + map.add_tempo (tempoB, 20.0, 0, TempoSection::Ramp, MusicTime); + map.add_tempo (tempoC, 30.0, 0, TempoSection::Ramp, MusicTime); + + map.recompute_map (map._metrics); + + TempoSection* tA = 0; + TempoSection* tB = 0; + TempoSection* tC = 0; + + list::iterator i; + + for (i = map._metrics.begin(); i != map._metrics.end(); ++i) { + TempoSection* t; + if ((t = dynamic_cast (*i)) != 0) { + if (!tA) { + tA = t; + continue; + } + if (!tB) { + tB = t; + continue; + } + if (!tC) { + tC = t; + continue; + } + } + } + + CPPUNIT_ASSERT_EQUAL (tB->beats_per_minute(), tA->tempo_at_pulse (20.0)); + CPPUNIT_ASSERT_EQUAL (tC->beats_per_minute(), tB->tempo_at_pulse (30.0)); + + /* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/ + CPPUNIT_ASSERT_EQUAL (((tA->beats_per_minute() - tB->beats_per_minute()) / 2.0) + tB->beats_per_minute(), tA->tempo_at_pulse (10.0)); + CPPUNIT_ASSERT_EQUAL (((tA->pulse() - tB->pulse()) / 2.0) + tB->pulse(), tA->pulse_at_tempo (120, 0, sampling_rate)); + CPPUNIT_ASSERT_EQUAL (((tB->beats_per_minute() - tC->beats_per_minute()) / 2.0) + tC->beats_per_minute(), tB->tempo_at_pulse (25.0)); + CPPUNIT_ASSERT_EQUAL (((tB->pulse() - tC->pulse()) / 2.0) + tC->pulse(), tB->pulse_at_tempo (141.5, 0, sampling_rate)); + + CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (tB->pulse(), sampling_rate)); + CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_pulse (tC->pulse(), sampling_rate)); + + /* self-check tempo at pulse @ 125 bpm. */ + CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0, sampling_rate)), 0.00000000000000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL (160.0, tA->tempo_at_pulse (tB->pulse()), 0.00000000000000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL (123.0, tB->tempo_at_pulse (tC->pulse()), 0.00000000000000001); +} -- cgit v1.2.3