1 #include "framepos_plus_beats_test.h"
2 #include "ardour/tempo.h"
3 #include "timecode/bbt_time.h"
5 CPPUNIT_TEST_SUITE_REGISTRATION (FrameposPlusBeatsTest);
8 using namespace ARDOUR;
9 using namespace Timecode;
11 /* Basic tests with no tempo / meter changes */
13 FrameposPlusBeatsTest::singleTempoTest ()
15 int const sampling_rate = 48000;
18 double const frames_per_beat = (60 / double (bpm)) * double (sampling_rate);
20 TempoMap map (sampling_rate);
24 map.add_meter (meter, BBT_Time (1, 1, 0));
25 map.add_tempo (tempo, BBT_Time (1, 1, 0));
27 /* Add 1 beat to beat 3 of the first bar */
28 framepos_t r = map.framepos_plus_beats (frames_per_beat * 2, 1);
29 CPPUNIT_ASSERT_EQUAL (framepos_t (frames_per_beat * 3), r);
31 /* Add 4 beats to a -ve frame of 1 beat before zero */
32 r = map.framepos_plus_beats (-frames_per_beat * 1, 4);
33 CPPUNIT_ASSERT_EQUAL (framepos_t (frames_per_beat * 3), r);
36 /* Test adding things that overlap a tempo change */
38 FrameposPlusBeatsTest::doubleTempoTest ()
40 int const sampling_rate = 48000;
42 TempoMap map (sampling_rate);
44 map.add_meter (meter, BBT_Time (1, 1, 0));
47 120bpm at bar 1, 240bpm at bar 4
49 120bpm = 24e3 samples per beat
50 240bpm = 12e3 samples per beat
60 | 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 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
67 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
71 /* Add 1 beat to 1|2 */
72 framepos_t r = map.framepos_plus_beats (24e3, 1);
73 CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
75 /* Add 2 beats to 3|4 (over the tempo change) */
76 r = map.framepos_plus_beats (264e3, 2);
77 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
79 /* Add 2.5 beats to 3|3|960 (over the tempo change) */
80 r = map.framepos_plus_beats (264e3 - 12e3, 2.5);
81 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
84 /* Same as doubleTempoTest () except put a meter change at the same time as the
85 tempo change (which shouldn't affect anything, since we are just dealing with
90 FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
92 int const sampling_rate = 48000;
94 TempoMap map (sampling_rate);
96 map.add_meter (meterA, BBT_Time (1, 1, 0));
99 120bpm at bar 1, 240bpm at bar 4
101 120bpm = 24e3 samples per beat
102 240bpm = 12e3 samples per beat
110 0 frames 288e3 frames
112 | 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 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
119 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
121 map.add_meter (meterB, BBT_Time (4, 1, 0));
125 /* Add 1 beat to 1|2 */
126 framepos_t r = map.framepos_plus_beats (24e3, 1);
127 CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
129 /* Add 2 beats to 3|4 (over the tempo change) */
130 r = map.framepos_plus_beats (264e3, 2);
131 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
133 /* Add 2.5 beats to 3|3|960 (over the tempo change) */
134 r = map.framepos_plus_beats (264e3 - 12e3, 2.5);
135 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);