summaryrefslogtreecommitdiff
path: root/libs/ardour/test/tempo_test.cc
blob: 25fbc32a5ad37f4ba0cd51b97fca54b289fd72ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "ardour/tempo.h"
#include "tempo_test.h"

CPPUNIT_TEST_SUITE_REGISTRATION (TempoTest);

using namespace std;
using namespace ARDOUR;
using namespace Timecode;

void
TempoTest::recomputeMapTest ()
{
	int const sampling_rate = 48000;

	TempoMap map (sampling_rate);
	Meter meterA (4, 4);
	map.add_meter (meterA, BBT_Time (1, 1, 0));

	/*
	  120bpm at bar 1, 240bpm at bar 4
	  
	  120bpm = 24e3 samples per beat
	  240bpm = 12e3 samples per beat
	*/
	

	/*
	  
	  120bpm                                                240bpm
	  0 beats                                               12 beats
	  0 frames                                              288e3 frames
	  |                 |                 |                 |             |
	  | 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 |

	*/

	Tempo tempoA (120);
	map.add_tempo (tempoA, BBT_Time (1, 1, 0));
	Tempo tempoB (240);
	map.add_tempo (tempoB, BBT_Time (4, 1, 0));
	Meter meterB (3, 4);
	map.add_meter (meterB, BBT_Time (4, 1, 0));

	cout << "\n\n\n";
	for (list<MetricSection*>::iterator i = map.metrics->begin(); i != map.metrics->end(); ++i) {
		if (dynamic_cast<TempoSection*> (*i)) {
			cout << "\tTempo MS @ " << (*i)->start() << " " << (*i)->frame() << "\n";
		} else {
			cout << "\tMeter MS @ " << (*i)->start() << " " << (*i)->frame() << "\n";
		}
	}
	
	list<MetricSection*>::iterator i = map.metrics->begin();
	CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());
	CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());

	i = map.metrics->end();
	--i;
	CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), (*i)->frame ());
	CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), (*i)->frame ());
}