ardour
framepos_minus_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 using namespace Evoral;
11 
12 /* Basic tests with no tempo / meter changes */
13 void
15 {
16  int const sampling_rate = 48000;
17  int const bpm = 120;
18 
19  double const frames_per_beat = (60 / double (bpm)) * double (sampling_rate);
20 
21  TempoMap map (sampling_rate);
22  Tempo tempo (bpm);
23  Meter meter (4, 4);
24 
25  map.add_meter (meter, BBT_Time (1, 1, 0));
26  map.add_tempo (tempo, BBT_Time (1, 1, 0));
27 
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));
31 
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));
35 }
36 
37 /* Test adding things that overlap a tempo change */
38 void
40 {
41  int const sampling_rate = 48000;
42 
43  TempoMap map (sampling_rate);
44  Meter meter (4, 4);
45  map.add_meter (meter, BBT_Time (1, 1, 0));
46 
47  /*
48  120bpm at bar 1, 240bpm at bar 4
49 
50  120bpm = 24e3 samples per beat
51  240bpm = 12e3 samples per beat
52  */
53 
54 
55  /*
56 
57  120bpm 240bpm
58  0 beats 12 beats
59  0 frames 288e3 frames
60  | | | | |
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 |
62 
63  */
64 
65  Tempo tempoA (120);
66  map.add_tempo (tempoA, BBT_Time (1, 1, 0));
67  Tempo tempoB (240);
68  map.add_tempo (tempoB, BBT_Time (4, 1, 0));
69 
70  /* Now some tests */
71 
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));
75 
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));
79 
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));
83 }
84 
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
87  beats)
88 */
89 
90 void
92 {
93  int const sampling_rate = 48000;
94 
95  TempoMap map (sampling_rate);
96  Meter meterA (4, 4);
97  map.add_meter (meterA, BBT_Time (1, 1, 0));
98 
99  /*
100  120bpm at bar 1, 240bpm at bar 4
101 
102  120bpm = 24e3 samples per beat
103  240bpm = 12e3 samples per beat
104  */
105 
106 
107  /*
108 
109  120bpm 240bpm
110  0 beats 12 beats
111  0 frames 288e3 frames
112  | | | | |
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 |
114 
115  */
116 
117  Tempo tempoA (120);
118  map.add_tempo (tempoA, BBT_Time (1, 1, 0));
119  Tempo tempoB (240);
120  map.add_tempo (tempoB, BBT_Time (4, 1, 0));
121  Meter meterB (3, 4);
122  map.add_meter (meterB, BBT_Time (4, 1, 0));
123 
124  /* Now some tests */
125 
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));
129 
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));
133 
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));
137 }
138 
139 
void add_tempo(const Tempo &, Timecode::BBT_Time where)
Definition: tempo.cc:513
Definition: Beats.hpp:239
framepos_t framepos_minus_beats(framepos_t, Evoral::Beats) const
Definition: tempo.cc:2052
void add_meter(const Meter &, Timecode::BBT_Time where)
Definition: tempo.cc:590
Definition: amp.h:29
int64_t framepos_t
Definition: types.h:66
CPPUNIT_TEST_SUITE_REGISTRATION(FrameposMinusBeatsTest)
LIBEVORAL_API uint64_t Beats