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;
10 using namespace Evoral;
12 /* Basic tests with no tempo / meter changes */
14 FrameposMinusBeatsTest::singleTempoTest ()
16 int const sampling_rate = 48000;
19 double const frames_per_beat = (60 / double (bpm)) * double (sampling_rate);
21 TempoMap map (sampling_rate);
25 map.add_meter (meter, BBT_Time (1, 1, 0));
26 map.add_tempo (tempo, BBT_Time (1, 1, 0));
28 /* Subtract 1 beat from beat 3 of the first bar */
29 framepos_t r = map.framepos_minus_beats (frames_per_beat * 2, Beats(1));
30 CPPUNIT_ASSERT_EQUAL (r, framepos_t (frames_per_beat * 1));
32 /* Subtract 4 beats from 3 beats in, to go beyond zero */
33 r = map.framepos_minus_beats (frames_per_beat * 3, Beats(4));
34 CPPUNIT_ASSERT_EQUAL (r, framepos_t (- frames_per_beat));
37 /* Test adding things that overlap a tempo change */
39 FrameposMinusBeatsTest::doubleTempoTest ()
41 int const sampling_rate = 48000;
43 TempoMap map (sampling_rate);
45 map.add_meter (meter, BBT_Time (1, 1, 0));
48 120bpm at bar 1, 240bpm at bar 4
50 120bpm = 24e3 samples per beat
51 240bpm = 12e3 samples per beat
61 | 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 |
66 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
68 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
72 /* Subtract 1 beat from 1|2 */
73 framepos_t r = map.framepos_minus_beats (24e3, Beats(1));
74 CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
76 /* Subtract 2 beats from 4|2 (over the tempo change) */
77 r = map.framepos_minus_beats (288e3 + 12e3, Beats(2));
78 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
80 /* Subtract 2.5 beats from 4|2 (over the tempo change) */
81 r = map.framepos_minus_beats (288e3 + 12e3, Beats(2.5));
82 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));
85 /* Same as doubleTempoTest () except put a meter change at the same time as the
86 tempo change (which shouldn't affect anything, since we are just dealing with
91 FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
93 int const sampling_rate = 48000;
95 TempoMap map (sampling_rate);
97 map.add_meter (meterA, BBT_Time (1, 1, 0));
100 120bpm at bar 1, 240bpm at bar 4
102 120bpm = 24e3 samples per beat
103 240bpm = 12e3 samples per beat
111 0 frames 288e3 frames
113 | 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 |
118 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
120 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
122 map.add_meter (meterB, BBT_Time (4, 1, 0));
126 /* Subtract 1 beat from 1|2 */
127 framepos_t r = map.framepos_minus_beats (24e3, Beats(1));
128 CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
130 /* Subtract 2 beats from 4|2 (over the tempo change) */
131 r = map.framepos_minus_beats (288e3 + 12e3, Beats(2));
132 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
134 /* Subtract 2.5 beats from 4|2 (over the tempo change) */
135 r = map.framepos_minus_beats (288e3 + 12e3, Beats(2.5));
136 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));