add plural forms for pt to gtk2_ardour/po/pt.po
[ardour.git] / gtk2_ardour / audio_clock.h
1 /*
2     Copyright (C) 1999 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __audio_clock_h__
21 #define __audio_clock_h__
22
23 #include <map>
24 #include <vector>
25
26 #include <pangomm.h>
27
28 #include <gtkmm/alignment.h>
29 #include <gtkmm/box.h>
30 #include <gtkmm/menu.h>
31 #include <gtkmm/label.h>
32
33 #include "ardour/ardour.h"
34 #include "ardour/session_handle.h"
35
36 #include "gtkmm2ext/cairo_widget.h"
37
38 namespace ARDOUR {
39         class Session;
40 }
41
42 class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr
43 {
44         public:
45         enum Mode {
46                 Timecode,
47                 BBT,
48                 MinSec,
49                 Frames
50         };
51
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,
54                     bool accept_on_focus_out = false);
55         ~AudioClock ();
56
57         Mode mode() const { return _mode; }
58         void set_off (bool yn);
59         bool off() const { return _off; }
60         void set_widget_name (const std::string& name);
61         void set_active_state (Gtkmm2ext::ActiveState s);
62         void set_editable (bool yn);
63         void set_corner_radius (double);
64
65         void focus ();
66
67         void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0);
68         void set_from_playhead ();
69         void locate ();
70         void set_mode (Mode, bool noemit = false);
71         void set_bbt_reference (framepos_t);
72         void set_is_duration (bool);
73
74         void copy_text_to_clipboard () const;
75
76         std::string name() const { return _name; }
77
78         framepos_t current_time (framepos_t position = 0) const;
79         framepos_t current_duration (framepos_t position = 0) const;
80         void set_session (ARDOUR::Session *s);
81         void set_negative_allowed (bool yn);
82
83         /** Alter cairo scaling during rendering.
84          *
85          * Used by clocks that resize themselves
86          * to fit any given space. Can lead
87          * to font distortion.
88          */
89         void set_scale (double x, double y);
90
91         static void print_minsec (framepos_t, char* buf, size_t bufsize, float frame_rate);
92
93         sigc::signal<void> ValueChanged;
94         sigc::signal<void> mode_changed;
95         sigc::signal<void> ChangeAborted;
96
97         static sigc::signal<void> ModeChanged;
98         static std::vector<AudioClock*> clocks;
99
100         protected:
101         void render (cairo_t*, cairo_rectangle_t*);
102         bool get_is_duration () const { return is_duration; } ;
103
104         virtual void build_ops_menu ();
105         Gtk::Menu  *ops_menu;
106
107         bool on_button_press_event (GdkEventButton *ev);
108         bool on_button_release_event(GdkEventButton *ev);
109         bool is_lower_layout_click(int y) const {
110                 return y > upper_height + separator_height;
111         }
112         bool is_right_layout_click(int x) const {
113                 return x > x_leading_padding + get_left_rect_width() + separator_height;
114         }
115         double get_left_rect_width() const {
116                return round (((get_width() - separator_height) * mode_based_info_ratio) + 0.5);
117         }
118         private:
119         Mode             _mode;
120         std::string      _name;
121         bool              is_transient;
122         bool              is_duration;
123         bool              editable;
124         /** true if this clock follows the playhead, meaning that certain operations are redundant */
125         bool             _follows_playhead;
126         bool             _accept_on_focus_out;
127         bool             _off;
128         int              em_width;
129         bool             _edit_by_click_field;
130         bool             _negative_allowed;
131         bool             edit_is_negative;
132
133         Glib::RefPtr<Pango::Layout> _layout;
134         Glib::RefPtr<Pango::Layout> _left_layout;
135         Glib::RefPtr<Pango::Layout> _right_layout;
136
137         Pango::AttrColor*    editing_attr;
138         Pango::AttrColor*    foreground_attr;
139
140         Pango::AttrList normal_attributes;
141         Pango::AttrList editing_attributes;
142         Pango::AttrList info_attributes;
143
144         int first_height;
145         int first_width;
146         bool style_resets_first;
147         int layout_height;
148         int layout_width;
149         int info_height;
150         int upper_height;
151         double mode_based_info_ratio;
152         double corner_radius;
153         uint32_t font_size;
154
155         static const double info_font_scale_factor;
156         static const double separator_height;
157         static const double x_leading_padding;
158
159         enum Field {
160                 Timecode_Hours = 1,
161                 Timecode_Minutes,
162                 Timecode_Seconds,
163                 Timecode_Frames,
164                 MS_Hours,
165                 MS_Minutes,
166                 MS_Seconds,
167                 MS_Milliseconds,
168                 Bars,
169                 Beats,
170                 Ticks,
171                 AudioFrames,
172         };
173
174         Field index_to_field (int index) const;
175
176         /* this maps the number of input characters/digits when editing
177            to a cursor position. insert_map[N] = index of character/digit
178            where the cursor should be after N chars/digits. it is
179            mode specific and so it is filled during set_mode().
180         */
181
182         std::vector<int> insert_map;
183
184         bool editing;
185         std::string edit_string;
186         std::string pre_edit_string;
187         std::string input_string;
188
189         framepos_t bbt_reference_time;
190         framepos_t last_when;
191         bool last_pdelta;
192         bool last_sdelta;
193
194         bool dragging;
195         double drag_start_y;
196         double drag_y;
197         double drag_accum;
198         Field  drag_field;
199
200         void on_realize ();
201         bool on_key_press_event (GdkEventKey *);
202         bool on_key_release_event (GdkEventKey *);
203         bool on_scroll_event (GdkEventScroll *ev);
204         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
205         void on_size_request (Gtk::Requisition* req);
206         bool on_motion_notify_event (GdkEventMotion *ev);
207         void on_size_allocate (Gtk::Allocation&);
208         bool on_focus_out_event (GdkEventFocus*);
209
210         void set_slave_info ();
211         void set_timecode (framepos_t, bool);
212         void set_bbt (framepos_t, bool);
213         void set_minsec (framepos_t, bool);
214         void set_frames (framepos_t, bool);
215
216         void set_clock_dimensions (Gtk::Requisition&);
217
218         framepos_t get_frame_step (Field, framepos_t pos = 0, int dir = 1);
219
220         bool timecode_validate_edit (const std::string&);
221         bool bbt_validate_edit (const std::string&);
222         bool minsec_validate_edit (const std::string&);
223
224         framepos_t frames_from_timecode_string (const std::string&) const;
225         framepos_t frames_from_bbt_string (framepos_t, const std::string&) const;
226         framepos_t frame_duration_from_bbt_string (framepos_t, const std::string&) const;
227         framepos_t frames_from_minsec_string (const std::string&) const;
228         framepos_t frames_from_audioframes_string (const std::string&) const;
229
230         void session_configuration_changed (std::string);
231         void session_property_changed (const PBD::PropertyChange&);
232         void metric_position_changed ();
233
234         Field index_to_field () const;
235
236         void start_edit (Field f = Field (0));
237         void end_edit (bool);
238         void end_edit_relative (bool);
239         void edit_next_field ();
240         ARDOUR::framecnt_t parse_as_distance (const std::string&);
241
242         ARDOUR::framecnt_t parse_as_timecode_distance (const std::string&);
243         ARDOUR::framecnt_t parse_as_minsec_distance (const std::string&);
244         ARDOUR::framecnt_t parse_as_bbt_distance (const std::string&);
245         ARDOUR::framecnt_t parse_as_frames_distance (const std::string&);
246
247         void set_font (Pango::FontDescription);
248         void set_colors ();
249         void show_edit_status (int length);
250         int  merge_input_and_edit_string ();
251         std::string get_field (Field);
252
253         void drop_focus ();
254         void dpi_reset ();
255
256         double bg_r, bg_g, bg_b, bg_a;
257         double cursor_r, cursor_g, cursor_b, cursor_a;
258
259         double xscale;
260         double yscale;
261 };
262
263 #endif /* __audio_clock_h__ */