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"
37 #include "widgets/ardour_button.h"
43 class AudioClock : public CairoWidget, 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,
56 bool accept_on_focus_out = false);
59 Mode mode() const { return _mode; }
60 void set_off (bool yn);
61 bool off() const { return _off; }
62 bool on() const { return !_off; }
63 void set_widget_name (const std::string& name);
64 void set_active_state (Gtkmm2ext::ActiveState s);
65 void set_editable (bool yn);
66 void set_corner_radius (double);
70 virtual void set (samplepos_t, bool force = false, ARDOUR::samplecnt_t offset = 0);
71 void set_from_playhead ();
73 void set_mode (Mode, bool noemit = false);
74 void set_bbt_reference (samplepos_t);
75 void set_is_duration (bool);
77 void copy_text_to_clipboard () const;
79 std::string name() const { return _name; }
81 samplepos_t current_time (samplepos_t position = 0) const;
82 samplepos_t current_duration (samplepos_t position = 0) const;
83 void set_session (ARDOUR::Session *s);
84 void set_negative_allowed (bool yn);
86 ArdourWidgets::ArdourButton* left_btn () { return &_left_btn; }
87 ArdourWidgets::ArdourButton* right_btn () { return &_right_btn; }
89 /** Alter cairo scaling during rendering.
91 * Used by clocks that resize themselves
92 * to fit any given space. Can lead
95 void set_scale (double x, double y);
97 static void print_minsec (samplepos_t, char* buf, size_t bufsize, float sample_rate);
99 sigc::signal<void> ValueChanged;
100 sigc::signal<void> mode_changed;
101 sigc::signal<void> ChangeAborted;
103 static sigc::signal<void> ModeChanged;
104 static std::vector<AudioClock*> clocks;
107 void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
108 bool get_is_duration () const { return is_duration; }
109 ARDOUR::samplecnt_t offset () const { return _offset; }
111 virtual void build_ops_menu ();
114 bool on_button_press_event (GdkEventButton *ev);
115 bool on_button_release_event(GdkEventButton *ev);
117 ArdourWidgets::ArdourButton _left_btn;
118 ArdourWidgets::ArdourButton _right_btn;
126 /** true if this clock follows the playhead, meaning that certain operations are redundant */
127 bool _follows_playhead;
128 bool _accept_on_focus_out;
131 bool _edit_by_click_field;
132 bool _negative_allowed;
133 bool edit_is_negative;
135 samplepos_t _limit_pos;
137 ARDOUR::samplecnt_t _offset;
139 Glib::RefPtr<Pango::Layout> _layout;
143 Pango::AttrColor* editing_attr;
144 Pango::AttrColor* foreground_attr;
146 Pango::AttrList normal_attributes;
147 Pango::AttrList editing_attributes;
151 bool style_resets_first;
154 double corner_radius;
157 static const double info_font_scale_factor;
158 static const double separator_height;
159 static const double x_leading_padding;
178 Field index_to_field (int index) const;
180 /* this maps the number of input characters/digits when editing
181 to a cursor position. insert_map[N] = index of character/digit
182 where the cursor should be after N chars/digits. it is
183 mode specific and so it is filled during set_mode().
186 std::vector<int> insert_map;
189 std::string edit_string;
190 std::string pre_edit_string;
191 std::string input_string;
193 samplepos_t bbt_reference_time;
194 samplepos_t last_when;
205 bool on_key_press_event (GdkEventKey *);
206 bool on_key_release_event (GdkEventKey *);
207 bool on_scroll_event (GdkEventScroll *ev);
208 void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
209 void on_size_request (Gtk::Requisition* req);
210 bool on_motion_notify_event (GdkEventMotion *ev);
211 bool on_focus_out_event (GdkEventFocus*);
213 void set_slave_info ();
214 void set_timecode (samplepos_t, bool);
215 void set_bbt (samplepos_t, ARDOUR::samplecnt_t, bool);
216 void set_minsec (samplepos_t, bool);
217 void set_seconds (samplepos_t, bool);
218 void set_samples (samplepos_t, bool);
219 void set_out_of_bounds (bool negative);
221 void set_clock_dimensions (Gtk::Requisition&);
223 samplepos_t get_sample_step (Field, samplepos_t pos = 0, int dir = 1);
225 bool timecode_validate_edit (const std::string&);
226 bool bbt_validate_edit (std::string&);
227 bool minsec_validate_edit (const std::string&);
229 samplepos_t samples_from_timecode_string (const std::string&) const;
230 samplepos_t samples_from_bbt_string (samplepos_t, const std::string&) const;
231 samplepos_t sample_duration_from_bbt_string (samplepos_t, const std::string&) const;
232 samplepos_t samples_from_minsec_string (const std::string&) const;
233 samplepos_t samples_from_seconds_string (const std::string&) const;
234 samplepos_t samples_from_audiosamples_string (const std::string&) const;
236 void session_configuration_changed (std::string);
237 void session_property_changed (const PBD::PropertyChange&);
239 Field index_to_field () const;
241 void start_edit (Field f = Field (0));
242 void end_edit (bool);
243 void end_edit_relative (bool);
244 void edit_next_field ();
245 ARDOUR::samplecnt_t parse_as_distance (const std::string&);
247 ARDOUR::samplecnt_t parse_as_timecode_distance (const std::string&);
248 ARDOUR::samplecnt_t parse_as_minsec_distance (const std::string&);
249 ARDOUR::samplecnt_t parse_as_bbt_distance (const std::string&);
250 ARDOUR::samplecnt_t parse_as_seconds_distance (const std::string&);
251 ARDOUR::samplecnt_t parse_as_samples_distance (const std::string&);
253 void set_font (Pango::FontDescription);
255 void show_edit_status (int length);
256 int merge_input_and_edit_string ();
257 std::string get_field (Field);
262 double bg_r, bg_g, bg_b, bg_a;
263 double cursor_r, cursor_g, cursor_b, cursor_a;
269 #endif /* __audio_clock_h__ */