1 #include "framepos_minus_beats_test.h"
2 #include "ardour/tempo.h"
3 #include "timecode/bbt_time.h"
5 CPPUNIT_TEST_SUITE_REGISTRATION (FrameposMinusBeatsTest);
8 using namespace ARDOUR;
9 using namespace Timecode;
11 /* Basic tests with no tempo / meter changes */
13 FrameposMinusBeatsTest::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 /* Subtract 1 beat from beat 3 of the first bar */
28 framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, 1);
29 CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 1));
32 /* Test adding things that overlap a tempo change */
34 FrameposMinusBeatsTest::doubleTempoTest ()
36 int const sampling_rate = 48000;
38 TempoMap map (sampling_rate);
40 map.add_meter (meter, BBT_Time (1, 1, 0));
43 120bpm at bar 1, 240bpm at bar 4
45 120bpm = 24e3 samples per beat
46 240bpm = 12e3 samples per beat
56 | 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 |
61 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
63 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
67 /* Subtract 1 beat from 1|2 */
68 framepos_t r = map.framepos_minus_beats (24e3, 1);
69 CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
71 /* Subtract 2 beats from 4|2 (over the tempo change) */
72 r = map.framepos_minus_beats (288e3 + 12e3, 2);
73 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
75 /* Subtract 2.5 beats from 4|2 (over the tempo change) */
76 r = map.framepos_minus_beats (288e3 + 12e3, 2.5);
77 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));
80 /* Same as doubleTempoTest () except put a meter change at the same time as the
81 tempo change (which shouldn't affect anything, since we are just dealing with
86 FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
88 int const sampling_rate = 48000;
90 TempoMap map (sampling_rate);
92 map.add_meter (meterA, BBT_Time (1, 1, 0));
95 120bpm at bar 1, 240bpm at bar 4
97 120bpm = 24e3 samples per beat
98 240bpm = 12e3 samples per beat
106 0 frames 288e3 frames
108 | 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 |
113 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
115 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
117 map.add_meter (meterB, BBT_Time (4, 1, 0));
121 /* Subtract 1 beat from 1|2 */
122 framepos_t r = map.framepos_minus_beats (24e3, 1);
123 CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
125 /* Subtract 2 beats from 4|2 (over the tempo change) */
126 r = map.framepos_minus_beats (288e3 + 12e3, 2);
127 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
129 /* Subtract 2.5 beats from 4|2 (over the tempo change) */
130 r = map.framepos_minus_beats (288e3 + 12e3, 2.5);
131 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));