Merge branch 'windows+cc' into cairocanvas
[ardour.git] / libs / ardour / test / midi_clock_slave_test.h
1 /* 
2  * Copyright(C) 2000-2008 Paul Davis
3  * Author: Hans Baier
4  * 
5  * Evoral is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 2 of the License, or(at your option) any later
8  * version.
9  * 
10  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
13  * 
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include <cassert>
20 #include <stdint.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23
24 #include "ardour/tempo.h"
25 #include "ardour/slave.h"
26
27 namespace ARDOUR {
28
29 class TestSlaveSessionProxy : public ISlaveSessionProxy {
30   #define FRAME_RATE 44100
31   framecnt_t _period_size;
32
33   double       transport_speed;
34   framepos_t _transport_frame;
35   framepos_t _frame_time;
36   TempoMap    *_tempo_map;
37
38   Tempo     tempo;
39   Meter     meter;
40
41   public:
42         TestSlaveSessionProxy() : 
43            transport_speed  (1.0), 
44           _transport_frame  (0), 
45           _frame_time       (1000000),
46           _tempo_map        (0),
47           tempo             (120),
48           meter             (4.0, 4.0)
49         {
50           _tempo_map = new TempoMap (FRAME_RATE);
51           _tempo_map->add_tempo (tempo, Timecode::BBT_Time(1, 1, 0));
52           _tempo_map->add_meter (meter, Timecode::BBT_Time(1, 1, 0));          
53         }
54
55         // Controlling the mock object
56         void        set_period_size (framecnt_t a_size) { _period_size = a_size; }
57         framecnt_t period_size () const                 { return _period_size; }
58         void next_period ()                       { 
59           _transport_frame += double(_period_size) * double(transport_speed); 
60           _frame_time += _period_size;
61         }
62
63         // Implementation
64         TempoMap&  tempo_map ()                const { return *_tempo_map; }
65         framecnt_t frame_rate ()               const { return FRAME_RATE; }
66         framepos_t audible_frame ()            const { return _transport_frame; }
67         framepos_t transport_frame ()          const { return _transport_frame; }
68         pframes_t  frames_since_cycle_start () const { return 0; }
69         framepos_t frame_time ()               const { return _frame_time; }
70
71         void request_locate (framepos_t frame, bool with_roll = false) { 
72           _transport_frame = frame; 
73         }
74
75         void request_transport_speed (const double speed) { transport_speed = speed; }
76 };
77
78 class MIDIClock_SlaveTest : public CppUnit::TestFixture, ARDOUR::MIDIClock_Slave
79 {
80     CPPUNIT_TEST_SUITE(MIDIClock_SlaveTest);
81     CPPUNIT_TEST(testStepResponse);
82     CPPUNIT_TEST_SUITE_END();
83
84     public:
85         MIDIClock_SlaveTest () : MIDIClock_Slave (new TestSlaveSessionProxy) {}
86         
87         void setUp() {
88         }
89         
90         void tearDown() {
91         }
92
93         void testStepResponse();
94 };
95
96 } // namespace ARDOUR