2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 1999 Paul Davis
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
#include "gtkmm2ext/cairocell.h"
|
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
|
|
|
|
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"
|
2012-10-12 18:04:21 -04:00
|
|
|
#include "ardour/slave.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/tempo.h"
|
2012-10-12 18:04:21 -04:00
|
|
|
#include "ardour/types.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "audio_clock.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "keyboard.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "gui_thread.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ui_config.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2014-06-25 15:27:37 -04:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
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;
|
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;
|
2015-05-21 18:23:04 -04:00
|
|
|
const double AudioClock::info_font_scale_factor = 0.68;
|
2012-11-10 14:23:07 -05:00
|
|
|
const double AudioClock::separator_height = 0.0;
|
2011-11-18 10:35:58 -05:00
|
|
|
const double AudioClock::x_leading_padding = 6.0;
|
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
|
2013-03-03 06:36:47 -05:00
|
|
|
#define INFO_FONT_SIZE ((int)lrint(font_size * info_font_scale_factor))
|
2013-03-04 15:00:51 -05:00
|
|
|
#define TXTSPAN "<span font-family=\"Sans\" foreground=\"white\">"
|
2011-11-20 10:10:53 -05:00
|
|
|
|
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)
|
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)
|
|
|
|
, info_height (0)
|
|
|
|
, upper_height (0)
|
2011-11-17 17:49:13 -05:00
|
|
|
, mode_based_info_ratio (1.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)
|
|
|
|
, bbt_reference_time (-1)
|
2011-06-02 17:43:10 -04:00
|
|
|
, last_when(0)
|
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
|
|
|
{
|
|
|
|
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
|
|
|
if (with_info) {
|
|
|
|
_left_layout = Pango::Layout::create (get_pango_context());
|
|
|
|
_right_layout = Pango::Layout::create (get_pango_context());
|
|
|
|
}
|
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);
|
|
|
|
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
|
|
|
|
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));
|
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 ()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2014-12-22 13:39:41 -05:00
|
|
|
// XXX FIX ME: define font based on ... ???
|
|
|
|
// set_font ();
|
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
|
2014-12-22 13:39:41 -05:00
|
|
|
AudioClock::set_font (Pango::FontDescription font)
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
Glib::RefPtr<Gtk::Style> style = get_style ();
|
|
|
|
Pango::AttrFontDesc* font_attr;
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2012-10-12 18:04:21 -04:00
|
|
|
font_size = font.get_size();
|
|
|
|
font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
normal_attributes.change (*font_attr);
|
|
|
|
editing_attributes.change (*font_attr);
|
2006-11-30 11:43:11 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
/* now a smaller version of the same font */
|
2007-01-08 12:12:29 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
delete font_attr;
|
2013-03-03 06:36:47 -05:00
|
|
|
font.set_size (INFO_FONT_SIZE);
|
2011-11-17 17:49:13 -05:00
|
|
|
font.set_weight (Pango::WEIGHT_NORMAL);
|
|
|
|
font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
info_attributes.change (*font_attr);
|
2012-10-12 18:04:21 -04:00
|
|
|
|
|
|
|
/* and an even smaller one */
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
delete font_attr;
|
2011-11-21 12:39:55 -05:00
|
|
|
|
|
|
|
/* get the figure width for the font. This doesn't have to super
|
|
|
|
* accurate since we only use it to measure the (roughly 1 character)
|
|
|
|
* offset from the position Pango tells us for the "cursor"
|
|
|
|
*/
|
|
|
|
|
|
|
|
Glib::RefPtr<Pango::Layout> tmp = Pango::Layout::create (get_pango_context());
|
|
|
|
int ignore_height;
|
|
|
|
|
|
|
|
tmp->set_text ("8");
|
|
|
|
tmp->get_pixel_size (em_width, ignore_height);
|
2012-11-12 12:54:52 -05:00
|
|
|
|
|
|
|
/* force redraw of markup with new font-size */
|
|
|
|
set (last_when, true);
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2011-06-07 19:07:08 -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);
|
|
|
|
info_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
|
2014-03-20 18:50:40 -04:00
|
|
|
AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
|
2006-11-30 11:43:11 -05:00
|
|
|
{
|
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) {
|
2012-11-10 14:23:07 -05:00
|
|
|
if (_left_layout) {
|
2012-11-12 21:00:51 -05:00
|
|
|
Gtkmm2ext::rounded_top_half_rectangle (cr, 0, 0, get_width(), upper_height, corner_radius);
|
2012-11-10 14:23:07 -05:00
|
|
|
} else {
|
|
|
|
Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), upper_height, corner_radius);
|
|
|
|
}
|
2011-11-19 09:27:05 -05:00
|
|
|
} else {
|
|
|
|
cairo_rectangle (cr, 0, 0, get_width(), upper_height);
|
|
|
|
}
|
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
|
|
|
|
2015-09-28 20:15:03 -04:00
|
|
|
cairo_move_to (cr, (get_width() - lw) / 2.0, (upper_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-17 17:49:13 -05:00
|
|
|
if (_left_layout) {
|
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
double h = get_height() - upper_height - separator_height;
|
|
|
|
|
|
|
|
if (_need_bg) {
|
|
|
|
cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
if (mode_based_info_ratio != 1.0) {
|
|
|
|
|
2015-02-15 13:26:15 -05:00
|
|
|
double left_rect_width = get_left_rect_width();
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
if (_need_bg) {
|
2011-11-19 09:27:05 -05:00
|
|
|
if (corner_radius) {
|
2012-11-11 11:27:29 -05:00
|
|
|
Gtkmm2ext::rounded_bottom_half_rectangle (cr, 0, upper_height + separator_height,
|
|
|
|
left_rect_width + (separator_height == 0 ? corner_radius : 0),
|
2012-11-12 21:00:51 -05:00
|
|
|
h, corner_radius);
|
2011-11-19 09:27:05 -05:00
|
|
|
} else {
|
|
|
|
cairo_rectangle (cr, 0, upper_height + separator_height, left_rect_width, h);
|
|
|
|
}
|
2011-11-18 10:35:58 -05:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_move_to (cr, x_leading_padding, upper_height + separator_height + ((h - info_height)/2.0));
|
2011-11-17 17:49:13 -05:00
|
|
|
pango_cairo_show_layout (cr, _left_layout->gobj());
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
if (_need_bg) {
|
2011-11-19 09:27:05 -05:00
|
|
|
if (corner_radius) {
|
2012-11-11 11:27:29 -05:00
|
|
|
Gtkmm2ext::rounded_bottom_half_rectangle (cr, left_rect_width + separator_height,
|
|
|
|
upper_height + separator_height,
|
2012-11-12 21:00:51 -05:00
|
|
|
get_width() - separator_height - left_rect_width,
|
|
|
|
h, corner_radius);
|
2011-11-19 09:27:05 -05:00
|
|
|
} else {
|
2012-11-11 09:31:17 -05:00
|
|
|
cairo_rectangle (cr, left_rect_width + separator_height, upper_height + separator_height,
|
2011-11-19 09:27:05 -05:00
|
|
|
get_width() - separator_height - left_rect_width, h);
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
cairo_fill (cr);
|
2011-11-18 10:35:58 -05:00
|
|
|
}
|
|
|
|
|
2012-10-29 13:29:36 -04:00
|
|
|
|
|
|
|
if (_right_layout->get_alignment() == Pango::ALIGN_RIGHT) {
|
|
|
|
/* right-align does not work per se beacuse layout width is unset.
|
|
|
|
* Using _right_layout->set_width([value >=0]) would also enable
|
|
|
|
* word-wrapping which is not wanted here.
|
|
|
|
* The solution is to custom align the layout depending on its size.
|
|
|
|
* if it is larger than the available space it will be cropped on the
|
|
|
|
* right edge rather than override text on the left side.
|
|
|
|
*/
|
|
|
|
int x, rw, rh;
|
|
|
|
_right_layout->get_pixel_size(rw, rh);
|
2012-11-12 21:00:51 -05:00
|
|
|
x = get_width() - rw - separator_height - x_leading_padding;
|
2012-10-29 13:29:36 -04:00
|
|
|
if (x < x_leading_padding + left_rect_width + separator_height) {
|
2012-11-12 11:49:20 -05:00
|
|
|
/* rather cut off the right end than overlap with the text on the left */
|
2012-10-29 13:29:36 -04:00
|
|
|
x = x_leading_padding + left_rect_width + separator_height;
|
|
|
|
}
|
2012-11-11 09:31:14 -05:00
|
|
|
cairo_move_to (cr, x, upper_height + separator_height + ((h - info_height)/2.0));
|
2012-10-29 13:29:36 -04:00
|
|
|
} else {
|
|
|
|
cairo_move_to (cr, x_leading_padding + left_rect_width + separator_height, upper_height + separator_height + ((h - info_height)/2.0));
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
pango_cairo_show_layout (cr, _right_layout->gobj());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* no info to display, or just one */
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
if (_need_bg) {
|
2011-11-19 09:27:05 -05:00
|
|
|
if (corner_radius) {
|
2012-11-10 14:23:07 -05:00
|
|
|
Gtkmm2ext::rounded_bottom_half_rectangle (cr, 0, upper_height + separator_height, get_width(), h, corner_radius);
|
2011-11-19 09:27:05 -05:00
|
|
|
} else {
|
|
|
|
cairo_rectangle (cr, 0, upper_height + separator_height, get_width(), h);
|
|
|
|
}
|
2011-11-18 10:35:58 -05:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
cursor = _layout->get_cursor_strong_pos (edit_string.length() - 1);
|
|
|
|
} else {
|
|
|
|
cursor = _layout->get_cursor_strong_pos (insert_map[input_string.length()]);
|
|
|
|
}
|
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,
|
2015-09-28 20:15:03 -04:00
|
|
|
min (get_width() - 2.0,
|
|
|
|
(double) xcenter + cursor.get_x()/PANGO_SCALE + em_width),
|
|
|
|
(upper_height - layout_height)/2.0,
|
|
|
|
2.0, cursor.get_height()/PANGO_SCALE);
|
|
|
|
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),
|
|
|
|
(upper_height - layout_height)/2.0,
|
|
|
|
2.0, upper_height);
|
|
|
|
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-06-02 13:47:58 -04:00
|
|
|
void
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::on_size_allocate (Gtk::Allocation& alloc)
|
2011-06-02 13:47:58 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
CairoWidget::on_size_allocate (alloc);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_left_layout) {
|
2011-11-18 10:35:58 -05:00
|
|
|
upper_height = (get_height()/2.0) - 1.0;
|
2011-11-17 17:49:13 -05:00
|
|
|
} else {
|
2011-11-18 10:35:58 -05:00
|
|
|
upper_height = get_height();
|
2011-05-21 21:18:22 -04:00
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
2011-05-21 21:18:22 -04: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 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_left_layout) {
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
Glib::RefPtr<Pango::Layout> tmp;
|
|
|
|
Glib::RefPtr<Gtk::Style> style = get_style ();
|
|
|
|
Pango::FontDescription font;
|
2011-11-17 17:49:13 -05:00
|
|
|
int w;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
tmp = Pango::Layout::create (get_pango_context());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
if (!is_realized()) {
|
|
|
|
font = get_font_for_style (get_name());
|
|
|
|
} else {
|
|
|
|
font = style->get_font();
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-12-29 10:59:38 -05:00
|
|
|
tmp->set_font_description (font);
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2013-03-03 06:36:47 -05:00
|
|
|
font.set_size (INFO_FONT_SIZE);
|
2011-11-17 17:49:13 -05:00
|
|
|
font.set_weight (Pango::WEIGHT_NORMAL);
|
|
|
|
tmp->set_font_description (font);
|
2011-06-02 13:47:58 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
/* we only care about height, so put as much stuff in here
|
|
|
|
as possible that might change the height.
|
|
|
|
*/
|
|
|
|
tmp->set_text ("qyhH|"); /* one ascender, one descender */
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
tmp->get_pixel_size (w, info_height);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
/* silly extra padding that seems necessary to correct the info
|
|
|
|
* that pango just gave us. I have no idea why.
|
|
|
|
*/
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
req->height += info_height;
|
|
|
|
req->height += separator_height;
|
2011-06-02 17:43:10 -04:00
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
}
|
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;
|
|
|
|
case Timecode_Frames:
|
|
|
|
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;
|
|
|
|
case AudioFrames:
|
|
|
|
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
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case Frames:
|
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;
|
2011-11-18 18:46:55 -05:00
|
|
|
framepos_t pos = 0; /* stupid gcc */
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
pos = frames_from_timecode_string (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case BBT:
|
|
|
|
if (is_duration) {
|
|
|
|
pos = frame_duration_from_bbt_string (0, edit_string);
|
|
|
|
} else {
|
|
|
|
pos = frames_from_bbt_string (0, edit_string);
|
|
|
|
}
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case MinSec:
|
|
|
|
pos = frames_from_minsec_string (edit_string);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case Frames:
|
|
|
|
pos = frames_from_audioframes_string (edit_string);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set (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 */
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 21:36:30 -05:00
|
|
|
Widget* top = get_toplevel();
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 21:36:30 -05:00
|
|
|
if (top->is_toplevel ()) {
|
|
|
|
Window* win = dynamic_cast<Window*> (top);
|
|
|
|
win->grab_focus ();
|
|
|
|
}
|
2011-06-02 13:47:58 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2012-11-11 09:31:17 -05:00
|
|
|
framecnt_t
|
2011-11-17 20:22:40 -05:00
|
|
|
AudioClock::parse_as_frames_distance (const std::string& str)
|
|
|
|
{
|
|
|
|
framecnt_t f;
|
|
|
|
|
|
|
|
if (sscanf (str.c_str(), "%" PRId64, &f) == 1) {
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-11 09:31:17 -05:00
|
|
|
framecnt_t
|
2011-11-17 20:22:40 -05:00
|
|
|
AudioClock::parse_as_minsec_distance (const std::string& str)
|
|
|
|
{
|
2011-11-18 00:04:18 -05:00
|
|
|
framecnt_t sr = _session->frame_rate();
|
|
|
|
int msecs;
|
|
|
|
int secs;
|
|
|
|
int mins;
|
|
|
|
int hrs;
|
|
|
|
|
|
|
|
switch (str.length()) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
sscanf (str.c_str(), "%" PRId32, &msecs);
|
|
|
|
return msecs * (sr / 1000);
|
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);
|
|
|
|
return (secs * sr) + (msecs * (sr/1000));
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &msecs);
|
|
|
|
return (secs * sr) + (msecs * (sr/1000));
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &msecs);
|
|
|
|
return (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &msecs);
|
|
|
|
return (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &msecs);
|
|
|
|
return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &msecs);
|
|
|
|
return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-17 20:22:40 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-11 09:31:17 -05:00
|
|
|
framecnt_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();
|
|
|
|
framecnt_t sr = _session->frame_rate();
|
|
|
|
int frames;
|
|
|
|
int secs;
|
|
|
|
int mins;
|
|
|
|
int hrs;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
switch (str.length()) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
sscanf (str.c_str(), "%" PRId32, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return llrint ((frames/(float)fps) * sr);
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%" PRId32, &secs, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return (secs * sr) + llrint ((frames/(float)fps) * sr);
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 4:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return (secs * sr) + llrint ((frames/(float)fps) * sr);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
case 5:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 6:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 7:
|
|
|
|
sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
|
2011-11-18 00:04:18 -05:00
|
|
|
|
|
|
|
case 8:
|
|
|
|
sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &frames);
|
2014-07-10 13:06:52 -04:00
|
|
|
return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-17 20:22:40 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-11 09:31:17 -05:00
|
|
|
framecnt_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
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-11 09:31:17 -05:00
|
|
|
framecnt_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;
|
|
|
|
case Frames:
|
2011-11-21 11:34:02 -05:00
|
|
|
return parse_as_frames_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;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-11-21 13:07:42 -05:00
|
|
|
case Frames:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-17 20:22:40 -05:00
|
|
|
framecnt_t frames = parse_as_distance (input_string);
|
|
|
|
|
|
|
|
editing = false;
|
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
editing = false;
|
|
|
|
_layout->set_attributes (normal_attributes);
|
|
|
|
|
2011-11-17 20:22:40 -05:00
|
|
|
if (frames != 0) {
|
|
|
|
if (add) {
|
|
|
|
set (current_time() + frames, true);
|
|
|
|
} else {
|
|
|
|
framepos_t c = current_time();
|
|
|
|
|
2012-11-13 15:29:28 -05:00
|
|
|
if (c > frames || _negative_allowed) {
|
2011-11-17 20:22:40 -05:00
|
|
|
set (c - frames, true);
|
|
|
|
} else {
|
|
|
|
set (0, true);
|
|
|
|
}
|
|
|
|
}
|
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
|
2013-01-04 17:46:51 -05:00
|
|
|
AudioClock::session_property_changed (const PropertyChange&)
|
2012-11-13 18:29:57 -05:00
|
|
|
{
|
|
|
|
set (last_when, true);
|
|
|
|
}
|
|
|
|
|
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") {
|
|
|
|
set (current_time(), true);
|
|
|
|
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
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
framecnt_t current;
|
|
|
|
|
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
|
|
|
if (is_duration) {
|
|
|
|
current = current_duration ();
|
|
|
|
} else {
|
|
|
|
current = current_time ();
|
|
|
|
}
|
|
|
|
set (current, true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-18 13:06:16 -05:00
|
|
|
AudioClock::set (framepos_t when, bool force, framecnt_t offset)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
if ((!force && !is_visible()) || _session == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-18 13:06:16 -05:00
|
|
|
if (is_duration) {
|
|
|
|
when = when - offset;
|
2012-11-11 09:31:17 -05:00
|
|
|
}
|
2007-05-13 22:48:28 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (!editing) {
|
2012-10-29 13:29:36 -04:00
|
|
|
if (_right_layout) {
|
|
|
|
_right_layout->set_alignment(Pango::ALIGN_LEFT);
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
2012-10-29 13:29:36 -04:00
|
|
|
if (_right_layout) {
|
|
|
|
_right_layout->set_alignment(Pango::ALIGN_RIGHT);
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
set_timecode (when, force);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case BBT:
|
|
|
|
set_bbt (when, force);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case MinSec:
|
2012-11-11 12:36:31 -05:00
|
|
|
if (_right_layout) {
|
|
|
|
_right_layout->set_alignment(Pango::ALIGN_RIGHT);
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
set_minsec (when, force);
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case Frames:
|
|
|
|
set_frames (when, force);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-09-25 14:42:24 -04: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 ()
|
|
|
|
{
|
|
|
|
if (!_left_layout || !_right_layout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncSource sync_src = Config->get_sync_source();
|
|
|
|
|
|
|
|
if (_session->config.get_external_sync()) {
|
|
|
|
Slave* slave = _session->slave();
|
|
|
|
|
|
|
|
switch (sync_src) {
|
2013-09-19 17:34:23 -04:00
|
|
|
case Engine:
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
|
2012-11-11 12:36:31 -05:00
|
|
|
INFO_FONT_SIZE, sync_source_to_string(sync_src, true)));
|
|
|
|
_right_layout->set_text ("");
|
|
|
|
break;
|
2012-11-11 18:11:53 -05:00
|
|
|
case MIDIClock:
|
|
|
|
if (slave) {
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
|
2012-11-11 18:11:53 -05:00
|
|
|
INFO_FONT_SIZE, sync_source_to_string(sync_src, true)));
|
2013-07-15 17:42:20 -04:00
|
|
|
_right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
|
2012-11-11 18:11:53 -05:00
|
|
|
INFO_FONT_SIZE, slave->approximate_current_delta()));
|
|
|
|
} else {
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
|
2012-11-11 18:11:53 -05:00
|
|
|
INFO_FONT_SIZE, _("--pending--")));
|
|
|
|
_right_layout->set_text ("");
|
|
|
|
}
|
|
|
|
break;
|
2012-11-11 12:36:31 -05:00
|
|
|
case LTC:
|
|
|
|
case MTC:
|
|
|
|
if (slave) {
|
2012-11-11 17:06:42 -05:00
|
|
|
bool matching;
|
|
|
|
TimecodeSlave* tcslave;
|
|
|
|
if ((tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
|
|
|
|
matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span><span foreground=\"%3\">%4</span></span>",
|
2012-11-12 12:54:55 -05:00
|
|
|
INFO_FONT_SIZE, sync_source_to_string(sync_src, true)[0], (matching?"green":"red"),
|
2012-11-12 11:48:50 -05:00
|
|
|
dynamic_cast<TimecodeSlave*>(slave)->approximate_current_position()));
|
2013-07-15 17:42:20 -04:00
|
|
|
_right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
|
2012-11-12 11:48:50 -05:00
|
|
|
INFO_FONT_SIZE, slave->approximate_current_delta()));
|
2012-11-11 17:06:42 -05:00
|
|
|
}
|
2012-11-11 12:36:31 -05:00
|
|
|
} else {
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
|
2012-11-11 12:36:31 -05:00
|
|
|
INFO_FONT_SIZE, _("--pending--")));
|
|
|
|
_right_layout->set_text ("");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "INT/%2</span></span>",
|
2012-11-11 12:36:31 -05:00
|
|
|
INFO_FONT_SIZE, sync_source_to_string(sync_src, true)));
|
|
|
|
_right_layout->set_text ("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
AudioClock::set_frames (framepos_t when, bool /*force*/)
|
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 (" ----------");
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
if (_left_layout) {
|
|
|
|
_left_layout->set_text ("");
|
|
|
|
_right_layout->set_text ("");
|
2011-06-07 19:07:08 -04:00
|
|
|
}
|
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-11-18 17:17:59 -05:00
|
|
|
if (when < 0) {
|
|
|
|
when = -when;
|
|
|
|
negative = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
snprintf (buf, sizeof (buf), "-%10" PRId64, when);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof (buf), " %10" PRId64, when);
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
_layout->set_text (buf);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_left_layout) {
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_t rate = _session->frame_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
|
|
|
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2 </span><span foreground=\"green\">%3</span></span>",
|
2012-11-11 09:31:14 -05:00
|
|
|
INFO_FONT_SIZE, _("SR"), buf));
|
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) {
|
2013-07-15 17:42:20 -04:00
|
|
|
_right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2 </span><span foreground=\"green\">off</span></span>",
|
2012-11-13 15:29:24 -05:00
|
|
|
INFO_FONT_SIZE, _("Pull")));
|
2006-11-30 11:43:11 -05:00
|
|
|
} else {
|
2012-11-13 15:29:24 -05:00
|
|
|
sprintf (buf, _("%+.4f%%"), vid_pullup);
|
2013-07-15 17:42:20 -04:00
|
|
|
_right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2 </span><span foreground=\"green\">%3</span></span>",
|
2012-11-13 15:29:24 -05:00
|
|
|
INFO_FONT_SIZE, _("Pull"), buf));
|
2006-11-30 11:43:11 -05:00
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
void
|
2014-07-09 19:13:18 -04:00
|
|
|
AudioClock::print_minsec (framepos_t when, char* buf, size_t bufsize, float frame_rate)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
left = when;
|
|
|
|
hrs = (int) floor (left / (frame_rate * 60.0f * 60.0f));
|
|
|
|
left -= (framecnt_t) floor (hrs * frame_rate * 60.0f * 60.0f);
|
|
|
|
mins = (int) floor (left / (frame_rate * 60.0f));
|
|
|
|
left -= (framecnt_t) floor (mins * frame_rate * 60.0f);
|
|
|
|
secs = (int) floor (left / (float) frame_rate);
|
|
|
|
left -= (framecnt_t) floor ((double)(secs * frame_rate));
|
|
|
|
millisecs = floor (left * 1000.0 / (float) frame_rate);
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
snprintf (buf, bufsize, "-%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, bufsize, " %02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_minsec (framepos_t when, bool /*force*/)
|
|
|
|
{
|
|
|
|
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 (" --:--:--.---");
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
if (_left_layout) {
|
|
|
|
_left_layout->set_text ("");
|
|
|
|
_right_layout->set_text ("");
|
2011-06-07 19:07:08 -04:00
|
|
|
}
|
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
|
|
|
|
2014-07-09 19:13:18 -04:00
|
|
|
print_minsec (when, buf, sizeof (buf), _session->frame_rate());
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
_layout->set_text (buf);
|
2012-11-11 12:36:31 -05:00
|
|
|
set_slave_info();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-02 16:29:46 -04:00
|
|
|
AudioClock::set_timecode (framepos_t when, bool /*force*/)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
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 (" --:--:--:--");
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_left_layout) {
|
|
|
|
_left_layout->set_text ("");
|
|
|
|
_right_layout->set_text ("");
|
2011-11-18 17:17:59 -05:00
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-06-07 19:07:08 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-18 14:28:07 -05:00
|
|
|
if (when < 0) {
|
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
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
if (is_duration) {
|
2011-06-02 13:47:58 -04:00
|
|
|
_session->timecode_duration (when, TC);
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
2011-06-02 13:47:58 -04:00
|
|
|
_session->timecode_time (when, 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
|
2012-05-02 16:29:46 -04:00
|
|
|
AudioClock::set_bbt (framepos_t when, bool /*force*/)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
char buf[16];
|
2011-06-02 13:47:58 -04:00
|
|
|
Timecode::BBT_Time BBT;
|
2011-11-18 17:17:59 -05:00
|
|
|
bool negative = false;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-06-07 19:07:08 -04:00
|
|
|
if (_off) {
|
2013-03-03 06:36:42 -05:00
|
|
|
_layout->set_text (" ---|--|----");
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_left_layout) {
|
|
|
|
_left_layout->set_text ("");
|
|
|
|
_right_layout->set_text ("");
|
2011-06-07 19:07:08 -04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-18 14:28:07 -05:00
|
|
|
if (when < 0) {
|
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 */
|
2008-12-12 09:43:24 -05:00
|
|
|
if (is_duration) {
|
|
|
|
if (when == 0) {
|
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 {
|
2011-06-02 13:47:58 -04:00
|
|
|
_session->tempo_map().bbt_time (when, BBT);
|
|
|
|
BBT.bars--;
|
|
|
|
BBT.beats--;
|
2008-12-12 09:43:24 -05:00
|
|
|
}
|
|
|
|
} else {
|
2011-06-02 13:47:58 -04:00
|
|
|
_session->tempo_map().bbt_time (when, BBT);
|
2008-04-11 10:06:50 -04: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
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (_right_layout) {
|
2010-09-17 14:20:37 -04:00
|
|
|
framepos_t pos;
|
2008-04-11 10:06:50 -04:00
|
|
|
|
|
|
|
if (bbt_reference_time < 0) {
|
|
|
|
pos = when;
|
|
|
|
} else {
|
|
|
|
pos = bbt_reference_time;
|
|
|
|
}
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
TempoMetric m (_session->tempo_map().metric_at (pos));
|
2008-04-11 10:06:50 -04:00
|
|
|
|
2013-03-05 08:24:04 -05:00
|
|
|
sprintf (buf, "%-5.1f", m.tempo().beats_per_minute());
|
2013-07-15 17:42:20 -04:00
|
|
|
_left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%3</span> <span foreground=\"green\">%2</span></span>",
|
2012-12-30 16:33:16 -05:00
|
|
|
INFO_FONT_SIZE, buf, _("Tempo")));
|
2011-06-02 17:43:10 -04:00
|
|
|
|
2011-12-12 21:46:36 -05:00
|
|
|
sprintf (buf, "%g/%g", m.meter().divisions_per_bar(), m.meter().note_divisor());
|
2013-07-15 17:42:20 -04:00
|
|
|
_right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%3</span> <span foreground=\"green\">%2</span></span>",
|
2012-12-30 16:33:16 -05:00
|
|
|
INFO_FONT_SIZE, buf, _("Meter")));
|
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
|
|
|
|
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());
|
2012-11-13 18:29:57 -05:00
|
|
|
_session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_property_changed, this, _1), gui_context());
|
2010-12-01 15:49:22 -05:00
|
|
|
|
2011-06-07 19:07:08 -04:00
|
|
|
const XMLProperty* prop;
|
2009-12-17 13:24:23 -05:00
|
|
|
XMLNode* node = _session->extra_xml (X_("ClockModes"));
|
2007-01-08 12:12:29 -05:00
|
|
|
AudioClock::Mode amode;
|
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) {
|
|
|
|
if ((prop = (*i)->property (X_("name"))) && prop->value() == _name) {
|
|
|
|
|
|
|
|
if ((prop = (*i)->property (X_("mode"))) != 0) {
|
|
|
|
amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
|
|
|
|
set_mode (amode);
|
|
|
|
}
|
|
|
|
if ((prop = (*i)->property (X_("on"))) != 0) {
|
|
|
|
set_off (!string_is_affirmative (prop->value()));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-01-08 12:12:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
set (last_when, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
framepos_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) {
|
|
|
|
case Frames:
|
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 {
|
2011-11-17 17:49:13 -05:00
|
|
|
return Timecode_Frames;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
case Frames:
|
|
|
|
return AudioFrames;
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2011-11-18 14:28:07 -05:00
|
|
|
y = ev->y - ((upper_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
|
|
|
{
|
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;
|
|
|
|
int y = ev->y - ((upper_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) {
|
|
|
|
case Timecode_Frames:
|
|
|
|
case MS_Milliseconds:
|
|
|
|
case Ticks:
|
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
2011-11-18 18:30:09 -05:00
|
|
|
if (editing || _session == 0 || !editable || _off) {
|
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;
|
2011-11-18 14:28:07 -05:00
|
|
|
y = ev->y - ((upper_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);
|
2010-12-03 17:26:29 -05:00
|
|
|
framepos_t frames = 0;
|
2006-04-09 22:14:05 -04:00
|
|
|
|
|
|
|
switch (ev->direction) {
|
|
|
|
|
|
|
|
case GDK_SCROLL_UP:
|
2011-11-17 17:49:13 -05:00
|
|
|
frames = get_frame_step (f);
|
2011-06-03 18:18:47 -04:00
|
|
|
if (frames != 0) {
|
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
|
|
|
frames *= 10;
|
|
|
|
}
|
|
|
|
set (current_time() + frames, true);
|
|
|
|
ValueChanged (); /* EMIT_SIGNAL */
|
|
|
|
}
|
|
|
|
break;
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2006-04-09 22:14:05 -04:00
|
|
|
case GDK_SCROLL_DOWN:
|
2011-11-17 17:49:13 -05:00
|
|
|
frames = get_frame_step (f);
|
2011-06-03 18:18:47 -04:00
|
|
|
if (frames != 0) {
|
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
|
|
|
frames *= 10;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2012-11-13 19:15:54 -05:00
|
|
|
if (!_negative_allowed && (double)current_time() - (double)frames < 0.0) {
|
2011-06-03 18:18:47 -04:00
|
|
|
set (0, true);
|
|
|
|
} else {
|
|
|
|
set (current_time() - frames, true);
|
|
|
|
}
|
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
|
|
|
{
|
2011-11-18 18:30:09 -05:00
|
|
|
if (editing || _session == 0 || !dragging) {
|
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
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
float pixel_frame_scale_factor = 0.2f;
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
2005-09-25 14:42:24 -04:00
|
|
|
pixel_frame_scale_factor = 0.1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->state,
|
2008-01-10 16:20:59 -05:00
|
|
|
Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
pixel_frame_scale_factor = 0.025f;
|
|
|
|
}
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
double y_delta = ev->y - drag_y;
|
|
|
|
|
|
|
|
drag_accum += y_delta*pixel_frame_scale_factor;
|
|
|
|
|
|
|
|
drag_y = ev->y;
|
|
|
|
|
2013-10-03 04:32:08 -04:00
|
|
|
if (floor (drag_accum) != 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framepos_t frames;
|
|
|
|
framepos_t pos;
|
2005-09-25 14:42:24 -04:00
|
|
|
int dir;
|
|
|
|
dir = (drag_accum < 0 ? 1:-1);
|
|
|
|
pos = current_time();
|
2012-06-28 11:56:51 -04:00
|
|
|
frames = get_frame_step (drag_field, pos, dir);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
if (frames != 0 && frames * drag_accum < current_time()) {
|
2011-11-17 17:49:13 -05:00
|
|
|
set ((framepos_t) floor (pos - drag_accum * frames), false); // minus because up is negative in GTK
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
|
|
|
set (0 , false);
|
|
|
|
}
|
|
|
|
|
|
|
|
drag_accum= 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
ValueChanged(); /* EMIT_SIGNAL */
|
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
|
|
|
}
|
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framepos_t
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::get_frame_step (Field field, framepos_t pos, int dir)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-06-02 13:47:58 -04:00
|
|
|
framecnt_t f = 0;
|
|
|
|
Timecode::BBT_Time BBT;
|
2005-09-25 14:42:24 -04:00
|
|
|
switch (field) {
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Hours:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) floor (3600.0 * _session->frame_rate());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Minutes:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) floor (60.0 * _session->frame_rate());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Seconds:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = _session->frame_rate();
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode_Frames:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) floor (_session->frame_rate() / _session->timecode_frames_per_second());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioFrames:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = 1;
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_Hours:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) floor (3600.0 * _session->frame_rate());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case MS_Minutes:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) floor (60.0 * _session->frame_rate());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case MS_Seconds:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) _session->frame_rate();
|
2011-05-21 21:18:05 -04:00
|
|
|
break;
|
|
|
|
case MS_Milliseconds:
|
2011-06-02 13:47:58 -04:00
|
|
|
f = (framecnt_t) floor (_session->frame_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;
|
|
|
|
f = _session->tempo_map().bbt_duration_at (pos,BBT,dir);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case Beats:
|
2011-06-02 13:47:58 -04:00
|
|
|
BBT.bars = 0;
|
|
|
|
BBT.beats = 1;
|
|
|
|
BBT.ticks = 0;
|
|
|
|
f = _session->tempo_map().bbt_duration_at(pos,BBT,dir);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case Ticks:
|
2011-06-02 13:47:58 -04:00
|
|
|
BBT.bars = 0;
|
|
|
|
BBT.beats = 0;
|
|
|
|
BBT.ticks = 1;
|
|
|
|
f = _session->tempo_map().bbt_duration_at(pos,BBT,dir);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error << string_compose (_("programming error: %1"), "attempt to get frames from non-text field!") << endmsg;
|
|
|
|
f = 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
|
|
|
}
|
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framepos_t
|
2012-05-02 16:29:46 -04:00
|
|
|
AudioClock::current_time (framepos_t) 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
|
|
|
}
|
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framepos_t
|
|
|
|
AudioClock::current_duration (framepos_t pos) const
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2010-12-03 17:26:29 -05:00
|
|
|
framepos_t ret = 0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
switch (_mode) {
|
2009-10-26 10:38:58 -04:00
|
|
|
case Timecode:
|
2011-11-18 00:04:18 -05:00
|
|
|
ret = last_when;
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
case BBT:
|
2011-11-18 00:04:18 -05:00
|
|
|
ret = frame_duration_from_bbt_string (pos, _layout->get_text());
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MinSec:
|
2011-11-18 00:04:18 -05:00
|
|
|
ret = last_when;
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Frames:
|
2011-11-18 00:04:18 -05:00
|
|
|
ret = last_when;
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AudioClock::bbt_validate_edit (const string& str)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-01-06 11:39:40 -05:00
|
|
|
if (any.bbt.ticks > Timecode::BBT_Time::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) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
framepos_t
|
2011-11-18 00:04:18 -05:00
|
|
|
AudioClock::frames_from_timecode_string (const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_session == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timecode::Time TC;
|
|
|
|
framepos_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
framepos_t
|
2011-11-18 00:04:18 -05:00
|
|
|
AudioClock::frames_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;
|
|
|
|
framecnt_t sr = _session->frame_rate();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
return (framepos_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr) + (millisecs * sr / 1000.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
framepos_t
|
2011-11-18 00:04:18 -05:00
|
|
|
AudioClock::frames_from_bbt_string (framepos_t 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnyTime any;
|
|
|
|
any.type = AnyTime::BBT;
|
|
|
|
|
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 0;
|
|
|
|
}
|
2012-11-11 09:31:17 -05:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
if (is_duration) {
|
|
|
|
any.bbt.bars++;
|
|
|
|
any.bbt.beats++;
|
|
|
|
return _session->any_duration_to_frames (pos, any);
|
|
|
|
} else {
|
|
|
|
return _session->convert_to_frames (any);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
framepos_t
|
2011-11-18 00:04:18 -05:00
|
|
|
AudioClock::frame_duration_from_bbt_string (framepos_t pos, const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
if (_session == 0) {
|
2013-07-31 13:22:58 -04:00
|
|
|
error << "AudioClock::frame_duration_from_bbt_string() called with BBT mode but without session!" << endmsg;
|
2011-11-17 17:49:13 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timecode::BBT_Time bbt;
|
|
|
|
|
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
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
return _session->tempo_map().bbt_duration_at(pos,bbt,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
framepos_t
|
2011-11-18 00:04:18 -05:00
|
|
|
AudioClock::frames_from_audioframes_string (const string& str) const
|
2011-11-17 17:49:13 -05:00
|
|
|
{
|
|
|
|
framepos_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");
|
|
|
|
|
|
|
|
if (!Profile->get_sae()) {
|
|
|
|
ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode)));
|
|
|
|
}
|
|
|
|
ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT)));
|
|
|
|
ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec)));
|
|
|
|
ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames)));
|
|
|
|
|
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());
|
|
|
|
ops_items.push_back (MenuElem (_("Set From Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
set (_session->transport_frame());
|
|
|
|
ValueChanged ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::locate ()
|
|
|
|
{
|
|
|
|
if (!_session || is_duration) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_session->request_locate (current_time(), _session->transport_rolling ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioClock::set_mode (Mode m)
|
|
|
|
{
|
|
|
|
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-18 17:17:59 -05:00
|
|
|
if (_left_layout) {
|
2012-10-29 13:29:36 -04:00
|
|
|
|
2012-11-10 21:45:01 -05:00
|
|
|
_left_layout->set_attributes (info_attributes);
|
|
|
|
_right_layout->set_attributes (info_attributes);
|
2012-10-29 13:29:36 -04:00
|
|
|
/* adjust info_height according to font size */
|
|
|
|
int ignored;
|
|
|
|
_left_layout->set_text (" 1234567890");
|
|
|
|
_left_layout->get_pixel_size (ignored, info_height);
|
|
|
|
|
2011-11-18 17:17:59 -05:00
|
|
|
_left_layout->set_text ("");
|
|
|
|
_right_layout->set_text ("");
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
switch (_mode) {
|
|
|
|
case Timecode:
|
2013-03-03 06:36:47 -05:00
|
|
|
mode_based_info_ratio = 0.6;
|
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:
|
|
|
|
mode_based_info_ratio = 0.5;
|
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:
|
2013-03-03 06:36:47 -05:00
|
|
|
mode_based_info_ratio = 0.6;
|
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
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
case Frames:
|
2013-03-03 06:36:47 -05:00
|
|
|
mode_based_info_ratio = 0.45;
|
2011-11-17 17:49:13 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set (last_when, true);
|
|
|
|
|
|
|
|
if (!is_transient) {
|
|
|
|
ModeChanged (); /* EMIT SIGNAL (the static one)*/
|
|
|
|
}
|
|
|
|
|
|
|
|
mode_changed (); /* EMIT SIGNAL (the member one) */
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-17 17:49:13 -05:00
|
|
|
AudioClock::set_bbt_reference (framepos_t 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
|
|
|
|
|
|
|
Gtk::Requisition req;
|
|
|
|
set_clock_dimensions (req);
|
|
|
|
|
2014-12-22 13:39:41 -05:00
|
|
|
/* XXXX fix me ... we shouldn't be using GTK styles anyway */
|
|
|
|
// set_font ();
|
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
|
|
|
|
AudioClock::set_is_duration (bool yn)
|
2011-05-21 21:18:22 -04:00
|
|
|
{
|
2011-11-17 17:49:13 -05:00
|
|
|
if (yn == is_duration) {
|
|
|
|
return;
|
|
|
|
}
|
2011-05-21 21:18:22 -04:00
|
|
|
|
2011-11-17 17:49:13 -05:00
|
|
|
is_duration = yn;
|
2011-11-18 13:06:16 -05: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
|
|
|
|
2011-11-18 00:04:18 -05:00
|
|
|
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;
|
|
|
|
}
|