MIDI region forking, plus Playlist::regions_to_read() fix forward ported from 2.X...
[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
22 #include "midi++/jack.h"
23 #include "pbd/signals.h"
24
25 #include "ardour/types.h"
26 #include "ardour/session_handle.h"
27
28
29 #ifndef TICKER_H_
30 #define TICKER_H_
31
32 namespace ARDOUR
33 {
34
35 class Session;
36
37 class Ticker : public SessionHandlePtr
38 {
39 public:
40         Ticker() {};
41         virtual ~Ticker() {}
42
43         virtual void tick(
44                 const nframes_t& transport_frames,
45                 const BBT_Time& transport_bbt,
46                 const Timecode::Time& transport_timecode) = 0;
47
48         void set_session (Session* s);
49 };
50
51 class MidiClockTicker : public Ticker
52 {
53         /// Singleton
54 private:
55         MidiClockTicker() : _midi_port(0), _ppqn(24), _last_tick(0.0) {};
56         MidiClockTicker( const MidiClockTicker& );
57         MidiClockTicker& operator= (const MidiClockTicker&);
58
59 public:
60         virtual ~MidiClockTicker() {};
61
62         static MidiClockTicker& instance() {
63                 static MidiClockTicker _instance;
64                 return _instance;
65         }
66
67         void tick(
68                 const nframes_t& transport_frames,
69                 const BBT_Time& transport_bbt,
70                 const Timecode::Time& transport_timecode);
71
72         void set_session (Session* s);
73         void session_going_away();
74
75         /// slot for the signal session::MIDIClock_PortChanged
76         void update_midi_clock_port();
77
78         /// slot for the signal session::TransportStateChange
79         void transport_state_changed();
80
81         /// slot for the signal session::PositionChanged
82         void position_changed(nframes_t position);
83
84         /// slot for the signal session::TransportLooped
85         void transport_looped();
86
87         /// pulses per quarter note (default 24)
88         void set_ppqn(int ppqn) { _ppqn = ppqn; }
89
90 private:
91         MIDI::Port*  _midi_port;
92         int          _ppqn;
93         double       _last_tick;
94
95         double one_ppqn_in_frames(nframes_t transport_position);
96
97         void send_midi_clock_event(nframes_t offset);
98         void send_start_event(nframes_t offset);
99         void send_continue_event(nframes_t offset);
100         void send_stop_event(nframes_t offset);
101 };
102
103 }
104
105 #endif /* TICKER_H_ */