lots of clock tweaks, but still, STILL! not done, really
[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/label.h>
29
30 #include "ardour/ardour.h"
31 #include "ardour/session_handle.h"
32
33 class CairoEditableText;
34 class CairoCell;
35 class CairoTextCell;
36
37 namespace ARDOUR {
38         class Session;
39 }
40
41 class AudioClock : public Gtk::VBox, public ARDOUR::SessionHandlePtr
42 {
43   public:
44         enum Mode {
45                 Timecode,
46                 BBT,
47                 MinSec,
48                 Frames,
49                 Off
50         };
51
52         AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name,
53                     bool editable, bool follows_playhead, bool duration = false, bool with_info = false);
54         ~AudioClock ();
55
56         Mode mode() const { return _mode; }
57
58         void focus ();
59
60         void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0, char which = 0);
61         void set_from_playhead ();
62         void locate ();
63         void set_mode (Mode);
64         void set_bbt_reference (framepos_t);
65         void set_is_duration (bool);
66
67         void set_widget_name (const std::string&);
68
69         std::string name() const { return _name; }
70
71         framepos_t current_time (framepos_t position = 0) const;
72         framepos_t current_duration (framepos_t position = 0) const;
73         void set_session (ARDOUR::Session *s);
74
75         sigc::signal<void> ValueChanged;
76         sigc::signal<void> mode_changed;
77         sigc::signal<void> ChangeAborted;
78
79         static sigc::signal<void> ModeChanged;
80         static std::vector<AudioClock*> clocks;
81
82         static bool has_focus() { return _has_focus; }
83
84         CairoEditableText& main_display () const { return *display; }
85         CairoEditableText* supplemental_left_display () const { return supplemental_left; }
86         CairoEditableText* supplemental_right_display () const { return supplemental_right; }
87
88   private:
89         Mode             _mode;
90         uint32_t          key_entry_state;
91         std::string      _name;
92         bool              is_transient;
93         bool              is_duration;
94         bool              editable;
95         /** true if this clock follows the playhead, meaning that certain operations are redundant */
96         bool             _follows_playhead;
97
98         Gtk::Menu  *ops_menu;
99
100         CairoEditableText* display;
101
102         enum Field {
103                 Timecode_Hours,
104                 Timecode_Minutes,
105                 Timecode_Seconds,
106                 Timecode_Frames,
107                 MS_Hours,
108                 MS_Minutes,
109                 MS_Seconds,
110                 MS_Milliseconds,
111                 Bars,
112                 Beats,
113                 Ticks,
114                 AudioFrames,
115
116                 Colon1,
117                 Colon2,
118                 Colon3,
119                 Bar1,
120                 Bar2,
121
122                 LowerLeft1,
123                 LowerLeft2,
124                 LowerRight1,
125                 LowerRight2,
126         };
127
128         /** CairoCells of various kinds for each of our non-text Fields */
129         std::map<Field,CairoCell*> _fixed_cells;
130         /** CairoTextCells for each of our text Fields */
131         std::map<Field, CairoTextCell*> _text_cells;
132         CairoTextCell* label (Field) const;
133
134         Gtk::HBox      off_hbox;
135         
136         CairoEditableText* supplemental_left;
137         CairoEditableText* supplemental_right;
138
139         Gtk::HBox top;
140         Gtk::HBox bottom;
141
142         Field editing_field;
143         framepos_t bbt_reference_time;
144         framepos_t last_when;
145         bool last_pdelta;
146         bool last_sdelta;
147
148         uint32_t last_hrs;
149         uint32_t last_mins;
150         uint32_t last_secs;
151         uint32_t last_frames;
152         bool last_negative;
153
154         long  ms_last_hrs;
155         long  ms_last_mins;
156         int   ms_last_secs;
157         int   ms_last_millisecs;
158
159         bool dragging;
160         double drag_start_y;
161         double drag_y;
162         double drag_accum;
163
164         /** true if the time of this clock is the one displayed in its widgets.
165          *  if false, the time in the widgets is an approximation of _canonical_time,
166          *  and _canonical_time should be returned as the `current' time of the clock.
167          */
168         bool _canonical_time_is_displayed;
169         framepos_t _canonical_time;
170
171         void on_realize ();
172
173         bool key_press (GdkEventKey *);
174         bool key_release (GdkEventKey *);
175
176         /* proxied from CairoEditableText */
177
178         bool scroll (GdkEventScroll *ev, CairoCell*);
179         bool button_press (GdkEventButton *ev, CairoCell*);
180         bool button_release (GdkEventButton *ev, CairoCell*);
181         sigc::connection scroll_connection;
182         sigc::connection button_press_connection;
183         sigc::connection button_release_connection;
184
185         bool field_motion_notify_event (GdkEventMotion *ev, Field);
186         bool field_focus_in_event (GdkEventFocus *, Field);
187         bool field_focus_out_event (GdkEventFocus *, Field);
188         bool drop_focus_handler (GdkEventFocus*);
189
190         void set_timecode (framepos_t, bool);
191         void set_bbt (framepos_t, bool);
192         void set_minsec (framepos_t, bool);
193         void set_frames (framepos_t, bool);
194
195         framepos_t get_frames (Field, framepos_t pos = 0, int dir = 1);
196
197         void timecode_sanitize_display();
198         framepos_t timecode_frame_from_display () const;
199         framepos_t bbt_frame_from_display (framepos_t) const;
200         framepos_t bbt_frame_duration_from_display (framepos_t) const;
201         framepos_t minsec_frame_from_display () const;
202         framepos_t audio_frame_from_display () const;
203
204         void build_ops_menu ();
205
206         void session_configuration_changed (std::string);
207
208         static uint32_t field_length[];
209         static bool _has_focus;
210
211         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
212         bool on_key_press_event (GdkEventKey*);
213         bool on_key_release_event (GdkEventKey*);
214
215         void end_edit ();
216         void edit_next_field ();
217
218         void connect_signals ();
219         void disconnect_signals ();
220
221         void set_theme ();
222 };
223
224 #endif /* __audio_clock_h__ */