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