2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2007 Doug McLain <doug@nostar.net>
|
|
|
|
* Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2012-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
|
|
|
|
* Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#ifndef __audio_clock_h__
|
|
|
|
#define __audio_clock_h__
|
|
|
|
|
2011-05-21 21:18:22 -04:00
|
|
|
#include <map>
|
2011-11-17 17:49:13 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <pangomm.h>
|
2011-06-02 13:47:58 -04:00
|
|
|
|
|
|
|
#include <gtkmm/alignment.h>
|
2005-09-26 14:24:59 -04:00
|
|
|
#include <gtkmm/box.h>
|
|
|
|
#include <gtkmm/menu.h>
|
|
|
|
#include <gtkmm/label.h>
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/ardour.h"
|
2009-12-17 13:24:23 -05:00
|
|
|
#include "ardour/session_handle.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-12-07 08:57:45 -05:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
2017-07-15 11:38:28 -04:00
|
|
|
#include "widgets/ardour_button.h"
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
class Session;
|
2006-07-19 12:47:04 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2022-11-18 09:11:32 -05:00
|
|
|
public:
|
2005-09-25 14:42:24 -04:00
|
|
|
enum Mode {
|
2009-10-26 10:38:58 -04:00
|
|
|
Timecode,
|
2005-09-25 14:42:24 -04:00
|
|
|
BBT,
|
|
|
|
MinSec,
|
2017-11-22 14:36:28 -05:00
|
|
|
Seconds,
|
2017-09-18 12:39:17 -04:00
|
|
|
Samples
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-06-01 13:00:29 -04:00
|
|
|
AudioClock (const std::string& clock_name, bool is_transient, const std::string& widget_name,
|
2015-06-16 11:18:23 -04:00
|
|
|
bool editable, bool follows_playhead, bool duration = false, bool with_info = false,
|
|
|
|
bool accept_on_focus_out = false);
|
2011-06-02 13:47:58 -04:00
|
|
|
~AudioClock ();
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
Mode mode() const { return _mode; }
|
2011-06-07 19:07:08 -04:00
|
|
|
void set_off (bool yn);
|
|
|
|
bool off() const { return _off; }
|
2016-08-28 18:57:43 -04:00
|
|
|
bool on() const { return !_off; }
|
2011-11-17 17:49:13 -05:00
|
|
|
void set_widget_name (const std::string& name);
|
|
|
|
void set_active_state (Gtkmm2ext::ActiveState s);
|
2011-11-18 12:06:11 -05:00
|
|
|
void set_editable (bool yn);
|
2011-11-19 09:27:05 -05:00
|
|
|
void set_corner_radius (double);
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
void focus ();
|
|
|
|
|
2022-10-15 14:40:50 -04:00
|
|
|
/* overridden by MainClock */
|
2022-10-07 18:12:27 -04:00
|
|
|
virtual void set (Temporal::timepos_t const &, bool force = false);
|
|
|
|
void set_duration (Temporal::timecnt_t const &, bool force = false);
|
2020-09-26 11:14:59 -04:00
|
|
|
|
2009-11-12 15:39:53 -05:00
|
|
|
void set_from_playhead ();
|
|
|
|
void locate ();
|
2022-11-18 09:29:34 -05:00
|
|
|
void set_mode (Mode);
|
2007-01-08 12:12:29 -05:00
|
|
|
|
2015-04-14 05:55:39 -04:00
|
|
|
void copy_text_to_clipboard () const;
|
|
|
|
|
2007-01-08 12:12:29 -05:00
|
|
|
std::string name() const { return _name; }
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2022-11-14 09:52:15 -05:00
|
|
|
Temporal::timepos_t last_when () const { return last_time.position(); }
|
2020-09-29 19:53:43 -04:00
|
|
|
Temporal::timecnt_t current_duration (Temporal::timepos_t position = Temporal::timepos_t()) const;
|
2005-09-25 14:42:24 -04:00
|
|
|
void set_session (ARDOUR::Session *s);
|
2016-04-24 08:39:22 -04:00
|
|
|
void set_negative_allowed (bool yn);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2017-07-15 11:38:28 -04:00
|
|
|
ArdourWidgets::ArdourButton* left_btn () { return &_left_btn; }
|
|
|
|
ArdourWidgets::ArdourButton* right_btn () { return &_right_btn; }
|
2016-12-11 11:24:30 -05:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/** Alter cairo scaling during rendering.
|
2014-12-31 06:52:47 -05:00
|
|
|
*
|
|
|
|
* Used by clocks that resize themselves
|
|
|
|
* to fit any given space. Can lead
|
|
|
|
* to font distortion.
|
|
|
|
*/
|
|
|
|
void set_scale (double x, double y);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2021-02-07 07:31:19 -05:00
|
|
|
static void print_minsec (samplepos_t, char* buf, size_t bufsize, float sample_rate, int decimals = 3);
|
2014-07-09 19:13:18 -04:00
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
sigc::signal<void> ValueChanged;
|
2008-09-19 10:38:46 -04:00
|
|
|
sigc::signal<void> mode_changed;
|
2007-01-08 12:12:29 -05:00
|
|
|
|
|
|
|
static std::vector<AudioClock*> clocks;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-11-18 09:11:32 -05:00
|
|
|
protected:
|
2017-03-20 12:11:56 -04:00
|
|
|
void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
|
2017-11-22 16:10:37 -05:00
|
|
|
bool get_is_duration () const { return is_duration; }
|
2011-06-03 18:18:47 -04:00
|
|
|
|
2012-05-31 19:14:03 -04:00
|
|
|
virtual void build_ops_menu ();
|
|
|
|
Gtk::Menu *ops_menu;
|
|
|
|
|
2015-02-15 13:26:15 -05:00
|
|
|
bool on_button_press_event (GdkEventButton *ev);
|
|
|
|
bool on_button_release_event(GdkEventButton *ev);
|
2016-12-11 11:24:30 -05:00
|
|
|
|
2017-07-15 11:38:28 -04:00
|
|
|
ArdourWidgets::ArdourButton _left_btn;
|
|
|
|
ArdourWidgets::ArdourButton _right_btn;
|
2016-12-11 11:24:30 -05:00
|
|
|
|
2022-11-18 09:11:32 -05:00
|
|
|
private:
|
2005-09-25 14:42:24 -04:00
|
|
|
Mode _mode;
|
2007-01-08 12:12:29 -05:00
|
|
|
std::string _name;
|
2005-09-25 14:42:24 -04:00
|
|
|
bool is_duration;
|
|
|
|
bool editable;
|
2009-11-25 21:15:44 -05:00
|
|
|
/** true if this clock follows the playhead, meaning that certain operations are redundant */
|
|
|
|
bool _follows_playhead;
|
2015-06-16 11:18:23 -04:00
|
|
|
bool _accept_on_focus_out;
|
2011-06-07 19:07:08 -04:00
|
|
|
bool _off;
|
2016-04-24 08:39:22 -04:00
|
|
|
bool _negative_allowed;
|
|
|
|
bool edit_is_negative;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
Temporal::timepos_t _limit_pos;
|
2017-05-08 06:37:17 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
Glib::RefPtr<Pango::Layout> _layout;
|
2016-12-11 11:24:30 -05:00
|
|
|
|
|
|
|
bool _with_info;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
Pango::AttrColor* editing_attr;
|
|
|
|
Pango::AttrColor* foreground_attr;
|
|
|
|
|
|
|
|
Pango::AttrList normal_attributes;
|
|
|
|
Pango::AttrList editing_attributes;
|
|
|
|
|
2011-11-19 09:27:05 -05:00
|
|
|
int first_height;
|
|
|
|
int first_width;
|
2016-04-24 08:39:22 -04:00
|
|
|
bool style_resets_first;
|
2011-11-17 17:49:13 -05:00
|
|
|
int layout_height;
|
|
|
|
int layout_width;
|
2011-11-19 09:27:05 -05:00
|
|
|
double corner_radius;
|
2012-11-10 21:45:01 -05:00
|
|
|
uint32_t font_size;
|
2011-11-18 12:06:11 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
enum Field {
|
2011-11-21 14:24:37 -05:00
|
|
|
Timecode_Hours = 1,
|
2009-10-26 10:38:58 -04:00
|
|
|
Timecode_Minutes,
|
|
|
|
Timecode_Seconds,
|
2017-09-18 12:39:17 -04:00
|
|
|
Timecode_frames,
|
2005-09-25 14:42:24 -04:00
|
|
|
MS_Hours,
|
|
|
|
MS_Minutes,
|
|
|
|
MS_Seconds,
|
2011-05-21 21:18:05 -04:00
|
|
|
MS_Milliseconds,
|
2005-09-25 14:42:24 -04:00
|
|
|
Bars,
|
2009-10-14 12:10:01 -04:00
|
|
|
Beats,
|
2005-09-25 14:42:24 -04:00
|
|
|
Ticks,
|
2017-11-22 14:36:28 -05:00
|
|
|
SS_Seconds,
|
|
|
|
SS_Deciseconds,
|
2017-09-18 12:39:17 -04:00
|
|
|
S_Samples,
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
Field index_to_field (int index) const;
|
2011-06-03 18:18:47 -04:00
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
/* this maps the number of input characters/digits when editing
|
|
|
|
to a cursor position. insert_map[N] = index of character/digit
|
2015-10-04 14:51:05 -04:00
|
|
|
where the cursor should be after N chars/digits. it is
|
2011-11-18 17:17:59 -05:00
|
|
|
mode specific and so it is filled during set_mode().
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::vector<int> insert_map;
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
bool editing;
|
|
|
|
std::string edit_string;
|
|
|
|
std::string pre_edit_string;
|
|
|
|
std::string input_string;
|
2011-11-18 10:35:58 -05:00
|
|
|
|
2022-10-07 18:12:27 -04:00
|
|
|
Temporal::timecnt_t last_time;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
bool dragging;
|
|
|
|
double drag_start_y;
|
|
|
|
double drag_y;
|
|
|
|
double drag_accum;
|
2011-11-17 17:49:13 -05:00
|
|
|
Field drag_field;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 22:48:59 -04:00
|
|
|
void on_realize ();
|
2011-11-17 17:49:13 -05:00
|
|
|
bool on_key_press_event (GdkEventKey *);
|
|
|
|
bool on_key_release_event (GdkEventKey *);
|
|
|
|
bool on_scroll_event (GdkEventScroll *ev);
|
|
|
|
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
|
|
|
void on_size_request (Gtk::Requisition* req);
|
|
|
|
bool on_motion_notify_event (GdkEventMotion *ev);
|
2011-11-17 20:22:40 -05:00
|
|
|
bool on_focus_out_event (GdkEventFocus*);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2012-11-11 12:36:31 -05:00
|
|
|
void set_slave_info ();
|
2022-11-07 06:12:05 -05:00
|
|
|
void set_timecode (Temporal::timepos_t const &);
|
|
|
|
void set_bbt (Temporal::timecnt_t const &);
|
|
|
|
void set_minsec (Temporal::timepos_t const &);
|
|
|
|
void set_seconds (Temporal::timepos_t const &);
|
|
|
|
void set_samples (Temporal::timepos_t const &);
|
2017-05-08 06:37:17 -04:00
|
|
|
void set_out_of_bounds (bool negative);
|
2020-09-26 11:14:59 -04:00
|
|
|
void finish_set (Temporal::timepos_t const &, bool);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2016-04-24 08:39:22 -04:00
|
|
|
void set_clock_dimensions (Gtk::Requisition&);
|
2012-12-29 10:59:38 -05:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
Temporal::timepos_t get_incremental_step (Field, Temporal::timepos_t const & pos = Temporal::timepos_t ());
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
bool timecode_validate_edit (const std::string&);
|
2018-02-20 17:19:43 -05:00
|
|
|
bool bbt_validate_edit (std::string&);
|
2011-11-21 12:51:15 -05:00
|
|
|
bool minsec_validate_edit (const std::string&);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t samples_from_timecode_string (const std::string&) const;
|
2020-09-29 19:53:43 -04:00
|
|
|
samplepos_t samples_from_bbt_string (Temporal::timepos_t const &, const std::string&) const;
|
|
|
|
samplepos_t sample_duration_from_bbt_string (Temporal::timepos_t const &, const std::string&) const;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t samples_from_minsec_string (const std::string&) const;
|
2017-11-22 14:36:28 -05:00
|
|
|
samplepos_t samples_from_seconds_string (const std::string&) const;
|
|
|
|
samplepos_t samples_from_audiosamples_string (const std::string&) const;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-12-01 15:49:22 -05:00
|
|
|
void session_configuration_changed (std::string);
|
2021-01-07 22:07:59 -05:00
|
|
|
void tempo_map_changed ();
|
2006-06-14 17:17:32 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
Field index_to_field () const;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
void start_edit (Field f = Field (0));
|
2011-11-17 17:49:13 -05:00
|
|
|
void end_edit (bool);
|
2011-11-17 20:22:40 -05:00
|
|
|
void end_edit_relative (bool);
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
Temporal::timecnt_t parse_as_distance (const std::string&);
|
|
|
|
Temporal::timecnt_t parse_as_timecode_distance (const std::string&);
|
|
|
|
Temporal::timecnt_t parse_as_minsec_distance (const std::string&);
|
|
|
|
Temporal::timecnt_t parse_as_bbt_distance (const std::string&);
|
|
|
|
Temporal::timecnt_t parse_as_seconds_distance (const std::string&);
|
|
|
|
Temporal::timecnt_t parse_as_samples_distance (const std::string&);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void set_colors ();
|
|
|
|
void show_edit_status (int length);
|
2011-11-21 14:24:37 -05:00
|
|
|
int merge_input_and_edit_string ();
|
|
|
|
std::string get_field (Field);
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
void drop_focus ();
|
2011-11-20 10:10:53 -05:00
|
|
|
void dpi_reset ();
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
double bg_r, bg_g, bg_b, bg_a;
|
2011-11-20 10:26:43 -05:00
|
|
|
double cursor_r, cursor_g, cursor_b, cursor_a;
|
2014-12-31 06:52:47 -05:00
|
|
|
|
|
|
|
double xscale;
|
|
|
|
double yscale;
|
2021-01-07 22:07:59 -05:00
|
|
|
|
|
|
|
PBD::ScopedConnection tempo_map_connection;
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __audio_clock_h__ */
|