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);
21 Tempo tempo (bpm, 4.0);
24 map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), AudioTime);
25 map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
27 /* Add 1 beat to beat 3 of the first bar */
28 framepos_t r = map.framepos_plus_qn (frames_per_beat * 2, Evoral::Beats(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_qn (-frames_per_beat * 1, Evoral::Beats(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.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), AudioTime);
47 120bpm at bar 1, 240bpm at bar 4
49 120bpm = 24e3 samples per beat
50 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 |
65 Tempo tempoA (120, 4.0);
66 map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
67 Tempo tempoB (240, 4.0);
68 map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
72 /* Add 1 beat to 1|2 */
73 framepos_t r = map.framepos_plus_qn (24e3, Evoral::Beats(1));
74 CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
76 /* Add 2 beats to 3|4 (over the tempo change) */
77 r = map.framepos_plus_qn (264e3, Evoral::Beats(2));
78 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
80 /* Add 2.5 beats to 3|3|960 (over the tempo change) */
81 r = map.framepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
82 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
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 FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
93 int const sampling_rate = 48000;
95 TempoMap map (sampling_rate);
97 map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
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
114 | 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 Tempo tempoA (120, 4.0);
119 map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
120 Tempo tempoB (240, 4.0);
121 map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
123 map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), MusicTime);
127 /* Add 1 beat to 1|2 */
128 framepos_t r = map.framepos_plus_qn (24e3, Evoral::Beats(1));
129 CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
131 /* Add 2 beats to 3|4 (over the tempo change) */
132 r = map.framepos_plus_qn (264e3, Evoral::Beats(2));
133 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
135 /* Add 2.5 beats to 3|3|960 (over the tempo change) */
136 r = map.framepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
137 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
140 /* Same as doubleTempoWithMeterTest () except use odd meter divisors
141 (which shouldn't affect anything, since we are just dealing with
146 FrameposPlusBeatsTest::doubleTempoWithComplexMeterTest ()
148 int const sampling_rate = 48000;
150 TempoMap map (sampling_rate);
152 map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
155 120bpm at bar 1, 240bpm at bar 4
157 120bpm = 24e3 samples per beat
158 240bpm = 12e3 samples per beat
165 0 beats 9 quarter note beats 12 quarter note beats
166 9 meter-based beat 15 meter-based beat
167 0 frames 288e3 frames
170 | 1.1 1.2 1.3 | 2.1 2.2 2.3 | 3.1 3.2 3.3 |4.14.24.34.44.5|5.15.2^5.35.45.5|
175 Tempo tempoA (120, 4.0);
176 map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
177 Tempo tempoB (240, 4.0);
178 map.add_tempo (tempoB, 12.0 / 4.0, 0, TempoSection::Constant, MusicTime);
180 map.add_meter (meterB, 9.0, BBT_Time (4, 1, 0), MusicTime);
183 /* Add 1 beat to 1|2 */
184 framepos_t r = map.framepos_plus_qn (24e3, Evoral::Beats(1));
185 CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
187 /* Add 2 beats to 5|1 (over the tempo change) */
188 r = map.framepos_plus_qn (264e3, Evoral::Beats(2));
189 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
191 /* Add 2.5 beats to 4|5 (over the tempo change) */
192 r = map.framepos_plus_qn (264e3 - 12e3, Evoral::Beats(2.5));
193 CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);