Trim some lines from AudioClock by using maps to keep the EventBoxes and Labels in.
[ardour2.git] / gtk2_ardour / audio_clock.h
blob87cb127dd6a84ee3f9f08ac37e3068c81d033fd6
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>
24 #include <gtkmm/box.h>
25 #include <gtkmm/menu.h>
26 #include <gtkmm/eventbox.h>
27 #include <gtkmm/label.h>
28 #include <gtkmm/frame.h>
29 #include "ardour/ardour.h"
30 #include "ardour/session_handle.h"
32 namespace ARDOUR {
33 class Session;
36 class AudioClock : public Gtk::HBox, public ARDOUR::SessionHandlePtr
38 public:
39 enum Mode {
40 Timecode,
41 BBT,
42 MinSec,
43 Frames,
44 Off
47 AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name,
48 bool editable, bool follows_playhead, bool duration = false, bool with_info = false);
50 Mode mode() const { return _mode; }
52 void focus ();
54 void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0, char which = 0);
55 void set_from_playhead ();
56 void locate ();
57 void set_mode (Mode);
58 void set_bbt_reference (framepos_t);
59 void set_is_duration (bool);
61 void set_widget_name (std::string);
63 std::string name() const { return _name; }
65 framepos_t current_time (framepos_t position = 0) const;
66 framepos_t current_duration (framepos_t position = 0) const;
67 void set_session (ARDOUR::Session *s);
69 sigc::signal<void> ValueChanged;
70 sigc::signal<void> mode_changed;
71 sigc::signal<void> ChangeAborted;
73 static sigc::signal<void> ModeChanged;
74 static std::vector<AudioClock*> clocks;
76 static bool has_focus() { return _has_focus; }
78 private:
79 Mode _mode;
80 uint32_t key_entry_state;
81 std::string _name;
82 bool is_transient;
83 bool is_duration;
84 bool editable;
85 /** true if this clock follows the playhead, meaning that certain operations are redundant */
86 bool _follows_playhead;
88 Gtk::Menu *ops_menu;
90 Gtk::HBox timecode_packer_hbox;
91 Gtk::HBox timecode_packer;
93 Gtk::HBox minsec_packer_hbox;
94 Gtk::HBox minsec_packer;
96 Gtk::HBox bbt_packer_hbox;
97 Gtk::HBox bbt_packer;
99 Gtk::HBox frames_packer_hbox;
100 Gtk::HBox frames_packer;
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
117 /** EventBoxes for each of our Field entries */
118 std::map<Field, Gtk::EventBox*> _eboxes;
119 Gtk::Label const * label (Field) const;
120 /** Labels for each of our Field entries */
121 std::map<Field, Gtk::Label*> _labels;
123 Gtk::HBox off_hbox;
125 Gtk::Label colon1, colon2, colon3;
126 Gtk::Label colon4, colon5;
127 Gtk::Label period1;
128 Gtk::Label b1;
129 Gtk::Label b2;
131 Gtk::Label* frames_upper_info_label;
132 Gtk::Label* frames_lower_info_label;
134 Gtk::Label* timecode_upper_info_label;
135 Gtk::Label* timecode_lower_info_label;
137 Gtk::Label* bbt_upper_info_label;
138 Gtk::Label* bbt_lower_info_label;
140 Gtk::VBox frames_info_box;
141 Gtk::VBox timecode_info_box;
142 Gtk::VBox bbt_info_box;
144 Gtk::EventBox clock_base;
145 Gtk::Frame clock_frame;
147 framepos_t bbt_reference_time;
148 framepos_t last_when;
149 bool last_pdelta;
150 bool last_sdelta;
152 uint32_t last_hrs;
153 uint32_t last_mins;
154 uint32_t last_secs;
155 uint32_t last_frames;
156 bool last_negative;
158 long ms_last_hrs;
159 long ms_last_mins;
160 int ms_last_secs;
161 int ms_last_millisecs;
163 bool dragging;
164 double drag_start_y;
165 double drag_y;
166 double drag_accum;
168 /** true if the time of this clock is the one displayed in its widgets.
169 * if false, the time in the widgets is an approximation of _canonical_time,
170 * and _canonical_time should be returned as the `current' time of the clock.
172 bool _canonical_time_is_displayed;
173 framepos_t _canonical_time;
175 void on_realize ();
177 bool field_motion_notify_event (GdkEventMotion *ev, Field);
178 bool field_button_press_event (GdkEventButton *ev, Field);
179 bool field_button_release_event (GdkEventButton *ev, Field);
180 bool field_button_scroll_event (GdkEventScroll *ev, Field);
181 bool field_key_press_event (GdkEventKey *, Field);
182 bool field_key_release_event (GdkEventKey *, Field);
183 bool field_focus_in_event (GdkEventFocus *, Field);
184 bool field_focus_out_event (GdkEventFocus *, Field);
185 bool drop_focus_handler (GdkEventFocus*);
187 void set_timecode (framepos_t, bool);
188 void set_bbt (framepos_t, bool);
189 void set_minsec (framepos_t, bool);
190 void set_frames (framepos_t, bool);
192 framepos_t get_frames (Field, framepos_t pos = 0, int dir = 1);
194 void timecode_sanitize_display();
195 framepos_t timecode_frame_from_display () const;
196 framepos_t bbt_frame_from_display (framepos_t) const;
197 framepos_t bbt_frame_duration_from_display (framepos_t) const;
198 framepos_t minsec_frame_from_display () const;
199 framepos_t audio_frame_from_display () const;
201 void build_ops_menu ();
202 void setup_events ();
204 void session_configuration_changed (std::string);
205 void set_size_requests ();
207 static const uint32_t field_length[(int)AudioFrames+1];
208 static bool _has_focus;
210 void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
213 #endif /* __audio_clock_h__ */