add extended info fields to clocks; clock tweaks
[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 <map>
24
25 #include <gtkmm/alignment.h>
26 #include <gtkmm/box.h>
27 #include <gtkmm/menu.h>
28 #include <gtkmm/eventbox.h>
29 #include <gtkmm/label.h>
30 #include <gtkmm/frame.h>
31
32 #include "ardour/ardour.h"
33 #include "ardour/session_handle.h"
34
35 class CairoEditableText;
36 class CairoCell;
37 class CairoTextCell;
38
39 namespace ARDOUR {
40         class Session;
41 }
42
43 class AudioClock : public Gtk::Alignment, public ARDOUR::SessionHandlePtr
44 {
45   public:
46         enum Mode {
47                 Timecode,
48                 BBT,
49                 MinSec,
50                 Frames,
51                 Off
52         };
53
54         AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name,
55                     bool editable, bool follows_playhead, bool duration = false, bool with_info = false);
56         ~AudioClock ();
57
58         Mode mode() const { return _mode; }
59
60         void focus ();
61
62         void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0, char which = 0);
63         void set_from_playhead ();
64         void locate ();
65         void set_mode (Mode);
66         void set_bbt_reference (framepos_t);
67         void set_is_duration (bool);
68
69         void set_widget_name (std::string);
70
71         std::string name() const { return _name; }
72
73         framepos_t current_time (framepos_t position = 0) const;
74         framepos_t current_duration (framepos_t position = 0) const;
75         void set_session (ARDOUR::Session *s);
76
77         sigc::signal<void> ValueChanged;
78         sigc::signal<void> mode_changed;
79         sigc::signal<void> ChangeAborted;
80
81         static sigc::signal<void> ModeChanged;
82         static std::vector<AudioClock*> clocks;
83
84         static bool has_focus() { return _has_focus; }
85
86   private:
87         Mode             _mode;
88         uint32_t          key_entry_state;
89         std::string      _name;
90         bool              is_transient;
91         bool              is_duration;
92         bool              editable;
93         /** true if this clock follows the playhead, meaning that certain operations are redundant */
94         bool             _follows_playhead;
95
96         Gtk::Menu  *ops_menu;
97
98         CairoEditableText* timecode;
99         CairoEditableText* minsec;
100         CairoEditableText* bbt;
101         CairoEditableText* frames;
102
103         enum Field {
104                 /* Field IDs must start at 1. Cell ID zero 
105                    is reserved in CairoEditableText
106                 */
107
108                 Timecode_Hours = 1,
109                 Timecode_Colon1,
110                 Timecode_Minutes,
111                 Timecode_Colon2,
112                 Timecode_Seconds,
113                 Timecode_Colon3,
114                 Timecode_Frames,
115                 MS_Hours,
116                 MS_Colon1,
117                 MS_Minutes,
118                 MS_Colon2,
119                 MS_Colon3, // to become a dot cell
120                 MS_Seconds,
121                 MS_Milliseconds,
122                 Bars,
123                 BBT_Bar1,
124                 Beats,
125                 BBT_Bar2,
126                 Ticks,
127                 AudioFrames,
128
129                 Timecode_LowerLeft1,
130                 Timecode_LowerLeft2,
131                 Timecode_LowerRight1,
132                 Timecode_LowerRight2,
133
134                 BBT_LowerLeft1,
135                 BBT_LowerLeft2,
136                 BBT_LowerRight1,
137                 BBT_LowerRight2,
138         };
139
140         /** CairoCells of various kinds for each of our non-text Fields */
141         std::map<Field,CairoCell*> _fixed_cells;
142         /** CairoTextCells for each of our text Fields */
143         std::map<Field, CairoTextCell*> _text_cells;
144         CairoTextCell* label (Field) const;
145
146         Gtk::HBox      off_hbox;
147         
148         CairoEditableText* timecode_supplemental_left;
149         CairoEditableText* timecode_supplemental_right;
150         CairoEditableText* bbt_supplemental_left;
151         CairoEditableText* bbt_supplemental_right;
152
153         Gtk::VBox timecode_packer;
154         Gtk::HBox timecode_top;
155         Gtk::HBox timecode_bottom;
156         Gtk::HBox minsec_packer;
157         Gtk::HBox bbt_top;
158         Gtk::HBox bbt_bottom;
159         Gtk::VBox bbt_packer;
160         Gtk::HBox frames_packer;
161
162         Gtk::Label*  frames_upper_info_label;
163         Gtk::Label*  frames_lower_info_label;
164         Gtk::VBox   frames_info_box;
165
166         CairoEditableText* current_cet;
167         Field editing_field;
168         framepos_t bbt_reference_time;
169         framepos_t last_when;
170         bool last_pdelta;
171         bool last_sdelta;
172
173         uint32_t last_hrs;
174         uint32_t last_mins;
175         uint32_t last_secs;
176         uint32_t last_frames;
177         bool last_negative;
178
179         long  ms_last_hrs;
180         long  ms_last_mins;
181         int   ms_last_secs;
182         int   ms_last_millisecs;
183
184         bool dragging;
185         double drag_start_y;
186         double drag_y;
187         double drag_accum;
188
189         /** true if the time of this clock is the one displayed in its widgets.
190          *  if false, the time in the widgets is an approximation of _canonical_time,
191          *  and _canonical_time should be returned as the `current' time of the clock.
192          */
193         bool _canonical_time_is_displayed;
194         framepos_t _canonical_time;
195
196         void on_realize ();
197
198         bool key_press (GdkEventKey *);
199         bool key_release (GdkEventKey *);
200
201         /* proxied from CairoEditableText */
202
203         bool scroll (GdkEventScroll *ev, uint32_t);
204         bool button_press (GdkEventButton *ev, uint32_t);
205         bool button_release (GdkEventButton *ev, uint32_t);
206         sigc::connection scroll_connection;
207         sigc::connection button_press_connection;
208         sigc::connection button_release_connection;
209
210         bool field_motion_notify_event (GdkEventMotion *ev, Field);
211         bool field_focus_in_event (GdkEventFocus *, Field);
212         bool field_focus_out_event (GdkEventFocus *, Field);
213         bool drop_focus_handler (GdkEventFocus*);
214
215         void set_timecode (framepos_t, bool);
216         void set_bbt (framepos_t, bool);
217         void set_minsec (framepos_t, bool);
218         void set_frames (framepos_t, bool);
219
220         framepos_t get_frames (Field, framepos_t pos = 0, int dir = 1);
221
222         void timecode_sanitize_display();
223         framepos_t timecode_frame_from_display () const;
224         framepos_t bbt_frame_from_display (framepos_t) const;
225         framepos_t bbt_frame_duration_from_display (framepos_t) const;
226         framepos_t minsec_frame_from_display () const;
227         framepos_t audio_frame_from_display () const;
228
229         void build_ops_menu ();
230
231         void session_configuration_changed (std::string);
232
233         static std::map<AudioClock::Field,uint32_t> field_length;
234         static void fill_field_lengths();
235         static bool _has_focus;
236
237         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
238         bool on_key_press_event (GdkEventKey*);
239         bool on_key_release_event (GdkEventKey*);
240
241         void end_edit ();
242         void edit_next_field ();
243
244         void connect_signals ();
245         void disconnect_signals ();
246
247         void set_theme ();
248 };
249
250 #endif /* __audio_clock_h__ */