#include "pbd/enumwriter.h"
#include <gtkmm/style.h>
+#include <sigc++/bind.h>
#include "gtkmm2ext/cairocell.h"
-#include <gtkmm2ext/utils.h>
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/rgb_macros.h"
-#include "ardour/ardour.h"
+#include "ardour/profile.h"
+#include "ardour/lmath.h"
#include "ardour/session.h"
+#include "ardour/slave.h"
#include "ardour/tempo.h"
-#include "ardour/profile.h"
-#include <sigc++/bind.h>
+#include "ardour/types.h"
-#include "ardour_ui.h"
#include "audio_clock.h"
#include "utils.h"
#include "keyboard.h"
#include "gui_thread.h"
-#include "i18n.h"
+#include "ui_config.h"
+#include "pbd/i18n.h"
using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
using namespace PBD;
using namespace Gtk;
using namespace std;
using Gtkmm2ext::Keyboard;
-using PBD::atoi;
-using PBD::atof;
-
sigc::signal<void> AudioClock::ModeChanged;
vector<AudioClock*> AudioClock::clocks;
+const double AudioClock::info_font_scale_factor = 0.68;
+const double AudioClock::separator_height = 0.0;
+const double AudioClock::x_leading_padding = 6.0;
-uint32_t AudioClock::field_length[] = {
- 1, /* Timecode_Sign */
- 2, /* Timecode_Hours */
- 2, /* Timecode_Minutes */
- 2, /* Timecode_Seconds */
- 2, /* Timecode_Frames */
- 2, /* MS_Hours */
- 2, /* MS_Minutes */
- 2, /* MS_Seconds */
- 3, /* MS_Milliseconds */
- 4, /* Bars */
- 2, /* Beats */
- 4, /* Ticks */
- 10, /* AudioFrames */
-};
+#define BBT_BAR_CHAR "|"
+#define BBT_SCANF_FORMAT "%" PRIu32 "%*c%" PRIu32 "%*c%" PRIu32
+#define INFO_FONT_SIZE ((int)lrint(font_size * info_font_scale_factor))
+#define TXTSPAN "<span font-family=\"Sans\" foreground=\"white\">"
AudioClock::AudioClock (const string& clock_name, bool transient, const string& widget_name,
- bool allow_edit, bool follows_playhead, bool duration, bool with_info)
- : _name (clock_name)
+ bool allow_edit, bool follows_playhead, bool duration, bool with_info,
+ bool accept_on_focus_out)
+ : ops_menu (0)
+ , _name (clock_name)
, is_transient (transient)
, is_duration (duration)
, editable (allow_edit)
, _follows_playhead (follows_playhead)
+ , _accept_on_focus_out (accept_on_focus_out)
, _off (false)
- , supplemental_left (0)
- , supplemental_right (0)
+ , em_width (0)
+ , _edit_by_click_field (false)
+ , _negative_allowed (false)
+ , edit_is_negative (false)
+ , editing_attr (0)
+ , foreground_attr (0)
+ , first_height (0)
+ , first_width (0)
+ , style_resets_first (true)
+ , layout_height (0)
+ , layout_width (0)
+ , info_height (0)
+ , upper_height (0)
+ , mode_based_info_ratio (1.0)
+ , corner_radius (4)
+ , font_size (10240)
+ , editing (false)
+ , bbt_reference_time (-1)
, last_when(0)
- , _canonical_time_is_displayed (true)
- , _canonical_time (0)
-{
- last_when = 0;
-
- last_hrs = 9999;
- last_mins = 9999;
- last_secs = 9999;
- last_frames = 99999;
-
- ms_last_hrs = 9999;
- ms_last_mins = 9999;
- ms_last_secs = 9999;
- ms_last_millisecs = 99999;
-
- last_negative = false;
-
- last_pdelta = 0;
- last_sdelta = 0;
- key_entry_state = 0;
- ops_menu = 0;
- dragging = false;
- bbt_reference_time = -1;
- editing_field = (Field) 0;
-
- /* basic per-mode editable text "arrays" */
-
- display = new CairoEditableText ();
- display->set_corner_radius (0);
-
- _fixed_cells[Colon1] = new CairoCharCell (Colon1, ':');
- _fixed_cells[Colon2] = new CairoCharCell (Colon2, ':');
- _fixed_cells[Colon3] = new CairoCharCell (Colon3, ':');
- _fixed_cells[Bar1] = new CairoCharCell (Bar1, '|');
- _fixed_cells[Bar2] = new CairoCharCell (Bar2, '|');
-
- _text_cells[Timecode_Sign] = new CairoTextCell (Timecode_Sign, field_length[Timecode_Sign]);
- _text_cells[Timecode_Hours] = new CairoTextCell (Timecode_Hours, field_length[Timecode_Hours]);
- _text_cells[Timecode_Minutes] = new CairoTextCell (Timecode_Minutes, field_length[Timecode_Minutes]);
- _text_cells[Timecode_Seconds] = new CairoTextCell (Timecode_Seconds, field_length[Timecode_Seconds]);
- _text_cells[Timecode_Frames] = new CairoTextCell (Timecode_Frames, field_length[Timecode_Frames]);
-
- /* Minutes/Seconds */
-
- _text_cells[MS_Hours] = new CairoTextCell (MS_Hours, field_length[MS_Hours]);
- _text_cells[MS_Minutes] = new CairoTextCell (MS_Minutes, field_length[MS_Minutes]);
- _text_cells[MS_Seconds] = new CairoTextCell (MS_Seconds, field_length[MS_Seconds]);
- _text_cells[MS_Milliseconds] = new CairoTextCell (MS_Milliseconds, field_length[MS_Milliseconds]);
-
- /* Beats/Bars/Ticks */
-
- _text_cells[Bars] = new CairoTextCell (Bars, field_length[Bars]);
- _text_cells[Beats] = new CairoTextCell (Beats, field_length[Beats]);
- _text_cells[Ticks] = new CairoTextCell (Ticks, field_length[Ticks]);
-
- /* Audio Frames */
-
- _text_cells[AudioFrames] = new CairoTextCell (AudioFrames, field_length[AudioFrames]);
-
- set_homogeneous (false);
-
- if (with_info) {
-
- supplemental_left = new CairoEditableText ();
- supplemental_right = new CairoEditableText ();
-
- supplemental_left->set_corner_radius (0);
- supplemental_right->set_corner_radius (0);
+ , last_pdelta (0)
+ , last_sdelta (0)
+ , dragging (false)
+ , drag_field (Field (0))
+ , xscale (1.0)
+ , yscale (1.0)
+{
+ set_flags (CAN_FOCUS);
- /* field lengths of these cells will be set dynamically by ::set_mode()
- */
+ _layout = Pango::Layout::create (get_pango_context());
+ _layout->set_attributes (normal_attributes);
- _text_cells[LowerLeft1] = new CairoTextCell (LowerLeft1, 0);
- _text_cells[LowerLeft2] = new CairoTextCell (LowerLeft2, 0);
- _text_cells[LowerRight1] = new CairoTextCell (LowerRight1, 0);
- _text_cells[LowerRight2] = new CairoTextCell (LowerRight2, 0);
-
- bottom.set_spacing (1);
- bottom.set_homogeneous (false);
- bottom.pack_start (*supplemental_left, true, true);
- bottom.pack_start (*supplemental_right, true, true);
-
- top.pack_start (*display, true, true);
-
- set_spacing (1);
-
- pack_start (top, true, true);
- pack_start (bottom, true, true);
- } else {
- pack_start (*display, true, true);
+ if (with_info) {
+ _left_layout = Pango::Layout::create (get_pango_context());
+ _right_layout = Pango::Layout::create (get_pango_context());
}
- show_all ();
-
set_widget_name (widget_name);
_mode = BBT; /* lie to force mode switch */
set_mode (Timecode);
set (last_when, true);
- connect_signals ();
-
if (!is_transient) {
clocks.push_back (this);
}
+
+ UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AudioClock::set_colors));
+ UIConfiguration::instance().DPIReset.connect (sigc::mem_fun (*this, &AudioClock::dpi_reset));
}
-
+
AudioClock::~AudioClock ()
{
- /* these are not manage()'d, so that we can add/remove
- them from containers as necessary.
- */
-
- delete display;
- delete supplemental_left;
- delete supplemental_right;
+ delete foreground_attr;
+ delete editing_attr;
+}
- for (std::map<Field,CairoCell*>::iterator i = _fixed_cells.begin(); i != _fixed_cells.end(); ++i) {
- delete i->second;
+void
+AudioClock::set_widget_name (const string& str)
+{
+ if (str.empty()) {
+ set_name ("clock");
+ } else {
+ set_name (str + " clock");
}
- for (std::map<Field,CairoTextCell*>::iterator i = _text_cells.begin(); i != _text_cells.end(); ++i) {
- delete i->second;
+ if (is_realized()) {
+ set_colors ();
}
}
+
void
-AudioClock::set_widget_name (const string& name)
+AudioClock::on_realize ()
{
- Widget::set_name (name);
+ Gtk::Requisition req;
+
+ CairoWidget::on_realize ();
+
+ set_clock_dimensions (req);
- set_theme ();
+ first_width = req.width;
+ first_height = req.height;
+
+ // XXX FIX ME: define font based on ... ???
+ // set_font ();
+ set_colors ();
}
void
-AudioClock::set_theme ()
+AudioClock::set_font (Pango::FontDescription font)
{
Glib::RefPtr<Gtk::Style> style = get_style ();
- double r, g, b, a;
+ Pango::AttrFontDesc* font_attr;
- if (!style) {
- return;
+ font_size = font.get_size();
+ font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
+
+ normal_attributes.change (*font_attr);
+ editing_attributes.change (*font_attr);
+
+ /* now a smaller version of the same font */
+
+ delete font_attr;
+ font.set_size (INFO_FONT_SIZE);
+ font.set_weight (Pango::WEIGHT_NORMAL);
+ font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
+
+ info_attributes.change (*font_attr);
+
+ /* and an even smaller one */
+
+ delete font_attr;
+
+ /* 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);
+
+ /* force redraw of markup with new font-size */
+ set (last_when, true);
+}
+
+void
+AudioClock::set_active_state (Gtkmm2ext::ActiveState s)
+{
+ CairoWidget::set_active_state (s);
+ set_colors ();
+}
+
+void
+AudioClock::set_colors ()
+{
+ int r, g, b, a;
+
+ uint32_t bg_color;
+ uint32_t text_color;
+ uint32_t editing_color;
+ uint32_t cursor_color;
+
+ if (active_state()) {
+ 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()));
+ } else {
+ 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()));
+ }
+
+ /* store for bg and cursor in render() */
+
+ UINT_TO_RGBA (bg_color, &r, &g, &b, &a);
+
+ bg_r = r/255.0;
+ bg_g = g/255.0;
+ bg_b = b/255.0;
+ bg_a = a/255.0;
+
+ 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;
+
+ /* rescale for Pango colors ... sigh */
+
+ r = lrint (r * 65535.0);
+ g = lrint (g * 65535.0);
+ b = lrint (b * 65535.0);
+
+ UINT_TO_RGBA (text_color, &r, &g, &b, &a);
+ r = lrint ((r/255.0) * 65535.0);
+ g = lrint ((g/255.0) * 65535.0);
+ b = lrint ((b/255.0) * 65535.0);
+ delete foreground_attr;
+ foreground_attr = new Pango::AttrColor (Pango::Attribute::create_attr_foreground (r, g, b));
+
+ UINT_TO_RGBA (editing_color, &r, &g, &b, &a);
+ r = lrint ((r/255.0) * 65535.0);
+ g = lrint ((g/255.0) * 65535.0);
+ b = lrint ((b/255.0) * 65535.0);
+ delete editing_attr;
+ editing_attr = new Pango::AttrColor (Pango::Attribute::create_attr_foreground (r, g, b));
+
+ 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);
+ }
+
+ queue_draw ();
+}
+
+void
+AudioClock::set_scale (double x, double y)
+{
+ xscale = x;
+ yscale = y;
+
+ queue_draw ();
+}
+
+void
+AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
+{
+ /* main layout: rounded rect, plus the text */
+
+ if (_need_bg) {
+ cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
+ if (corner_radius) {
+ if (_left_layout) {
+ Gtkmm2ext::rounded_top_half_rectangle (cr, 0, 0, get_width(), upper_height, corner_radius);
+ } else {
+ Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), upper_height, corner_radius);
+ }
+ } else {
+ cairo_rectangle (cr, 0, 0, get_width(), upper_height);
+ }
+ cairo_fill (cr);
+ }
+
+ double lw = layout_width * xscale;
+ double lh = layout_height * yscale;
+
+ cairo_move_to (cr, (get_width() - lw) / 2.0, (upper_height - lh) / 2.0);
+
+ if (xscale != 1.0 || yscale != 1.0) {
+ cairo_save (cr);
+ cairo_scale (cr, xscale, yscale);
+ }
+
+ pango_cairo_show_layout (cr, _layout->gobj());
+
+ if (xscale != 1.0 || yscale != 1.0) {
+ cairo_restore (cr);
+ }
+
+ if (_left_layout) {
+
+ double h = get_height() - upper_height - separator_height;
+
+ if (_need_bg) {
+ cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
+ }
+
+ if (mode_based_info_ratio != 1.0) {
+
+ double left_rect_width = get_left_rect_width();
+
+ if (_need_bg) {
+ if (corner_radius) {
+ Gtkmm2ext::rounded_bottom_half_rectangle (cr, 0, upper_height + separator_height,
+ left_rect_width + (separator_height == 0 ? corner_radius : 0),
+ h, corner_radius);
+ } else {
+ cairo_rectangle (cr, 0, upper_height + separator_height, left_rect_width, h);
+ }
+ cairo_fill (cr);
+ }
+
+ cairo_move_to (cr, x_leading_padding, upper_height + separator_height + ((h - info_height)/2.0));
+ pango_cairo_show_layout (cr, _left_layout->gobj());
+
+ if (_need_bg) {
+ if (corner_radius) {
+ Gtkmm2ext::rounded_bottom_half_rectangle (cr, left_rect_width + separator_height,
+ upper_height + separator_height,
+ get_width() - separator_height - left_rect_width,
+ h, corner_radius);
+ } else {
+ cairo_rectangle (cr, left_rect_width + separator_height, upper_height + separator_height,
+ get_width() - separator_height - left_rect_width, h);
+ }
+ cairo_fill (cr);
+ }
+
+
+ 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);
+ x = get_width() - rw - separator_height - x_leading_padding;
+ if (x < x_leading_padding + left_rect_width + separator_height) {
+ /* rather cut off the right end than overlap with the text on the left */
+ x = x_leading_padding + left_rect_width + separator_height;
+ }
+ cairo_move_to (cr, x, upper_height + separator_height + ((h - info_height)/2.0));
+ } else {
+ cairo_move_to (cr, x_leading_padding + left_rect_width + separator_height, upper_height + separator_height + ((h - info_height)/2.0));
+ }
+ pango_cairo_show_layout (cr, _right_layout->gobj());
+
+ } else {
+ /* no info to display, or just one */
+
+ if (_need_bg) {
+ if (corner_radius) {
+ Gtkmm2ext::rounded_bottom_half_rectangle (cr, 0, upper_height + separator_height, get_width(), h, corner_radius);
+ } else {
+ cairo_rectangle (cr, 0, upper_height + separator_height, get_width(), h);
+ }
+ cairo_fill (cr);
+ }
+ }
}
- Pango::FontDescription font;
+ if (editing) {
+ if (!insert_map.empty()) {
+
+ int xcenter = (get_width() - layout_width) /2;
+
+ if (input_string.length() < insert_map.size()) {
+ Pango::Rectangle cursor;
+
+ 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()]);
+ }
+
+ cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
+ cairo_rectangle (cr,
+ 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);
+ } else {
+ /* we've entered all possible digits, no cursor */
+ }
+
+ } else {
+ if (input_string.empty()) {
+ cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
+ cairo_rectangle (cr,
+ (get_width()/2.0),
+ (upper_height - layout_height)/2.0,
+ 2.0, upper_height);
+ cairo_fill (cr);
+ }
+ }
+ }
+}
+
+void
+AudioClock::on_size_allocate (Gtk::Allocation& alloc)
+{
+ CairoWidget::on_size_allocate (alloc);
+
+ if (_left_layout) {
+ upper_height = (get_height()/2.0) - 1.0;
+ } else {
+ upper_height = get_height();
+ }
+}
+
+void
+AudioClock::set_clock_dimensions (Gtk::Requisition& req)
+{
+ Glib::RefPtr<Pango::Layout> tmp;
+ Glib::RefPtr<Gtk::Style> style = get_style ();
+ Pango::FontDescription font;
+
+ tmp = Pango::Layout::create (get_pango_context());
if (!is_realized()) {
font = get_font_for_style (get_name());
font = style->get_font();
}
- display->set_font (font);
+ tmp->set_font_description (font);
+ /* this string is the longest thing we will ever display */
+ if (_mode == MinSec)
+ tmp->set_text (" 88:88:88,888 ");
+ else
+ tmp->set_text (" 88:88:88,88 ");
+ tmp->get_pixel_size (req.width, req.height);
- if (supplemental_left) {
- /* propagate font style, sort of, into supplemental text */
- boost::shared_ptr<CairoFontDescription> smaller_font (new CairoFontDescription (*display->font().get()));
- smaller_font->set_size (12);
- smaller_font->set_weight (Cairo::FONT_WEIGHT_NORMAL);
- supplemental_right->set_font (smaller_font);
- supplemental_left->set_font (smaller_font);
+ 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.
+ */
+
+ if (first_width) {
+ req->width = first_width;
+ req->height = first_height;
+ return;
}
- Gdk::Color bg = style->get_base (Gtk::STATE_NORMAL);
- Gdk::Color fg = style->get_text (Gtk::STATE_NORMAL);
- Gdk::Color eg = style->get_text (Gtk::STATE_ACTIVE);
+ set_clock_dimensions (*req);
+
+ /* now tackle height, for which we need to know the height of the lower
+ * layout
+ */
+
+ if (_left_layout) {
+
+ Glib::RefPtr<Pango::Layout> tmp;
+ Glib::RefPtr<Gtk::Style> style = get_style ();
+ Pango::FontDescription font;
+ int w;
+
+ tmp = Pango::Layout::create (get_pango_context());
+
+ if (!is_realized()) {
+ font = get_font_for_style (get_name());
+ } else {
+ font = style->get_font();
+ }
- r = bg.get_red_p ();
- g = bg.get_green_p ();
- b = bg.get_blue_p ();
- a = 1.0;
+ tmp->set_font_description (font);
- display->set_bg (r, g, b, a);
+ font.set_size (INFO_FONT_SIZE);
+ font.set_weight (Pango::WEIGHT_NORMAL);
+ tmp->set_font_description (font);
- if (supplemental_right) {
- supplemental_right->set_bg (r,g,b,a);
- supplemental_left->set_bg (r,g,b,a);
+ /* 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 */
+
+ tmp->get_pixel_size (w, info_height);
+
+ /* silly extra padding that seems necessary to correct the info
+ * that pango just gave us. I have no idea why.
+ */
+
+ req->height += info_height;
+ req->height += separator_height;
}
+}
+
+void
+AudioClock::show_edit_status (int length)
+{
+ editing_attr->set_start_index (edit_string.length() - length);
+ editing_attr->set_end_index (edit_string.length());
+
+ editing_attributes.change (*foreground_attr);
+ editing_attributes.change (*editing_attr);
+
+ _layout->set_attributes (editing_attributes);
+}
- r = fg.get_red_p ();
- g = fg.get_green_p ();
- b = fg.get_blue_p ();
- a = 1.0;
+void
+AudioClock::start_edit (Field f)
+{
+ if (!editing) {
+ pre_edit_string = _layout->get_text ();
+ if (!insert_map.empty()) {
+ edit_string = pre_edit_string;
+ } else {
+ edit_string.clear ();
+ _layout->set_text ("");
+ }
+
+ input_string.clear ();
+ editing = true;
+ edit_is_negative = false;
+
+ if (f) {
+ input_string = get_field (f);
+ show_edit_status (merge_input_and_edit_string ());
+ _layout->set_text (edit_string);
+ }
+
+ queue_draw ();
- display->set_colors (r, g, b, a);
+ Keyboard::magic_widget_grab_focus ();
+ grab_focus ();
+ }
+}
- if (supplemental_right) {
- supplemental_right->set_colors (r,g,b,a);
- supplemental_left->set_colors (r,g,b,a);
+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;
}
+ return "";
+}
+
+void
+AudioClock::end_edit (bool modify)
+{
+ if (modify) {
+
+ bool ok = true;
+
+ switch (_mode) {
+ case Timecode:
+ ok = timecode_validate_edit (edit_string);
+ break;
- r = eg.get_red_p ();
- g = eg.get_green_p ();
- b = eg.get_blue_p ();
- a = 1.0;
+ case BBT:
+ ok = bbt_validate_edit (edit_string);
+ break;
- display->set_edit_colors (r, g, b, a);
+ case MinSec:
+ ok = minsec_validate_edit (edit_string);
+ break;
- if (supplemental_right) {
- supplemental_right->set_edit_colors (r,g,b,a);
- supplemental_left->set_edit_colors (r,g,b,a);
+ case Frames:
+ if (edit_string.length() < 1) {
+ edit_string = pre_edit_string;
+ }
+ break;
+ }
+
+ if (!ok) {
+ edit_string = pre_edit_string;
+ input_string.clear ();
+ _layout->set_text (edit_string);
+ show_edit_status (0);
+ /* edit attributes remain in use */
+ } else {
+
+ editing = false;
+ framepos_t pos = 0; /* stupid gcc */
+
+ switch (_mode) {
+ case Timecode:
+ pos = frames_from_timecode_string (edit_string);
+ break;
+
+ case BBT:
+ if (is_duration) {
+ pos = frame_duration_from_bbt_string (0, edit_string);
+ } else {
+ pos = frames_from_bbt_string (0, edit_string);
+ }
+ break;
+
+ case MinSec:
+ pos = frames_from_minsec_string (edit_string);
+ break;
+
+ case Frames:
+ pos = frames_from_audioframes_string (edit_string);
+ break;
+ }
+
+ set (pos, true);
+ _layout->set_attributes (normal_attributes);
+ ValueChanged(); /* EMIT_SIGNAL */
+ }
+
+ } else {
+
+ editing = false;
+ edit_is_negative = false;
+ _layout->set_attributes (normal_attributes);
+ _layout->set_text (pre_edit_string);
}
queue_draw ();
+
+ if (!editing) {
+ drop_focus ();
+ }
}
void
-AudioClock::focus ()
+AudioClock::drop_focus ()
{
+ Keyboard::magic_widget_drop_focus ();
+
+ if (has_focus()) {
+
+ /* move focus back to the default widget in the top level window */
+
+ Widget* top = get_toplevel();
+
+ if (top->is_toplevel ()) {
+ Window* win = dynamic_cast<Window*> (top);
+ win->grab_focus ();
+ }
+ }
}
-void
-AudioClock::end_edit ()
+framecnt_t
+AudioClock::parse_as_frames_distance (const std::string& str)
{
- display->stop_editing ();
- editing_field = (Field) 0;
- key_entry_state = 0;
+ framecnt_t f;
- /* move focus back to the default widget in the top level window */
+ if (sscanf (str.c_str(), "%" PRId64, &f) == 1) {
+ return f;
+ }
- Keyboard::magic_widget_drop_focus ();
+ return 0;
+}
+
+framecnt_t
+AudioClock::parse_as_minsec_distance (const std::string& str)
+{
+ 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);
+
+ 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));
- Widget* top = get_toplevel();
+ 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));
- if (top->is_toplevel ()) {
- Window* win = dynamic_cast<Window*> (top);
- win->grab_focus ();
+ 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));
+
+ default:
+ break;
}
+
+ return 0;
}
-void
-AudioClock::on_realize ()
+framecnt_t
+AudioClock::parse_as_timecode_distance (const std::string& str)
+{
+ double fps = _session->timecode_frames_per_second();
+ framecnt_t sr = _session->frame_rate();
+ int frames;
+ int secs;
+ int mins;
+ int hrs;
+
+ switch (str.length()) {
+ case 0:
+ return 0;
+ case 1:
+ case 2:
+ sscanf (str.c_str(), "%" PRId32, &frames);
+ return llrint ((frames/(float)fps) * sr);
+
+ case 3:
+ sscanf (str.c_str(), "%1" PRId32 "%" PRId32, &secs, &frames);
+ return (secs * sr) + llrint ((frames/(float)fps) * sr);
+
+ case 4:
+ sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &frames);
+ return (secs * sr) + llrint ((frames/(float)fps) * sr);
+
+ case 5:
+ sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &frames);
+ return (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
+
+ case 6:
+ sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &frames);
+ return (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
+
+ case 7:
+ sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &frames);
+ return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
+
+ case 8:
+ sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &frames);
+ return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + llrint ((frames/(float)fps) * sr);
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+framecnt_t
+AudioClock::parse_as_bbt_distance (const std::string&)
{
- VBox::on_realize ();
+ return 0;
+}
- /* styles are not available until the widgets are bound to a window */
-
- set_theme ();
+framecnt_t
+AudioClock::parse_as_distance (const std::string& instr)
+{
+ switch (_mode) {
+ case Timecode:
+ return parse_as_timecode_distance (instr);
+ break;
+ case Frames:
+ return parse_as_frames_distance (instr);
+ break;
+ case BBT:
+ return parse_as_bbt_distance (instr);
+ break;
+ case MinSec:
+ return parse_as_minsec_distance (instr);
+ break;
+ }
+ return 0;
}
void
-AudioClock::set (framepos_t when, bool force, framecnt_t offset, char which)
+AudioClock::end_edit_relative (bool add)
{
- if ((!force && !is_visible()) || _session == 0) {
+ bool ok = true;
+
+ switch (_mode) {
+ case Timecode:
+ ok = timecode_validate_edit (edit_string);
+ break;
+
+ case BBT:
+ ok = bbt_validate_edit (edit_string);
+ break;
+
+ case MinSec:
+ ok = minsec_validate_edit (edit_string);
+ break;
+
+ case Frames:
+ break;
+ }
+
+ 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;
}
- bool const pdelta = Config->get_primary_clock_delta_edit_cursor ();
- bool const sdelta = Config->get_secondary_clock_delta_edit_cursor ();
+ framecnt_t frames = parse_as_distance (input_string);
+
+ editing = false;
- if (offset && which == 'p' && pdelta) {
- when = (when > offset) ? when - offset : offset - when;
- } else if (offset && which == 's' && sdelta) {
- when = (when > offset) ? when - offset : offset - when;
+ editing = false;
+ _layout->set_attributes (normal_attributes);
+
+ if (frames != 0) {
+ if (add) {
+ set (current_time() + frames, true);
+ } else {
+ framepos_t c = current_time();
+
+ if (c > frames || _negative_allowed) {
+ set (c - frames, true);
+ } else {
+ set (0, true);
+ }
+ }
+ ValueChanged (); /* EMIT SIGNAL */
}
- if (when == last_when && !force) {
+ input_string.clear ();
+ queue_draw ();
+ drop_focus ();
+}
+
+void
+AudioClock::session_property_changed (const PropertyChange&)
+{
+ set (last_when, true);
+}
+
+void
+AudioClock::metric_position_changed ()
+{
+ set (last_when, true);
+}
+
+void
+AudioClock::session_configuration_changed (std::string p)
+{
+ if (_negative_allowed) {
+ /* session option editor clock */
return;
}
- if (which == 'p' && pdelta && !last_pdelta) {
- set_widget_name("TransportClockDisplayDelta");
- last_pdelta = true;
- } else if (which == 'p' && !pdelta && last_pdelta) {
- set_widget_name("TransportClockDisplay");
- last_pdelta = false;
- } else if (which == 's' && sdelta && !last_sdelta) {
- set_widget_name("SecondaryClockDisplayDelta");
- last_sdelta = true;
- } else if (which == 's' && !sdelta && last_sdelta) {
- set_widget_name("SecondaryClockDisplay");
- last_sdelta = false;
+ if (p == "sync-source" || p == "external-sync") {
+ set (current_time(), true);
+ return;
}
+ if (p != "timecode-offset" && p != "timecode-offset-negative") {
+ return;
+ }
+
+ framecnt_t current;
+
switch (_mode) {
case Timecode:
- set_timecode (when, force);
+ if (is_duration) {
+ current = current_duration ();
+ } else {
+ current = current_time ();
+ }
+ set (current, true);
+ break;
+ default:
break;
+ }
+}
+
+void
+AudioClock::set (framepos_t when, bool force, framecnt_t offset)
+{
+ if ((!force && !is_visible()) || _session == 0) {
+ return;
+ }
+
+ if (is_duration) {
+ when = when - offset;
+ }
+
+ if (when == last_when && !force) {
+#if 0 // XXX return if no change and no change forced. verify Aug/2014
+ if (_mode != Timecode && _mode != MinSec) {
+ /* may need to force display of TC source
+ * time, so don't return early.
+ */
+ /* ^^ 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.
+ */
+ return;
+ }
+#else
+ return;
+#endif
+ }
+
+ if (!editing) {
+ if (_right_layout) {
+ _right_layout->set_alignment(Pango::ALIGN_LEFT);
+ }
- case BBT:
- set_bbt (when, force);
- break;
+ switch (_mode) {
+ case Timecode:
+ if (_right_layout) {
+ _right_layout->set_alignment(Pango::ALIGN_RIGHT);
+ }
+ set_timecode (when, force);
+ break;
- case MinSec:
- set_minsec (when, force);
- break;
+ case BBT:
+ set_bbt (when, force);
+ break;
- case Frames:
- set_frames (when, force);
- break;
+ case MinSec:
+ if (_right_layout) {
+ _right_layout->set_alignment(Pango::ALIGN_RIGHT);
+ }
+ set_minsec (when, force);
+ break;
+
+ case Frames:
+ set_frames (when, force);
+ break;
+ }
}
+ queue_draw ();
last_when = when;
-
- /* we're setting the time from a frames value, so keep it as the canonical value */
- _canonical_time = when;
- _canonical_time_is_displayed = false;
}
void
-AudioClock::session_configuration_changed (std::string p)
+AudioClock::set_slave_info ()
{
- if (p != "timecode-offset" && p != "timecode-offset-negative") {
+ if (!_left_layout || !_right_layout) {
return;
}
- framecnt_t current;
+ SyncSource sync_src = Config->get_sync_source();
- switch (_mode) {
- case Timecode:
- if (is_duration) {
- current = current_duration ();
- } else {
- current = current_time ();
+ if (_session->config.get_external_sync()) {
+ Slave* slave = _session->slave();
+
+ switch (sync_src) {
+ case Engine:
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+ INFO_FONT_SIZE, sync_source_to_string(sync_src, true)));
+ _right_layout->set_text ("");
+ break;
+ case MIDIClock:
+ if (slave) {
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+ INFO_FONT_SIZE, sync_source_to_string(sync_src, true)));
+ _right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+ INFO_FONT_SIZE, slave->approximate_current_delta()));
+ } else {
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+ INFO_FONT_SIZE, _("--pending--")));
+ _right_layout->set_text ("");
+ }
+ break;
+ case LTC:
+ case MTC:
+ if (slave) {
+ bool matching;
+ TimecodeSlave* tcslave;
+ if ((tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
+ matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span><span foreground=\"%3\">%4</span></span>",
+ INFO_FONT_SIZE, sync_source_to_string(sync_src, true)[0], (matching?"green":"red"),
+ dynamic_cast<TimecodeSlave*>(slave)->approximate_current_position()));
+ _right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+ INFO_FONT_SIZE, slave->approximate_current_delta()));
+ }
+ } else {
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+ INFO_FONT_SIZE, _("--pending--")));
+ _right_layout->set_text ("");
+ }
+ break;
}
- set (current, true);
- break;
- default:
- break;
+ } else {
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "INT/%2</span></span>",
+ INFO_FONT_SIZE, sync_source_to_string(sync_src, true)));
+ _right_layout->set_text ("");
}
}
AudioClock::set_frames (framepos_t when, bool /*force*/)
{
char buf[32];
- snprintf (buf, sizeof (buf), "%" PRId64, when);
+ bool negative = false;
if (_off) {
- display->set_text (_text_cells[AudioFrames], "-----------");
+ _layout->set_text (" ----------");
- if (supplemental_left) {
- supplemental_left->set_text (_text_cells[LowerLeft2], "");
- supplemental_right->set_text (_text_cells[LowerRight2], "");
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
}
-
+
return;
}
-
- display->set_text (_text_cells[AudioFrames], buf);
+ if (when < 0) {
+ when = -when;
+ negative = true;
+ }
+
+ if (negative) {
+ snprintf (buf, sizeof (buf), "-%10" PRId64, when);
+ } else {
+ snprintf (buf, sizeof (buf), " %10" PRId64, when);
+ }
+
+ _layout->set_text (buf);
- if (supplemental_left) {
+ if (_left_layout) {
framecnt_t rate = _session->frame_rate();
- if (fmod (rate, 1000.0) == 0.000) {
- sprintf (buf, "%" PRId64 "K", rate/1000);
+ if (fmod (rate, 100.0) == 0.0) {
+ sprintf (buf, "%.1fkHz", rate/1000.0);
} else {
- sprintf (buf, "%" PRId64, rate);
+ sprintf (buf, "%" PRId64 "Hz", rate);
}
- supplemental_left->set_text (_text_cells[LowerLeft2], buf);
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2 </span><span foreground=\"green\">%3</span></span>",
+ INFO_FONT_SIZE, _("SR"), buf));
float vid_pullup = _session->config.get_video_pullup();
if (vid_pullup == 0.0) {
- supplemental_right->set_text (_text_cells[LowerRight2], _("none"));
+ _right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2 </span><span foreground=\"green\">off</span></span>",
+ INFO_FONT_SIZE, _("Pull")));
} else {
- sprintf (buf, "%-6.4f", vid_pullup);
- supplemental_right->set_text (_text_cells[LowerRight2], buf);
+ sprintf (buf, _("%+.4f%%"), vid_pullup);
+ _right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2 </span><span foreground=\"green\">%3</span></span>",
+ INFO_FONT_SIZE, _("Pull"), buf));
}
}
}
void
-AudioClock::set_minsec (framepos_t when, bool force)
+AudioClock::print_minsec (framepos_t when, char* buf, size_t bufsize, float frame_rate)
{
- char buf[32];
framecnt_t left;
int hrs;
int mins;
int secs;
int millisecs;
+ bool negative;
- if (_off) {
- display->set_text (_text_cells[MS_Hours], "--");
- display->set_text (_text_cells[MS_Minutes], "--");
- display->set_text (_text_cells[MS_Seconds], "--");
- display->set_text (_text_cells[MS_Milliseconds], "--");
-
- if (supplemental_left) {
- supplemental_left->set_text (_text_cells[LowerLeft2], "");
- supplemental_right->set_text (_text_cells[LowerRight2], "");
- }
-
- return;
- }
-
- left = when;
- hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
- left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
- mins = (int) floor (left / (_session->frame_rate() * 60.0f));
- left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
- secs = (int) floor (left / (float) _session->frame_rate());
- left -= (framecnt_t) floor (secs * _session->frame_rate());
- millisecs = floor (left * 1000.0 / (float) _session->frame_rate());
-
- if (force || hrs != ms_last_hrs) {
- sprintf (buf, "%02d", hrs);
- display->set_text (_text_cells[MS_Hours], buf);
- ms_last_hrs = hrs;
- }
-
- if (force || mins != ms_last_mins) {
- sprintf (buf, "%02d", mins);
- display->set_text (_text_cells[MS_Minutes], buf);
- ms_last_mins = mins;
+ if (when < 0) {
+ when = -when;
+ negative = true;
+ } else {
+ negative = false;
}
- if (force || secs != ms_last_secs) {
- sprintf (buf, "%02d", secs);
- display->set_text (_text_cells[MS_Seconds], buf);
- ms_last_secs = secs;
+ 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);
}
- if (force || millisecs != ms_last_millisecs) {
- sprintf (buf, "%03d", millisecs);
- display->set_text (_text_cells[MS_Milliseconds], buf);
- ms_last_millisecs = millisecs;
- }
}
void
-AudioClock::set_timecode (framepos_t when, bool force)
+AudioClock::set_minsec (framepos_t when, bool /*force*/)
{
char buf[32];
- Timecode::Time TC;
if (_off) {
- display->set_text (_text_cells[Timecode_Sign], "");
- display->set_text (_text_cells[Timecode_Hours], "--");
- display->set_text (_text_cells[Timecode_Minutes], "--");
- display->set_text (_text_cells[Timecode_Seconds], "--");
- display->set_text (_text_cells[Timecode_Frames], "--");
-
- if (supplemental_left) {
- supplemental_left->set_text (_text_cells[LowerLeft2], "");
- supplemental_right->set_text (_text_cells[LowerRight2], "");
+ _layout->set_text (" --:--:--.---");
+
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
}
-
+
return;
}
- if (is_duration) {
- _session->timecode_duration (when, TC);
- } else {
- _session->timecode_time (when, TC);
- }
+ print_minsec (when, buf, sizeof (buf), _session->frame_rate());
- if (force || TC.hours != last_hrs || TC.negative != last_negative) {
- if (TC.negative) {
- display->set_text (_text_cells[Timecode_Sign], "-");
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Hours], TC.hours);
- } else {
- display->set_text (_text_cells[Timecode_Sign], " ");
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Hours], TC.hours);
+ _layout->set_text (buf);
+ set_slave_info();
+}
+
+void
+AudioClock::set_timecode (framepos_t when, bool /*force*/)
+{
+ Timecode::Time TC;
+ bool negative = false;
+
+ if (_off) {
+ _layout->set_text (" --:--:--:--");
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
}
- display->set_text (_text_cells[Timecode_Hours], buf);
- last_hrs = TC.hours;
- last_negative = TC.negative;
- }
- if (force || TC.minutes != last_mins) {
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Minutes], TC.minutes);
- display->set_text (_text_cells[Timecode_Minutes], buf);
- last_mins = TC.minutes;
+ return;
}
- if (force || TC.seconds != last_secs) {
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Seconds], TC.seconds);
- display->set_text (_text_cells[Timecode_Seconds], buf);
- last_secs = TC.seconds;
+ if (when < 0) {
+ when = -when;
+ negative = true;
}
- if (force || TC.frames != last_frames) {
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Frames], TC.frames);
- display->set_text (_text_cells[Timecode_Frames], buf);
- last_frames = TC.frames;
+ if (is_duration) {
+ _session->timecode_duration (when, TC);
+ } else {
+ _session->timecode_time (when, TC);
}
- if (supplemental_right) {
- double timecode_frames = _session->timecode_frames_per_second();
- bool drop;
+ TC.negative = TC.negative || negative;
- if ((fabs(timecode_frames - 29.97) < 0.0001) || timecode_frames == 30) {
- if (_session->timecode_drop_frames()) {
- drop = true;
- } else {
- drop = false;
- }
- }
-
- if (fmod(timecode_frames, 1.0) == 0.0) {
- sprintf (buf, "%u %s", int (timecode_frames), (drop ? "D" : ""));
- } else {
- sprintf (buf, "%.2f %s", timecode_frames, (drop ? "D" : ""));
- }
+ _layout->set_text (Timecode::timecode_format_time(TC));
- supplemental_right->set_text (_text_cells[LowerRight2], buf);
- }
+ set_slave_info();
}
void
-AudioClock::set_bbt (framepos_t when, bool force)
+AudioClock::set_bbt (framepos_t when, bool /*force*/)
{
char buf[16];
Timecode::BBT_Time BBT;
+ bool negative = false;
if (_off) {
- display->set_text (_text_cells[Bars], "--");
- display->set_text (_text_cells[Beats], "--");
- display->set_text (_text_cells[Ticks], "--");
-
- if (supplemental_left) {
- supplemental_left->set_text (_text_cells[LowerLeft2], "");
- supplemental_right->set_text (_text_cells[LowerRight2], "");
+ _layout->set_text (" ---|--|----");
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
}
-
return;
}
+ if (when < 0) {
+ when = -when;
+ negative = true;
+ }
+
/* handle a common case */
if (is_duration) {
if (when == 0) {
BBT.beats = 0;
BBT.ticks = 0;
} else {
- _session->tempo_map().bbt_time (when, BBT);
+ BBT = _session->tempo_map().bbt_at_frame (when);
BBT.bars--;
BBT.beats--;
}
} else {
- _session->tempo_map().bbt_time (when, BBT);
+ BBT = _session->tempo_map().bbt_at_frame (when);
}
- sprintf (buf, "%0*" PRIu32, field_length[Bars], BBT.bars);
- if (force || _text_cells[Bars]->get_text () != buf) {
- display->set_text (_text_cells[Bars], buf);
- }
- sprintf (buf, "%0*" PRIu32, field_length[Beats], BBT.beats);
- if (force || _text_cells[Beats]->get_text () != buf) {
- display->set_text (_text_cells[Beats], buf);
- }
- sprintf (buf, "%0*" PRIu32, field_length[Ticks], BBT.ticks);
- if (force || _text_cells[Ticks]->get_text () != buf) {
- display->set_text (_text_cells[Ticks], buf);
+ if (negative) {
+ snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
+ BBT.bars, BBT.beats, BBT.ticks);
+ } else {
+ snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
+ BBT.bars, BBT.beats, BBT.ticks);
}
- if (supplemental_right) {
+ _layout->set_text (buf);
+
+ if (_right_layout) {
framepos_t pos;
if (bbt_reference_time < 0) {
TempoMetric m (_session->tempo_map().metric_at (pos));
- sprintf (buf, "%-5.2f", m.tempo().beats_per_minute());
- supplemental_left->set_text (_text_cells[LowerLeft2], buf);
+ sprintf (buf, "%-5.3f", _session->tempo_map().tempo_at_frame (pos).beats_per_minute());
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%3</span> <span foreground=\"green\">%2</span></span>",
+ INFO_FONT_SIZE, buf, _("Tempo")));
- sprintf (buf, "%g|%g", m.meter().beats_per_bar(), m.meter().note_divisor());
- supplemental_right->set_text (_text_cells[LowerRight2], buf);
+ sprintf (buf, "%g/%g", m.meter().divisions_per_bar(), m.meter().note_divisor());
+ _right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%3</span> <span foreground=\"green\">%2</span></span>",
+ INFO_FONT_SIZE, buf, _("Meter")));
}
}
if (_session) {
_session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_configuration_changed, this, _1), gui_context());
+ _session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_property_changed, this, _1), gui_context());
+ _session->tempo_map().MetricPositionChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::metric_position_changed, this), gui_context());
- const XMLProperty* prop;
+ XMLProperty const * prop;
XMLNode* node = _session->extra_xml (X_("ClockModes"));
AudioClock::Mode amode;
if ((prop = (*i)->property (X_("mode"))) != 0) {
amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
- set_mode (amode);
+ set_mode (amode, true);
}
if ((prop = (*i)->property (X_("on"))) != 0) {
set_off (!string_is_affirmative (prop->value()));
}
}
-void
-AudioClock::edit_next_field ()
-{
- /* move on to the next field.
- */
-
- switch (editing_field) {
-
- /* Timecode */
-
- case Timecode_Hours:
- editing_field = Timecode_Minutes;
- display->start_editing (_text_cells[Timecode_Minutes]);
- break;
- case Timecode_Minutes:
- editing_field = Timecode_Seconds;
- display->start_editing (_text_cells[Timecode_Seconds]);
- break;
- case Timecode_Seconds:
- editing_field = Timecode_Frames;
- display->start_editing (_text_cells[Timecode_Frames]);
- break;
- case Timecode_Frames:
- end_edit ();
- break;
-
- /* Min:Sec */
-
- case MS_Hours:
- editing_field = MS_Minutes;
- display->start_editing (_text_cells[MS_Minutes]);
- break;
- case MS_Minutes:
- editing_field = MS_Seconds;
- display->start_editing (_text_cells[MS_Seconds]);
- break;
- case MS_Seconds:
- editing_field = MS_Milliseconds;
- display->start_editing (_text_cells[MS_Milliseconds]);
- break;
- case MS_Milliseconds:
- end_edit ();
- break;
-
- /* BBT */
-
- case Bars:
- editing_field = Beats;
- display->start_editing (_text_cells[Beats]);
- break;
- case Beats:
- editing_field = Ticks;
- display->start_editing (_text_cells[Ticks]);
- break;
- case Ticks:
- end_edit ();
- break;
-
- /* audio frames */
- case AudioFrames:
- end_edit ();
- break;
-
- default:
- break;
- }
-
- key_entry_state = 0;
-}
-
bool
AudioClock::on_key_press_event (GdkEventKey* ev)
{
- /* return true for keys that we MIGHT use
- at release
- */
- 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:
- return true;
- default:
- return false;
- }
-}
-
-bool
-AudioClock::on_key_release_event (GdkEventKey *ev)
-{
- if (editing_field == 0) {
- return false;
- }
-
- CairoTextCell *cell = _text_cells[editing_field];
-
- if (!cell) {
+ if (!editing) {
return false;
}
string new_text;
char new_char = 0;
- bool move_on = false;
+ int highlight_length;
+ framepos_t pos;
switch (ev->keyval) {
case GDK_0:
new_char = '9';
break;
- case GDK_period:
- case GDK_comma:
- case GDK_KP_Decimal:
- if (_mode == MinSec && editing_field == MS_Seconds) {
- new_char = '.'; // XXX i18n
+ case GDK_minus:
+ case GDK_KP_Subtract:
+ if (_negative_allowed && input_string.empty()) {
+ edit_is_negative = true;
+ edit_string.replace(0,1,"-");
+ _layout->set_text (edit_string);
+ queue_draw ();
} else {
- return false;
+ end_edit_relative (false);
}
+ return true;
+ break;
+
+ case GDK_plus:
+ end_edit_relative (true);
+ return true;
break;
case GDK_Tab:
case GDK_Return:
case GDK_KP_Enter:
- move_on = true;
+ end_edit (true);
+ return true;
break;
case GDK_Escape:
- end_edit ();
+ end_edit (false);
ChangeAborted(); /* EMIT SIGNAL */
return true;
+ case GDK_Delete:
+ case GDK_BackSpace:
+ if (!input_string.empty()) {
+ /* delete the last key entered
+ */
+ input_string = input_string.substr (0, input_string.length() - 1);
+ }
+ goto use_input_string;
+
default:
- return false;
+ /* do not allow other keys to passthru to the rest of the GUI
+ when editing.
+ */
+ return true;
}
- if (!move_on) {
-
- if (key_entry_state == 0) {
+ if (!insert_map.empty() && (input_string.length() >= insert_map.size())) {
+ /* too many digits: eat the key event, but do nothing with it */
+ return true;
+ }
- /* initialize with a fresh new string */
+ input_string.push_back (new_char);
- if (editing_field != AudioFrames) {
- for (uint32_t xn = 0; xn < field_length[editing_field] - 1; ++xn) {
- new_text += '0';
- }
- } else {
- new_text = "";
- }
+ use_input_string:
+ switch (_mode) {
+ case Frames:
+ /* get this one in the right order, and to the right width */
+ if (ev->keyval == GDK_Delete || ev->keyval == GDK_BackSpace) {
+ edit_string = edit_string.substr (0, edit_string.length() - 1);
} else {
-
- string existing = cell->get_text();
- if (existing.length() >= field_length[editing_field]) {
- new_text = existing.substr (1, field_length[editing_field] - 1);
- } else {
- new_text = existing.substr (0, field_length[editing_field] - 1);
- }
+ edit_string.push_back (new_char);
}
+ if (!edit_string.empty()) {
+ char buf[32];
+ sscanf (edit_string.c_str(), "%" PRId64, &pos);
+ snprintf (buf, sizeof (buf), " %10" PRId64, pos);
+ edit_string = buf;
+ }
+ /* highlight the whole thing */
+ highlight_length = edit_string.length();
+ break;
- new_text += new_char;
- display->set_text (cell, new_text);
- _canonical_time_is_displayed = true;
- key_entry_state++;
+ default:
+ highlight_length = merge_input_and_edit_string ();
}
- if (key_entry_state == field_length[editing_field]) {
- move_on = true;
+ if (edit_is_negative) {
+ edit_string.replace(0,1,"-");
+ } else {
+ if (!pre_edit_string.empty() && (pre_edit_string.at(0) == '-')) {
+ edit_string.replace(0,1,"_");
+ } else {
+ edit_string.replace(0,1," ");
+ }
}
- if (move_on) {
+ show_edit_status (highlight_length);
+ _layout->set_text (edit_string);
+ queue_draw ();
- if (key_entry_state) {
+ return true;
+}
- /* if key_entry_state != then we edited the text
- */
+int
+AudioClock::merge_input_and_edit_string ()
+{
+ /* merge with pre-edit-string into edit string */
- char buf[16];
+ edit_string = pre_edit_string;
- switch (editing_field) {
- case Timecode_Hours:
- case Timecode_Minutes:
- case Timecode_Seconds:
- case Timecode_Frames:
- // Check Timecode fields for sanity (may also adjust fields)
- timecode_sanitize_display();
- break;
- case Bars:
- case Beats:
- case Ticks:
- // Bars should never be zero, unless this clock is for a duration
- if (atoi (_text_cells[Bars]->get_text()) == 0 && !is_duration) {
- snprintf (buf, sizeof (buf), "%0*" PRIu32, field_length[Bars], 1);
- display->set_text (_text_cells[Bars], buf);
- _canonical_time_is_displayed = true;
- }
- // beats should never be zero, unless this clock is for a duration
- if (atoi (_text_cells[Beats]->get_text()) == 0 && !is_duration) {
- snprintf (buf, sizeof (buf), "%0*" PRIu32, field_length[Beats], 1);
- display->set_text (_text_cells[Beats], buf);
- _canonical_time_is_displayed = true;
- }
- break;
- default:
- break;
- }
+ if (input_string.empty()) {
+ return 0;
+ }
- ValueChanged(); /* EMIT_SIGNAL */
- }
-
- edit_next_field ();
+ 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];
+}
+
+
+bool
+AudioClock::on_key_release_event (GdkEventKey *ev)
+{
+ if (!editing) {
+ return false;
+ }
+
+ /* 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;
}
+}
- //if user hit Enter, lose focus
- switch (ev->keyval) {
- case GDK_Return:
- case GDK_KP_Enter:
- end_edit ();
+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;
+ } else {
+ return Timecode_Frames;
+ }
+ break;
+ case BBT:
+ if (index < 5) {
+ return Bars;
+ } else if (index < 7) {
+ return Beats;
+ } else {
+ 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;
+ } else {
+ return MS_Milliseconds;
+ }
+ break;
+ case Frames:
+ return AudioFrames;
+ break;
}
- return true;
+ return Field (0);
}
bool
-AudioClock::button_press (GdkEventButton *ev, CairoCell* cell)
+AudioClock::on_button_press_event (GdkEventButton *ev)
{
switch (ev->button) {
case 1:
- if (editable) {
- if (cell) {
- Field f = (Field) cell->id ();
- switch (f) {
- case Timecode_Hours:
- case Timecode_Minutes:
- case Timecode_Seconds:
- case Timecode_Frames:
- case MS_Hours:
- case MS_Minutes:
- case MS_Seconds:
- case MS_Milliseconds:
- case Bars:
- case Beats:
- case Ticks:
- case AudioFrames:
- editing_field = f;
- display->start_editing (cell);
- break;
- default:
- return false;
- }
+ if (editable && !_off) {
+ int index;
+ int trailing;
+ int y;
+ int x;
+
+ /* the text has been centered vertically, so adjust
+ * x and y.
+ */
+ int xcenter = (get_width() - layout_width) /2;
+
+ y = ev->y - ((upper_height - layout_height)/2);
+ x = ev->x - xcenter;
+
+ if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
+ /* pretend it is a character on the far right */
+ index = 99;
}
-
- Keyboard::magic_widget_grab_focus ();
-
+ 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);
- dragging = true;
drag_accum = 0;
drag_start_y = ev->y;
drag_y = ev->y;
}
break;
-
+
default:
return false;
break;
}
bool
-AudioClock::button_release (GdkEventButton *ev, CairoCell* cell)
+AudioClock::on_button_release_event (GdkEventButton *ev)
{
- if (editable) {
+ if (editable && !_off) {
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)){
- // we actually dragged so return without setting editing focus, or we shift clicked
+ // we actually dragged so return without
+ // setting editing focus, or we shift clicked
return true;
+ } else {
+ if (ev->button == 1) {
+
+ if (_edit_by_click_field) {
+
+ int xcenter = (get_width() - layout_width) /2;
+ int index = 0;
+ int trailing;
+ int y = ev->y - ((upper_height - layout_height)/2);
+ int x = ev->x - xcenter;
+ Field f;
+
+ if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
+ return true;
+ }
+
+ f = index_to_field (index);
+
+ switch (f) {
+ case Timecode_Frames:
+ case MS_Milliseconds:
+ case Ticks:
+ f = Field (0);
+ break;
+ default:
+ break;
+ }
+ start_edit (f);
+ } else {
+ start_edit ();
+ }
+ }
}
}
}
}
bool
-AudioClock::scroll (GdkEventScroll *ev, CairoCell* cell)
+AudioClock::on_focus_out_event (GdkEventFocus* ev)
+{
+ bool ret = CairoWidget::on_focus_out_event (ev);
+
+ if (editing) {
+ end_edit (_accept_on_focus_out);
+ }
+
+ return ret;
+}
+
+bool
+AudioClock::on_scroll_event (GdkEventScroll *ev)
{
- if (_session == 0 || !editable) {
+ int index;
+ int trailing;
+
+ if (editing || _session == 0 || !editable || _off) {
return false;
}
- if (cell) {
- Field f = (Field) cell->id ();
- switch (f) {
- case Timecode_Hours:
- case Timecode_Minutes:
- case Timecode_Seconds:
- case Timecode_Frames:
- case MS_Hours:
- case MS_Minutes:
- case MS_Seconds:
- case MS_Milliseconds:
- case Bars:
- case Beats:
- case Ticks:
- case AudioFrames:
- break;
- default:
- return false;
- }
+ int y;
+ int x;
+
+ /* the text has been centered vertically, so adjust
+ * x and y.
+ */
+
+ int xcenter = (get_width() - layout_width) /2;
+ y = ev->y - ((upper_height - layout_height)/2);
+ x = ev->x - xcenter;
+
+ if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
+ /* not in the main layout */
+ return false;
}
-
+
+ Field f = index_to_field (index);
framepos_t frames = 0;
switch (ev->direction) {
case GDK_SCROLL_UP:
- frames = get_frames ((Field) cell->id());
+ frames = get_frame_step (f);
if (frames != 0) {
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
frames *= 10;
ValueChanged (); /* EMIT_SIGNAL */
}
break;
-
+
case GDK_SCROLL_DOWN:
- frames = get_frames ((Field) cell->id());
+ frames = get_frame_step (f);
if (frames != 0) {
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
frames *= 10;
}
-
- if ((double)current_time() - (double)frames < 0.0) {
+
+ if (!_negative_allowed && (double)current_time() - (double)frames < 0.0) {
set (0, true);
} else {
set (current_time() - frames, true);
}
-
+
ValueChanged (); /* EMIT_SIGNAL */
}
break;
-
+
default:
return false;
break;
}
-
+
return true;
}
bool
-AudioClock::field_motion_notify_event (GdkEventMotion *ev, Field field)
+AudioClock::on_motion_notify_event (GdkEventMotion *ev)
{
- if (_session == 0 || !dragging) {
+ if (editing || _session == 0 || !dragging) {
return false;
}
float pixel_frame_scale_factor = 0.2f;
-/*
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
pixel_frame_scale_factor = 0.1f;
}
pixel_frame_scale_factor = 0.025f;
}
-*/
+
double y_delta = ev->y - drag_y;
drag_accum += y_delta*pixel_frame_scale_factor;
drag_y = ev->y;
- if (trunc(drag_accum) != 0) {
+ if (floor (drag_accum) != 0) {
framepos_t frames;
framepos_t pos;
int dir;
dir = (drag_accum < 0 ? 1:-1);
pos = current_time();
- frames = get_frames (field,pos,dir);
+ frames = get_frame_step (drag_field, pos, dir);
if (frames != 0 && frames * drag_accum < current_time()) {
-
- set ((framepos_t) floor (pos - drag_accum * frames), false); // minus because up is negative in computer-land
-
+ set ((framepos_t) floor (pos - drag_accum * frames), false); // minus because up is negative in GTK
} else {
set (0 , false);
-
}
drag_accum= 0;
ValueChanged(); /* EMIT_SIGNAL */
-
-
}
return true;
}
framepos_t
-AudioClock::get_frames (Field field, framepos_t pos, int dir)
+AudioClock::get_frame_step (Field field, framepos_t pos, int dir)
{
framecnt_t f = 0;
Timecode::BBT_Time BBT;
}
framepos_t
-AudioClock::current_time (framepos_t pos) const
+AudioClock::current_time (framepos_t) const
{
- if (!_canonical_time_is_displayed) {
- return _canonical_time;
- }
-
- framepos_t ret = 0;
-
- switch (_mode) {
- case Timecode:
- ret = timecode_frame_from_display ();
- break;
- case BBT:
- ret = bbt_frame_from_display (pos);
- break;
-
- case MinSec:
- ret = minsec_frame_from_display ();
- break;
-
- case Frames:
- ret = audio_frame_from_display ();
- break;
- }
-
- return ret;
+ return last_when;
}
framepos_t
switch (_mode) {
case Timecode:
- ret = timecode_frame_from_display ();
+ ret = last_when;
break;
case BBT:
- ret = bbt_frame_duration_from_display (pos);
+ ret = frame_duration_from_bbt_string (pos, _layout->get_text());
break;
case MinSec:
- ret = minsec_frame_from_display ();
+ ret = last_when;
break;
case Frames:
- ret = audio_frame_from_display ();
+ ret = last_when;
break;
}
return ret;
}
-void
-AudioClock::timecode_sanitize_display()
+bool
+AudioClock::bbt_validate_edit (const string& str)
{
- // Check Timecode fields for sanity, possibly adjusting values
- if (atoi (_text_cells[Timecode_Minutes]->get_text()) > 59) {
- display->set_text (_text_cells[Timecode_Minutes], "59");
- _canonical_time_is_displayed = true;
- }
+ AnyTime any;
- if (atoi (_text_cells[Timecode_Seconds]->get_text()) > 59) {
- display->set_text (_text_cells[Timecode_Seconds], "59");
- _canonical_time_is_displayed = true;
+ if (sscanf (str.c_str(), BBT_SCANF_FORMAT, &any.bbt.bars, &any.bbt.beats, &any.bbt.ticks) != 3) {
+ return false;
}
- switch ((long)rint(_session->timecode_frames_per_second())) {
- case 24:
- if (atoi (_text_cells[Timecode_Frames]->get_text()) > 23) {
- display->set_text (_text_cells[Timecode_Frames], "23");
- _canonical_time_is_displayed = true;
- }
- break;
- case 25:
- if (atoi (_text_cells[Timecode_Frames]->get_text()) > 24) {
- display->set_text (_text_cells[Timecode_Frames], "24");
- _canonical_time_is_displayed = true;
- }
- break;
- case 30:
- if (atoi (_text_cells[Timecode_Frames]->get_text()) > 29) {
- display->set_text (_text_cells[Timecode_Frames], "29");
- _canonical_time_is_displayed = true;
- }
- break;
- default:
- break;
+ if (any.bbt.ticks > Timecode::BBT_Time::ticks_per_beat) {
+ return false;
}
- if (_session->timecode_drop_frames()) {
- if ((atoi (_text_cells[Timecode_Minutes]->get_text()) % 10) && (atoi (_text_cells[Timecode_Seconds]->get_text()) == 0) && (atoi (_text_cells[Timecode_Frames]->get_text()) < 2)) {
- display->set_text (_text_cells[Timecode_Frames], "02");
- _canonical_time_is_displayed = true;
- }
+ if (!is_duration && any.bbt.bars == 0) {
+ return false;
}
-}
-/** This is necessary because operator[] isn't const with std::map.
- * @param f Field.
- * @return Label widget.
- */
-CairoTextCell*
-AudioClock::label (Field f) const
-{
- std::map<Field,CairoTextCell*>::const_iterator i = _text_cells.find (f);
- assert (i != _text_cells.end ());
+ if (!is_duration && any.bbt.beats == 0) {
+ return false;
+ }
- return i->second;
+ return true;
}
-framepos_t
-AudioClock::timecode_frame_from_display () const
+bool
+AudioClock::timecode_validate_edit (const string&)
{
- if (_session == 0) {
- return 0;
- }
-
Timecode::Time TC;
- framepos_t sample;
+ int hours;
+ char ignored[2];
- if (!label (Timecode_Sign)->get_text().empty()) {
- TC.hours = atoi (label (Timecode_Hours)->get_text());
- } else {
- TC.hours = -atoi (label (Timecode_Hours)->get_text());
+ if (sscanf (_layout->get_text().c_str(), "%[- _]%" PRId32 ":%" PRId32 ":%" PRId32 "%[:;]%" PRId32,
+ ignored, &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 6) {
+ return false;
}
- TC.minutes = atoi (label (Timecode_Minutes)->get_text());
- TC.seconds = atoi (label (Timecode_Seconds)->get_text());
- TC.frames = atoi (label (Timecode_Frames)->get_text());
- 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 */ );
-
-
-#if 0
-#define Timecode_SAMPLE_TEST_1
-#define Timecode_SAMPLE_TEST_2
-#define Timecode_SAMPLE_TEST_3
-#define Timecode_SAMPLE_TEST_4
-#define Timecode_SAMPLE_TEST_5
-#define Timecode_SAMPLE_TEST_6
-#define Timecode_SAMPLE_TEST_7
-
- // Testcode for timecode<->sample conversions (P.S.)
- Timecode::Time timecode1;
- framepos_t sample1;
- framepos_t oldsample = 0;
- Timecode::Time timecode2;
- framecnt_t sample_increment;
-
- sample_increment = (framecnt_t)rint(_session->frame_rate() / _session->timecode_frames_per_second);
-
-#ifdef Timecode_SAMPLE_TEST_1
- // Test 1: use_offset = false, use_subframes = false
- cout << "use_offset = false, use_subframes = false" << endl;
- for (int i = 0; i < 108003; i++) {
- _session->timecode_to_sample( timecode1, sample1, false /* use_offset */, false /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, false /* use_offset */, false /* use_subframes */ );
-
- if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
- cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
- cout << "timecode1: " << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
-
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode1: " << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_increment( timecode1 );
+ if (hours < 0) {
+ TC.hours = hours * -1;
+ TC.negative = true;
+ } else {
+ TC.hours = hours;
+ TC.negative = false;
}
- cout << "sample_increment: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-#endif
-
-#ifdef Timecode_SAMPLE_TEST_2
- // Test 2: use_offset = true, use_subframes = false
- cout << "use_offset = true, use_subframes = false" << endl;
-
- timecode1.hours = 0;
- timecode1.minutes = 0;
- timecode1.seconds = 0;
- timecode1.frames = 0;
- timecode1.subframes = 0;
- sample1 = oldsample = 0;
-
- _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
- cout << "Starting at sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
-
- for (int i = 0; i < 108003; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
-
-// cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
-// cout << "sample: " << sample1 << endl;
-// cout << "sample: " << sample1 << " -> ";
-// cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-
- if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
- cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
-
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_increment( timecode1 );
+ if (TC.negative && !_negative_allowed) {
+ return false;
}
- cout << "sample_increment: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-#endif
-
-#ifdef Timecode_SAMPLE_TEST_3
- // Test 3: use_offset = true, use_subframes = false, decrement
- cout << "use_offset = true, use_subframes = false, decrement" << endl;
-
- _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
- cout << "Starting at sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
-
- for (int i = 0; i < 108003; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
-
-// cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
-// cout << "sample: " << sample1 << endl;
-// cout << "sample: " << sample1 << " -> ";
-// cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-
- if ((i > 0) && ( ((oldsample - sample1) != sample_increment) && ((oldsample - sample1) != (sample_increment + 1)) && ((oldsample - sample1) != (sample_increment - 1)))) {
- cout << "ERROR: sample increment not right: " << (oldsample - sample1) << " != " << sample_increment << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
-
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_decrement( timecode1 );
+ if (TC.hours > 23U || TC.minutes > 59U || TC.seconds > 59U) {
+ return false;
}
- cout << "sample_decrement: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-#endif
-
-
-#ifdef Timecode_SAMPLE_TEST_4
- // Test 4: use_offset = true, use_subframes = true
- cout << "use_offset = true, use_subframes = true" << endl;
-
- for (long sub = 5; sub < 80; sub += 5) {
- timecode1.hours = 0;
- timecode1.minutes = 0;
- timecode1.seconds = 0;
- timecode1.frames = 0;
- timecode1.subframes = 0;
- sample1 = oldsample = (sample_increment * sub) / 80;
-
- _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, true /* use_subframes */ );
-
- cout << "starting at sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
-
- for (int i = 0; i < 108003; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, true /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, true /* use_subframes */ );
-
- if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
- cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- //break;
- }
+ if (TC.frames > (uint32_t) rint (_session->timecode_frames_per_second()) - 1) {
+ return false;
+ }
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames || timecode2.subframes != timecode1.subframes) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_increment( timecode1 );
+ if (_session->timecode_drop_frames()) {
+ if (TC.minutes % 10 && TC.seconds == 0U && TC.frames < 2U) {
+ return false;
}
+ }
- cout << "sample_increment: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-
- for (int i = 0; i < 108003; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, true /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, true /* use_subframes */ );
-
- if ((i > 0) && ( ((oldsample - sample1) != sample_increment) && ((oldsample - sample1) != (sample_increment + 1)) && ((oldsample - sample1) != (sample_increment - 1)))) {
- cout << "ERROR: sample increment not right: " << (oldsample - sample1) << " != " << sample_increment << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- //break;
- }
+ return true;
+}
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames || timecode2.subframes != timecode1.subframes) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_decrement( timecode1 );
- }
+bool
+AudioClock::minsec_validate_edit (const string& str)
+{
+ int hrs, mins, secs, millisecs;
- cout << "sample_decrement: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
+ if (sscanf (str.c_str(), "%d:%d:%d.%d", &hrs, &mins, &secs, &millisecs) != 4) {
+ return false;
}
-#endif
-
-#ifdef Timecode_SAMPLE_TEST_5
- // Test 5: use_offset = true, use_subframes = false, increment seconds
- cout << "use_offset = true, use_subframes = false, increment seconds" << endl;
-
- timecode1.hours = 0;
- timecode1.minutes = 0;
- timecode1.seconds = 0;
- timecode1.frames = 0;
- timecode1.subframes = 0;
- sample1 = oldsample = 0;
- sample_increment = _session->frame_rate();
-
- _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
- cout << "Starting at sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
-
- for (int i = 0; i < 3600; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
-
-// cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
-// cout << "sample: " << sample1 << endl;
-// cout << "sample: " << sample1 << " -> ";
-// cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-
-// if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
-// {
-// cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
-// break;
-// }
-
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_increment_seconds( timecode1 );
+ if (hrs > 23 || mins > 59 || secs > 59 || millisecs > 999) {
+ return false;
}
- cout << "sample_increment: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-#endif
-
+ return true;
+}
-#ifdef Timecode_SAMPLE_TEST_6
- // Test 6: use_offset = true, use_subframes = false, increment minutes
- cout << "use_offset = true, use_subframes = false, increment minutes" << endl;
-
- timecode1.hours = 0;
- timecode1.minutes = 0;
- timecode1.seconds = 0;
- timecode1.frames = 0;
- timecode1.subframes = 0;
- sample1 = oldsample = 0;
- sample_increment = _session->frame_rate() * 60;
-
- _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
- cout << "Starting at sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
-
- for (int i = 0; i < 60; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
-
-// cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
-// cout << "sample: " << sample1 << endl;
-// cout << "sample: " << sample1 << " -> ";
-// cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-
-// if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
-// {
-// cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
-// break;
-// }
-
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_increment_minutes( timecode1 );
+framepos_t
+AudioClock::frames_from_timecode_string (const string& str) const
+{
+ if (_session == 0) {
+ return 0;
}
- cout << "sample_increment: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-#endif
+ Timecode::Time TC;
+ framepos_t sample;
+ char ignored[2];
+ int hours;
-#ifdef Timecode_SAMPLE_TEST_7
- // Test 7: use_offset = true, use_subframes = false, increment hours
- cout << "use_offset = true, use_subframes = false, increment hours" << endl;
-
- timecode1.hours = 0;
- timecode1.minutes = 0;
- timecode1.seconds = 0;
- timecode1.frames = 0;
- timecode1.subframes = 0;
- sample1 = oldsample = 0;
- sample_increment = _session->frame_rate() * 60 * 60;
-
- _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
- cout << "Starting at sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
-
- for (int i = 0; i < 10; i++) {
- _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
- _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
-
-// cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
-// cout << "sample: " << sample1 << endl;
-// cout << "sample: " << sample1 << " -> ";
-// cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-
-// if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
-// {
-// cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
-// break;
-// }
-
- if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
- cout << "ERROR: timecode2 not equal timecode1" << endl;
- cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
- cout << "sample: " << sample1 << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
- break;
- }
- oldsample = sample1;
- _session->timecode_increment_hours( timecode1 );
+ if (sscanf (str.c_str(), "%[- _]%d:%d:%d%[:;]%d", ignored, &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 6) {
+ error << string_compose (_("programming error: %1 %2"), "badly formatted timecode clock string", str) << endmsg;
+ return 0;
}
+ TC.hours = abs(hours);
+ TC.rate = _session->timecode_frames_per_second();
+ TC.drop= _session->timecode_drop_frames();
- cout << "sample_increment: " << sample_increment << endl;
- cout << "sample: " << sample1 << " -> ";
- cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
-#endif
+ _session->timecode_to_sample (TC, sample, false /* use_offset */, false /* use_subframes */ );
-#endif
+ // timecode_tester ();
+ if (edit_is_negative) {
+ sample = - sample;
+ }
return sample;
}
framepos_t
-AudioClock::minsec_frame_from_display () const
+AudioClock::frames_from_minsec_string (const string& str) const
{
if (_session == 0) {
return 0;
}
- int hrs = atoi (label (MS_Hours)->get_text());
- int mins = atoi (label (MS_Minutes)->get_text());
- int secs = atoi (label (MS_Seconds)->get_text());
- int millisecs = atoi (label (MS_Milliseconds)->get_text());
-
+ int hrs, mins, secs, millisecs;
framecnt_t sr = _session->frame_rate();
+ 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;
+ }
+
return (framepos_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr) + (millisecs * sr / 1000.0));
}
framepos_t
-AudioClock::bbt_frame_from_display (framepos_t pos) const
+AudioClock::frames_from_bbt_string (framepos_t pos, const string& str) const
{
if (_session == 0) {
error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
AnyTime any;
any.type = AnyTime::BBT;
- any.bbt.bars = atoi (label (Bars)->get_text());
- any.bbt.beats = atoi (label (Beats)->get_text());
- any.bbt.ticks = atoi (label (Ticks)->get_text());
+ if (sscanf (str.c_str(), BBT_SCANF_FORMAT, &any.bbt.bars, &any.bbt.beats, &any.bbt.ticks) != 3) {
+ return 0;
+ }
if (is_duration) {
any.bbt.bars++;
framepos_t
-AudioClock::bbt_frame_duration_from_display (framepos_t pos) const
+AudioClock::frame_duration_from_bbt_string (framepos_t pos, const string& str) const
{
if (_session == 0) {
- error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
+ error << "AudioClock::frame_duration_from_bbt_string() called with BBT mode but without session!" << endmsg;
return 0;
}
Timecode::BBT_Time bbt;
-
- bbt.bars = atoi (label (Bars)->get_text());
- bbt.beats = atoi (label (Beats)->get_text());
- bbt.ticks = atoi (label (Ticks)->get_text());
+ if (sscanf (str.c_str(), BBT_SCANF_FORMAT, &bbt.bars, &bbt.beats, &bbt.ticks) != 3) {
+ return 0;
+ }
return _session->tempo_map().bbt_duration_at(pos,bbt,1);
}
framepos_t
-AudioClock::audio_frame_from_display () const
+AudioClock::frames_from_audioframes_string (const string& str) const
+{
+ framepos_t f;
+ sscanf (str.c_str(), "%" PRId64, &f);
+ return f;
+}
+
+void
+AudioClock::copy_text_to_clipboard () const
{
- return (framepos_t) atoi (label (AudioFrames)->get_text ());
+ 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));
}
void
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)));
+ ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode, false)));
+ ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT, false)));
+ ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec, false)));
+ ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames, false)));
- if (editable && !is_duration && !_follows_playhead) {
+ if (editable && !_off && !is_duration && !_follows_playhead) {
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 (_("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)));
}
+ ops_items.push_back (SeparatorElem());
+ ops_items.push_back (MenuElem (_("Copy to clipboard"), sigc::mem_fun(*this, &AudioClock::copy_text_to_clipboard)));
}
void
}
void
-AudioClock::connect_signals ()
-{
- scroll_connection = display->scroll.connect (sigc::mem_fun (*this, &AudioClock::scroll));
- button_press_connection = display->button_press.connect (sigc::mem_fun (*this, &AudioClock::button_press));
- button_release_connection = display->button_release.connect (sigc::mem_fun (*this, &AudioClock::button_release));
-}
-
-void
-AudioClock::set_mode (Mode m)
+AudioClock::set_mode (Mode m, bool noemit)
{
if (_mode == m) {
return;
_mode = m;
- display->clear_cells ();
+ insert_map.clear();
+
+ _layout->set_text ("");
- if (supplemental_left) {
- supplemental_left->clear_cells ();
- supplemental_right->clear_cells ();
+ Gtk::Requisition req;
+ set_clock_dimensions (req);
+
+ if (_left_layout) {
+
+ _left_layout->set_attributes (info_attributes);
+ _right_layout->set_attributes (info_attributes);
+ /* adjust info_height according to font size */
+ int ignored;
+ _left_layout->set_text (" 1234567890");
+ _left_layout->get_pixel_size (ignored, info_height);
+
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
}
switch (_mode) {
case Timecode:
- display->add_cell (_text_cells[Timecode_Sign]);
- display->add_cell (_text_cells[Timecode_Hours]);
- display->add_cell (_fixed_cells[Colon1]);
- display->add_cell (_text_cells[Timecode_Minutes]);
- display->add_cell (_fixed_cells[Colon2]);
- display->add_cell (_text_cells[Timecode_Seconds]);
- display->add_cell (_fixed_cells[Colon3]);
- display->add_cell (_text_cells[Timecode_Frames]);
-
- if (supplemental_left) {
- supplemental_left->add_cell (_text_cells[LowerLeft1]);
- supplemental_left->add_cell (_text_cells[LowerLeft2]);
- supplemental_right->add_cell (_text_cells[LowerRight1]);
- supplemental_right->add_cell (_text_cells[LowerRight2]);
-
- supplemental_left->set_width_chars (_text_cells[LowerLeft1], 4);
- supplemental_left->set_width_chars (_text_cells[LowerLeft2], 8);
-
- supplemental_right->set_width_chars (_text_cells[LowerRight1], 4);
- supplemental_right->set_width_chars (_text_cells[LowerRight2], 6.25);
-
- supplemental_left->set_text (_text_cells[LowerLeft1], _("EXT"));
- supplemental_right->set_text (_text_cells[LowerRight1], _("FPS"));
- }
+ mode_based_info_ratio = 0.6;
+ 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);
+ insert_map.push_back (2);
+ insert_map.push_back (1);
break;
case BBT:
- display->add_cell (_text_cells[Bars]);
- display->add_cell (_fixed_cells[Bar1]);
- display->add_cell (_text_cells[Beats]);
- display->add_cell (_fixed_cells[Bar2]);
- display->add_cell (_text_cells[Ticks]);
- if (supplemental_left) {
- supplemental_left->add_cell (_text_cells[LowerLeft1]);
- supplemental_left->add_cell (_text_cells[LowerLeft2]);
- supplemental_right->add_cell (_text_cells[LowerRight1]);
- supplemental_right->add_cell (_text_cells[LowerRight2]);
-
- supplemental_left->set_width_chars (_text_cells[LowerLeft1], 1);
- supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5.25);
-
- supplemental_right->set_width_chars (_text_cells[LowerRight1], 2); // why not 1? M is too wide
- supplemental_right->set_width_chars (_text_cells[LowerRight2], 5);
-
- supplemental_left->set_text (_text_cells[LowerLeft1], _("T"));
- supplemental_right->set_text (_text_cells[LowerRight1], _("M"));
- }
+ mode_based_info_ratio = 0.5;
+ 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);
+ insert_map.push_back (5);
+ insert_map.push_back (3);
+ insert_map.push_back (2);
+ insert_map.push_back (1);
break;
case MinSec:
- display->add_cell (_text_cells[MS_Hours]);
- display->add_cell (_fixed_cells[Colon1]);
- display->add_cell (_text_cells[MS_Minutes]);
- display->add_cell (_fixed_cells[Colon2]);
- display->add_cell (_text_cells[MS_Seconds]);
- display->add_cell (_fixed_cells[Colon3]);
- display->add_cell (_text_cells[MS_Milliseconds]);
- if (supplemental_left) {
- supplemental_left->add_cell (_text_cells[LowerLeft1]);
- supplemental_left->add_cell (_text_cells[LowerLeft2]);
- supplemental_right->add_cell (_text_cells[LowerRight1]);
- supplemental_right->add_cell (_text_cells[LowerRight2]);
-
- /* These are going to remain empty */
-
- supplemental_left->set_width_chars (_text_cells[LowerLeft1], 1);
- supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5);
-
- supplemental_right->set_width_chars (_text_cells[LowerRight1], 1);
- supplemental_right->set_width_chars (_text_cells[LowerRight2], 1);
-
- supplemental_left->set_text (_text_cells[LowerLeft1], _(" "));
- supplemental_right->set_text (_text_cells[LowerRight1], _(" "));
- }
+ mode_based_info_ratio = 0.6;
+ 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);
+ insert_map.push_back (2);
+ insert_map.push_back (1);
break;
case Frames:
- display->add_cell (_text_cells[AudioFrames]);
- if (supplemental_left) {
- supplemental_left->add_cell (_text_cells[LowerLeft1]);
- supplemental_left->add_cell (_text_cells[LowerLeft2]);
- supplemental_right->add_cell (_text_cells[LowerRight1]);
- supplemental_right->add_cell (_text_cells[LowerRight2]);
-
- supplemental_left->set_width_chars (_text_cells[LowerLeft1], 3);
- supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5);
-
- supplemental_right->set_width_chars (_text_cells[LowerRight1], 5);
- supplemental_right->set_width_chars (_text_cells[LowerRight2], 5);
-
- supplemental_left->set_text (_text_cells[LowerLeft1], _("SR"));
- supplemental_right->set_text (_text_cells[LowerRight1], _("Pull"));
- }
+ mode_based_info_ratio = 0.45;
break;
}
- if (supplemental_left) {
- /* clear information cells */
- supplemental_left->set_text (_text_cells[LowerLeft2], _(""));
- supplemental_right->set_text (_text_cells[LowerRight2], _(""));
- }
-
set (last_when, true);
- if (!is_transient) {
- ModeChanged (); /* EMIT SIGNAL (the static one)*/
- }
+ if (!is_transient && !noemit) {
+ ModeChanged (); /* EMIT SIGNAL (the static one)*/
+ }
- mode_changed (); /* EMIT SIGNAL (the member one) */
+ mode_changed (); /* EMIT SIGNAL (the member one) */
}
void
void
AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
{
- VBox::on_style_changed (old_style);
- set_theme ();
+ CairoWidget::on_style_changed (old_style);
+
+ Gtk::Requisition req;
+ set_clock_dimensions (req);
+
+ /* XXXX fix me ... we shouldn't be using GTK styles anyway */
+ // set_font ();
+ set_colors ();
+}
+
+void
+AudioClock::set_editable (bool yn)
+{
+ editable = yn;
}
void
}
is_duration = yn;
- set (last_when, true, 0, 's');
+ set (last_when, true);
}
void
-AudioClock::set_off (bool yn)
+AudioClock::set_off (bool yn)
{
if (_off == yn) {
return;
_off = yn;
- if (_off) {
- _canonical_time = current_time ();
- _canonical_time_is_displayed = false;
- } else {
- _canonical_time_is_displayed = true;
- }
+ /* force a redraw. last_when will be preserved, but the clock text will
+ * change
+ */
+
+ set (last_when, true);
+}
+
+void
+AudioClock::focus ()
+{
+ start_edit (Field (0));
+}
+
+void
+AudioClock::set_corner_radius (double r)
+{
+ corner_radius = r;
+ first_width = 0;
+ first_height = 0;
+ queue_resize ();
+}
- /* force a possible redraw */
-
- set (_canonical_time, true);
+void
+AudioClock::dpi_reset ()
+{
+ /* force recomputation of size even if we are fixed width
+ */
+ first_width = 0;
+ first_height = 0;
+ queue_resize ();
}
+void
+AudioClock::set_negative_allowed (bool yn)
+{
+ _negative_allowed = yn;
+}