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