Ardour  8.12
audio_clock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2007 Doug McLain <doug@nostar.net>
5  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
6  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2012-2017 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
9  * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifndef __audio_clock_h__
27 #define __audio_clock_h__
28 
29 #include <map>
30 #include <vector>
31 
32 #include <pangomm.h>
33 
34 #include <gtkmm/alignment.h>
35 #include <gtkmm/box.h>
36 #include <gtkmm/menu.h>
37 #include <gtkmm/label.h>
38 
39 #include "ardour/ardour.h"
40 #include "ardour/session_handle.h"
41 
42 #include "gtkmm2ext/cairo_widget.h"
43 #include "widgets/ardour_button.h"
44 
45 namespace ARDOUR {
46  class Session;
47 }
48 
50 {
51 public:
52  enum Mode {
54  BBT,
57  Samples
58  };
59 
60  AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name,
61  bool editable, bool follows_playhead, bool duration = false, bool with_info = false,
62  bool accept_on_focus_out = false);
64 
65  Mode mode() const { return _mode; }
66  void set_off (bool yn);
67  bool off() const { return _off; }
68  bool on() const { return !_off; }
69  void set_widget_name (const std::string& name);
71  void set_editable (bool yn);
72  void set_corner_radius (double);
73 
74  void focus ();
75 
76  /* overridden by MainClock */
77  virtual void set (Temporal::timepos_t const &, bool force = false);
78  void set_duration (Temporal::timecnt_t const &, bool force = false);
79 
81  void locate ();
82  void set_mode (Mode);
83 
84  void copy_text_to_clipboard () const;
85 
86  std::string name() const { return _name; }
87 
91  void set_negative_allowed (bool yn);
92 
95 
102  void set_scale (double x, double y);
103 
104  static void print_minsec (samplepos_t, char* buf, size_t bufsize, float sample_rate, int decimals = 3);
105 
106  sigc::signal<void> ValueChanged;
107  sigc::signal<void> mode_changed;
108 
109  static std::vector<AudioClock*> clocks;
110 
111 protected:
112  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
113  bool get_is_duration () const { return is_duration; }
114 
115  virtual void build_ops_menu ();
117 
120 
123 
124 private:
126  std::string _name;
128  bool editable;
132  bool _off;
135 
137 
138  Glib::RefPtr<Pango::Layout> _layout;
139 
141 
142  Pango::AttrColor* editing_attr;
143  Pango::AttrColor* foreground_attr;
144 
145  Pango::AttrList normal_attributes;
146  Pango::AttrList editing_attributes;
147 
154  uint32_t font_size;
155 
156  enum Field {
171  };
172 
173  Field index_to_field (int index) const;
174 
175  /* this maps the number of input characters/digits when editing
176  to a cursor position. insert_map[N] = index of character/digit
177  where the cursor should be after N chars/digits. it is
178  mode specific and so it is filled during set_mode().
179  */
180 
181  std::vector<int> insert_map;
182 
183  bool editing;
184  std::string edit_string;
185  std::string pre_edit_string;
186  std::string input_string;
187 
189 
190  bool dragging;
191  double drag_start_y;
192  double drag_y;
193  double drag_accum;
195 
196  void on_realize ();
200  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
204 
205  void set_slave_info ();
207  void set_bbt (Temporal::timecnt_t const &);
211  void set_out_of_bounds (bool negative);
212  void finish_set (Temporal::timepos_t const &, bool);
213 
215 
217 
218  bool timecode_validate_edit (const std::string&);
219  bool bbt_validate_edit (std::string&);
220  bool minsec_validate_edit (const std::string&);
221 
222  samplepos_t samples_from_timecode_string (const std::string&) const;
223  samplepos_t samples_from_bbt_string (Temporal::timepos_t const &, const std::string&) const;
225  samplepos_t samples_from_minsec_string (const std::string&) const;
226  samplepos_t samples_from_seconds_string (const std::string&) const;
227  samplepos_t samples_from_audiosamples_string (const std::string&) const;
228 
229  void session_configuration_changed (std::string);
231 
233 
234  void start_edit (Field f = Field (0));
235  void end_edit (bool);
236  void end_edit_relative (bool);
237 
244 
245  void set_colors ();
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 
260 };
261 
262 #endif /* __audio_clock_h__ */
Temporal::timecnt_t parse_as_distance(const std::string &)
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
std::string get_field(Field)
bool minsec_validate_edit(const std::string &)
void set_corner_radius(double)
std::vector< int > insert_map
Definition: audio_clock.h:181
bool off() const
Definition: audio_clock.h:67
std::string _name
Definition: audio_clock.h:126
bool dragging
Definition: audio_clock.h:190
Temporal::timecnt_t parse_as_timecode_distance(const std::string &)
@ Timecode_Seconds
Definition: audio_clock.h:159
@ Timecode_Minutes
Definition: audio_clock.h:158
void start_edit(Field f=Field(0))
Field index_to_field(int index) const
virtual void build_ops_menu()
void copy_text_to_clipboard() const
double cursor_g
Definition: audio_clock.h:254
bool on_motion_notify_event(GdkEventMotion *ev)
This is a default handler for the signal signal_motion_notify_event().
bool on_focus_out_event(GdkEventFocus *)
This is a default handler for the signal signal_focus_out_event().
std::string pre_edit_string
Definition: audio_clock.h:185
Pango::AttrColor * foreground_attr
Definition: audio_clock.h:143
Gtk::Menu * ops_menu
Definition: audio_clock.h:116
bool on_button_press_event(GdkEventButton *ev)
This is a default handler for the signal signal_button_press_event().
double yscale
Definition: audio_clock.h:257
void locate()
bool edit_is_negative
Definition: audio_clock.h:134
void set_bbt(Temporal::timecnt_t const &)
ArdourWidgets::ArdourButton _right_btn
Definition: audio_clock.h:122
bool on() const
Definition: audio_clock.h:68
Temporal::timecnt_t parse_as_samples_distance(const std::string &)
Temporal::timecnt_t current_duration(Temporal::timepos_t position=Temporal::timepos_t()) const
void set_from_playhead()
Pango::AttrColor * editing_attr
Definition: audio_clock.h:142
void set_mode(Mode)
bool _follows_playhead
Definition: audio_clock.h:130
Field index_to_field() const
virtual void set(Temporal::timepos_t const &, bool force=false)
double bg_r
Definition: audio_clock.h:253
void set_minsec(Temporal::timepos_t const &)
ArdourWidgets::ArdourButton * left_btn()
Definition: audio_clock.h:93
void on_size_request(Gtk::Requisition *req)
This is a default handler for the signal signal_size_request().
int layout_height
Definition: audio_clock.h:151
bool on_button_release_event(GdkEventButton *ev)
This is a default handler for the signal signal_button_release_event().
bool _with_info
Definition: audio_clock.h:140
void drop_focus()
void dpi_reset()
double bg_b
Definition: audio_clock.h:253
double xscale
Definition: audio_clock.h:256
void set_active_state(Gtkmm2ext::ActiveState s)
void set_seconds(Temporal::timepos_t const &)
samplepos_t samples_from_seconds_string(const std::string &) const
Temporal::timepos_t _limit_pos
Definition: audio_clock.h:136
Temporal::timepos_t last_when() const
Definition: audio_clock.h:88
bool editing
Definition: audio_clock.h:183
ArdourWidgets::ArdourButton * right_btn()
Definition: audio_clock.h:94
void set_colors()
ArdourWidgets::ArdourButton _left_btn
Definition: audio_clock.h:121
double cursor_a
Definition: audio_clock.h:254
void end_edit_relative(bool)
samplepos_t sample_duration_from_bbt_string(Temporal::timepos_t const &, const std::string &) const
bool _negative_allowed
Definition: audio_clock.h:133
std::string edit_string
Definition: audio_clock.h:184
void render(Cairo::RefPtr< Cairo::Context > const &, cairo_rectangle_t *)
sigc::signal< void > mode_changed
Definition: audio_clock.h:107
static void print_minsec(samplepos_t, char *buf, size_t bufsize, float sample_rate, int decimals=3)
static std::vector< AudioClock * > clocks
Definition: audio_clock.h:109
void session_configuration_changed(std::string)
double drag_y
Definition: audio_clock.h:192
samplepos_t samples_from_minsec_string(const std::string &) const
void set_scale(double x, double y)
std::string input_string
Definition: audio_clock.h:186
int first_width
Definition: audio_clock.h:149
Pango::AttrList editing_attributes
Definition: audio_clock.h:146
void set_out_of_bounds(bool negative)
void show_edit_status(int length)
void set_session(ARDOUR::Session *s)
std::string name() const
Definition: audio_clock.h:86
Mode mode() const
Definition: audio_clock.h:65
void on_realize()
This is a default handler for the signal signal_realize().
samplepos_t samples_from_bbt_string(Temporal::timepos_t const &, const std::string &) const
bool on_scroll_event(GdkEventScroll *ev)
This is a default handler for the signal signal_scroll_event().
sigc::signal< void > ValueChanged
Definition: audio_clock.h:106
uint32_t font_size
Definition: audio_clock.h:154
int merge_input_and_edit_string()
bool get_is_duration() const
Definition: audio_clock.h:113
int layout_width
Definition: audio_clock.h:152
void tempo_map_changed()
void set_widget_name(const std::string &name)
Temporal::timecnt_t parse_as_minsec_distance(const std::string &)
Glib::RefPtr< Pango::Layout > _layout
Definition: audio_clock.h:138
double cursor_r
Definition: audio_clock.h:254
bool on_key_press_event(GdkEventKey *)
This is a default handler for the signal signal_key_press_event().
void set_clock_dimensions(Gtk::Requisition &)
double drag_accum
Definition: audio_clock.h:193
void set_timecode(Temporal::timepos_t const &)
Temporal::timepos_t get_incremental_step(Field, Temporal::timepos_t const &pos=Temporal::timepos_t())
samplepos_t samples_from_timecode_string(const std::string &) const
int first_height
Definition: audio_clock.h:148
double bg_g
Definition: audio_clock.h:253
void end_edit(bool)
double drag_start_y
Definition: audio_clock.h:191
samplepos_t samples_from_audiosamples_string(const std::string &) const
double cursor_b
Definition: audio_clock.h:254
bool style_resets_first
Definition: audio_clock.h:150
Field drag_field
Definition: audio_clock.h:194
double bg_a
Definition: audio_clock.h:253
bool _accept_on_focus_out
Definition: audio_clock.h:131
void finish_set(Temporal::timepos_t const &, bool)
Pango::AttrList normal_attributes
Definition: audio_clock.h:145
PBD::ScopedConnection tempo_map_connection
Definition: audio_clock.h:259
void set_duration(Temporal::timecnt_t const &, bool force=false)
Temporal::timecnt_t parse_as_seconds_distance(const std::string &)
void set_slave_info()
bool bbt_validate_edit(std::string &)
Temporal::timecnt_t parse_as_bbt_distance(const std::string &)
Temporal::timecnt_t last_time
Definition: audio_clock.h:188
void set_editable(bool yn)
bool timecode_validate_edit(const std::string &)
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, bool accept_on_focus_out=false)
void set_off(bool yn)
bool on_key_release_event(GdkEventKey *)
This is a default handler for the signal signal_key_release_event().
bool editable
Definition: audio_clock.h:128
void focus()
double corner_radius
Definition: audio_clock.h:153
void set_samples(Temporal::timepos_t const &)
void set_negative_allowed(bool yn)
bool is_duration
Definition: audio_clock.h:127
timepos_t const & position() const
Definition: timeline.h:342
PBD::PropertyDescriptor< timecnt_t > length
Temporal::samplepos_t samplepos_t