summaryrefslogtreecommitdiff
path: root/libs/ardour/test
diff options
context:
space:
mode:
authornick_m <mainsbridge@gmail.com>2016-10-13 14:14:27 +1100
committernick_m <mainsbridge@gmail.com>2016-10-13 14:14:27 +1100
commitd824e696c0322ebc8e14320f9ef1d713ea9d9404 (patch)
treec2755cdbd757150ffbf645d66bac89bd3f94bede /libs/ardour/test
parenteae567bd9e2fe1ac3820490b65f199f6cc23c83d (diff)
Fix ramp test, add tempoAtPulseTest.
Diffstat (limited to 'libs/ardour/test')
-rw-r--r--libs/ardour/test/tempo_test.cc68
-rw-r--r--libs/ardour/test/tempo_test.h2
2 files changed, 67 insertions, 3 deletions
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<MetricSection*>::iterator i;
+
+ for (i = map._metrics.begin(); i != map._metrics.end(); ++i) {
+ TempoSection* t;
+ if ((t = dynamic_cast<TempoSection*> (*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);
+}
diff --git a/libs/ardour/test/tempo_test.h b/libs/ardour/test/tempo_test.h
index e2a6701228..7df6a089e8 100644
--- a/libs/ardour/test/tempo_test.h
+++ b/libs/ardour/test/tempo_test.h
@@ -7,6 +7,7 @@ class TempoTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE (TempoTest);
CPPUNIT_TEST (recomputeMapTest);
CPPUNIT_TEST (rampTest);
+ CPPUNIT_TEST (tempoAtPulseTest);
CPPUNIT_TEST_SUITE_END ();
public:
@@ -15,5 +16,6 @@ public:
void recomputeMapTest ();
void rampTest ();
+ void tempoAtPulseTest();
};