ardour
audio_clock.h
Go to the documentation of this file.
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 
43 {
44  public:
45  enum Mode {
47  BBT,
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  ~AudioClock ();
55 
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 
64  void focus ();
65 
66  void set (framepos_t, bool force = false, ARDOUR::framecnt_t offset = 0);
67  void set_from_playhead ();
68  void locate ();
69  void set_mode (Mode);
71  void set_is_duration (bool);
72 
73  void copy_text_to_clipboard () const;
74 
75  std::string name() const { return _name; }
76 
79  void set_session (ARDOUR::Session *s);
80  void set_negative_allowed (bool yn);
81 
88  void set_scale (double x, double y);
89 
90  static void print_minsec (framepos_t, char* buf, size_t bufsize, float frame_rate);
91 
92  sigc::signal<void> ValueChanged;
93  sigc::signal<void> mode_changed;
94  sigc::signal<void> ChangeAborted;
95 
96  static sigc::signal<void> ModeChanged;
97  static std::vector<AudioClock*> clocks;
98 
99  protected:
100  void render (cairo_t*, cairo_rectangle_t*);
101  bool get_is_duration () const { return is_duration; } ;
102 
103  virtual void build_ops_menu ();
104  Gtk::Menu *ops_menu;
105 
106  bool on_button_press_event (GdkEventButton *ev);
107  bool on_button_release_event(GdkEventButton *ev);
108  bool is_lower_layout_click(int y) const {
109  return y > upper_height + separator_height;
110  }
111  bool is_right_layout_click(int x) const {
113  }
114  double get_left_rect_width() const {
115  return round (((get_width() - separator_height) * mode_based_info_ratio) + 0.5);
116  }
117  private:
119  std::string _name;
122  bool editable;
125  bool _off;
126  int em_width;
130 
131  Glib::RefPtr<Pango::Layout> _layout;
132  Glib::RefPtr<Pango::Layout> _left_layout;
133  Glib::RefPtr<Pango::Layout> _right_layout;
134 
135  Pango::AttrColor* editing_attr;
136  Pango::AttrColor* foreground_attr;
137 
138  Pango::AttrList normal_attributes;
139  Pango::AttrList editing_attributes;
140  Pango::AttrList info_attributes;
141 
151  uint32_t font_size;
152 
153  static const double info_font_scale_factor;
154  static const double separator_height;
155  static const double x_leading_padding;
156 
157  enum Field {
170  };
171 
172  Field index_to_field (int index) const;
173 
174  /* this maps the number of input characters/digits when editing
175  to a cursor position. insert_map[N] = index of character/digit
176  where the cursor should be after N chars/digits. it is
177  mode specific and so it is filled during set_mode().
178  */
179 
180  std::vector<int> insert_map;
181 
182  bool editing;
183  std::string edit_string;
184  std::string pre_edit_string;
185  std::string input_string;
186 
191 
192  bool dragging;
193  double drag_start_y;
194  double drag_y;
195  double drag_accum;
197 
198  void on_realize ();
199  bool on_key_press_event (GdkEventKey *);
200  bool on_key_release_event (GdkEventKey *);
201  bool on_scroll_event (GdkEventScroll *ev);
202  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
203  void on_size_request (Gtk::Requisition* req);
204  bool on_motion_notify_event (GdkEventMotion *ev);
205  void on_size_allocate (Gtk::Allocation&);
206  bool on_focus_out_event (GdkEventFocus*);
207 
208  void set_slave_info ();
209  void set_timecode (framepos_t, bool);
210  void set_bbt (framepos_t, bool);
211  void set_minsec (framepos_t, bool);
212  void set_frames (framepos_t, bool);
213 
214  void set_clock_dimensions (Gtk::Requisition&);
215 
216  framepos_t get_frame_step (Field, framepos_t pos = 0, int dir = 1);
217 
218  bool timecode_validate_edit (const std::string&);
219  bool bbt_validate_edit (const std::string&);
220  bool minsec_validate_edit (const std::string&);
221 
222  framepos_t frames_from_timecode_string (const std::string&) const;
223  framepos_t frames_from_bbt_string (framepos_t, const std::string&) const;
224  framepos_t frame_duration_from_bbt_string (framepos_t, const std::string&) const;
225  framepos_t frames_from_minsec_string (const std::string&) const;
226  framepos_t frames_from_audioframes_string (const std::string&) const;
227 
228  void session_configuration_changed (std::string);
230 
231  Field index_to_field () const;
232 
233  void start_edit (Field f = Field (0));
234  void end_edit (bool);
235  void end_edit_relative (bool);
236  void edit_next_field ();
237  ARDOUR::framecnt_t parse_as_distance (const std::string&);
238 
239  ARDOUR::framecnt_t parse_as_timecode_distance (const std::string&);
240  ARDOUR::framecnt_t parse_as_minsec_distance (const std::string&);
241  ARDOUR::framecnt_t parse_as_bbt_distance (const std::string&);
242  ARDOUR::framecnt_t parse_as_frames_distance (const std::string&);
243 
244  void set_font (Pango::FontDescription);
245  void set_colors ();
246  void show_edit_status (int length);
248  std::string get_field (Field);
249 
250  void drop_focus ();
251  void dpi_reset ();
252 
253  double bg_r, bg_g, bg_b, bg_a;
255 
256  double xscale;
257  double yscale;
258 };
259 
260 #endif /* __audio_clock_h__ */
double bg_b
Definition: audio_clock.h:253
void end_edit_relative(bool)
Definition: audio_clock.cc:858
void set_clock_dimensions(Gtk::Requisition &)
Definition: audio_clock.cc:456
double corner_radius
Definition: audio_clock.h:150
bool on_button_release_event(GdkEventButton *ev)
framepos_t current_time(framepos_t position=0) const
Glib::RefPtr< Pango::Layout > _layout
Definition: audio_clock.h:131
int first_width
Definition: audio_clock.h:143
void session_property_changed(const PBD::PropertyChange &)
Definition: audio_clock.cc:917
std::string name() const
Definition: audio_clock.h:75
void dpi_reset()
framepos_t frame_duration_from_bbt_string(framepos_t, const std::string &) const
void set(framepos_t, bool force=false, ARDOUR::framecnt_t offset=0)
Definition: audio_clock.cc:956
void end_edit(bool)
Definition: audio_clock.cc:623
bool _follows_playhead
Definition: audio_clock.h:124
std::string _name
Definition: audio_clock.h:119
void set_session(ARDOUR::Session *s)
void copy_text_to_clipboard() const
void drop_focus()
Definition: audio_clock.cc:703
double yscale
Definition: audio_clock.h:257
framepos_t frames_from_timecode_string(const std::string &) const
AudioClock(const std::string &clock_name, bool is_transient, const std::string &widget_name, bool editable, bool follows_playhead, bool duration=false, bool with_info=false)
Definition: audio_clock.cc:67
framepos_t frames_from_bbt_string(framepos_t, const std::string &) const
double drag_start_y
Definition: audio_clock.h:193
Pango::AttrColor * editing_attr
Definition: audio_clock.h:135
static std::vector< AudioClock * > clocks
Definition: audio_clock.h:97
void locate()
Pango::AttrList info_attributes
Definition: audio_clock.h:140
ARDOUR::framecnt_t parse_as_bbt_distance(const std::string &)
Definition: audio_clock.cc:832
double get_left_rect_width() const
Definition: audio_clock.h:114
std::string input_string
Definition: audio_clock.h:185
Pango::AttrList editing_attributes
Definition: audio_clock.h:139
sigc::signal< void > mode_changed
Definition: audio_clock.h:93
Pango::AttrList normal_attributes
Definition: audio_clock.h:138
ARDOUR::framecnt_t parse_as_timecode_distance(const std::string &)
Definition: audio_clock.cc:783
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
void on_realize()
Definition: audio_clock.cc:148
tuple f
Definition: signals.py:35
double bg_r
Definition: audio_clock.h:253
bool is_duration
Definition: audio_clock.h:121
std::string pre_edit_string
Definition: audio_clock.h:184
void on_size_request(Gtk::Requisition *req)
Definition: audio_clock.cc:481
double mode_based_info_ratio
Definition: audio_clock.h:149
bool is_right_layout_click(int x) const
Definition: audio_clock.h:111
virtual void build_ops_menu()
void set_scale(double x, double y)
Definition: audio_clock.cc:284
std::string get_field(Field)
Definition: audio_clock.cc:579
Field index_to_field() const
bool on_motion_notify_event(GdkEventMotion *ev)
int layout_width
Definition: audio_clock.h:146
double drag_accum
Definition: audio_clock.h:195
bool on_key_press_event(GdkEventKey *)
Glib::RefPtr< Pango::Layout > _right_layout
Definition: audio_clock.h:133
bool _edit_by_click_field
Definition: audio_clock.h:127
int layout_height
Definition: audio_clock.h:145
bool last_pdelta
Definition: audio_clock.h:189
bool off() const
Definition: audio_clock.h:58
void start_edit(Field f=Field(0))
Definition: audio_clock.cc:550
bool dragging
Definition: audio_clock.h:192
bool edit_is_negative
Definition: audio_clock.h:129
void on_size_allocate(Gtk::Allocation &)
Definition: audio_clock.cc:444
double cursor_b
Definition: audio_clock.h:254
void set_slave_info()
void set_widget_name(const std::string &name)
Definition: audio_clock.cc:133
double cursor_r
Definition: audio_clock.h:254
void set_colors()
Definition: audio_clock.cc:212
framepos_t get_frame_step(Field, framepos_t pos=0, int dir=1)
int64_t framecnt_t
Definition: types.h:76
static const double separator_height
Definition: audio_clock.h:154
Mode mode() const
Definition: audio_clock.h:56
std::string edit_string
Definition: audio_clock.h:183
bool style_resets_first
Definition: audio_clock.h:144
void session_configuration_changed(std::string)
Definition: audio_clock.cc:923
static const double x_leading_padding
Definition: audio_clock.h:155
void set_bbt(framepos_t, bool)
Definition: amp.h:29
framepos_t bbt_reference_time
Definition: audio_clock.h:187
bool is_lower_layout_click(int y) const
Definition: audio_clock.h:108
int first_height
Definition: audio_clock.h:142
void set_frames(framepos_t, bool)
ARDOUR::framecnt_t parse_as_frames_distance(const std::string &)
Definition: audio_clock.cc:721
bool minsec_validate_edit(const std::string &)
std::vector< int > insert_map
Definition: audio_clock.h:180
Field drag_field
Definition: audio_clock.h:196
bool editing
Definition: audio_clock.h:182
bool on_focus_out_event(GdkEventFocus *)
void set_mode(Mode)
ARDOUR::framecnt_t parse_as_minsec_distance(const std::string &)
Definition: audio_clock.cc:733
sigc::signal< void > ValueChanged
Definition: audio_clock.h:92
bool _negative_allowed
Definition: audio_clock.h:128
bool is_transient
Definition: audio_clock.h:120
int info_height
Definition: audio_clock.h:147
void focus()
double cursor_g
Definition: audio_clock.h:254
static sigc::signal< void > ModeChanged
Definition: audio_clock.h:96
void set_corner_radius(double)
void set_off(bool yn)
bool last_sdelta
Definition: audio_clock.h:190
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
double drag_y
Definition: audio_clock.h:194
void set_bbt_reference(framepos_t)
bool timecode_validate_edit(const std::string &)
Glib::RefPtr< Pango::Layout > _left_layout
Definition: audio_clock.h:132
Pango::AttrColor * foreground_attr
Definition: audio_clock.h:136
uint32_t font_size
Definition: audio_clock.h:151
static const double info_font_scale_factor
Definition: audio_clock.h:153
Gtk::Menu * ops_menu
Definition: audio_clock.h:104
framepos_t current_duration(framepos_t position=0) const
void render(cairo_t *, cairo_rectangle_t *)
Definition: audio_clock.cc:293
double cursor_a
Definition: audio_clock.h:254
ARDOUR::framecnt_t parse_as_distance(const std::string &)
Definition: audio_clock.cc:838
bool on_key_release_event(GdkEventKey *)
bool editable
Definition: audio_clock.h:122
bool on_scroll_event(GdkEventScroll *ev)
void set_from_playhead()
void set_negative_allowed(bool yn)
int merge_input_and_edit_string()
framepos_t last_when
Definition: audio_clock.h:188
void show_edit_status(int length)
Definition: audio_clock.cc:538
void set_is_duration(bool)
framepos_t frames_from_minsec_string(const std::string &) const
void set_minsec(framepos_t, bool)
void set_timecode(framepos_t, bool)
framepos_t frames_from_audioframes_string(const std::string &) const
bool get_is_duration() const
Definition: audio_clock.h:101
int upper_height
Definition: audio_clock.h:148
double bg_g
Definition: audio_clock.h:253
int64_t framepos_t
bool bbt_validate_edit(const std::string &)
void edit_next_field()
void set_font(Pango::FontDescription)
Definition: audio_clock.cc:165
void set_editable(bool yn)
sigc::signal< void > ChangeAborted
Definition: audio_clock.h:94
static void print_minsec(framepos_t, char *buf, size_t bufsize, float frame_rate)
double bg_a
Definition: audio_clock.h:253
double xscale
Definition: audio_clock.h:256
bool on_button_press_event(GdkEventButton *ev)
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > length
Definition: region.cc:64
void set_active_state(Gtkmm2ext::ActiveState s)
Definition: audio_clock.cc:205