Separate milliseconds from seconds in the clock widget (#4053).
[ardour.git] / gtk2_ardour / audio_clock.h
1 /*
2     Copyright (C) 1999 Paul Davis
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 */
19
20 #ifndef __audio_clock_h__
21 #define __audio_clock_h__
22
23 #include <gtkmm/box.h>
24 #include <gtkmm/menu.h>
25 #include <gtkmm/eventbox.h>
26 #include <gtkmm/label.h>
27 #include <gtkmm/frame.h>
28 #include "ardour/ardour.h"
29 #include "ardour/session_handle.h"
30
31 namespace ARDOUR {
32         class Session;
33 }
34
35 class AudioClock : public Gtk::HBox, public ARDOUR::SessionHandlePtr
36 {
37   public:
38         enum Mode {
39                 Timecode,
40                 BBT,
41                 MinSec,
42                 Frames,
43                 Off
44         };
45
46         AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name, 
47                     bool editable, bool follows_playhead, bool duration = false, bool with_info = false);
48
49         Mode mode() const { return _mode; }
50
51         void focus ();
52
53         void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0, char which = 0);
54         void set_from_playhead ();
55         void locate ();
56         void set_mode (Mode);
57         void set_bbt_reference (framepos_t);
58         void set_is_duration (bool);
59
60         void set_widget_name (std::string);
61
62         std::string name() const { return _name; }
63
64         framepos_t current_time (framepos_t position = 0) const;
65         framepos_t current_duration (framepos_t position = 0) const;
66         void set_session (ARDOUR::Session *s);
67
68         sigc::signal<void> ValueChanged;
69         sigc::signal<void> mode_changed;
70         sigc::signal<void> ChangeAborted;
71
72         static sigc::signal<void> ModeChanged;
73         static std::vector<AudioClock*> clocks;
74
75         static bool has_focus() { return _has_focus; }
76
77   private:
78         Mode             _mode;
79         uint32_t          key_entry_state;
80         std::string      _name;
81         bool              is_transient;
82         bool              is_duration;
83         bool              editable;
84         /** true if this clock follows the playhead, meaning that certain operations are redundant */
85         bool             _follows_playhead;
86
87         Gtk::Menu  *ops_menu;
88
89         Gtk::HBox   timecode_packer_hbox;
90         Gtk::HBox   timecode_packer;
91
92         Gtk::HBox   minsec_packer_hbox;
93         Gtk::HBox   minsec_packer;
94
95         Gtk::HBox   bbt_packer_hbox;
96         Gtk::HBox   bbt_packer;
97
98         Gtk::HBox   frames_packer_hbox;
99         Gtk::HBox   frames_packer;
100
101         enum Field {
102                 Timecode_Hours,
103                 Timecode_Minutes,
104                 Timecode_Seconds,
105                 Timecode_Frames,
106                 MS_Hours,
107                 MS_Minutes,
108                 MS_Seconds,
109                 MS_Milliseconds,
110                 Bars,
111                 Beats,
112                 Ticks,
113                 AudioFrames
114         };
115
116         Gtk::EventBox  audio_frames_ebox;
117         Gtk::Label     audio_frames_label;
118
119         Gtk::HBox      off_hbox;
120
121         Gtk::EventBox  hours_ebox;
122         Gtk::EventBox  minutes_ebox;
123         Gtk::EventBox  seconds_ebox;
124         Gtk::EventBox  frames_ebox;
125
126         Gtk::EventBox  ms_hours_ebox;
127         Gtk::EventBox  ms_minutes_ebox;
128         Gtk::EventBox  ms_seconds_ebox;
129         Gtk::EventBox  ms_milliseconds_ebox;
130
131         Gtk::EventBox  bars_ebox;
132         Gtk::EventBox  beats_ebox;
133         Gtk::EventBox  ticks_ebox;
134
135         Gtk::Label  hours_label;
136         Gtk::Label  minutes_label;
137         Gtk::Label  seconds_label;
138         Gtk::Label  frames_label;
139         Gtk::Label  colon1, colon2, colon3;
140
141         Gtk::Label  ms_hours_label;
142         Gtk::Label  ms_minutes_label;
143         Gtk::Label  ms_seconds_label;
144         Gtk::Label  ms_milliseconds_label;
145         Gtk::Label  colon4, colon5;
146         Gtk::Label  period1;
147
148         Gtk::Label  bars_label;
149         Gtk::Label  beats_label;
150         Gtk::Label  ticks_label;
151         Gtk::Label  b1;
152         Gtk::Label  b2;
153
154         Gtk::Label*  frames_upper_info_label;
155         Gtk::Label*  frames_lower_info_label;
156
157         Gtk::Label*  timecode_upper_info_label;
158         Gtk::Label*  timecode_lower_info_label;
159
160         Gtk::Label*  bbt_upper_info_label;
161         Gtk::Label*  bbt_lower_info_label;
162
163         Gtk::VBox   frames_info_box;
164         Gtk::VBox   timecode_info_box;
165         Gtk::VBox   bbt_info_box;
166
167         Gtk::EventBox  clock_base;
168         Gtk::Frame     clock_frame;
169
170         framepos_t bbt_reference_time;
171         framepos_t last_when;
172         bool last_pdelta;
173         bool last_sdelta;
174
175         uint32_t last_hrs;
176         uint32_t last_mins;
177         uint32_t last_secs;
178         uint32_t last_frames;
179         bool last_negative;
180
181         long  ms_last_hrs;
182         long  ms_last_mins;
183         int   ms_last_secs;
184         int   ms_last_millisecs;
185
186         bool dragging;
187         double drag_start_y;
188         double drag_y;
189         double drag_accum;
190
191         /** true if the time of this clock is the one displayed in its widgets.
192          *  if false, the time in the widgets is an approximation of _canonical_time,
193          *  and _canonical_time should be returned as the `current' time of the clock.
194          */
195         bool _canonical_time_is_displayed;
196         framepos_t _canonical_time;
197
198         void on_realize ();
199
200         bool field_motion_notify_event (GdkEventMotion *ev, Field);
201         bool field_button_press_event (GdkEventButton *ev, Field);
202         bool field_button_release_event (GdkEventButton *ev, Field);
203         bool field_button_scroll_event (GdkEventScroll *ev, Field);
204         bool field_key_press_event (GdkEventKey *, Field);
205         bool field_key_release_event (GdkEventKey *, Field);
206         bool field_focus_in_event (GdkEventFocus *, Field);
207         bool field_focus_out_event (GdkEventFocus *, Field);
208         bool drop_focus_handler (GdkEventFocus*);
209
210         void set_timecode (framepos_t, bool);
211         void set_bbt (framepos_t, bool);
212         void set_minsec (framepos_t, bool);
213         void set_frames (framepos_t, bool);
214
215         framepos_t get_frames (Field, framepos_t pos = 0, int dir = 1);
216
217         void timecode_sanitize_display();
218         framepos_t timecode_frame_from_display () const;
219         framepos_t bbt_frame_from_display (framepos_t) const;
220         framepos_t bbt_frame_duration_from_display (framepos_t) const;
221         framepos_t minsec_frame_from_display () const;
222         framepos_t audio_frame_from_display () const;
223
224         void build_ops_menu ();
225         void setup_events ();
226
227         void session_configuration_changed (std::string);
228         void set_size_requests ();
229
230         static const uint32_t field_length[(int)AudioFrames+1];
231         static bool _has_focus;
232
233         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
234 };
235
236 #endif /* __audio_clock_h__ */