Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
27 
28 #include <map>
29 #include <vector>
30 
31 #include <pangomm.h>
32 
33 #include <gtkmm/alignment.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/menu.h>
36 #include <gtkmm/label.h>
37 
38 #include "ardour/ardour.h"
39 #include "ardour/session_handle.h"
40 
41 #include "gtkmm2ext/cairo_widget.h"
42 #include "widgets/ardour_button.h"
43 
44 namespace ARDOUR {
45  class Session;
46 }
47 
49 {
50 public:
51  enum Mode {
53  BBT,
56  Samples
57  };
58 
59  AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name,
60  bool editable, bool follows_playhead, bool duration = false, bool with_info = false,
61  bool accept_on_focus_out = false);
63 
64  Mode mode() const { return _mode; }
65  void set_off (bool yn);
66  bool off() const { return _off; }
67  bool on() const { return !_off; }
68  void set_widget_name (const std::string& name);
70  void set_editable (bool yn);
71  void set_corner_radius (double);
72 
73  void focus ();
74 
75  /* overridden by MainClock */
76  virtual void set (Temporal::timepos_t const &, bool force = false, bool round_to_beat = false);
77  void set_duration (Temporal::timecnt_t const &, bool force = false);
78 
79  virtual void set_mode (Mode);
80 
82  void locate ();
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>&);
206 
207  void set_slave_info ();
209  void set_bbt (Temporal::timecnt_t const &);
213  void set_out_of_bounds (bool negative);
214  void finish_set (Temporal::timepos_t const &, bool);
215 
217 
219 
220  bool timecode_validate_edit (const std::string&);
221  bool bbt_validate_edit (std::string&);
222  bool minsec_validate_edit (const std::string&);
223 
224  samplepos_t samples_from_timecode_string (const std::string&) const;
225  samplepos_t samples_from_bbt_string (Temporal::timepos_t const &, const std::string&) const;
227  samplepos_t samples_from_minsec_string (const std::string&) const;
228  samplepos_t samples_from_seconds_string (const std::string&) const;
229  samplepos_t samples_from_audiosamples_string (const std::string&) const;
230 
231  void session_configuration_changed (std::string);
233 
235 
236  void start_edit (Field f = Field (0));
237  void end_edit (bool);
238  void end_edit_relative (bool);
239 
246 
247  void set_colors ();
250  std::string get_field (Field);
251 
252  void drop_focus ();
253  void dpi_reset ();
254 
255  double bg_r, bg_g, bg_b, bg_a;
257 
258  double xscale;
259  double yscale;
260 
261  bool _hovering;
262 
264 };
265 
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:66
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:256
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:259
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:67
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
bool _follows_playhead
Definition: audio_clock.h:130
Field index_to_field() const
double bg_r
Definition: audio_clock.h:255
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:255
double xscale
Definition: audio_clock.h:258
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:256
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)
bool on_enter_notify_event(GdkEventCrossing *)
This is a default handler for the signal signal_enter_notify_event().
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)
bool _hovering
Definition: audio_clock.h:261
std::string name() const
Definition: audio_clock.h:86
Mode mode() const
Definition: audio_clock.h:64
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:256
bool on_key_press_event(GdkEventKey *)
This is a default handler for the signal signal_key_press_event().
void set_clock_dimensions(Gtk::Requisition &)
virtual void set_mode(Mode)
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:255
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:256
bool style_resets_first
Definition: audio_clock.h:150
Field drag_field
Definition: audio_clock.h:194
double bg_a
Definition: audio_clock.h:255
bool on_leave_notify_event(GdkEventCrossing *)
This is a default handler for the signal signal_leave_notify_event().
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
virtual void set(Temporal::timepos_t const &, bool force=false, bool round_to_beat=false)
PBD::ScopedConnection tempo_map_connection
Definition: audio_clock.h:263
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:341
PBD::PropertyDescriptor< timecnt_t > length
Temporal::samplepos_t samplepos_t