ardour
framepos_plus_beats_test.cc
Go to the documentation of this file.
2 #include "ardour/tempo.h"
3 #include "timecode/bbt_time.h"
4 
6 
7 using namespace std;
8 using namespace ARDOUR;
9 using namespace Timecode;
10 
11 /* Basic tests with no tempo / meter changes */
12 void
14 {
15  int const sampling_rate = 48000;
16  int const bpm = 120;
17 
18  double const frames_per_beat = (60 / double (bpm)) * double (sampling_rate);
19 
20  TempoMap map (sampling_rate);
21  Tempo tempo (bpm);
22  Meter meter (4, 4);
23 
24  map.add_meter (meter, BBT_Time (1, 1, 0));
25  map.add_tempo (tempo, BBT_Time (1, 1, 0));
26 
27  /* Add 1 beat to beat 3 of the first bar */
28  framepos_t r = map.framepos_plus_beats (frames_per_beat * 2, Evoral::Beats(1));
29  CPPUNIT_ASSERT_EQUAL (framepos_t (frames_per_beat * 3), r);
30 
31  /* Add 4 beats to a -ve frame of 1 beat before zero */
32  r = map.framepos_plus_beats (-frames_per_beat * 1, Evoral::Beats(4));
33  CPPUNIT_ASSERT_EQUAL (framepos_t (frames_per_beat * 3), r);
34 }
35 
36 /* Test adding things that overlap a tempo change */
37 void
39 {
40  int const sampling_rate = 48000;
41 
42  TempoMap map (sampling_rate);
43  Meter meter (4, 4);
44  map.add_meter (meter, BBT_Time (1, 1, 0));
45 
46  /*
47  120bpm at bar 1, 240bpm at bar 4
48 
49  120bpm = 24e3 samples per beat
50  240bpm = 12e3 samples per beat
51  */
52 
53 
54  /*
55 
56  120bpm 240bpm
57  0 beats 12 beats
58  0 frames 288e3 frames
59  | | | | |
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 |
61 
62  */
63 
64  Tempo tempoA (120);
65  map.add_tempo (tempoA, BBT_Time (1, 1, 0));
66  Tempo tempoB (240);
67  map.add_tempo (tempoB, BBT_Time (4, 1, 0));
68 
69  /* Now some tests */
70 
71  /* Add 1 beat to 1|2 */
72  framepos_t r = map.framepos_plus_beats (24e3, Evoral::Beats(1));
73  CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
74 
75  /* Add 2 beats to 3|4 (over the tempo change) */
76  r = map.framepos_plus_beats (264e3, Evoral::Beats(2));
77  CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
78 
79  /* Add 2.5 beats to 3|3|960 (over the tempo change) */
80  r = map.framepos_plus_beats (264e3 - 12e3, Evoral::Beats(2.5));
81  CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
82 }
83 
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
86  beats)
87 */
88 
89 void
91 {
92  int const sampling_rate = 48000;
93 
94  TempoMap map (sampling_rate);
95  Meter meterA (4, 4);
96  map.add_meter (meterA, BBT_Time (1, 1, 0));
97 
98  /*
99  120bpm at bar 1, 240bpm at bar 4
100 
101  120bpm = 24e3 samples per beat
102  240bpm = 12e3 samples per beat
103  */
104 
105 
106  /*
107 
108  120bpm 240bpm
109  0 beats 12 beats
110  0 frames 288e3 frames
111  | | | | |
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 |
113 
114  */
115 
116  Tempo tempoA (120);
117  map.add_tempo (tempoA, BBT_Time (1, 1, 0));
118  Tempo tempoB (240);
119  map.add_tempo (tempoB, BBT_Time (4, 1, 0));
120  Meter meterB (3, 4);
121  map.add_meter (meterB, BBT_Time (4, 1, 0));
122 
123  /* Now some tests */
124 
125  /* Add 1 beat to 1|2 */
126  framepos_t r = map.framepos_plus_beats (24e3, Evoral::Beats(1));
127  CPPUNIT_ASSERT_EQUAL (framepos_t (48e3), r);
128 
129  /* Add 2 beats to 3|4 (over the tempo change) */
130  r = map.framepos_plus_beats (264e3, Evoral::Beats(2));
131  CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
132 
133  /* Add 2.5 beats to 3|3|960 (over the tempo change) */
134  r = map.framepos_plus_beats (264e3 - 12e3, Evoral::Beats(2.5));
135  CPPUNIT_ASSERT_EQUAL (framepos_t (264e3 + 24e3 + 12e3), r);
136 }
137 
138 
void add_tempo(const Tempo &, Timecode::BBT_Time where)
Definition: tempo.cc:513
Definition: Beats.hpp:239
CPPUNIT_TEST_SUITE_REGISTRATION(FrameposPlusBeatsTest)
void add_meter(const Meter &, Timecode::BBT_Time where)
Definition: tempo.cc:590
Definition: amp.h:29
framepos_t framepos_plus_beats(framepos_t, Evoral::Beats) const
Definition: tempo.cc:1960
int64_t framepos_t
Definition: types.h:66