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__
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>
32 #include "ardour/ardour.h"
33 #include "ardour/session_handle.h"
35 class CairoEditableText;
43 class AudioClock : public Gtk::Alignment, public ARDOUR::SessionHandlePtr
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);
58 Mode mode() const { return _mode; }
62 void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0, char which = 0);
63 void set_from_playhead ();
66 void set_bbt_reference (framepos_t);
67 void set_is_duration (bool);
69 void set_widget_name (std::string);
71 std::string name() const { return _name; }
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);
77 sigc::signal<void> ValueChanged;
78 sigc::signal<void> mode_changed;
79 sigc::signal<void> ChangeAborted;
81 static sigc::signal<void> ModeChanged;
82 static std::vector<AudioClock*> clocks;
84 static bool has_focus() { return _has_focus; }
88 uint32_t key_entry_state;
93 /** true if this clock follows the playhead, meaning that certain operations are redundant */
94 bool _follows_playhead;
98 CairoEditableText* timecode;
99 CairoEditableText* minsec;
100 CairoEditableText* bbt;
101 CairoEditableText* frames;
104 /* Field IDs must start at 1. Cell ID zero
105 is reserved in CairoEditableText
119 MS_Colon3, // to become a dot cell
130 /** CairoCells of various kinds for each of our non-text Fields */
131 std::map<Field,CairoCell*> _fixed_cells;
132 /** CairoTextCells for each of our text Fields */
133 std::map<Field, CairoTextCell*> _text_cells;
134 CairoTextCell* label (Field) const;
138 Gtk::HBox timecode_packer;
139 Gtk::HBox minsec_packer;
140 Gtk::HBox bbt_packer;
141 Gtk::HBox frames_packer;
143 Gtk::Label* frames_upper_info_label;
144 Gtk::Label* frames_lower_info_label;
146 Gtk::Label* timecode_upper_info_label;
147 Gtk::Label* timecode_lower_info_label;
149 Gtk::Label* bbt_upper_info_label;
150 Gtk::Label* bbt_lower_info_label;
152 Gtk::VBox frames_info_box;
153 Gtk::VBox timecode_info_box;
154 Gtk::VBox bbt_info_box;
156 CairoEditableText* current_cet;
158 framepos_t bbt_reference_time;
159 framepos_t last_when;
166 uint32_t last_frames;
172 int ms_last_millisecs;
179 /** true if the time of this clock is the one displayed in its widgets.
180 * if false, the time in the widgets is an approximation of _canonical_time,
181 * and _canonical_time should be returned as the `current' time of the clock.
183 bool _canonical_time_is_displayed;
184 framepos_t _canonical_time;
188 bool key_press (GdkEventKey *);
189 bool key_release (GdkEventKey *);
191 /* proxied from CairoEditableText */
193 bool scroll (GdkEventScroll *ev, uint32_t);
194 bool button_press (GdkEventButton *ev, uint32_t);
195 bool button_release (GdkEventButton *ev, uint32_t);
196 sigc::connection scroll_connection;
197 sigc::connection button_press_connection;
198 sigc::connection button_release_connection;
200 bool field_motion_notify_event (GdkEventMotion *ev, Field);
201 bool field_focus_in_event (GdkEventFocus *, Field);
202 bool field_focus_out_event (GdkEventFocus *, Field);
203 bool drop_focus_handler (GdkEventFocus*);
205 void set_timecode (framepos_t, bool);
206 void set_bbt (framepos_t, bool);
207 void set_minsec (framepos_t, bool);
208 void set_frames (framepos_t, bool);
210 framepos_t get_frames (Field, framepos_t pos = 0, int dir = 1);
212 void timecode_sanitize_display();
213 framepos_t timecode_frame_from_display () const;
214 framepos_t bbt_frame_from_display (framepos_t) const;
215 framepos_t bbt_frame_duration_from_display (framepos_t) const;
216 framepos_t minsec_frame_from_display () const;
217 framepos_t audio_frame_from_display () const;
219 void build_ops_menu ();
221 void session_configuration_changed (std::string);
223 static std::map<AudioClock::Field,uint32_t> field_length;
224 static void fill_field_lengths();
225 static bool _has_focus;
227 void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
228 bool on_key_press_event (GdkEventKey*);
229 bool on_key_release_event (GdkEventKey*);
232 void edit_next_field ();
234 void connect_signals ();
235 void disconnect_signals ();
240 #endif /* __audio_clock_h__ */