* sending MIDI clock works, hooray\!
[ardour.git] / libs / ardour / ardour / ticker.h
1 /*
2     Copyright (C) 2008 Hans Baier 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <sigc++/sigc++.h>
22
23 #include "ardour/types.h"
24 #include "midi++/jack.h"
25
26 #ifndef TICKER_H_
27 #define TICKER_H_
28
29 namespace ARDOUR
30 {
31
32 class Session;
33
34 class Ticker : public sigc::trackable
35 {
36 public:
37         Ticker() : _session(0) {};
38         virtual ~Ticker() {};
39         
40         virtual void tick(
41                 const nframes_t& transport_frames, 
42                 const BBT_Time& transport_bbt, 
43                 const SMPTE::Time& transport_smpte) = 0;
44         
45         virtual void set_session(Session& s);
46         virtual void going_away() { _session = 0;  delete this; }
47
48 protected:
49         Session* _session;
50 };
51
52 class MidiClockTicker : public Ticker
53 {
54 public:
55         MidiClockTicker() : _jack_port(0), _ppqn(24), _last_tick(0.0) {};
56         virtual ~MidiClockTicker() {};
57         
58         void tick(
59                 const nframes_t& transport_frames, 
60                 const BBT_Time& transport_bbt, 
61                 const SMPTE::Time& transport_smpte);
62         
63         void set_session(Session& s);
64         void going_away() { Ticker::going_away(); _jack_port = 0;}
65         
66         /// slot for the signal session::MIDIClock_PortChanged
67         void update_midi_clock_port();
68         
69         /// slot for the signal session::TransportStateChange
70         void transport_state_changed();
71         
72         /// slot for the signal session::PositionChanged
73         void position_changed(nframes_t position);
74
75         /// slot for the signal session::TransportLooped
76         void transport_looped();
77         
78         /// pulses per quarter note (default 24)
79         void set_ppqn(int ppqn) { _ppqn = ppqn; }
80
81 private:        
82         MIDI::JACK_MidiPort* _jack_port;
83         int                  _ppqn;
84         double               _last_tick;
85         
86         void send_midi_clock_event(nframes_t offset);
87         void send_start_event(nframes_t offset);
88         void send_continue_event(nframes_t offset);
89         void send_stop_event(nframes_t offset);
90 };
91
92 }
93
94 #endif /* TICKER_H_ */