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__
28 #include <gtkmm/alignment.h>
29 #include <gtkmm/box.h>
30 #include <gtkmm/menu.h>
31 #include <gtkmm/label.h>
33 #include "ardour/ardour.h"
34 #include "ardour/session_handle.h"
36 #include "gtkmm2ext/cairo_widget.h"
42 class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr
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);
56 Mode mode() const { return _mode; }
57 void set_off (bool yn);
58 bool off() const { return _off; }
59 void set_widget_name (const std::string& name);
60 void set_active_state (Gtkmm2ext::ActiveState s);
61 void set_editable (bool yn);
62 void set_corner_radius (double);
63 void set_fixed_width (bool);
67 void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0);
68 void set_from_playhead ();
71 void set_bbt_reference (framepos_t);
72 void set_is_duration (bool);
74 std::string name() const { return _name; }
76 framepos_t current_time (framepos_t position = 0) const;
77 framepos_t current_duration (framepos_t position = 0) const;
78 void set_session (ARDOUR::Session *s);
79 void set_negative_allowed (bool yn);
81 sigc::signal<void> ValueChanged;
82 sigc::signal<void> mode_changed;
83 sigc::signal<void> ChangeAborted;
85 static sigc::signal<void> ModeChanged;
86 static std::vector<AudioClock*> clocks;
89 void render (cairo_t*);
91 virtual void build_ops_menu ();
100 /** true if this clock follows the playhead, meaning that certain operations are redundant */
101 bool _follows_playhead;
106 bool _edit_by_click_field;
107 int _mode_width[4]; /* enum Mode entries */
108 bool _negative_allowed;
109 bool edit_is_negative;
111 Glib::RefPtr<Pango::Layout> _layout;
112 Glib::RefPtr<Pango::Layout> _left_layout;
113 Glib::RefPtr<Pango::Layout> _right_layout;
115 Pango::AttrColor* editing_attr;
116 Pango::AttrColor* foreground_attr;
118 Pango::AttrList normal_attributes;
119 Pango::AttrList editing_attributes;
120 Pango::AttrList info_attributes;
128 double mode_based_info_ratio;
129 double corner_radius;
132 static const double info_font_scale_factor;
133 static const double separator_height;
134 static const double x_leading_padding;
151 Field index_to_field (int index) const;
153 /* this maps the number of input characters/digits when editing
154 to a cursor position. insert_map[N] = index of character/digit
155 where the cursor should be after N chars/digits. it is
156 mode specific and so it is filled during set_mode().
159 std::vector<int> insert_map;
162 std::string edit_string;
163 std::string pre_edit_string;
164 std::string input_string;
166 framepos_t bbt_reference_time;
167 framepos_t last_when;
178 bool on_key_press_event (GdkEventKey *);
179 bool on_key_release_event (GdkEventKey *);
180 bool on_scroll_event (GdkEventScroll *ev);
181 bool on_button_press_event (GdkEventButton *ev);
182 bool on_button_release_event(GdkEventButton *ev);
183 void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
184 void on_size_request (Gtk::Requisition* req);
185 bool on_motion_notify_event (GdkEventMotion *ev);
186 void on_size_allocate (Gtk::Allocation&);
187 bool on_focus_out_event (GdkEventFocus*);
189 void set_slave_info ();
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);
195 framepos_t get_frame_step (Field, framepos_t pos = 0, int dir = 1);
197 bool timecode_validate_edit (const std::string&);
198 bool bbt_validate_edit (const std::string&);
199 bool minsec_validate_edit (const std::string&);
201 framepos_t frames_from_timecode_string (const std::string&) const;
202 framepos_t frames_from_bbt_string (framepos_t, const std::string&) const;
203 framepos_t frame_duration_from_bbt_string (framepos_t, const std::string&) const;
204 framepos_t frames_from_minsec_string (const std::string&) const;
205 framepos_t frames_from_audioframes_string (const std::string&) const;
207 void session_configuration_changed (std::string);
208 void session_property_changed (const PBD::PropertyChange&);
210 Field index_to_field () const;
212 void start_edit (Field f = Field (0));
213 void end_edit (bool);
214 void end_edit_relative (bool);
215 void edit_next_field ();
216 ARDOUR::framecnt_t parse_as_distance (const std::string&);
218 ARDOUR::framecnt_t parse_as_timecode_distance (const std::string&);
219 ARDOUR::framecnt_t parse_as_minsec_distance (const std::string&);
220 ARDOUR::framecnt_t parse_as_bbt_distance (const std::string&);
221 ARDOUR::framecnt_t parse_as_frames_distance (const std::string&);
225 void show_edit_status (int length);
226 int merge_input_and_edit_string ();
227 std::string get_field (Field);
232 double bg_r, bg_g, bg_b, bg_a;
233 double cursor_r, cursor_g, cursor_b, cursor_a;
236 #endif /* __audio_clock_h__ */