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) 2006-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2007 Doug McLain <doug@nostar.net>
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2013-2017 John Emmas <john@creativepost.co.uk>
|
|
|
|
* Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2015 Ben Loftis <ben@harrisonconsoles.com>
|
|
|
|
* 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
|
|
|
|
|
|
|
#include <cstdio> // for sprintf
|
|
|
|
#include <cmath>
|
2006-04-25 16:23:50 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/convert.h"
|
|
|
|
#include "pbd/enumwriter.h"
|
2006-04-25 16:23:50 -04:00
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
#include <gtkmm/style.h>
|
2012-05-24 02:09:29 -04:00
|
|
|
#include <sigc++/bind.h>
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
#include "gtkmm2ext/rgb_macros.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2017-07-15 11:38:28 -04:00
|
|
|
#include "widgets/tooltips.h"
|
|
|
|
|
2012-10-12 18:04:21 -04:00
|
|
|
#include "ardour/profile.h"
|
2015-03-31 10:05:15 -04:00
|
|
|
#include "ardour/lmath.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/session.h"
|
2018-09-18 18:52:20 -04:00
|
|
|
#include "ardour/transport_master.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/tempo.h"
|
2018-10-05 12:35:13 -04:00
|
|
|
#include "ardour/transport_master_manager.h"
|
2012-10-12 18:04:21 -04:00
|
|
|
#include "ardour/types.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2016-09-06 16:17:39 -04:00
|
|
|
#include "ardour_ui.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "audio_clock.h"
|
2016-08-30 03:16:34 -04:00
|
|
|
#include "enums_convert.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "gui_thread.h"
|
2016-09-06 15:40:22 -04:00
|
|
|
#include "keyboard.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ui_config.h"
|
2016-09-06 15:40:22 -04:00
|
|
|
#include "utils.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2014-06-25 15:27:37 -04:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
2017-07-15 11:38:28 -04:00
|
|
|
using namespace ArdourWidgets;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Gtk;
|
2007-01-08 12:12:29 -05:00
|
|
|
using namespace std;
|
2020-11-24 17:06:35 -05:00
|
|
|
using namespace Temporal;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-12-04 17:51:32 -05:00
|
|
|
using Gtkmm2ext::Keyboard;
|
|
|
|
|
2007-01-08 12:12:29 -05:00
|
|
|
sigc::signal<void> AudioClock::ModeChanged;
|
|
|
|
vector<AudioClock*> AudioClock::clocks;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-20 10:10:53 -05:00
|
|
|
#define BBT_BAR_CHAR "|"
|
|
|
|
#define BBT_SCANF_FORMAT "%" PRIu32 "%*c%" PRIu32 "%*c%" PRIu32
|
|
|
|
|
2011-06-01 13:00:29 -04:00
|
|
|
AudioClock::AudioClock (const string& clock_name, bool transient, const string& widget_name,
|
2015-06-16 11:18:23 -04:00
|
|
|
bool allow_edit, bool follows_playhead, bool duration, bool with_info,
|
|
|
|
bool accept_on_focus_out)
|
2012-05-31 19:14:03 -04:00
|
|
|
: ops_menu (0)
|
|
|
|
, _name (clock_name)
|
2011-06-02 17:43:10 -04:00
|
|
|
, is_transient (transient)
|
|
|
|
, is_duration (duration)
|
|
|
|
, editable (allow_edit)
|
|
|
|
, _follows_playhead (follows_playhead)
|
2015-06-16 11:18:23 -04:00
|
|
|
, _accept_on_focus_out (accept_on_focus_out)
|
2011-06-07 19:07:08 -04:00
|
|
|
, _off (false)
|
2011-11-21 12:39:55 -05:00
|
|
|
, em_width (0)
|
2011-11-21 14:24:37 -05:00
|
|
|
, _edit_by_click_field (false)
|
2012-11-11 17:20:40 -05:00
|
|
|
, _negative_allowed (false)
|
|
|
|
, edit_is_negative (false)
|
2020-12-02 00:33:30 -05:00
|
|
|
, _limit_pos (timepos_t::max (Temporal::AudioTime))
|
2016-12-11 11:24:30 -05:00
|
|
|
, _with_info (with_info)
|
2011-11-17 17:49:13 -05:00
|
|
|
, editing_attr (0)
|
|
|
|
, foreground_attr (0)
|
2011-11-19 09:27:05 -05:00
|
|
|
, first_height (0)
|
|
|
|
, first_width (0)
|
2012-12-27 13:49:12 -05:00
|
|
|
, style_resets_first (true)
|
2011-11-19 09:27:05 -05:00
|
|
|
, layout_height (0)
|
|
|
|
, layout_width (0)
|
2012-12-06 15:48:44 -05:00
|
|
|
, corner_radius (4)
|
2012-11-10 21:45:01 -05:00
|
|
|
, font_size (10240)
|
2011-11-17 17:49:13 -05:00
|
|
|
, editing (false)
|
2021-11-12 16:20:15 -05:00
|
|
|
, bbt_reference_time (timepos_t::from_superclock (-1)) /* needs to be some negative value but SR may not be available at init */
|
2011-11-17 17:49:13 -05:00
|
|
|
, last_pdelta (0)
|
|
|
|
, last_sdelta (0)
|
|
|
|
, dragging (false)
|
|
|
|
, drag_field (Field (0))
|
2014-12-31 06:52:47 -05:00
|
|
|
, xscale (1.0)
|
|
|
|
, yscale (1.0)
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
2020-03-11 11:07:28 -04:00
|
|
|
if (editable) {
|
|
|
|
set_flags (CAN_FOCUS);
|
|
|
|
}
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
_layout = Pango::Layout::create (get_pango_context());
|
|
|
|
_layout->set_attributes (normal_attributes);
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
set_widget_name (widget_name);
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
_mode = BBT; /* lie to force mode switch */
|
|
|
|
set_mode (Timecode);
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (last_when, true);
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!is_transient) {
|
|
|
|
clocks.push_back (this);
|
|
|
|
}
|
2011-11-18 11:23:37 -05:00
|
|
|
|
2020-01-12 18:22:39 -05:00
|
|
|
_left_btn.set_name ("transport option button");
|
|
|
|
_right_btn.set_name ("transport option button");
|
|
|
|
|
2016-12-11 11:24:30 -05:00
|
|
|
_left_btn.set_sizing_text (_("0000000000000"));
|
2020-05-12 09:08:39 -04:00
|
|
|
_right_btn.set_sizing_text (_("0000000000000"));
|
2016-12-11 11:24:30 -05:00
|
|
|
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_layout_font (UIConfiguration::instance().get_SmallMonospaceFont());
|
|
|
|
_right_btn.set_layout_font (UIConfiguration::instance().get_SmallMonospaceFont());
|
2016-12-11 11:24:30 -05:00
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AudioClock::set_colors));
|
|
|
|
UIConfiguration::instance().DPIReset.connect (sigc::mem_fun (*this, &AudioClock::dpi_reset));
|
2021-01-07 22:07:59 -05:00
|
|
|
|
|
|
|
TempoMap::MapChanged.connect (tempo_map_connection, invalidator (*this), boost::bind (&AudioClock::tempo_map_changed, this), gui_context());
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::~AudioClock ()
|
|
|
|
{
|
2019-03-07 10:40:16 -05:00
|
|
|
delete ops_menu;
|
2011-11-17 17:49:13 -05:00
|
|
|
delete foreground_attr;
|
|
|
|
delete editing_attr;
|
|
|
|
}
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::set_widget_name (const string& str)
|
|
|
|
{
|
|
|
|
if (str.empty()) {
|
|
|
|
set_name ("clock");
|
|
|
|
} else {
|
|
|
|
set_name (str + " clock");
|
|
|
|
}
|
2011-11-18 13:06:16 -05:00
|
|
|
|
|
|
|
if (is_realized()) {
|
|
|
|
set_colors ();
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-06-08 15:48:57 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::on_realize ()
|
|
|
|
{
|
2012-12-29 10:59:38 -05:00
|
|
|
Gtk::Requisition req;
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
CairoWidget::on_realize ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
set_clock_dimensions (req);
|
|
|
|
|
|
|
|
first_width = req.width;
|
|
|
|
first_height = req.height;
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
set_colors ();
|
|
|
|
}
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::set_active_state (Gtkmm2ext::ActiveState s)
|
|
|
|
{
|
|
|
|
CairoWidget::set_active_state (s);
|
|
|
|
set_colors ();
|
2006-11-30 11:43:11 -05:00
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_colors ()
|
2011-06-02 13:47:58 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
int r, g, b, a;
|
|
|
|
|
|
|
|
uint32_t bg_color;
|
|
|
|
uint32_t text_color;
|
|
|
|
uint32_t editing_color;
|
2011-11-20 10:26:43 -05:00
|
|
|
uint32_t cursor_color;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
if (active_state()) {
|
2015-01-02 09:44:54 -05:00
|
|
|
bg_color = UIConfiguration::instance().color (string_compose ("%1 active: background", get_name()));
|
|
|
|
text_color = UIConfiguration::instance().color (string_compose ("%1 active: text", get_name()));
|
|
|
|
editing_color = UIConfiguration::instance().color (string_compose ("%1 active: edited text", get_name()));
|
|
|
|
cursor_color = UIConfiguration::instance().color (string_compose ("%1 active: cursor", get_name()));
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
2015-01-02 09:44:54 -05:00
|
|
|
bg_color = UIConfiguration::instance().color (string_compose ("%1: background", get_name()));
|
|
|
|
text_color = UIConfiguration::instance().color (string_compose ("%1: text", get_name()));
|
|
|
|
editing_color = UIConfiguration::instance().color (string_compose ("%1: edited text", get_name()));
|
|
|
|
cursor_color = UIConfiguration::instance().color (string_compose ("%1: cursor", get_name()));
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
2011-11-20 10:26:43 -05:00
|
|
|
/* store for bg and cursor in render() */
|
2011-11-18 10:35:58 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
UINT_TO_RGBA (bg_color, &r, &g, &b, &a);
|
2011-11-19 09:27:05 -05:00
|
|
|
|
|
|
|
bg_r = r/255.0;
|
|
|
|
bg_g = g/255.0;
|
|
|
|
bg_b = b/255.0;
|
|
|
|
bg_a = a/255.0;
|
|
|
|
|
2011-11-20 10:26:43 -05:00
|
|
|
UINT_TO_RGBA (cursor_color, &r, &g, &b, &a);
|
|
|
|
|
|
|
|
cursor_r = r/255.0;
|
|
|
|
cursor_g = g/255.0;
|
|
|
|
cursor_b = b/255.0;
|
|
|
|
cursor_a = a/255.0;
|
|
|
|
|
2011-11-19 09:27:05 -05:00
|
|
|
/* rescale for Pango colors ... sigh */
|
|
|
|
|
|
|
|
r = lrint (r * 65535.0);
|
|
|
|
g = lrint (g * 65535.0);
|
|
|
|
b = lrint (b * 65535.0);
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
UINT_TO_RGBA (text_color, &r, &g, &b, &a);
|
2011-11-19 09:27:05 -05:00
|
|
|
r = lrint ((r/255.0) * 65535.0);
|
|
|
|
g = lrint ((g/255.0) * 65535.0);
|
|
|
|
b = lrint ((b/255.0) * 65535.0);
|
2014-09-10 20:34:09 -04:00
|
|
|
delete foreground_attr;
|
2011-11-17 17:49:13 -05:00
|
|
|
foreground_attr = new Pango::AttrColor (Pango::Attribute::create_attr_foreground (r, g, b));
|
|
|
|
|
|
|
|
UINT_TO_RGBA (editing_color, &r, &g, &b, &a);
|
2011-11-19 09:27:05 -05:00
|
|
|
r = lrint ((r/255.0) * 65535.0);
|
|
|
|
g = lrint ((g/255.0) * 65535.0);
|
|
|
|
b = lrint ((b/255.0) * 65535.0);
|
2014-09-10 20:34:09 -04:00
|
|
|
delete editing_attr;
|
2011-11-17 17:49:13 -05:00
|
|
|
editing_attr = new Pango::AttrColor (Pango::Attribute::create_attr_foreground (r, g, b));
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
normal_attributes.change (*foreground_attr);
|
|
|
|
editing_attributes.change (*foreground_attr);
|
|
|
|
editing_attributes.change (*editing_attr);
|
|
|
|
|
|
|
|
if (!editing) {
|
|
|
|
_layout->set_attributes (normal_attributes);
|
|
|
|
} else {
|
|
|
|
_layout->set_attributes (editing_attributes);
|
2011-06-07 19:07:08 -04:00
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
queue_draw ();
|
2011-06-02 13:47:58 -04:00
|
|
|
}
|
2006-11-30 11:43:11 -05:00
|
|
|
|
2014-12-31 06:52:47 -05:00
|
|
|
void
|
|
|
|
AudioClock::set_scale (double x, double y)
|
|
|
|
{
|
|
|
|
xscale = x;
|
|
|
|
yscale = y;
|
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2011-06-03 18:18:47 -04:00
|
|
|
void
|
2017-03-20 12:11:56 -04:00
|
|
|
AudioClock::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
|
2006-11-30 11:43:11 -05:00
|
|
|
{
|
2017-03-20 12:11:56 -04:00
|
|
|
cairo_t* cr = ctx->cobj();
|
2011-11-18 10:35:58 -05:00
|
|
|
/* main layout: rounded rect, plus the text */
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_need_bg) {
|
2011-11-18 10:35:58 -05:00
|
|
|
cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
|
2011-11-19 09:27:05 -05:00
|
|
|
if (corner_radius) {
|
2016-12-16 19:40:22 -05:00
|
|
|
Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), corner_radius);
|
2011-11-19 09:27:05 -05:00
|
|
|
} else {
|
2016-12-16 19:40:22 -05:00
|
|
|
cairo_rectangle (cr, 0, 0, get_width(), get_height());
|
2011-11-19 09:27:05 -05:00
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
2014-12-31 06:52:47 -05:00
|
|
|
double lw = layout_width * xscale;
|
|
|
|
double lh = layout_height * yscale;
|
2011-11-19 09:27:05 -05:00
|
|
|
|
2016-12-16 19:40:22 -05:00
|
|
|
cairo_move_to (cr, (get_width() - lw) / 2.0, (get_height() - lh) / 2.0);
|
2014-12-31 06:52:47 -05:00
|
|
|
|
|
|
|
if (xscale != 1.0 || yscale != 1.0) {
|
|
|
|
cairo_save (cr);
|
|
|
|
cairo_scale (cr, xscale, yscale);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
pango_cairo_show_layout (cr, _layout->gobj());
|
|
|
|
|
2014-12-31 06:52:47 -05:00
|
|
|
if (xscale != 1.0 || yscale != 1.0) {
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
if (editing) {
|
2015-09-22 18:25:14 -04:00
|
|
|
if (!insert_map.empty()) {
|
2011-11-21 11:34:02 -05:00
|
|
|
|
2015-09-28 20:15:03 -04:00
|
|
|
int xcenter = (get_width() - layout_width) /2;
|
|
|
|
|
2011-11-21 11:34:02 -05:00
|
|
|
if (input_string.length() < insert_map.size()) {
|
2015-09-28 20:15:03 -04:00
|
|
|
Pango::Rectangle cursor;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2015-09-28 20:15:03 -04:00
|
|
|
if (input_string.empty()) {
|
|
|
|
/* nothing entered yet, put cursor at the end
|
|
|
|
of string
|
|
|
|
*/
|
2020-10-26 10:56:18 -04:00
|
|
|
cursor = _layout->get_cursor_strong_pos (edit_string.length());
|
2015-09-28 20:15:03 -04:00
|
|
|
} else {
|
2020-10-26 10:56:18 -04:00
|
|
|
cursor = _layout->get_cursor_strong_pos (1 + insert_map[input_string.length()]);
|
2015-09-28 20:15:03 -04:00
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 11:34:02 -05:00
|
|
|
cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
|
2012-12-29 10:59:38 -05:00
|
|
|
cairo_rectangle (cr,
|
2017-07-01 12:42:24 -04:00
|
|
|
min (get_width() - 2.0,
|
|
|
|
(double) xcenter + cursor.get_x()/PANGO_SCALE + em_width),
|
|
|
|
(get_height() - layout_height)/2.0,
|
|
|
|
2.0, cursor.get_height()/PANGO_SCALE);
|
2015-09-28 20:15:03 -04:00
|
|
|
cairo_fill (cr);
|
2011-11-20 10:26:43 -05:00
|
|
|
} else {
|
2011-11-21 11:34:02 -05:00
|
|
|
/* we've entered all possible digits, no cursor */
|
2011-11-20 10:26:43 -05:00
|
|
|
}
|
2011-11-21 11:34:02 -05:00
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
} else {
|
2015-09-28 20:15:03 -04:00
|
|
|
if (input_string.empty()) {
|
|
|
|
cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
|
2015-09-22 18:25:14 -04:00
|
|
|
cairo_rectangle (cr,
|
2015-09-28 20:15:03 -04:00
|
|
|
(get_width()/2.0),
|
2016-12-16 19:40:22 -05:00
|
|
|
(get_height() - layout_height)/2.0,
|
|
|
|
2.0, get_height());
|
2015-09-28 20:15:03 -04:00
|
|
|
cairo_fill (cr);
|
2011-11-18 17:17:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
}
|
2006-11-30 11:43:11 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
2012-12-29 10:59:38 -05:00
|
|
|
AudioClock::set_clock_dimensions (Gtk::Requisition& req)
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
Glib::RefPtr<Pango::Layout> tmp;
|
|
|
|
Glib::RefPtr<Gtk::Style> style = get_style ();
|
2012-11-11 09:31:17 -05:00
|
|
|
Pango::FontDescription font;
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
tmp = Pango::Layout::create (get_pango_context());
|
|
|
|
|
2011-06-02 13:47:58 -04:00
|
|
|
if (!is_realized()) {
|
|
|
|
font = get_font_for_style (get_name());
|
|
|
|
} else {
|
|
|
|
font = style->get_font();
|
2011-05-21 21:18:22 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
tmp->set_font_description (font);
|
2011-06-08 13:27:26 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
/* this string is the longest thing we will ever display */
|
2015-05-21 18:23:04 -04:00
|
|
|
if (_mode == MinSec)
|
|
|
|
tmp->set_text (" 88:88:88,888 ");
|
|
|
|
else
|
|
|
|
tmp->set_text (" 88:88:88,88 ");
|
2012-12-29 10:59:38 -05:00
|
|
|
tmp->get_pixel_size (req.width, req.height);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
layout_height = req.height;
|
|
|
|
layout_width = req.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::on_size_request (Gtk::Requisition* req)
|
|
|
|
{
|
|
|
|
/* even for non fixed width clocks, the size we *ask* for never changes,
|
|
|
|
even though the size we receive might. so once we've computed it,
|
|
|
|
just return it.
|
|
|
|
*/
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
if (first_width) {
|
|
|
|
req->width = first_width;
|
|
|
|
req->height = first_height;
|
|
|
|
return;
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
set_clock_dimensions (*req);
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
/* now tackle height, for which we need to know the height of the lower
|
|
|
|
* layout
|
|
|
|
*/
|
|
|
|
}
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::show_edit_status (int length)
|
|
|
|
{
|
|
|
|
editing_attr->set_start_index (edit_string.length() - length);
|
|
|
|
editing_attr->set_end_index (edit_string.length());
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
editing_attributes.change (*foreground_attr);
|
|
|
|
editing_attributes.change (*editing_attr);
|
|
|
|
|
|
|
|
_layout->set_attributes (editing_attributes);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-21 14:24:37 -05:00
|
|
|
AudioClock::start_edit (Field f)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2012-12-19 12:07:27 -05:00
|
|
|
if (!editing) {
|
|
|
|
pre_edit_string = _layout->get_text ();
|
|
|
|
if (!insert_map.empty()) {
|
|
|
|
edit_string = pre_edit_string;
|
|
|
|
} else {
|
|
|
|
edit_string.clear ();
|
|
|
|
_layout->set_text ("");
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-19 12:07:27 -05:00
|
|
|
input_string.clear ();
|
|
|
|
editing = true;
|
|
|
|
edit_is_negative = false;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-19 12:07:27 -05:00
|
|
|
if (f) {
|
|
|
|
input_string = get_field (f);
|
|
|
|
show_edit_status (merge_input_and_edit_string ());
|
|
|
|
_layout->set_text (edit_string);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-19 12:07:27 -05:00
|
|
|
queue_draw ();
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2012-12-19 12:07:27 -05:00
|
|
|
Keyboard::magic_widget_grab_focus ();
|
|
|
|
grab_focus ();
|
2011-11-21 14:24:37 -05:00
|
|
|
}
|
2007-05-22 20:06:16 -04:00
|
|
|
}
|
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
string
|
|
|
|
AudioClock::get_field (Field f)
|
|
|
|
{
|
|
|
|
switch (f) {
|
|
|
|
case Timecode_Hours:
|
|
|
|
return edit_string.substr (1, 2);
|
|
|
|
break;
|
|
|
|
case Timecode_Minutes:
|
|
|
|
return edit_string.substr (4, 2);
|
|
|
|
break;
|
|
|
|
case Timecode_Seconds:
|
|
|
|
return edit_string.substr (7, 2);
|
|
|
|
break;
|
2017-09-18 12:39:17 -04:00
|
|
|
case Timecode_frames:
|
2011-11-21 14:24:37 -05:00
|
|
|
return edit_string.substr (10, 2);
|
|
|
|
break;
|
|
|
|
case MS_Hours:
|
|
|
|
return edit_string.substr (1, 2);
|
|
|
|
break;
|
|
|
|
case MS_Minutes:
|
|
|
|
return edit_string.substr (4, 2);
|
|
|
|
break;
|
|
|
|
case MS_Seconds:
|
|
|
|
return edit_string.substr (7, 2);
|
|
|
|
break;
|
|
|
|
case MS_Milliseconds:
|
|
|
|
return edit_string.substr (10, 3);
|
|
|
|
break;
|
|
|
|
case Bars:
|
|
|
|
return edit_string.substr (1, 3);
|
|
|
|
break;
|
|
|
|
case Beats:
|
|
|
|
return edit_string.substr (5, 2);
|
|
|
|
break;
|
|
|
|
case Ticks:
|
|
|
|
return edit_string.substr (8, 4);
|
|
|
|
break;
|
2017-11-22 14:36:28 -05:00
|
|
|
case SS_Seconds:
|
|
|
|
return edit_string.substr (0, 8);
|
|
|
|
case SS_Deciseconds:
|
|
|
|
return edit_string.substr (9, 1);
|
2017-09-18 12:39:17 -04:00
|
|
|
case S_Samples:
|
2011-11-21 14:24:37 -05:00
|
|
|
return edit_string;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-23 02:49:59 -05:00
|
|
|
return "";
|
2011-11-21 14:24:37 -05:00
|
|
|
}
|
|
|
|
|
2011-06-02 13:47:58 -04:00
|
|
|
void
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::end_edit (bool modify)
|
2007-05-22 20:06:16 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
if (modify) {
|
|
|
|
|
|
|
|
bool ok = true;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
ok = timecode_validate_edit (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case BBT:
|
|
|
|
ok = bbt_validate_edit (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case MinSec:
|
2011-11-21 12:51:15 -05:00
|
|
|
ok = minsec_validate_edit (edit_string);
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
2019-09-18 11:27:56 -04:00
|
|
|
/* fallthrough */
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
2013-11-10 20:33:57 -05:00
|
|
|
if (edit_string.length() < 1) {
|
|
|
|
edit_string = pre_edit_string;
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!ok) {
|
|
|
|
edit_string = pre_edit_string;
|
|
|
|
input_string.clear ();
|
|
|
|
_layout->set_text (edit_string);
|
2011-11-18 18:37:19 -05:00
|
|
|
show_edit_status (0);
|
2011-11-18 00:04:18 -05:00
|
|
|
/* edit attributes remain in use */
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
2011-11-18 00:04:18 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
editing = false;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t pos = 0; /* stupid gcc */
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
2017-09-18 12:39:17 -04:00
|
|
|
pos = samples_from_timecode_string (edit_string);
|
2011-11-18 00:04:18 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case BBT:
|
|
|
|
if (is_duration) {
|
2017-09-18 12:39:17 -04:00
|
|
|
pos = sample_duration_from_bbt_string (bbt_reference_time, edit_string);
|
2011-11-18 00:04:18 -05:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
pos = samples_from_bbt_string (timepos_t(), edit_string);
|
2011-11-18 00:04:18 -05:00
|
|
|
}
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case MinSec:
|
2017-09-18 12:39:17 -04:00
|
|
|
pos = samples_from_minsec_string (edit_string);
|
2011-11-18 00:04:18 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
|
|
|
pos = samples_from_seconds_string (edit_string);
|
|
|
|
break;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
2017-11-22 14:36:28 -05:00
|
|
|
pos = samples_from_audiosamples_string (edit_string);
|
2011-11-18 00:04:18 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set (timepos_t (pos), true);
|
2011-11-17 17:49:13 -05:00
|
|
|
_layout->set_attributes (normal_attributes);
|
|
|
|
ValueChanged(); /* EMIT_SIGNAL */
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
2011-11-18 10:35:58 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
editing = false;
|
2012-11-11 17:20:40 -05:00
|
|
|
edit_is_negative = false;
|
2011-11-17 20:22:40 -05:00
|
|
|
_layout->set_attributes (normal_attributes);
|
2011-11-17 17:49:13 -05:00
|
|
|
_layout->set_text (pre_edit_string);
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
queue_draw ();
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!editing) {
|
2011-11-18 00:04:18 -05:00
|
|
|
drop_focus ();
|
|
|
|
}
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
void
|
|
|
|
AudioClock::drop_focus ()
|
|
|
|
{
|
|
|
|
Keyboard::magic_widget_drop_focus ();
|
2011-11-18 21:36:30 -05:00
|
|
|
|
|
|
|
if (has_focus()) {
|
|
|
|
/* move focus back to the default widget in the top level window */
|
2016-09-06 16:17:39 -04:00
|
|
|
ARDOUR_UI::instance()->reset_focus (this);
|
2011-06-02 13:47:58 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
2017-11-22 14:36:28 -05:00
|
|
|
AudioClock::parse_as_seconds_distance (const std::string& str)
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
|
|
|
|
if (sscanf (str.c_str(), "%f", &f) == 1) {
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t (f * _session->sample_rate());
|
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t (samplecnt_t (0));
|
2017-11-22 14:36:28 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
2017-09-18 12:39:17 -04:00
|
|
|
AudioClock::parse_as_samples_distance (const std::string& str)
|
2011-11-17 20:22:40 -05:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
samplecnt_t samples = 0;
|
2011-11-17 20:22:40 -05:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
if (sscanf (str.c_str(), "%" PRId64, &samples) == 1) {
|
|
|
|
return timecnt_t (samples);
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t (samples);
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
2011-11-17 20:22:40 -05:00
|
|
|
AudioClock::parse_as_minsec_distance (const std::string& str)
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t sr = _session->sample_rate();
|
2011-11-18 00:04:18 -05:00
|
|
|
int msecs;
|
|
|
|
int secs;
|
|
|
|
int mins;
|
|
|
|
int hrs;
|
2020-09-29 19:53:43 -04:00
|
|
|
samplecnt_t samples = 0;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
switch (str.length()) {
|
|
|
|
case 0:
|
2020-09-29 19:53:43 -04:00
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
sscanf (str.c_str(), "%" PRId32, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = msecs * (sr / 1000);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case 5:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%" PRId32, &secs, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = (secs * sr) + (msecs * (sr/1000));
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 6:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = (secs * sr) + (msecs * (sr/1000));
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 7:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 8:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 9:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 10:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &msecs);
|
2020-09-29 19:53:43 -04:00
|
|
|
samples = (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t (samples);
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
2011-11-17 20:22:40 -05:00
|
|
|
AudioClock::parse_as_timecode_distance (const std::string& str)
|
|
|
|
{
|
2011-11-18 00:04:18 -05:00
|
|
|
double fps = _session->timecode_frames_per_second();
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t sr = _session->sample_rate();
|
|
|
|
int samples;
|
2011-11-18 00:04:18 -05:00
|
|
|
int secs;
|
|
|
|
int mins;
|
|
|
|
int hrs;
|
2020-09-29 19:53:43 -04:00
|
|
|
samplecnt_t ret = 0;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
switch (str.length()) {
|
|
|
|
case 0:
|
2020-09-29 19:53:43 -04:00
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
case 1:
|
|
|
|
case 2:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%" PRId32, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2021-03-17 19:26:33 -04:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case 3:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%" PRId32, &secs, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = (secs * sr) + llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 4:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = (secs * sr) + llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case 5:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = (mins * 60 * sr) + (secs * sr) + llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 6:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = (mins * 60 * sr) + (secs * sr) + llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 7:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 8:
|
2017-09-18 12:39:17 -04:00
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &samples);
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + llrint ((samples/(float)fps) * sr);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t (ret);
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
2012-05-02 16:29:46 -04:00
|
|
|
AudioClock::parse_as_bbt_distance (const std::string&)
|
2011-11-17 20:22:40 -05:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t ();
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
2011-11-18 00:04:18 -05:00
|
|
|
AudioClock::parse_as_distance (const std::string& instr)
|
2011-11-17 20:22:40 -05:00
|
|
|
{
|
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
2011-11-21 11:34:02 -05:00
|
|
|
return parse_as_timecode_distance (instr);
|
2011-11-17 20:22:40 -05:00
|
|
|
break;
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
|
|
|
return parse_as_samples_distance (instr);
|
2011-11-17 20:22:40 -05:00
|
|
|
break;
|
|
|
|
case BBT:
|
2011-11-21 11:34:02 -05:00
|
|
|
return parse_as_bbt_distance (instr);
|
2011-11-17 20:22:40 -05:00
|
|
|
break;
|
|
|
|
case MinSec:
|
2011-11-21 11:34:02 -05:00
|
|
|
return parse_as_minsec_distance (instr);
|
2011-11-17 20:22:40 -05:00
|
|
|
break;
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
|
|
|
return parse_as_seconds_distance (instr);
|
|
|
|
break;
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
2020-09-29 19:53:43 -04:00
|
|
|
return timecnt_t();
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::end_edit_relative (bool add)
|
|
|
|
{
|
2011-11-21 13:07:42 -05:00
|
|
|
bool ok = true;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 13:07:42 -05:00
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
ok = timecode_validate_edit (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 13:07:42 -05:00
|
|
|
case BBT:
|
|
|
|
ok = bbt_validate_edit (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 13:07:42 -05:00
|
|
|
case MinSec:
|
|
|
|
ok = minsec_validate_edit (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
|
|
|
break;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
2011-11-21 13:07:42 -05:00
|
|
|
break;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 13:07:42 -05:00
|
|
|
if (!ok) {
|
|
|
|
edit_string = pre_edit_string;
|
|
|
|
input_string.clear ();
|
|
|
|
_layout->set_text (edit_string);
|
|
|
|
show_edit_status (0);
|
|
|
|
/* edit attributes remain in use */
|
|
|
|
queue_draw ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t distance = parse_as_distance (input_string);
|
2011-11-17 20:22:40 -05:00
|
|
|
|
|
|
|
editing = false;
|
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
editing = false;
|
|
|
|
_layout->set_attributes (normal_attributes);
|
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (!distance.is_zero ()) {
|
2011-11-17 20:22:40 -05:00
|
|
|
if (add) {
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set (current_time() + timepos_t (distance), true);
|
2011-11-17 20:22:40 -05:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t c = current_time();
|
2011-11-17 20:22:40 -05:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
if (c > timepos_t (distance)|| _negative_allowed) {
|
|
|
|
AudioClock::set (c.earlier (distance), true);
|
2011-11-17 20:22:40 -05:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set (timepos_t(), true);
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
}
|
2011-11-18 00:04:18 -05:00
|
|
|
ValueChanged (); /* EMIT SIGNAL */
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
input_string.clear ();
|
|
|
|
queue_draw ();
|
|
|
|
drop_focus ();
|
2011-11-17 20:22:40 -05:00
|
|
|
}
|
|
|
|
|
2012-11-13 18:29:57 -05:00
|
|
|
void
|
2021-01-07 22:07:59 -05:00
|
|
|
AudioClock::tempo_map_changed ()
|
2012-11-13 18:29:57 -05:00
|
|
|
{
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (last_when, true);
|
2012-11-13 18:29:57 -05:00
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::session_configuration_changed (std::string p)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2012-11-13 15:29:28 -05:00
|
|
|
if (_negative_allowed) {
|
|
|
|
/* session option editor clock */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:30:09 -05:00
|
|
|
if (p == "sync-source" || p == "external-sync") {
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (current_time(), true);
|
2011-11-18 18:30:09 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (p != "timecode-offset" && p != "timecode-offset-negative") {
|
|
|
|
return;
|
|
|
|
}
|
2005-12-12 15:54:55 -05:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t current;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
if (is_duration) {
|
2020-09-29 19:53:43 -04:00
|
|
|
current = timepos_t (current_duration ());
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
|
|
|
current = current_time ();
|
|
|
|
}
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (current, true);
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set (timepos_t const & w, bool force, timecnt_t const & offset)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t when (w);
|
|
|
|
|
2020-12-02 00:33:54 -05:00
|
|
|
if ((!force && !is_visible()) || !_session) {
|
2005-09-25 14:42:24 -04:00
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2017-11-22 16:10:37 -05:00
|
|
|
_offset = offset;
|
2011-11-18 13:06:16 -05:00
|
|
|
if (is_duration) {
|
2020-12-02 00:33:54 -05:00
|
|
|
when = when.earlier (offset);
|
2012-11-11 09:31:17 -05:00
|
|
|
}
|
2007-05-13 22:48:28 -04:00
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
if (when > _limit_pos) {
|
|
|
|
when = _limit_pos;
|
|
|
|
} else if (when < -_limit_pos) {
|
|
|
|
when = -_limit_pos;
|
|
|
|
}
|
|
|
|
|
2011-01-19 15:54:51 -05:00
|
|
|
if (when == last_when && !force) {
|
2014-08-30 14:17:34 -04:00
|
|
|
#if 0 // XXX return if no change and no change forced. verify Aug/2014
|
2012-11-11 12:36:31 -05:00
|
|
|
if (_mode != Timecode && _mode != MinSec) {
|
|
|
|
/* may need to force display of TC source
|
2012-10-12 18:04:21 -04:00
|
|
|
* time, so don't return early.
|
|
|
|
*/
|
2014-08-30 14:17:34 -04:00
|
|
|
/* ^^ Why was that?, delta times?
|
|
|
|
* Timecode FPS, pull-up/down, etc changes
|
|
|
|
* trigger a 'session_property_changed' which
|
|
|
|
* eventually calls set(last_when, true)
|
|
|
|
*
|
|
|
|
* re-rendering the clock every 40ms or so just
|
|
|
|
* because we can is not ideal.
|
|
|
|
*/
|
2012-10-12 18:04:21 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-30 14:17:34 -04:00
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
2011-01-19 15:54:51 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 11:24:30 -05:00
|
|
|
bool btn_en = false;
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!editing) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
set_timecode (when, force);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case BBT:
|
2016-10-15 11:33:49 -04:00
|
|
|
set_bbt (when, offset, force);
|
2016-12-11 11:24:30 -05:00
|
|
|
btn_en = true;
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case MinSec:
|
|
|
|
set_minsec (when, force);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
|
|
|
set_seconds (when, force);
|
|
|
|
break;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
|
|
|
set_samples (when, force);
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
finish_set (when, btn_en);
|
2020-09-26 11:14:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_duration (Temporal::timecnt_t const & d, bool force, Temporal::timecnt_t const & offset)
|
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
set (timepos_t (d), force, offset);
|
2020-09-26 11:14:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::finish_set (Temporal::timepos_t const & when, bool btn_en)
|
|
|
|
{
|
2016-12-11 11:24:30 -05:00
|
|
|
if (_with_info) {
|
|
|
|
_left_btn.set_sensitive (btn_en);
|
|
|
|
_right_btn.set_sensitive (btn_en);
|
|
|
|
_left_btn.set_visual_state (Gtkmm2ext::NoVisualState);
|
|
|
|
_right_btn.set_visual_state (Gtkmm2ext::NoVisualState);
|
|
|
|
if (btn_en) {
|
|
|
|
_left_btn.set_elements (ArdourButton::Element(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text));
|
|
|
|
_right_btn.set_elements (ArdourButton::Element(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text));
|
|
|
|
_left_btn.set_alignment (.5, .5);
|
|
|
|
_right_btn.set_alignment (.5, .5);
|
2016-12-18 13:23:12 -05:00
|
|
|
set_tooltip (_left_btn, _("Change current tempo"));
|
|
|
|
set_tooltip (_right_btn, _("Change current time signature"));
|
2016-12-11 11:24:30 -05:00
|
|
|
} else {
|
|
|
|
_left_btn.set_elements (ArdourButton::Text);
|
|
|
|
_right_btn.set_elements (ArdourButton::Text);
|
|
|
|
_left_btn.set_alignment (0, .5);
|
|
|
|
_right_btn.set_alignment (1, .5);
|
2016-12-18 13:23:12 -05:00
|
|
|
set_tooltip (_left_btn, _(""));
|
|
|
|
set_tooltip (_right_btn, _(""));
|
2016-12-11 11:24:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:30:09 -05:00
|
|
|
queue_draw ();
|
2005-09-25 14:42:24 -04:00
|
|
|
last_when = when;
|
|
|
|
}
|
|
|
|
|
2012-11-11 12:36:31 -05:00
|
|
|
void
|
|
|
|
AudioClock::set_slave_info ()
|
|
|
|
{
|
2020-11-19 19:11:34 -05:00
|
|
|
if (!_with_info || !_session) {
|
2012-11-11 12:36:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-05 12:35:13 -04:00
|
|
|
boost::shared_ptr<TransportMaster> tm = TransportMasterManager::instance().current();
|
2012-11-11 12:36:31 -05:00
|
|
|
|
2018-09-18 18:52:20 -04:00
|
|
|
if (_session->transport_master_is_external()) {
|
2012-11-11 12:36:31 -05:00
|
|
|
|
2018-09-18 18:52:20 -04:00
|
|
|
switch (tm->type()) {
|
2013-09-19 17:34:23 -04:00
|
|
|
case Engine:
|
2018-09-18 18:52:20 -04:00
|
|
|
_left_btn.set_text (tm->name(), true);
|
2017-01-31 05:39:24 -05:00
|
|
|
_right_btn.set_text ("", true);
|
2012-11-11 12:36:31 -05:00
|
|
|
break;
|
2012-11-11 18:11:53 -05:00
|
|
|
case MIDIClock:
|
2018-09-18 18:52:20 -04:00
|
|
|
if (tm) {
|
2018-10-05 12:35:13 -04:00
|
|
|
_left_btn.set_text (tm->display_name(), true);
|
2018-09-18 18:52:20 -04:00
|
|
|
_right_btn.set_text (tm->delta_string (), true);
|
2012-11-11 18:11:53 -05:00
|
|
|
} else {
|
2017-01-31 05:39:24 -05:00
|
|
|
_left_btn.set_text (_("--pending--"), true);
|
|
|
|
_right_btn.set_text ("", true);
|
2012-11-11 18:11:53 -05:00
|
|
|
}
|
|
|
|
break;
|
2012-11-11 12:36:31 -05:00
|
|
|
case LTC:
|
|
|
|
case MTC:
|
2018-09-18 18:52:20 -04:00
|
|
|
if (tm) {
|
|
|
|
boost::shared_ptr<TimecodeTransportMaster> tcmaster;
|
|
|
|
if ((tcmaster = boost::dynamic_pointer_cast<TimecodeTransportMaster>(tm)) != 0) {
|
2020-05-12 09:08:39 -04:00
|
|
|
//TODO: _left_btn.set_name () // tcmaster->apparent_timecode_format() != _session->config.get_timecode_format();
|
|
|
|
_left_btn.set_text (string_compose ("%1%2", tm->display_name()[0], tcmaster->position_string ()), false);
|
|
|
|
_right_btn.set_text (tm->delta_string (), false);
|
2012-11-11 17:06:42 -05:00
|
|
|
}
|
2012-11-11 12:36:31 -05:00
|
|
|
} else {
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text (_("--pending--"), false);
|
|
|
|
_right_btn.set_text ("", false);
|
2012-11-11 12:36:31 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text (string_compose ("%1/%2", _("INT"), tm->display_name()), false);
|
|
|
|
_right_btn.set_text ("", false);
|
2012-11-11 12:36:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
void
|
|
|
|
AudioClock::set_out_of_bounds (bool negative)
|
|
|
|
{
|
|
|
|
if (is_duration) {
|
|
|
|
if (negative) {
|
|
|
|
_layout->set_text (" >>> -- <<< ");
|
|
|
|
} else {
|
|
|
|
_layout->set_text (" >>> ++ <<< ");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (negative) {
|
|
|
|
_layout->set_text (" <<<<<<<<<< ");
|
|
|
|
} else {
|
|
|
|
_layout->set_text (" >>>>>>>>>> ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set_samples (timepos_t const & w, bool /*force*/)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t when (w);
|
2005-09-25 14:42:24 -04:00
|
|
|
char buf[32];
|
2011-11-18 17:17:59 -05:00
|
|
|
bool negative = false;
|
2011-06-07 19:07:08 -04:00
|
|
|
|
|
|
|
if (_off) {
|
2013-03-03 06:36:42 -05:00
|
|
|
_layout->set_text (" ----------");
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text ("", false);
|
|
|
|
_right_btn.set_text ("", false);
|
2011-06-07 19:07:08 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (when.is_negative ()) {
|
2011-11-18 17:17:59 -05:00
|
|
|
when = -when;
|
|
|
|
negative = true;
|
|
|
|
}
|
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
if (when >= _limit_pos) {
|
|
|
|
set_out_of_bounds (negative);
|
|
|
|
} else if (negative) {
|
2020-09-29 19:53:43 -04:00
|
|
|
snprintf (buf, sizeof (buf), "-%10" PRId64, when.samples());
|
2017-05-08 06:37:17 -04:00
|
|
|
_layout->set_text (buf);
|
2011-11-18 17:17:59 -05:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
snprintf (buf, sizeof (buf), " %10" PRId64, when.samples());
|
2017-05-08 06:37:17 -04:00
|
|
|
_layout->set_text (buf);
|
2011-11-18 17:17:59 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 11:24:30 -05:00
|
|
|
if (_with_info) {
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t rate = _session->sample_rate();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
if (fmod (rate, 100.0) == 0.0) {
|
2012-11-11 09:31:14 -05:00
|
|
|
sprintf (buf, "%.1fkHz", rate/1000.0);
|
2006-11-30 11:43:11 -05:00
|
|
|
} else {
|
2012-11-11 09:31:14 -05:00
|
|
|
sprintf (buf, "%" PRId64 "Hz", rate);
|
2006-11-30 11:43:11 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text (string_compose ("%1 %2", _("SR"), buf), false);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
float vid_pullup = _session->config.get_video_pullup();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-11-30 11:43:11 -05:00
|
|
|
if (vid_pullup == 0.0) {
|
2020-05-12 09:08:39 -04:00
|
|
|
_right_btn.set_text ("", false);
|
2006-11-30 11:43:11 -05:00
|
|
|
} else {
|
2012-11-13 15:29:24 -05:00
|
|
|
sprintf (buf, _("%+.4f%%"), vid_pullup);
|
2020-05-12 09:08:39 -04:00
|
|
|
_right_btn.set_text (string_compose ("%1 %2", _("Pull"), buf), false);
|
2006-11-30 11:43:11 -05:00
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
void
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set_seconds (timepos_t const & when, bool /*force*/)
|
2017-11-22 14:36:28 -05:00
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
if (_off) {
|
|
|
|
_layout->set_text (" ----------");
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text ("", false);
|
|
|
|
_right_btn.set_text ("", false);
|
2017-11-22 14:36:28 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (when >= _limit_pos || when <= -_limit_pos) {
|
2021-12-11 09:51:31 -05:00
|
|
|
set_out_of_bounds (when.is_negative ());
|
2017-11-22 14:36:28 -05:00
|
|
|
} else {
|
2021-12-11 09:51:31 -05:00
|
|
|
if (when.is_negative ()) {
|
2020-09-29 19:53:43 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%12.1f", when.samples() / (float)_session->sample_rate());
|
2017-11-22 14:36:28 -05:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
snprintf (buf, sizeof (buf), " %11.1f", when.samples() / (float)_session->sample_rate());
|
2017-11-22 14:36:28 -05:00
|
|
|
}
|
|
|
|
_layout->set_text (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_slave_info();
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2021-02-07 07:31:19 -05:00
|
|
|
AudioClock::print_minsec (samplepos_t when, char* buf, size_t bufsize, float sample_rate, int decimals)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t left;
|
2005-09-25 14:42:24 -04:00
|
|
|
int hrs;
|
|
|
|
int mins;
|
2011-05-21 21:18:05 -04:00
|
|
|
int secs;
|
|
|
|
int millisecs;
|
2014-07-09 19:13:18 -04:00
|
|
|
bool negative;
|
|
|
|
|
|
|
|
if (when < 0) {
|
|
|
|
when = -when;
|
|
|
|
negative = true;
|
|
|
|
} else {
|
|
|
|
negative = false;
|
|
|
|
}
|
|
|
|
|
2021-02-07 07:31:19 -05:00
|
|
|
float dmult;
|
|
|
|
switch (decimals) {
|
|
|
|
case 1:
|
|
|
|
dmult = 10.f;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dmult = 100.f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 3:
|
|
|
|
dmult = 1000.f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-09 19:13:18 -04:00
|
|
|
left = when;
|
2017-09-18 12:39:17 -04:00
|
|
|
hrs = (int) floor (left / (sample_rate * 60.0f * 60.0f));
|
|
|
|
left -= (samplecnt_t) floor (hrs * sample_rate * 60.0f * 60.0f);
|
|
|
|
mins = (int) floor (left / (sample_rate * 60.0f));
|
|
|
|
left -= (samplecnt_t) floor (mins * sample_rate * 60.0f);
|
|
|
|
secs = (int) floor (left / (float) sample_rate);
|
|
|
|
left -= (samplecnt_t) floor ((double)(secs * sample_rate));
|
2021-02-07 07:31:19 -05:00
|
|
|
millisecs = floor (left * dmult / (float) sample_rate);
|
2014-07-09 19:13:18 -04:00
|
|
|
|
2021-02-07 07:31:19 -05:00
|
|
|
switch (decimals) {
|
|
|
|
case 0:
|
|
|
|
snprintf (buf, bufsize, "%c%02" PRId32 ":%02" PRId32 ":%02" PRId32, negative ? '-' : ' ', hrs, mins, secs);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
snprintf (buf, bufsize, "%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%01" PRId32, negative ? '-' : ' ', hrs, mins, secs, millisecs);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
snprintf (buf, bufsize, "%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%02" PRId32, negative ? '-' : ' ', hrs, mins, secs, millisecs);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 3:
|
|
|
|
snprintf (buf, bufsize, "%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, negative ? '-' : ' ', hrs, mins, secs, millisecs);
|
|
|
|
break;
|
2014-07-09 19:13:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set_minsec (timepos_t const & when, bool /*force*/)
|
2014-07-09 19:13:18 -04:00
|
|
|
{
|
|
|
|
char buf[32];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-06-07 19:07:08 -04:00
|
|
|
if (_off) {
|
2013-03-03 06:36:42 -05:00
|
|
|
_layout->set_text (" --:--:--.---");
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text ("", false);
|
|
|
|
_right_btn.set_text ("", false);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-06-07 19:07:08 -04:00
|
|
|
return;
|
2012-11-11 09:31:17 -05:00
|
|
|
}
|
2011-06-07 19:07:08 -04:00
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
if (when >= _limit_pos || when <= -_limit_pos) {
|
2021-12-11 09:51:31 -05:00
|
|
|
set_out_of_bounds (when.is_negative ());
|
2017-05-08 06:37:17 -04:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
print_minsec (when.samples(), buf, sizeof (buf), _session->sample_rate());
|
2017-05-08 06:37:17 -04:00
|
|
|
_layout->set_text (buf);
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2012-11-11 12:36:31 -05:00
|
|
|
set_slave_info();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set_timecode (timepos_t const & w, bool /*force*/)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t when (w);
|
2011-06-02 13:47:58 -04:00
|
|
|
Timecode::Time TC;
|
2011-11-18 17:17:59 -05:00
|
|
|
bool negative = false;
|
2011-11-18 13:22:00 -05:00
|
|
|
|
2011-06-07 19:07:08 -04:00
|
|
|
if (_off) {
|
2013-03-03 06:36:42 -05:00
|
|
|
_layout->set_text (" --:--:--:--");
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text ("", false);
|
|
|
|
_right_btn.set_text ("", false);
|
2011-06-07 19:07:08 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (when.is_negative ()) {
|
2011-11-18 13:22:00 -05:00
|
|
|
when = -when;
|
2011-11-18 14:28:07 -05:00
|
|
|
negative = true;
|
2011-11-18 13:22:00 -05:00
|
|
|
}
|
2017-05-08 06:37:17 -04:00
|
|
|
if (when >= _limit_pos) {
|
|
|
|
set_out_of_bounds (negative);
|
|
|
|
set_slave_info();
|
|
|
|
return;
|
|
|
|
}
|
2011-11-18 13:22:00 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
if (is_duration) {
|
2020-09-29 19:53:43 -04:00
|
|
|
_session->timecode_duration (when.samples(), TC);
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
2020-09-29 19:53:43 -04:00
|
|
|
_session->timecode_time (when.samples(), TC);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2012-10-14 22:46:54 -04:00
|
|
|
TC.negative = TC.negative || negative;
|
|
|
|
|
|
|
|
_layout->set_text (Timecode::timecode_format_time(TC));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2012-11-11 12:36:31 -05:00
|
|
|
set_slave_info();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set_bbt (timepos_t const & w, timecnt_t const & o, bool /*force*/)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t when (w);
|
|
|
|
timecnt_t offset (o);
|
2016-11-12 10:19:27 -05:00
|
|
|
char buf[64];
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time BBT;
|
2011-11-18 17:17:59 -05:00
|
|
|
bool negative = false;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
if (_off || when >= _limit_pos || when < -_limit_pos) {
|
2013-03-03 06:36:42 -05:00
|
|
|
_layout->set_text (" ---|--|----");
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text ("", false);
|
|
|
|
_right_btn.set_text ("", false);
|
2011-06-07 19:07:08 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (when.is_negative ()) {
|
2011-11-18 13:22:00 -05:00
|
|
|
when = -when;
|
2011-11-18 14:28:07 -05:00
|
|
|
negative = true;
|
2011-11-18 13:22:00 -05:00
|
|
|
}
|
|
|
|
|
2008-04-11 10:06:50 -04:00
|
|
|
/* handle a common case */
|
2020-11-24 17:06:35 -05:00
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
if (is_duration) {
|
2021-12-11 09:51:31 -05:00
|
|
|
if (when.is_zero ()) {
|
2011-06-02 13:47:58 -04:00
|
|
|
BBT.bars = 0;
|
|
|
|
BBT.beats = 0;
|
|
|
|
BBT.ticks = 0;
|
2008-12-12 09:43:24 -05:00
|
|
|
} else {
|
2020-11-27 14:41:11 -05:00
|
|
|
TempoMap::SharedPtr tmap (TempoMap::use());
|
2016-10-15 14:09:49 -04:00
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (offset.is_zero ()) {
|
2020-09-29 19:53:43 -04:00
|
|
|
offset = timecnt_t (bbt_reference_time);
|
2016-10-20 11:49:04 -04:00
|
|
|
}
|
|
|
|
|
2020-11-27 14:41:11 -05:00
|
|
|
const int divisions = tmap->meter_at (timepos_t (offset)).divisions_per_bar();
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time sub_bbt;
|
2016-10-15 11:33:49 -04:00
|
|
|
|
|
|
|
if (negative) {
|
2021-03-25 12:24:20 -04:00
|
|
|
BBT = tmap->bbt_at (timepos_t (tmap->quarters_at (timepos_t (offset))));
|
2020-11-27 14:41:11 -05:00
|
|
|
sub_bbt = tmap->bbt_at (timepos_t (offset - when));
|
2016-10-15 11:33:49 -04:00
|
|
|
} else {
|
2021-03-25 12:24:20 -04:00
|
|
|
BBT = tmap->bbt_at (timepos_t (tmap->quarters_at (when + offset)));
|
2020-11-27 14:41:11 -05:00
|
|
|
sub_bbt = tmap->bbt_at (timepos_t (offset));
|
2016-10-15 12:26:30 -04:00
|
|
|
}
|
2016-10-15 11:33:49 -04:00
|
|
|
|
2016-10-15 12:26:30 -04:00
|
|
|
BBT.bars -= sub_bbt.bars;
|
|
|
|
|
|
|
|
if (BBT.ticks < sub_bbt.ticks) {
|
|
|
|
if (BBT.beats == 1) {
|
2016-10-15 11:33:49 -04:00
|
|
|
BBT.bars--;
|
2016-10-15 12:26:30 -04:00
|
|
|
BBT.beats = divisions;
|
2016-10-15 11:33:49 -04:00
|
|
|
} else {
|
2016-10-15 12:26:30 -04:00
|
|
|
BBT.beats--;
|
2016-10-15 11:33:49 -04:00
|
|
|
}
|
2020-07-23 19:46:49 -04:00
|
|
|
BBT.ticks = Temporal::ticks_per_beat - (sub_bbt.ticks - BBT.ticks);
|
2016-10-15 12:26:30 -04:00
|
|
|
} else {
|
|
|
|
BBT.ticks -= sub_bbt.ticks;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BBT.beats < sub_bbt.beats) {
|
|
|
|
BBT.bars--;
|
|
|
|
BBT.beats = divisions - (sub_bbt.beats - BBT.beats);
|
|
|
|
} else {
|
|
|
|
BBT.beats -= sub_bbt.beats;
|
2016-10-15 11:33:49 -04:00
|
|
|
}
|
2008-12-12 09:43:24 -05:00
|
|
|
}
|
|
|
|
} else {
|
2020-11-27 14:41:11 -05:00
|
|
|
BBT = TempoMap::use()->bbt_at (when);
|
2008-04-11 10:06:50 -04:00
|
|
|
}
|
2020-11-24 17:06:35 -05:00
|
|
|
|
2011-11-18 13:22:00 -05:00
|
|
|
if (negative) {
|
2012-11-11 09:31:17 -05:00
|
|
|
snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
|
2011-11-20 10:10:53 -05:00
|
|
|
BBT.bars, BBT.beats, BBT.ticks);
|
2011-11-18 13:22:00 -05:00
|
|
|
} else {
|
2012-11-11 09:31:17 -05:00
|
|
|
snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
|
2011-11-20 10:10:53 -05:00
|
|
|
BBT.bars, BBT.beats, BBT.ticks);
|
2011-11-18 13:22:00 -05:00
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
_layout->set_text (buf);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2016-12-11 11:24:30 -05:00
|
|
|
if (_with_info) {
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t pos;
|
2008-04-11 10:06:50 -04:00
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (bbt_reference_time.is_negative ()) {
|
2008-04-11 10:06:50 -04:00
|
|
|
pos = when;
|
|
|
|
} else {
|
|
|
|
pos = bbt_reference_time;
|
|
|
|
}
|
|
|
|
|
2020-11-27 14:41:11 -05:00
|
|
|
TempoMetric m (TempoMap::use()->metric_at (pos));
|
2008-04-11 10:06:50 -04:00
|
|
|
|
2020-08-14 19:53:22 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
|
|
|
/* UTF8 1/4 note and 1/8 note ♩ (\u2669) and ♪ (\u266a) are n/a on Windows */
|
2016-12-11 11:24:30 -05:00
|
|
|
if (m.tempo().note_type() == 4) {
|
2021-11-12 16:21:40 -05:00
|
|
|
snprintf (buf, sizeof(buf), "\u2669 = %.3f", m.tempo().note_types_per_minute_at_DOUBLE (pos));
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text (string_compose ("%1", buf), false);
|
2016-12-11 11:24:30 -05:00
|
|
|
} else if (m.tempo().note_type() == 8) {
|
2021-11-12 16:21:40 -05:00
|
|
|
snprintf (buf, sizeof(buf), "\u266a = %.3f", m.tempo().note_types_per_minute_at_DOUBLE (pos));
|
2020-05-12 09:08:39 -04:00
|
|
|
_left_btn.set_text (string_compose ("%1", buf), false);
|
2020-08-14 19:53:22 -04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2021-11-12 16:21:40 -05:00
|
|
|
snprintf (buf, sizeof(buf), "1/%d = %.3f",m.tempo().note_type(), m.tempo().note_types_per_minute_at_DOUBLE (pos));
|
2021-04-13 13:46:47 -04:00
|
|
|
_left_btn.set_text (buf, false);
|
2016-12-11 11:24:30 -05:00
|
|
|
}
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2020-11-24 17:06:35 -05:00
|
|
|
snprintf (buf, sizeof(buf), "%d/%d", m.meter().divisions_per_bar(), m.meter().note_value());
|
2020-05-12 09:08:39 -04:00
|
|
|
_right_btn.set_text (string_compose ("%1: %2", S_("TimeSignature|TS"), buf), false);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_session (Session *s)
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
SessionHandlePtr::set_session (s);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
if (_session) {
|
2007-01-08 12:12:29 -05:00
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
int64_t limit_sec = UIConfiguration::instance().get_clock_display_limit ();
|
2020-12-02 00:34:32 -05:00
|
|
|
|
2017-05-08 06:37:17 -04:00
|
|
|
if (limit_sec > 0) {
|
2020-12-02 00:34:32 -05:00
|
|
|
_limit_pos = timepos_t (limit_sec * _session->sample_rate());
|
2017-05-08 06:37:17 -04:00
|
|
|
}
|
|
|
|
|
2016-12-11 11:24:30 -05:00
|
|
|
Config->ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_configuration_changed, this, _1), gui_context());
|
2010-12-01 15:49:22 -05:00
|
|
|
_session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_configuration_changed, this, _1), gui_context());
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
XMLNode* node = _session->extra_xml (X_("ClockModes"));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-01-08 12:12:29 -05:00
|
|
|
if (node) {
|
2011-06-07 19:07:08 -04:00
|
|
|
for (XMLNodeList::const_iterator i = node->children().begin(); i != node->children().end(); ++i) {
|
2016-08-30 03:16:34 -04:00
|
|
|
std::string name;
|
|
|
|
if ((*i)->get_property (X_("name"), name) && name == _name) {
|
2011-06-07 19:07:08 -04:00
|
|
|
|
2016-08-30 03:16:34 -04:00
|
|
|
AudioClock::Mode amode;
|
|
|
|
if ((*i)->get_property (X_("mode"), amode)) {
|
2016-04-24 08:39:12 -04:00
|
|
|
set_mode (amode, true);
|
2011-06-07 19:07:08 -04:00
|
|
|
}
|
2016-08-30 03:16:34 -04:00
|
|
|
bool on;
|
|
|
|
if ((*i)->get_property (X_("on"), on)) {
|
|
|
|
set_off (!on);
|
2011-06-07 19:07:08 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-01-08 12:12:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (last_when, true);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
bool
|
|
|
|
AudioClock::on_key_press_event (GdkEventKey* ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!editing) {
|
2011-06-02 13:47:58 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
string new_text;
|
|
|
|
char new_char = 0;
|
2011-11-21 14:24:37 -05:00
|
|
|
int highlight_length;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t pos;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_0:
|
|
|
|
case GDK_KP_0:
|
|
|
|
new_char = '0';
|
|
|
|
break;
|
|
|
|
case GDK_1:
|
|
|
|
case GDK_KP_1:
|
|
|
|
new_char = '1';
|
|
|
|
break;
|
|
|
|
case GDK_2:
|
|
|
|
case GDK_KP_2:
|
|
|
|
new_char = '2';
|
|
|
|
break;
|
|
|
|
case GDK_3:
|
|
|
|
case GDK_KP_3:
|
|
|
|
new_char = '3';
|
|
|
|
break;
|
|
|
|
case GDK_4:
|
|
|
|
case GDK_KP_4:
|
|
|
|
new_char = '4';
|
|
|
|
break;
|
|
|
|
case GDK_5:
|
|
|
|
case GDK_KP_5:
|
|
|
|
new_char = '5';
|
|
|
|
break;
|
|
|
|
case GDK_6:
|
|
|
|
case GDK_KP_6:
|
|
|
|
new_char = '6';
|
|
|
|
break;
|
|
|
|
case GDK_7:
|
|
|
|
case GDK_KP_7:
|
|
|
|
new_char = '7';
|
|
|
|
break;
|
|
|
|
case GDK_8:
|
|
|
|
case GDK_KP_8:
|
|
|
|
new_char = '8';
|
|
|
|
break;
|
|
|
|
case GDK_9:
|
|
|
|
case GDK_KP_9:
|
|
|
|
new_char = '9';
|
|
|
|
break;
|
|
|
|
|
2011-11-17 20:22:40 -05:00
|
|
|
case GDK_minus:
|
|
|
|
case GDK_KP_Subtract:
|
2012-11-11 17:20:40 -05:00
|
|
|
if (_negative_allowed && input_string.empty()) {
|
|
|
|
edit_is_negative = true;
|
2012-11-13 19:15:54 -05:00
|
|
|
edit_string.replace(0,1,"-");
|
|
|
|
_layout->set_text (edit_string);
|
|
|
|
queue_draw ();
|
2012-11-11 17:20:40 -05:00
|
|
|
} else {
|
|
|
|
end_edit_relative (false);
|
|
|
|
}
|
2011-11-18 00:04:18 -05:00
|
|
|
return true;
|
2011-11-17 20:22:40 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_plus:
|
|
|
|
end_edit_relative (true);
|
2011-11-18 00:04:18 -05:00
|
|
|
return true;
|
2011-11-17 20:22:40 -05:00
|
|
|
break;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
case GDK_Tab:
|
2008-09-10 11:03:30 -04:00
|
|
|
case GDK_Return:
|
|
|
|
case GDK_KP_Enter:
|
2011-11-17 17:49:13 -05:00
|
|
|
end_edit (true);
|
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Escape:
|
2011-11-17 17:49:13 -05:00
|
|
|
end_edit (false);
|
2008-09-10 11:03:30 -04:00
|
|
|
ChangeAborted(); /* EMIT SIGNAL */
|
2007-05-22 20:06:16 -04:00
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-18 18:46:55 -05:00
|
|
|
case GDK_Delete:
|
|
|
|
case GDK_BackSpace:
|
2011-11-20 22:37:22 -05:00
|
|
|
if (!input_string.empty()) {
|
2011-11-21 11:34:02 -05:00
|
|
|
/* delete the last key entered
|
2011-11-20 22:37:22 -05:00
|
|
|
*/
|
2011-11-21 11:34:02 -05:00
|
|
|
input_string = input_string.substr (0, input_string.length() - 1);
|
2011-11-20 22:37:22 -05:00
|
|
|
}
|
2011-11-18 18:46:55 -05:00
|
|
|
goto use_input_string;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
default:
|
2015-09-22 18:24:49 -04:00
|
|
|
/* do not allow other keys to passthru to the rest of the GUI
|
|
|
|
when editing.
|
|
|
|
*/
|
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
if (!insert_map.empty() && (input_string.length() >= insert_map.size())) {
|
2011-11-20 22:37:22 -05:00
|
|
|
/* too many digits: eat the key event, but do nothing with it */
|
2011-11-17 17:49:13 -05:00
|
|
|
return true;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-21 11:34:02 -05:00
|
|
|
input_string.push_back (new_char);
|
2011-11-18 18:46:55 -05:00
|
|
|
|
|
|
|
use_input_string:
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
switch (_mode) {
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
2011-11-18 17:17:59 -05:00
|
|
|
/* get this one in the right order, and to the right width */
|
2011-11-21 14:24:37 -05:00
|
|
|
if (ev->keyval == GDK_Delete || ev->keyval == GDK_BackSpace) {
|
2011-11-18 18:46:55 -05:00
|
|
|
edit_string = edit_string.substr (0, edit_string.length() - 1);
|
2011-11-21 14:24:37 -05:00
|
|
|
} else {
|
|
|
|
edit_string.push_back (new_char);
|
2011-11-18 18:46:55 -05:00
|
|
|
}
|
|
|
|
if (!edit_string.empty()) {
|
2011-11-21 11:34:02 -05:00
|
|
|
char buf[32];
|
2011-11-18 18:46:55 -05:00
|
|
|
sscanf (edit_string.c_str(), "%" PRId64, &pos);
|
|
|
|
snprintf (buf, sizeof (buf), " %10" PRId64, pos);
|
|
|
|
edit_string = buf;
|
|
|
|
}
|
2011-11-21 11:34:02 -05:00
|
|
|
/* highlight the whole thing */
|
2011-11-17 17:49:13 -05:00
|
|
|
highlight_length = edit_string.length();
|
|
|
|
break;
|
2011-11-21 11:34:02 -05:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
default:
|
|
|
|
highlight_length = merge_input_and_edit_string ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2011-11-21 14:24:37 -05:00
|
|
|
|
2012-11-13 19:15:54 -05:00
|
|
|
if (edit_is_negative) {
|
|
|
|
edit_string.replace(0,1,"-");
|
|
|
|
} else {
|
2012-12-19 12:07:27 -05:00
|
|
|
if (!pre_edit_string.empty() && (pre_edit_string.at(0) == '-')) {
|
2012-11-13 22:35:23 -05:00
|
|
|
edit_string.replace(0,1,"_");
|
|
|
|
} else {
|
|
|
|
edit_string.replace(0,1," ");
|
|
|
|
}
|
2012-11-13 19:15:54 -05:00
|
|
|
}
|
|
|
|
|
2011-11-21 11:34:02 -05:00
|
|
|
show_edit_status (highlight_length);
|
|
|
|
_layout->set_text (edit_string);
|
|
|
|
queue_draw ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
return true;
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
int
|
|
|
|
AudioClock::merge_input_and_edit_string ()
|
|
|
|
{
|
|
|
|
/* merge with pre-edit-string into edit string */
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
edit_string = pre_edit_string;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
if (input_string.empty()) {
|
|
|
|
return 0;
|
2012-11-11 09:31:17 -05:00
|
|
|
}
|
2011-11-21 14:24:37 -05:00
|
|
|
|
|
|
|
string::size_type target;
|
|
|
|
for (string::size_type i = 0; i < input_string.length(); ++i) {
|
|
|
|
target = insert_map[input_string.length() - 1 - i];
|
|
|
|
edit_string[target] = input_string[i];
|
|
|
|
}
|
|
|
|
/* highlight from end to wherever the last character was added */
|
|
|
|
return edit_string.length() - insert_map[input_string.length()-1];
|
|
|
|
}
|
|
|
|
|
2011-11-20 22:37:22 -05:00
|
|
|
|
|
|
|
bool
|
|
|
|
AudioClock::on_key_release_event (GdkEventKey *ev)
|
|
|
|
{
|
|
|
|
if (!editing) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-20 22:37:22 -05:00
|
|
|
/* return true for keys that we used on press
|
|
|
|
so that they cannot possibly do double-duty
|
|
|
|
*/
|
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_0:
|
|
|
|
case GDK_KP_0:
|
|
|
|
case GDK_1:
|
|
|
|
case GDK_KP_1:
|
|
|
|
case GDK_2:
|
|
|
|
case GDK_KP_2:
|
|
|
|
case GDK_3:
|
|
|
|
case GDK_KP_3:
|
|
|
|
case GDK_4:
|
|
|
|
case GDK_KP_4:
|
|
|
|
case GDK_5:
|
|
|
|
case GDK_KP_5:
|
|
|
|
case GDK_6:
|
|
|
|
case GDK_KP_6:
|
|
|
|
case GDK_7:
|
|
|
|
case GDK_KP_7:
|
|
|
|
case GDK_8:
|
|
|
|
case GDK_KP_8:
|
|
|
|
case GDK_9:
|
|
|
|
case GDK_KP_9:
|
|
|
|
case GDK_period:
|
|
|
|
case GDK_comma:
|
|
|
|
case GDK_KP_Decimal:
|
|
|
|
case GDK_Tab:
|
|
|
|
case GDK_Return:
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
case GDK_Escape:
|
|
|
|
case GDK_minus:
|
|
|
|
case GDK_plus:
|
|
|
|
case GDK_KP_Add:
|
|
|
|
case GDK_KP_Subtract:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::Field
|
|
|
|
AudioClock::index_to_field (int index) const
|
|
|
|
{
|
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
if (index < 4) {
|
|
|
|
return Timecode_Hours;
|
|
|
|
} else if (index < 7) {
|
|
|
|
return Timecode_Minutes;
|
|
|
|
} else if (index < 10) {
|
|
|
|
return Timecode_Seconds;
|
2011-11-18 21:36:30 -05:00
|
|
|
} else {
|
2017-09-18 12:39:17 -04:00
|
|
|
return Timecode_frames;
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BBT:
|
|
|
|
if (index < 5) {
|
|
|
|
return Bars;
|
|
|
|
} else if (index < 7) {
|
|
|
|
return Beats;
|
2011-11-18 21:36:30 -05:00
|
|
|
} else {
|
2011-11-17 17:49:13 -05:00
|
|
|
return Ticks;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MinSec:
|
|
|
|
if (index < 3) {
|
|
|
|
return Timecode_Hours;
|
|
|
|
} else if (index < 6) {
|
|
|
|
return MS_Minutes;
|
|
|
|
} else if (index < 9) {
|
|
|
|
return MS_Seconds;
|
2011-11-18 21:36:30 -05:00
|
|
|
} else {
|
2011-11-17 17:49:13 -05:00
|
|
|
return MS_Milliseconds;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
|
|
|
if (index < 10) {
|
|
|
|
return SS_Seconds;
|
|
|
|
} else {
|
|
|
|
return SS_Deciseconds;
|
|
|
|
}
|
|
|
|
break;
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
|
|
|
return S_Samples;
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2008-09-10 11:03:30 -04:00
|
|
|
}
|
2011-11-18 15:44:13 -05:00
|
|
|
|
|
|
|
return Field (0);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2005-12-12 15:54:55 -05:00
|
|
|
bool
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::on_button_press_event (GdkEventButton *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2017-05-31 13:04:03 -04:00
|
|
|
if (!_session || _session->actively_recording()) {
|
|
|
|
/* swallow event, do nothing */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-02 13:47:58 -04:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
2011-11-18 13:06:16 -05:00
|
|
|
if (editable && !_off) {
|
2011-11-17 17:49:13 -05:00
|
|
|
int index;
|
|
|
|
int trailing;
|
2011-11-18 13:06:16 -05:00
|
|
|
int y;
|
|
|
|
int x;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2011-11-18 13:06:16 -05:00
|
|
|
/* the text has been centered vertically, so adjust
|
2012-11-11 09:31:17 -05:00
|
|
|
* x and y.
|
2011-11-18 13:06:16 -05:00
|
|
|
*/
|
2012-12-29 10:59:38 -05:00
|
|
|
int xcenter = (get_width() - layout_width) /2;
|
2011-11-18 13:06:16 -05:00
|
|
|
|
2016-12-16 19:40:22 -05:00
|
|
|
y = ev->y - ((get_height() - layout_height)/2);
|
2012-12-29 10:59:38 -05:00
|
|
|
x = ev->x - xcenter;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2012-11-06 14:30:36 -05:00
|
|
|
if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
|
|
|
|
/* pretend it is a character on the far right */
|
|
|
|
index = 99;
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2012-11-06 14:30:36 -05:00
|
|
|
drag_field = index_to_field (index);
|
|
|
|
dragging = true;
|
|
|
|
/* make absolutely sure that the pointer is grabbed */
|
|
|
|
gdk_pointer_grab(ev->window,false ,
|
|
|
|
GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
|
|
|
|
NULL,NULL,ev->time);
|
|
|
|
drag_accum = 0;
|
|
|
|
drag_start_y = ev->y;
|
|
|
|
drag_y = ev->y;
|
2011-06-03 18:18:47 -04:00
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-06-02 13:47:58 -04:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-22 20:06:16 -04:00
|
|
|
|
2011-06-02 13:47:58 -04:00
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2005-12-12 15:54:55 -05:00
|
|
|
bool
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::on_button_release_event (GdkEventButton *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2017-05-31 13:04:03 -04:00
|
|
|
if (!_session || _session->actively_recording()) {
|
|
|
|
/* swallow event, do nothing */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-18 13:06:16 -05:00
|
|
|
if (editable && !_off) {
|
2011-06-07 14:20:22 -04:00
|
|
|
if (dragging) {
|
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
dragging = false;
|
|
|
|
if (ev->y > drag_start_y+1 || ev->y < drag_start_y-1 || Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)){
|
2011-11-17 17:49:13 -05:00
|
|
|
// we actually dragged so return without
|
|
|
|
// setting editing focus, or we shift clicked
|
2011-06-07 14:20:22 -04:00
|
|
|
return true;
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
|
|
|
if (ev->button == 1) {
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
if (_edit_by_click_field) {
|
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
int xcenter = (get_width() - layout_width) /2;
|
2011-11-21 14:24:37 -05:00
|
|
|
int index = 0;
|
|
|
|
int trailing;
|
2016-12-16 19:40:22 -05:00
|
|
|
int y = ev->y - ((get_height() - layout_height)/2);
|
2012-12-29 10:59:38 -05:00
|
|
|
int x = ev->x - xcenter;
|
2011-11-21 14:24:37 -05:00
|
|
|
Field f;
|
|
|
|
|
|
|
|
if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
f = index_to_field (index);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 14:24:37 -05:00
|
|
|
switch (f) {
|
2017-09-18 12:39:17 -04:00
|
|
|
case Timecode_frames:
|
2011-11-21 14:24:37 -05:00
|
|
|
case MS_Milliseconds:
|
|
|
|
case Ticks:
|
2017-11-22 14:36:28 -05:00
|
|
|
case SS_Deciseconds:
|
2011-11-21 14:24:37 -05:00
|
|
|
f = Field (0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
start_edit (f);
|
|
|
|
} else {
|
|
|
|
start_edit ();
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2011-06-07 14:20:22 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Keyboard::is_context_menu_event (ev)) {
|
|
|
|
if (ops_menu == 0) {
|
|
|
|
build_ops_menu ();
|
|
|
|
}
|
2017-03-24 09:36:17 -04:00
|
|
|
ops_menu->popup (1, ev->time);
|
2007-05-22 20:06:16 -04:00
|
|
|
return true;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-06-07 14:20:22 -04:00
|
|
|
return false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2011-11-17 20:22:40 -05:00
|
|
|
bool
|
|
|
|
AudioClock::on_focus_out_event (GdkEventFocus* ev)
|
|
|
|
{
|
|
|
|
bool ret = CairoWidget::on_focus_out_event (ev);
|
|
|
|
|
2011-11-18 11:48:01 -05:00
|
|
|
if (editing) {
|
2015-06-16 11:18:23 -04:00
|
|
|
end_edit (_accept_on_focus_out);
|
2011-11-18 11:48:01 -05:00
|
|
|
}
|
2011-11-17 20:22:40 -05:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-12 15:54:55 -05:00
|
|
|
bool
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::on_scroll_event (GdkEventScroll *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
int index;
|
|
|
|
int trailing;
|
|
|
|
|
2017-05-31 13:04:03 -04:00
|
|
|
if (editing || _session == 0 || !editable || _off || _session->actively_recording()) {
|
2007-05-22 20:06:16 -04:00
|
|
|
return false;
|
|
|
|
}
|
2006-04-09 22:14:05 -04:00
|
|
|
|
2011-11-18 13:06:16 -05:00
|
|
|
int y;
|
|
|
|
int x;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 13:06:16 -05:00
|
|
|
/* the text has been centered vertically, so adjust
|
2012-11-11 09:31:17 -05:00
|
|
|
* x and y.
|
2011-11-18 13:06:16 -05:00
|
|
|
*/
|
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
int xcenter = (get_width() - layout_width) /2;
|
2016-12-16 19:40:22 -05:00
|
|
|
y = ev->y - ((get_height() - layout_height)/2);
|
2012-12-29 10:59:38 -05:00
|
|
|
x = ev->x - xcenter;
|
2011-11-18 13:06:16 -05:00
|
|
|
|
|
|
|
if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
|
2011-11-17 17:49:13 -05:00
|
|
|
/* not in the main layout */
|
|
|
|
return false;
|
2011-06-08 14:29:36 -04:00
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
Field f = index_to_field (index);
|
2021-03-17 19:26:33 -04:00
|
|
|
timepos_t step;
|
2006-04-09 22:14:05 -04:00
|
|
|
|
|
|
|
switch (ev->direction) {
|
|
|
|
|
|
|
|
case GDK_SCROLL_UP:
|
2021-03-18 13:58:22 -04:00
|
|
|
step = get_incremental_step (f, current_time());
|
2021-12-11 09:51:31 -05:00
|
|
|
if (!step.is_zero ()) {
|
2011-06-03 18:18:47 -04:00
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
2021-03-17 19:26:33 -04:00
|
|
|
step *= 10;
|
2011-06-03 18:18:47 -04:00
|
|
|
}
|
2021-03-17 19:26:33 -04:00
|
|
|
AudioClock::set (current_time() + step, true);
|
2011-06-03 18:18:47 -04:00
|
|
|
ValueChanged (); /* EMIT_SIGNAL */
|
|
|
|
}
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2006-04-09 22:14:05 -04:00
|
|
|
case GDK_SCROLL_DOWN:
|
2021-03-18 13:58:22 -04:00
|
|
|
step = get_incremental_step (f, current_time());
|
2021-12-11 09:51:31 -05:00
|
|
|
if (!step.is_zero ()) {
|
2011-06-03 18:18:47 -04:00
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
2021-03-17 19:26:33 -04:00
|
|
|
step *= 10;
|
2011-06-03 18:18:47 -04:00
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2021-03-17 19:26:33 -04:00
|
|
|
if (!_negative_allowed && current_time() < step) {
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set (timepos_t (), true);
|
2011-06-03 18:18:47 -04:00
|
|
|
} else {
|
2021-03-17 19:26:33 -04:00
|
|
|
AudioClock::set (current_time().earlier (step), true);
|
2011-06-03 18:18:47 -04:00
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-06-03 18:18:47 -04:00
|
|
|
ValueChanged (); /* EMIT_SIGNAL */
|
|
|
|
}
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2006-04-09 22:14:05 -04:00
|
|
|
default:
|
2007-05-22 20:06:16 -04:00
|
|
|
return false;
|
2006-04-09 22:14:05 -04:00
|
|
|
break;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2007-05-22 20:06:16 -04:00
|
|
|
return true;
|
2006-04-09 22:14:05 -04:00
|
|
|
}
|
|
|
|
|
2005-12-12 15:54:55 -05:00
|
|
|
bool
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::on_motion_notify_event (GdkEventMotion *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2017-05-31 13:04:03 -04:00
|
|
|
if (editing || _session == 0 || !dragging || _session->actively_recording()) {
|
2007-05-22 20:06:16 -04:00
|
|
|
return false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
const double y_delta = ev->y - drag_y;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
drag_accum += y_delta;
|
|
|
|
drag_y = ev->y;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
if (drag_accum) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
timepos_t pos = current_time ();
|
|
|
|
timepos_t step = get_incremental_step (drag_field, pos);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
step *= fabs (drag_accum);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
if (drag_accum > 0) { /* positive, so downward motion ... decrement clock */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2021-12-11 09:51:31 -05:00
|
|
|
if (!step.is_zero () && (step < pos)) {
|
2021-03-18 13:58:22 -04:00
|
|
|
AudioClock::set (pos.earlier (step), false);
|
|
|
|
} else {
|
|
|
|
AudioClock::set (timepos_t () , false);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { /* negative so upward motion .. increment clock */
|
|
|
|
AudioClock::set (pos + step, false);
|
2017-05-31 13:04:03 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2021-03-18 13:58:22 -04:00
|
|
|
|
|
|
|
drag_accum = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
ValueChanged(); /* EMIT_SIGNAL */
|
2021-03-18 13:58:22 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2007-05-22 20:06:16 -04:00
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2021-03-17 19:26:33 -04:00
|
|
|
timepos_t
|
2021-03-18 13:58:22 -04:00
|
|
|
AudioClock::get_incremental_step (Field field, timepos_t const & pos)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2021-03-17 19:26:33 -04:00
|
|
|
timepos_t f;
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time BBT;
|
2021-03-17 19:26:33 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
switch (field) {
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Hours:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (floor (3600.0 * _session->sample_rate()));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Minutes:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (floor (60.0 * _session->sample_rate()));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Seconds:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (_session->sample_rate());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2017-09-18 12:39:17 -04:00
|
|
|
case Timecode_frames:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (floor (_session->sample_rate() / _session->timecode_frames_per_second()));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
case S_Samples:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (1);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case SS_Seconds:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (_session->sample_rate());
|
2017-11-22 14:36:28 -05:00
|
|
|
break;
|
|
|
|
case SS_Deciseconds:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (_session->sample_rate() / 10.f);
|
2017-11-22 14:36:28 -05:00
|
|
|
break;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
case MS_Hours:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (floor (3600.0 * _session->sample_rate()));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case MS_Minutes:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (floor (60.0 * _session->sample_rate()));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case MS_Seconds:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (_session->sample_rate());
|
2011-05-21 21:18:05 -04:00
|
|
|
break;
|
|
|
|
case MS_Milliseconds:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (floor (_session->sample_rate() / 1000.0));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Bars:
|
2011-06-02 13:47:58 -04:00
|
|
|
BBT.bars = 1;
|
|
|
|
BBT.beats = 0;
|
|
|
|
BBT.ticks = 0;
|
2021-03-17 19:26:33 -04:00
|
|
|
f = TempoMap::use()->bbt_duration_at (pos,BBT);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case Beats:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (Temporal::Beats (1, 0));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case Ticks:
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (Temporal::Beats (0, 1));
|
2011-06-02 13:47:58 -04:00
|
|
|
break;
|
|
|
|
default:
|
2017-09-18 12:39:17 -04:00
|
|
|
error << string_compose (_("programming error: %1"), "attempt to get samples from non-text field!") << endmsg;
|
2021-03-17 19:26:33 -04:00
|
|
|
f = timepos_t (0);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-06-02 13:47:58 -04:00
|
|
|
return f;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timepos_t
|
|
|
|
AudioClock::current_time () const
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-11-18 00:04:18 -05:00
|
|
|
return last_when;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t
|
|
|
|
AudioClock::current_duration (timepos_t pos) const
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2020-09-29 19:53:43 -04:00
|
|
|
timecnt_t ret;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
switch (_mode) {
|
|
|
|
case BBT:
|
2020-12-06 14:57:48 -05:00
|
|
|
ret = timecnt_t (sample_duration_from_bbt_string (pos, _layout->get_text()));
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case Timecode:
|
2005-09-25 14:42:24 -04:00
|
|
|
case MinSec:
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
2020-09-29 19:53:43 -04:00
|
|
|
ret = timecnt_t (last_when, pos);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-02-20 17:19:43 -05:00
|
|
|
AudioClock::bbt_validate_edit (string & str)
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
AnyTime any;
|
|
|
|
|
2011-11-20 10:10:53 -05:00
|
|
|
if (sscanf (str.c_str(), BBT_SCANF_FORMAT, &any.bbt.bars, &any.bbt.beats, &any.bbt.ticks) != 3) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-21 12:51:15 -05:00
|
|
|
|
2020-07-23 19:46:49 -04:00
|
|
|
if (any.bbt.ticks > Temporal::ticks_per_beat) {
|
2011-11-21 12:51:15 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!is_duration && any.bbt.bars == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_duration && any.bbt.beats == 0) {
|
2018-02-20 17:19:43 -05:00
|
|
|
/* user could not have mean zero beats because for a
|
|
|
|
* non-duration clock that's impossible. Assume that they
|
|
|
|
* mis-entered things and meant Bar|1|ticks
|
|
|
|
*/
|
|
|
|
|
|
|
|
char buf[128];
|
|
|
|
snprintf (buf, sizeof (buf), "%" PRIu32 "|%" PRIu32 "|%" PRIu32, any.bbt.bars, 1, any.bbt.ticks);
|
|
|
|
str = buf;
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-02 16:29:46 -04:00
|
|
|
AudioClock::timecode_validate_edit (const string&)
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
Timecode::Time TC;
|
2012-11-13 15:29:28 -05:00
|
|
|
int hours;
|
2012-11-12 21:25:59 -05:00
|
|
|
char ignored[2];
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2012-11-15 08:19:07 -05:00
|
|
|
if (sscanf (_layout->get_text().c_str(), "%[- _]%" PRId32 ":%" PRId32 ":%" PRId32 "%[:;]%" PRId32,
|
2017-07-01 12:42:24 -04:00
|
|
|
ignored, &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 6) {
|
2012-11-13 15:29:28 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hours < 0) {
|
|
|
|
TC.hours = hours * -1;
|
|
|
|
TC.negative = true;
|
|
|
|
} else {
|
|
|
|
TC.hours = hours;
|
|
|
|
TC.negative = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TC.negative && !_negative_allowed) {
|
2011-11-17 17:49:13 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-21 12:51:15 -05:00
|
|
|
if (TC.hours > 23U || TC.minutes > 59U || TC.seconds > 59U) {
|
2011-11-17 17:49:13 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-27 06:44:42 -05:00
|
|
|
if (TC.frames > (uint32_t) rint (_session->timecode_frames_per_second()) - 1) {
|
2011-11-17 17:49:13 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_session->timecode_drop_frames()) {
|
2011-11-21 12:03:06 -05:00
|
|
|
if (TC.minutes % 10 && TC.seconds == 0U && TC.frames < 2U) {
|
2011-11-17 17:49:13 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-21 12:51:15 -05:00
|
|
|
bool
|
|
|
|
AudioClock::minsec_validate_edit (const string& str)
|
|
|
|
{
|
|
|
|
int hrs, mins, secs, millisecs;
|
|
|
|
|
|
|
|
if (sscanf (str.c_str(), "%d:%d:%d.%d", &hrs, &mins, &secs, &millisecs) != 4) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-21 12:51:15 -05:00
|
|
|
if (hrs > 23 || mins > 59 || secs > 59 || millisecs > 999) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
|
|
|
AudioClock::samples_from_timecode_string (const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_session == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timecode::Time TC;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t sample;
|
2012-11-12 21:25:59 -05:00
|
|
|
char ignored[2];
|
2012-11-13 15:29:28 -05:00
|
|
|
int hours;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2012-11-15 08:19:07 -05:00
|
|
|
if (sscanf (str.c_str(), "%[- _]%d:%d:%d%[:;]%d", ignored, &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 6) {
|
2011-11-18 17:17:59 -05:00
|
|
|
error << string_compose (_("programming error: %1 %2"), "badly formatted timecode clock string", str) << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-13 15:29:28 -05:00
|
|
|
TC.hours = abs(hours);
|
2011-11-17 17:49:13 -05:00
|
|
|
TC.rate = _session->timecode_frames_per_second();
|
|
|
|
TC.drop= _session->timecode_drop_frames();
|
|
|
|
|
|
|
|
_session->timecode_to_sample (TC, sample, false /* use_offset */, false /* use_subframes */ );
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
// timecode_tester ();
|
2012-11-13 15:29:28 -05:00
|
|
|
if (edit_is_negative) {
|
|
|
|
sample = - sample;
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
return sample;
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
|
|
|
AudioClock::samples_from_minsec_string (const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_session == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hrs, mins, secs, millisecs;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t sr = _session->sample_rate();
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
if (sscanf (str.c_str(), "%d:%d:%d.%d", &hrs, &mins, &secs, &millisecs) != 4) {
|
|
|
|
error << string_compose (_("programming error: %1 %2"), "badly formatted minsec clock string", str) << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
return (samplepos_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr) + (millisecs * sr / 1000.0));
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::samples_from_bbt_string (timepos_t const & pos, const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_session == 0) {
|
|
|
|
error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-24 17:06:35 -05:00
|
|
|
BBT_Time bbt;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2020-11-24 17:06:35 -05:00
|
|
|
if (sscanf (str.c_str(), BBT_SCANF_FORMAT, &bbt.bars, &bbt.beats, &bbt.ticks) != 3) {
|
2011-11-20 10:10:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (is_duration) {
|
2020-11-24 17:06:35 -05:00
|
|
|
bbt.bars++;
|
|
|
|
bbt.beats++;
|
2020-11-27 14:41:11 -05:00
|
|
|
return TempoMap::use()->bbt_duration_at (pos, bbt).samples();
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
2021-11-17 17:57:30 -05:00
|
|
|
return TempoMap::use()->sample_at (bbt);
|
2017-07-01 12:42:24 -04:00
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::sample_duration_from_bbt_string (timepos_t const & pos, const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_session == 0) {
|
2017-09-18 12:39:17 -04:00
|
|
|
error << "AudioClock::sample_duration_from_bbt_string() called with BBT mode but without session!" << endmsg;
|
2011-11-17 17:49:13 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time bbt;
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2011-12-26 21:15:28 -05:00
|
|
|
if (sscanf (str.c_str(), BBT_SCANF_FORMAT, &bbt.bars, &bbt.beats, &bbt.ticks) != 3) {
|
2011-11-20 10:10:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2012-10-01 16:55:10 -04:00
|
|
|
|
2020-11-27 14:41:11 -05:00
|
|
|
return TempoMap::use()->bbt_duration_at(pos,bbt).samples();
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
2017-11-22 14:36:28 -05:00
|
|
|
AudioClock::samples_from_seconds_string (const string& str) const
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
sscanf (str.c_str(), "%f", &f);
|
|
|
|
return f * _session->sample_rate();
|
|
|
|
}
|
|
|
|
|
|
|
|
samplepos_t
|
|
|
|
AudioClock::samples_from_audiosamples_string (const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t f;
|
2011-11-18 00:04:18 -05:00
|
|
|
sscanf (str.c_str(), "%" PRId64, &f);
|
2011-11-17 17:49:13 -05:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2015-04-14 05:55:39 -04:00
|
|
|
void
|
|
|
|
AudioClock::copy_text_to_clipboard () const
|
|
|
|
{
|
|
|
|
string val;
|
|
|
|
if (editing) {
|
|
|
|
val = pre_edit_string;
|
|
|
|
} else {
|
|
|
|
val = _layout->get_text ();
|
|
|
|
}
|
|
|
|
const size_t trim = val.find_first_not_of(" ");
|
|
|
|
if (trim == string::npos) {
|
|
|
|
assert(0); // empty clock, can't be right.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Glib::RefPtr<Clipboard> cl = Gtk::Clipboard::get();
|
|
|
|
cl->set_text (val.substr(trim));
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::build_ops_menu ()
|
|
|
|
{
|
|
|
|
using namespace Menu_Helpers;
|
|
|
|
ops_menu = new Menu;
|
|
|
|
MenuList& ops_items = ops_menu->items();
|
|
|
|
ops_menu->set_name ("ArdourContextMenu");
|
|
|
|
|
2016-04-24 08:39:12 -04:00
|
|
|
ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode, false)));
|
|
|
|
ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT, false)));
|
|
|
|
ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec, false)));
|
2017-11-22 14:36:28 -05:00
|
|
|
ops_items.push_back (MenuElem (_("Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Seconds, false)));
|
2017-09-18 12:39:17 -04:00
|
|
|
ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Samples, false)));
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2011-11-18 13:06:16 -05:00
|
|
|
if (editable && !_off && !is_duration && !_follows_playhead) {
|
2011-11-17 17:49:13 -05:00
|
|
|
ops_items.push_back (SeparatorElem());
|
2015-11-29 14:17:11 -05:00
|
|
|
ops_items.push_back (MenuElem (_("Set from Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
|
2011-11-17 17:49:13 -05:00
|
|
|
ops_items.push_back (MenuElem (_("Locate to This Time"), sigc::mem_fun(*this, &AudioClock::locate)));
|
|
|
|
}
|
2015-04-14 05:55:39 -04:00
|
|
|
ops_items.push_back (SeparatorElem());
|
|
|
|
ops_items.push_back (MenuElem (_("Copy to clipboard"), sigc::mem_fun(*this, &AudioClock::copy_text_to_clipboard)));
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_from_playhead ()
|
|
|
|
{
|
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
AudioClock::set (timepos_t (_session->transport_sample()));
|
2011-11-17 17:49:13 -05:00
|
|
|
ValueChanged ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::locate ()
|
|
|
|
{
|
|
|
|
if (!_session || is_duration) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-03 13:56:08 -04:00
|
|
|
if (_session->actively_recording()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
_session->request_locate (current_time().samples());
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-24 08:39:12 -04:00
|
|
|
AudioClock::set_mode (Mode m, bool noemit)
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_mode == m) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mode = m;
|
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.clear();
|
|
|
|
|
|
|
|
_layout->set_text ("");
|
|
|
|
|
2015-05-21 18:23:04 -04:00
|
|
|
Gtk::Requisition req;
|
|
|
|
set_clock_dimensions (req);
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
2011-11-21 11:34:02 -05:00
|
|
|
insert_map.push_back (11);
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.push_back (10);
|
2011-11-21 11:34:02 -05:00
|
|
|
insert_map.push_back (8);
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.push_back (7);
|
2011-11-21 11:34:02 -05:00
|
|
|
insert_map.push_back (5);
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.push_back (4);
|
2011-11-21 11:34:02 -05:00
|
|
|
insert_map.push_back (2);
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.push_back (1);
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case BBT:
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.push_back (11);
|
|
|
|
insert_map.push_back (10);
|
|
|
|
insert_map.push_back (9);
|
|
|
|
insert_map.push_back (8);
|
|
|
|
insert_map.push_back (6);
|
2012-11-11 09:31:17 -05:00
|
|
|
insert_map.push_back (5);
|
|
|
|
insert_map.push_back (3);
|
|
|
|
insert_map.push_back (2);
|
|
|
|
insert_map.push_back (1);
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case MinSec:
|
2011-11-18 17:17:59 -05:00
|
|
|
insert_map.push_back (12);
|
|
|
|
insert_map.push_back (11);
|
|
|
|
insert_map.push_back (10);
|
|
|
|
insert_map.push_back (8);
|
|
|
|
insert_map.push_back (7);
|
|
|
|
insert_map.push_back (5);
|
|
|
|
insert_map.push_back (4);
|
2012-11-11 09:31:17 -05:00
|
|
|
insert_map.push_back (2);
|
|
|
|
insert_map.push_back (1);
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case Seconds:
|
|
|
|
insert_map.push_back (11);
|
|
|
|
insert_map.push_back (9);
|
|
|
|
insert_map.push_back (8);
|
|
|
|
insert_map.push_back (7);
|
|
|
|
insert_map.push_back (6);
|
|
|
|
insert_map.push_back (5);
|
|
|
|
insert_map.push_back (4);
|
|
|
|
insert_map.push_back (3);
|
|
|
|
insert_map.push_back (2);
|
|
|
|
insert_map.push_back (1);
|
|
|
|
break;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
case Samples:
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (last_when, true);
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2016-04-24 08:39:12 -04:00
|
|
|
if (!is_transient && !noemit) {
|
|
|
|
ModeChanged (); /* EMIT SIGNAL (the static one)*/
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2016-04-24 08:39:12 -04:00
|
|
|
mode_changed (); /* EMIT SIGNAL (the member one) */
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-10-19 14:37:54 -04:00
|
|
|
AudioClock::set_bbt_reference (timepos_t const & pos)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
bbt_reference_time = pos;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
|
|
|
|
{
|
|
|
|
CairoWidget::on_style_changed (old_style);
|
2012-12-29 10:59:38 -05:00
|
|
|
|
2021-01-29 20:22:55 -05:00
|
|
|
Glib::RefPtr<Gtk::Style> const& new_style = get_style ();
|
|
|
|
if (_layout && (_layout->get_font_description ().gobj () == 0 || _layout->get_font_description () != new_style->get_font ())) {
|
|
|
|
_layout->set_font_description (new_style->get_font ());
|
|
|
|
queue_resize ();
|
|
|
|
} else if (is_realized ()) {
|
|
|
|
queue_resize ();
|
|
|
|
}
|
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
Gtk::Requisition req;
|
|
|
|
set_clock_dimensions (req);
|
|
|
|
|
2021-01-29 20:22:55 -05:00
|
|
|
/* set-colors also sets up font-attributes */
|
2011-11-17 17:49:13 -05:00
|
|
|
set_colors ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2011-11-18 12:06:11 -05:00
|
|
|
void
|
|
|
|
AudioClock::set_editable (bool yn)
|
|
|
|
{
|
|
|
|
editable = yn;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
2020-09-26 11:14:59 -04:00
|
|
|
AudioClock::set_is_duration (bool yn, timepos_t const & p)
|
2011-05-21 21:18:22 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
if (yn == is_duration) {
|
2020-09-26 11:14:59 -04:00
|
|
|
if (yn) {
|
|
|
|
/* just reset position */
|
|
|
|
duration_position = p;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
return;
|
|
|
|
}
|
2011-05-21 21:18:22 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
is_duration = yn;
|
2020-09-26 11:14:59 -04:00
|
|
|
if (yn) {
|
|
|
|
duration_position = p;
|
|
|
|
} else {
|
|
|
|
duration_position = timepos_t ();
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:53:43 -04:00
|
|
|
set (last_when, true);
|
2011-05-21 21:18:22 -04:00
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
2012-11-11 09:31:17 -05:00
|
|
|
AudioClock::set_off (bool yn)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_off == yn) {
|
|
|
|
return;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
_off = yn;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
/* force a redraw. last_when will be preserved, but the clock text will
|
2012-11-11 09:31:17 -05:00
|
|
|
* change
|
2011-11-18 00:04:18 -05:00
|
|
|
*/
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2017-11-22 16:10:37 -05:00
|
|
|
AudioClock::set (last_when, true);
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2006-06-14 17:17:32 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
void
|
|
|
|
AudioClock::focus ()
|
|
|
|
{
|
2011-11-21 14:24:37 -05:00
|
|
|
start_edit (Field (0));
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-19 09:27:05 -05:00
|
|
|
void
|
|
|
|
AudioClock::set_corner_radius (double r)
|
|
|
|
{
|
|
|
|
corner_radius = r;
|
2012-11-11 11:27:29 -05:00
|
|
|
first_width = 0;
|
|
|
|
first_height = 0;
|
|
|
|
queue_resize ();
|
2011-11-19 09:27:05 -05:00
|
|
|
}
|
2011-11-20 10:10:53 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::dpi_reset ()
|
|
|
|
{
|
2012-11-11 09:31:17 -05:00
|
|
|
/* force recomputation of size even if we are fixed width
|
2011-11-20 10:10:53 -05:00
|
|
|
*/
|
|
|
|
first_width = 0;
|
|
|
|
first_height = 0;
|
|
|
|
queue_resize ();
|
|
|
|
}
|
2012-11-11 17:20:40 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_negative_allowed (bool yn)
|
|
|
|
{
|
|
|
|
_negative_allowed = yn;
|
|
|
|
}
|