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.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
26 map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
28 /* Subtract 1 beat from beat 3 of the first bar */
29 framepos_t r = map.framepos_minus_qn (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_qn (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.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
48 120bpm at bar 1, 240bpm at bar 4
50 120bpm = 24e3 samples per beat
51 240bpm = 12e3 samples per beat
62 | 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 |
67 map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
69 map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
73 /* Subtract 1 beat from 1|2 */
74 framepos_t r = map.framepos_minus_qn (24e3, Beats(1));
75 CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
77 /* Subtract 2 beats from 4|2 (over the tempo change) */
78 r = map.framepos_minus_qn (288e3 + 12e3, Beats(2));
79 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
81 /* Subtract 2.5 beats from 4|2 (over the tempo change) */
82 r = map.framepos_minus_qn (288e3 + 12e3, Beats(2.5));
83 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));
86 /* Same as doubleTempoTest () except put a meter change at the same time as the
87 tempo change (which shouldn't affect anything, since we are just dealing with
92 FrameposMinusBeatsTest::doubleTempoWithMeterTest ()
94 int const sampling_rate = 48000;
96 TempoMap map (sampling_rate);
98 map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
101 120bpm at bar 1, 240bpm at bar 4
103 120bpm = 24e3 samples per beat
104 240bpm = 12e3 samples per beat
112 0 frames 288e3 frames
115 | 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 |
120 map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
122 map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
124 map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), 0, MusicTime);
128 /* Subtract 1 beat from 1|2 */
129 framepos_t r = map.framepos_minus_qn (24e3, Beats(1));
130 CPPUNIT_ASSERT_EQUAL (r, framepos_t (0));
132 /* Subtract 2 beats from 4|2 (over the tempo change) */
133 r = map.framepos_minus_qn (288e3 + 12e3, Beats(2));
134 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3));
136 /* Subtract 2.5 beats from 4|2 (over the tempo change) */
137 r = map.framepos_minus_qn (288e3 + 12e3, Beats(2.5));
138 CPPUNIT_ASSERT_EQUAL (r, framepos_t (288e3 - 24e3 - 12e3));