Merge branch 'master' into audioengine
[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 <boost/noncopyable.hpp>
22 #include <boost/scoped_ptr.hpp>
23
24 #include "pbd/signals.h"
25
26 #include "ardour/types.h"
27 #include "ardour/session_handle.h"
28
29
30 #ifndef __libardour_ticker_h__
31 #define __libardour_ticker_h__
32
33 namespace ARDOUR {
34
35 class Session;
36 class MidiPort;
37
38 class MidiClockTicker : public SessionHandlePtr, boost::noncopyable
39 {
40 public:
41         MidiClockTicker ();
42         virtual ~MidiClockTicker();
43
44         void tick (const framepos_t& transport_frames, pframes_t nframes);
45
46         bool has_midi_port() const { return _midi_port != 0; }
47
48         void set_session (Session* s);
49         void session_going_away();
50
51         /// slot for the signal session::MIDIClock_PortChanged
52         void update_midi_clock_port();
53
54         /// slot for the signal session::TransportStateChange
55         void transport_state_changed();
56
57         /// slot for the signal session::TransportLooped
58         void transport_looped();
59
60         /// slot for the signal session::Located
61         void session_located();
62
63         /// pulses per quarter note (default 24)
64         void set_ppqn(int ppqn) { _ppqn = ppqn; }
65
66   private:
67     boost::shared_ptr<MidiPort> _midi_port;
68     int        _ppqn;
69     double     _last_tick;
70     bool       _send_pos;
71     bool       _send_state;
72
73     class Position;
74     boost::scoped_ptr<Position> _pos;
75     
76     double one_ppqn_in_frames (framepos_t transport_position);
77
78     void send_midi_clock_event (pframes_t offset, pframes_t nframes);
79     void send_start_event (pframes_t offset, pframes_t nframes);
80     void send_continue_event (pframes_t offset, pframes_t nframes);
81     void send_stop_event (pframes_t offset, pframes_t nframes);
82     void send_position_event (uint32_t midi_clocks, pframes_t offset, pframes_t nframes);
83 };
84 }
85  // namespace 
86
87 #endif /* __libardour_ticker_h__ */