#include <gtkmm/style.h>
#include "gtkmm2ext/cairocell.h"
-#include <gtkmm2ext/utils.h>
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/rgb_macros.h"
#include "ardour/ardour.h"
#include "ardour/session.h"
using Gtkmm2ext::Keyboard;
-using PBD::atoi;
-using PBD::atof;
-
sigc::signal<void> AudioClock::ModeChanged;
vector<AudioClock*> AudioClock::clocks;
-
-std::map<AudioClock::Field,uint32_t> AudioClock::field_length;
-
-void
-AudioClock::fill_field_lengths()
-{
- field_length[Timecode_Hours] = 2;
- field_length[Timecode_Minutes] = 2;
- field_length[Timecode_Seconds] = 2;
- field_length[Timecode_Frames] = 2;
- field_length[MS_Hours] = 2;
- field_length[MS_Minutes] = 2;
- field_length[MS_Seconds] = 2;
- field_length[MS_Milliseconds] = 3;
- field_length[Bars] = 4;
- field_length[Beats] = 2;
- field_length[Ticks] = 4;
- field_length[AudioFrames] = 10;
-};
+const double AudioClock::info_font_scale_factor = 0.6;
+const double AudioClock::separator_height = 2.0;
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),
- is_transient (transient),
- is_duration (duration),
- editable (allow_edit),
- _follows_playhead (follows_playhead),
- last_when(0),
- _canonical_time_is_displayed (true),
- _canonical_time (0)
+ : _name (clock_name)
+ , is_transient (transient)
+ , is_duration (duration)
+ , editable (allow_edit)
+ , _follows_playhead (follows_playhead)
+ , _off (false)
+ , _need_bg (true)
+ , ops_menu (0)
+ , editing_attr (0)
+ , background_attr (0)
+ , foreground_attr (0)
+ , mode_based_info_ratio (1.0)
+ , editing (false)
+ , bbt_reference_time (-1)
+ , last_when(0)
+ , last_pdelta (0)
+ , last_sdelta (0)
+ , dragging (false)
+ , drag_field (Field (0))
+
{
- CairoTextCell* tc;
- CairoBarCell* bc;
- CairoColonCell* cc;
+ set_flags (CAN_FOCUS);
+
+ _layout = Pango::Layout::create (get_pango_context());
+ _layout->set_attributes (normal_attributes);
- if (field_length.empty()) {
- fill_field_lengths ();
+ if (with_info) {
+ _left_layout = Pango::Layout::create (get_pango_context());
+ _right_layout = Pango::Layout::create (get_pango_context());
}
- timecode = new CairoEditableText ();
- minsec = new CairoEditableText ();
- bbt = new CairoEditableText ();
- frames = new CairoEditableText ();
+ set_widget_name (widget_name);
- // add an extra 0.6 "average char width" for the negative sign
- tc = new CairoTextCell (field_length[Timecode_Hours] + 0.6);
- _text_cells[Timecode_Hours] = tc;
- timecode->add_cell (Timecode_Hours, tc);
+ _mode = BBT; /* lie to force mode switch */
+ set_mode (Timecode);
+ set (last_when, true);
- cc = new CairoColonCell ();
- _fixed_cells[Timecode_Colon1] = cc;
- timecode->add_cell (Timecode_Colon1, cc);
+ if (!is_transient) {
+ clocks.push_back (this);
+ }
+}
- tc = new CairoTextCell (field_length[Timecode_Minutes]);
- _text_cells[Timecode_Minutes] = tc;
- timecode->add_cell (Timecode_Minutes, tc);
-
- cc = new CairoColonCell ();
- _fixed_cells[Timecode_Colon2] = cc;
- timecode->add_cell (Timecode_Colon2, cc);
+AudioClock::~AudioClock ()
+{
+ delete background_attr;
+ delete foreground_attr;
+ delete editing_attr;
+}
- tc = new CairoTextCell (field_length[Timecode_Seconds]);
- _text_cells[Timecode_Seconds] = tc;
- timecode->add_cell (Timecode_Seconds, tc);
+void
+AudioClock::set_widget_name (const string& str)
+{
+ if (str.empty()) {
+ set_name ("clock");
+ } else {
+ set_name (str + " clock");
+ }
+}
- cc = new CairoColonCell ();
- _fixed_cells[Timecode_Colon3] = cc;
- timecode->add_cell (Timecode_Colon3, cc);
- tc = new CairoTextCell (field_length[Timecode_Frames]);
- _text_cells[Timecode_Frames] = tc;
- timecode->add_cell (Timecode_Frames, tc);
+void
+AudioClock::on_realize ()
+{
+ CairoWidget::on_realize ();
+ set_font ();
+ set_colors ();
+}
- /* Minutes/Seconds */
-
- tc = new CairoTextCell (field_length[MS_Hours]);
- _text_cells[MS_Hours] = tc;
- minsec->add_cell (MS_Hours, tc);
-
- cc = new CairoColonCell ();
- _fixed_cells[MS_Colon1] = cc;
- minsec->add_cell (MS_Colon1, cc);
+void
+AudioClock::set_font ()
+{
+ Glib::RefPtr<Gtk::Style> style = get_style ();
+ Pango::FontDescription font;
+ Pango::AttrFontDesc* font_attr;
- tc = new CairoTextCell (field_length[MS_Minutes]);
- _text_cells[MS_Minutes] = tc;
- minsec->add_cell (MS_Minutes, tc);
-
- cc = new CairoColonCell ();
- _fixed_cells[MS_Colon2] = cc;
- minsec->add_cell (MS_Colon2, cc);
+ if (!is_realized()) {
+ font = get_font_for_style (get_name());
+ } else {
+ font = style->get_font();
+ }
- tc = new CairoTextCell (field_length[MS_Seconds]);
- _text_cells[MS_Seconds] = tc;
- minsec->add_cell (MS_Seconds, tc);
+ font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
- cc = new CairoColonCell ();
- _fixed_cells[MS_Colon3] = cc;
- minsec->add_cell (MS_Colon3, cc);
-
- tc = new CairoTextCell (field_length[MS_Milliseconds]);
- _text_cells[MS_Milliseconds] = tc;
- minsec->add_cell (MS_Milliseconds, tc);
+ normal_attributes.change (*font_attr);
+ editing_attributes.change (*font_attr);
- /* Beats/Bars/Ticks */
-
- tc = new CairoTextCell (field_length[Bars]);
- _text_cells[Bars] = tc;
- bbt->add_cell (Bars, tc);
+ /* now a smaller version of the same font */
- bc = new CairoBarCell ();
- _fixed_cells[BBT_Bar1] = bc;
- bbt->add_cell (BBT_Bar1, bc);
-
- tc = new CairoTextCell (field_length[Beats]);
- _text_cells[Beats] = tc;
- bbt->add_cell (Beats, tc);
+ delete font_attr;
+ font.set_size ((int) lrint (font.get_size() * info_font_scale_factor));
+ font.set_weight (Pango::WEIGHT_NORMAL);
+ font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
+
+ info_attributes.change (*font_attr);
- bc = new CairoBarCell ();
- _fixed_cells[BBT_Bar2] = bc;
- bbt->add_cell (BBT_Bar2, bc);
-
- tc = new CairoTextCell (field_length[Ticks]);
- _text_cells[Ticks] = tc;
- bbt->add_cell (Ticks, tc);
+ delete font_attr;
+}
- /* Audio Frames */
-
- tc = new CairoTextCell (field_length[AudioFrames]);
- _text_cells[AudioFrames] = tc;
- frames->add_cell (AudioFrames, tc);
+void
+AudioClock::set_active_state (Gtkmm2ext::ActiveState s)
+{
+ CairoWidget::set_active_state (s);
+ set_colors ();
+}
- last_when = 0;
-
- last_hrs = 9999;
- last_mins = 9999;
- last_secs = 9999;
- last_frames = 99999;
+void
+AudioClock::set_colors ()
+{
+ int r, g, b, a;
- ms_last_hrs = 9999;
- ms_last_mins = 9999;
- ms_last_secs = 9999;
- ms_last_millisecs = 99999;
+ uint32_t bg_color;
+ uint32_t text_color;
+ uint32_t editing_color;
- last_negative = false;
+ if (active_state()) {
+ bg_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 active: background", get_name()));
+ text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 active: text", get_name()));
+ editing_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 active: edited text", get_name()));
+ } else {
+ bg_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: background", get_name()));
+ text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text", get_name()));
+ editing_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: edited text", get_name()));
+ }
+
+ UINT_TO_RGBA (bg_color, &r, &g, &b, &a);
+ r = lrint ((r/256.0) * 65535.0);
+ g = lrint ((g/256.0) * 65535.0);
+ b = lrint ((b/256.0) * 65535.0);
+ background_attr = new Pango::AttrColor (Pango::Attribute::create_attr_background (r, g, b));
+
+ /* store for bg in ::render() */
+ bg_r = r/256.0;
+ bg_g = g/256.0;
+ bg_b = b/256.0;
+ bg_a = a/256.0;
+
+ UINT_TO_RGBA (text_color, &r, &g, &b, &a);
+ r = lrint ((r/256.0) * 65535.0);
+ g = lrint ((g/256.0) * 65535.0);
+ b = lrint ((b/256.0) * 65535.0);
+ 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/256.0) * 65535.0);
+ g = lrint ((g/256.0) * 65535.0);
+ b = lrint ((b/256.0) * 65535.0);
+ editing_attr = new Pango::AttrColor (Pango::Attribute::create_attr_foreground (r, g, b));
- last_pdelta = 0;
- last_sdelta = 0;
- key_entry_state = 0;
- ops_menu = 0;
- dragging = false;
- bbt_reference_time = -1;
- editing_field = (Field) 0;
- current_cet = 0;
+ normal_attributes.change (*background_attr);
+ normal_attributes.change (*foreground_attr);
- if (with_info) {
- frames_upper_info_label = manage (new Label);
- frames_lower_info_label = manage (new Label);
- timecode_upper_info_label = manage (new Label);
- timecode_lower_info_label = manage (new Label);
- bbt_upper_info_label = manage (new Label);
- bbt_lower_info_label = manage (new Label);
-
- frames_upper_info_label->set_name ("AudioClockFramesUpperInfo");
- frames_lower_info_label->set_name ("AudioClockFramesLowerInfo");
- timecode_upper_info_label->set_name ("AudioClockTimecodeUpperInfo");
- timecode_lower_info_label->set_name ("AudioClockTimecodeLowerInfo");
- bbt_upper_info_label->set_name ("AudioClockBBTUpperInfo");
- bbt_lower_info_label->set_name ("AudioClockBBTLowerInfo");
-
- Gtkmm2ext::set_size_request_to_display_given_text(*timecode_upper_info_label, "23.98",0,0);
- Gtkmm2ext::set_size_request_to_display_given_text(*timecode_lower_info_label, "NDF",0,0);
-
- Gtkmm2ext::set_size_request_to_display_given_text(*bbt_upper_info_label, "88|88",0,0);
- Gtkmm2ext::set_size_request_to_display_given_text(*bbt_lower_info_label, "888.88",0,0);
-
- frames_info_box.pack_start (*frames_upper_info_label, true, true);
- frames_info_box.pack_start (*frames_lower_info_label, true, true);
- timecode_info_box.pack_start (*timecode_upper_info_label, true, true);
- timecode_info_box.pack_start (*timecode_lower_info_label, true, true);
- bbt_info_box.pack_start (*bbt_upper_info_label, true, true);
- bbt_info_box.pack_start (*bbt_lower_info_label, true, true);
+ info_attributes.change (*background_attr);
+ info_attributes.change (*foreground_attr);
+
+ editing_attributes.change (*background_attr);
+ editing_attributes.change (*foreground_attr);
+ editing_attributes.change (*editing_attr);
+ if (!editing) {
+ _layout->set_attributes (normal_attributes);
} else {
- frames_upper_info_label = 0;
- frames_lower_info_label = 0;
- timecode_upper_info_label = 0;
- timecode_lower_info_label = 0;
- bbt_upper_info_label = 0;
- bbt_lower_info_label = 0;
+ _layout->set_attributes (editing_attributes);
}
- frames_packer.set_homogeneous (false);
- frames_packer.set_border_width (2);
- frames_packer.pack_start (*frames);
+ if (_left_layout) {
+ _left_layout->set_attributes (info_attributes);
+ _right_layout->set_attributes (info_attributes);
+ }
-#ifdef CLOCKFIX
- /* XXX THE with_info CLAUSES NEED HANDLING BECAUSE WE'RE NOT PACKING
- INTO BOXES
- */
+ queue_draw ();
+}
- if (with_info) {
- frames_packer.pack_start (frames_info_box, false, false, 5);
+void
+AudioClock::render (cairo_t* cr)
+{
+ if (_need_bg) {
+ /* paint entire area the color of the parent window bg
+
+ XXX try to optimize this so that we just paint the corners and
+ other areas that may be exposed by rounded corners.
+ */
+
+ Gdk::Color bg (get_parent_bg());
+ cairo_rectangle (cr, 0, 0, _width, _height);
+ cairo_stroke_preserve (cr);
+ cairo_set_source_rgb (cr, bg.get_red_p(), bg.get_green_p(), bg.get_blue_p());
+ cairo_fill (cr);
}
-#endif
- timecode_packer.set_homogeneous (false);
- timecode_packer.set_border_width (2);
- timecode_packer.pack_start (*timecode);
+ /* main layout: rounded rect, plus the text */
-#ifdef CLOCKFIX
- if (with_info) {
- timecode_packer.pack_start (timecode_info_box, false, false, 5);
- }
-#endif
+ cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
+ Gtkmm2ext::rounded_rectangle (cr, 0, 0, _width, upper_height, 9);
- bbt_packer.set_homogeneous (false);
- bbt_packer.set_border_width (2);
- bbt_packer.pack_start (*bbt);
-
-#ifdef CLOCKFIX
- if (with_info) {
- bbt_packer.pack_start (bbt_info_box, false, false, 5);
- }
-#endif
-
- minsec_packer.set_homogeneous (false);
- minsec_packer.set_border_width (2);
- minsec_packer.pack_start (*minsec);
+ cairo_move_to (cr, 6, (upper_height - layout_height) / 2.0);
+ pango_cairo_show_layout (cr, _layout->gobj());
- set_widget_name (widget_name);
+ if (_left_layout) {
- _mode = BBT; /* lie to force mode switch */
- set_mode (Timecode);
- set (last_when, true);
+ double h = _height - upper_height - separator_height;
- if (!is_transient) {
- clocks.push_back (this);
+ if (mode_based_info_ratio != 1.0) {
+
+ double left_rect_width = round (((_width - separator_height) * mode_based_info_ratio) + 0.5);
+
+ cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
+ Gtkmm2ext::rounded_rectangle (cr, 0, upper_height + separator_height, left_rect_width, h, 9);
+
+ cairo_move_to (cr, 6, upper_height + separator_height + ((h - info_height)/2.0));
+ pango_cairo_show_layout (cr, _left_layout->gobj());
+
+ Gtkmm2ext::rounded_rectangle (cr, left_rect_width + separator_height, upper_height + separator_height,
+ _width - separator_height - left_rect_width, h, 9);
+
+ cairo_move_to (cr, 6 + 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 */
+
+ cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
+ Gtkmm2ext::rounded_rectangle (cr, 0, upper_height + separator_height, _width, h, 9);
+ }
}
}
-
-AudioClock::~AudioClock ()
-{
- delete timecode;
- delete minsec;
- delete bbt;
- delete frames;
-}
void
-AudioClock::set_widget_name (string name)
+AudioClock::on_size_allocate (Gtk::Allocation& alloc)
{
- Widget::set_name (name);
- set_theme ();
+ CairoWidget::on_size_allocate (alloc);
+
+ if (_left_layout) {
+ upper_height = (_height/2.0) - 1.0;
+ } else {
+ upper_height = _height;
+ }
}
void
-AudioClock::set_theme ()
+AudioClock::on_size_request (Gtk::Requisition* req)
{
+ Glib::RefPtr<Pango::Layout> tmp;
Glib::RefPtr<Gtk::Style> style = get_style ();
- double r, g, b, a;
-
- if (!style) {
- return;
- }
-
Pango::FontDescription font;
+ tmp = Pango::Layout::create (get_pango_context());
+
if (!is_realized()) {
font = get_font_for_style (get_name());
} else {
font = style->get_font();
}
- timecode->set_font (font);
- minsec->set_font (font);
- bbt->set_font (font);
- frames->set_font (font);
+ tmp->set_font_description (font);
- 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);
+ /* this string is the longest thing we will ever display,
+ and also includes the BBT "|" that may descends below
+ the baseline a bit, and a comma for the minsecs mode
+ where we printf a fractional value (XXX or should)
+ */
- r = bg.get_red_p ();
- g = bg.get_green_p ();
- b = bg.get_blue_p ();
- a = 1.0;
+ tmp->set_text (" 88|88:88:88,88");
- timecode->set_bg (r, g, b, a);
- minsec->set_bg (r, g, b, a);
- bbt->set_bg (r, g, b, a);
- frames->set_bg (r, g, b, a);
+ tmp->get_pixel_size (req->width, req->height);
- r = fg.get_red_p ();
- g = fg.get_green_p ();
- b = fg.get_blue_p ();
- a = 1.0;
+ layout_height = req->height;
+ layout_width = req->width;
- timecode->set_colors (r, g, b, a);
- minsec->set_colors (r, g, b, a);
- bbt->set_colors (r, g, b, a);
- frames->set_colors (r, g, b, a);
+ /* now tackle height, for which we need to know the height of the lower
+ * layout
+ */
- r = eg.get_red_p ();
- g = eg.get_green_p ();
- b = eg.get_blue_p ();
- a = 1.0;
+ if (_left_layout) {
- timecode->set_edit_colors (r, g, b, a);
- minsec->set_edit_colors (r, g, b, a);
- bbt->set_edit_colors (r, g, b, a);
- frames->set_edit_colors (r, g, b, a);
+ int w;
- queue_draw ();
+ font.set_size ((int) lrint (font.get_size() * info_font_scale_factor));
+ font.set_weight (Pango::WEIGHT_NORMAL);
+ tmp->set_font_description (font);
+
+ /* 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);
+
+ info_height += 4;
+
+ req->height += info_height;
+ req->height += separator_height;
+ }
}
void
-AudioClock::focus ()
+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 (*background_attr);
+ editing_attributes.change (*foreground_attr);
+ editing_attributes.change (*editing_attr);
+
+ _layout->set_attributes (editing_attributes);
}
void
-AudioClock::end_edit ()
+AudioClock::start_edit ()
{
- current_cet->stop_editing ();
- editing_field = (Field) 0;
- key_entry_state = 0;
+ edit_string = _layout->get_text ();
+ pre_edit_string = edit_string;
+ input_string.clear ();
+ editing = true;
- /* move focus back to the default widget in the top level window */
+ show_edit_status (1);
+ queue_draw ();
- Keyboard::magic_widget_drop_focus ();
+ Keyboard::magic_widget_grab_focus ();
+ grab_focus ();
+}
- Widget* top = get_toplevel();
+void
+AudioClock::end_edit (bool modify)
+{
+ if (modify) {
+
+ 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:
+ break;
+
+ case Frames:
+ break;
+ }
+
+ if (!ok) {
+ edit_string = pre_edit_string;
+ input_string.clear ();
+ _layout->set_text (edit_string);
+ show_edit_status (1);
+ /* edit attributes remain in use */
+ } else {
+
+ editing = false;
+ framepos_t pos;
+
+ 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;
+ _layout->set_attributes (normal_attributes);
+ _layout->set_text (pre_edit_string);
+ }
+
+ queue_draw ();
+
+ if (!editing) {
+ drop_focus ();
+ }
+}
+
+void
+AudioClock::drop_focus ()
+{
+ /* move focus back to the default widget in the top level window */
+
+ Keyboard::magic_widget_drop_focus ();
+ Widget* top = get_toplevel();
if (top->is_toplevel ()) {
Window* win = dynamic_cast<Window*> (top);
win->grab_focus ();
}
}
-void
-AudioClock::on_realize ()
+framecnt_t
+AudioClock::parse_as_frames_distance (const std::string& str)
{
- Alignment::on_realize ();
+ framecnt_t f;
- /* styles are not available until the widgets are bound to a window */
-
- set_theme ();
+ if (sscanf (str.c_str(), "%" PRId64, &f) == 1) {
+ return f;
+ }
+
+ return 0;
}
-void
-AudioClock::set (framepos_t when, bool force, framecnt_t offset, char which)
+framecnt_t
+AudioClock::parse_as_minsec_distance (const std::string& str)
{
- if ((!force && !is_visible()) || _session == 0) {
- return;
- }
+ framecnt_t sr = _session->frame_rate();
+ int msecs;
+ int secs;
+ int mins;
+ int hrs;
- bool const pdelta = Config->get_primary_clock_delta_edit_cursor ();
- bool const sdelta = Config->get_secondary_clock_delta_edit_cursor ();
+ 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));
- 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;
- }
+ case 6:
+ sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &msecs);
+ return (secs * sr) + (msecs * (sr/1000));
- if (when == last_when && !force) {
- return;
+ case 7:
+ sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &msecs);
+ return (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
+
+ case 8:
+ sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &msecs);
+ return (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
+
+ case 9:
+ sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &msecs);
+ return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
+
+ case 10:
+ sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%2" PRId32 "%" PRId32, &hrs, &mins, &secs, &msecs);
+ return (hrs * 3600 * sr) + (mins * 60 * sr) + (secs * sr) + (msecs * (sr/1000));
+
+ default:
+ break;
}
- 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;
+ return 0;
+}
+
+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 lrint ((frames/(float)fps) * sr);
+
+ case 3:
+ sscanf (str.c_str(), "%1" PRId32 "%" PRId32, &secs, &frames);
+ return (secs * sr) + lrint ((frames/(float)fps) * sr);
+
+ case 4:
+ sscanf (str.c_str(), "%2" PRId32 "%" PRId32, &secs, &frames);
+ return (secs * sr) + lrint ((frames/(float)fps) * sr);
+
+ case 5:
+ sscanf (str.c_str(), "%1" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &frames);
+ return (mins * 60 * sr) + (secs * sr) + lrint ((frames/(float)fps) * sr);
+
+ case 6:
+ sscanf (str.c_str(), "%2" PRId32 "%2" PRId32 "%" PRId32, &mins, &secs, &frames);
+ return (mins * 60 * sr) + (secs * sr) + lrint ((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) + lrint ((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) + lrint ((frames/(float)fps) * sr);
+
+ default:
+ break;
}
+ return 0;
+}
+
+framecnt_t
+AudioClock::parse_as_bbt_distance (const std::string& str)
+{
+ return 0;
+}
+
+framecnt_t
+AudioClock::parse_as_distance (const std::string& instr)
+{
+ string str = instr;
+
+ /* the input string is in reverse order */
+
+ std::reverse (str.begin(), str.end());
+
switch (_mode) {
case Timecode:
- set_timecode (when, force);
+ return parse_as_timecode_distance (str);
+ break;
+ case Frames:
+ return parse_as_frames_distance (str);
break;
-
case BBT:
- set_bbt (when, force);
+ return parse_as_bbt_distance (str);
break;
-
case MinSec:
- set_minsec (when, force);
+ return parse_as_minsec_distance (str);
break;
+ }
+ return 0;
+}
- case Frames:
- set_frames (when, force);
- break;
+void
+AudioClock::end_edit_relative (bool add)
+{
+ framecnt_t frames = parse_as_distance (input_string);
- case Off:
- break;
- }
+ editing = false;
- last_when = when;
+ editing = false;
+ _layout->set_attributes (normal_attributes);
+
+ if (frames != 0) {
+ if (add) {
+ set (current_time() + frames, true);
+ } else {
+ framepos_t c = current_time();
- /* we're setting the time from a frames value, so keep it as the canonical value */
- _canonical_time = when;
- _canonical_time_is_displayed = false;
+ if (c > frames) {
+ set (c - frames, true);
+ } else {
+ set (0, true);
+ }
+ }
+ ValueChanged (); /* EMIT SIGNAL */
+ }
+
+ input_string.clear ();
+ queue_draw ();
+ drop_focus ();
}
void
}
}
+void
+AudioClock::set (framepos_t when, bool force, framecnt_t offset, char which)
+{
+ if ((!force && !is_visible()) || _session == 0) {
+ return;
+ }
+
+ bool const pdelta = Config->get_primary_clock_delta_edit_cursor ();
+ bool const sdelta = Config->get_secondary_clock_delta_edit_cursor ();
+
+ 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;
+ }
+
+ if (when == last_when && !force) {
+ return;
+ }
+
+ if (which == 'p' && pdelta && !last_pdelta) {
+ set_name("TransportClockDisplayDelta");
+ last_pdelta = true;
+ } else if (which == 'p' && !pdelta && last_pdelta) {
+ set_name("TransportClockDisplay");
+ last_pdelta = false;
+ } else if (which == 's' && sdelta && !last_sdelta) {
+ set_name("SecondaryClockDisplayDelta");
+ last_sdelta = true;
+ } else if (which == 's' && !sdelta && last_sdelta) {
+ set_name("SecondaryClockDisplay");
+ last_sdelta = false;
+ }
+
+ if (!editing) {
+
+ switch (_mode) {
+ case Timecode:
+ set_timecode (when, force);
+ break;
+
+ case BBT:
+ set_bbt (when, force);
+ break;
+
+ case MinSec:
+ set_minsec (when, force);
+ break;
+
+ case Frames:
+ set_frames (when, force);
+ break;
+ }
+ }
+
+ if (when != last_when || force) {
+ queue_draw ();
+ }
+
+ last_when = when;
+}
+
void
AudioClock::set_frames (framepos_t when, bool /*force*/)
{
char buf[32];
- snprintf (buf, sizeof (buf), "%" PRId64, when);
+
+ if (_off) {
+ /* XXX with cairo, we can do better, surely? */
+
+ _layout->set_text ("-----------");
+
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
+ }
+
+ return;
+ }
- frames->set_text (AudioFrames, buf);
+ snprintf (buf, sizeof (buf), "%10" PRId64, when);
+ _layout->set_text (buf);
- if (frames_upper_info_label) {
+ if (_left_layout) {
framecnt_t rate = _session->frame_rate();
if (fmod (rate, 1000.0) == 0.000) {
sprintf (buf, "%" PRId64 "K", rate/1000);
} else {
- sprintf (buf, "%.3fK", rate/1000.0f);
+ sprintf (buf, "%" PRId64, rate);
}
- if (frames_upper_info_label->get_text() != buf) {
- frames_upper_info_label->set_text (buf);
- }
+ _left_layout->set_text (buf);
float vid_pullup = _session->config.get_video_pullup();
if (vid_pullup == 0.0) {
- if (frames_lower_info_label->get_text () != _("none")) {
- frames_lower_info_label->set_text(_("none"));
- }
+ _right_layout->set_text (_("none"));
} else {
sprintf (buf, "%-6.4f", vid_pullup);
- if (frames_lower_info_label->get_text() != buf) {
- frames_lower_info_label->set_text (buf);
- }
+ _right_layout->set_text (buf);
}
}
}
int secs;
int millisecs;
+ if (_off) {
+ _layout->set_text ("--:--:--");
+
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
+ }
+
+ 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);
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);
- minsec->set_text (MS_Hours, buf);
- ms_last_hrs = hrs;
- }
-
- if (force || mins != ms_last_mins) {
- sprintf (buf, "%02d", mins);
- minsec->set_text (MS_Minutes, buf);
- ms_last_mins = mins;
- }
-
- if (force || secs != ms_last_secs) {
- sprintf (buf, "%02d", secs);
- minsec->set_text (MS_Seconds, buf);
- ms_last_secs = secs;
- }
-
- if (force || millisecs != ms_last_millisecs) {
- sprintf (buf, "%03d", millisecs);
- minsec->set_text (MS_Milliseconds, buf);
- ms_last_millisecs = millisecs;
- }
+ snprintf (buf, sizeof (buf), "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32, hrs, mins, secs, millisecs);
+ _layout->set_text (buf);
}
void
{
char buf[32];
Timecode::Time TC;
+
+ if (_off) {
+ _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);
}
-
- if (force || TC.hours != last_hrs || TC.negative != last_negative) {
- if (TC.negative) {
- sprintf (buf, "-%0*" PRIu32, field_length[Timecode_Hours], TC.hours);
- } else {
- sprintf (buf, " %0*" PRIu32, field_length[Timecode_Hours], TC.hours);
- }
- timecode->set_text (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);
- timecode->set_text (Timecode_Minutes, buf);
- last_mins = TC.minutes;
- }
-
- if (force || TC.seconds != last_secs) {
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Seconds], TC.seconds);
- timecode->set_text (Timecode_Seconds, buf);
- last_secs = TC.seconds;
+
+ if (TC.negative) {
+ snprintf (buf, sizeof (buf), "-%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32, TC.hours, TC.minutes, TC.seconds, TC.frames);
+ } else {
+ snprintf (buf, sizeof (buf), " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32, TC.hours, TC.minutes, TC.seconds, TC.frames);
}
- if (force || TC.frames != last_frames) {
- sprintf (buf, "%0*" PRIu32, field_length[Timecode_Frames], TC.frames);
- timecode->set_text (Timecode_Frames, buf);
- last_frames = TC.frames;
- }
+ _layout->set_text (buf);
- if (timecode_upper_info_label) {
+ if (_right_layout) {
double timecode_frames = _session->timecode_frames_per_second();
-
+
if (fmod(timecode_frames, 1.0) == 0.0) {
- sprintf (buf, "%u", int (timecode_frames));
- } else {
- sprintf (buf, "%.2f", timecode_frames);
- }
-
- if (timecode_upper_info_label->get_text() != buf) {
- timecode_upper_info_label->set_text (buf);
- }
-
- if ((fabs(timecode_frames - 29.97) < 0.0001) || timecode_frames == 30) {
- if (_session->timecode_drop_frames()) {
- sprintf (buf, "DF");
- } else {
- sprintf (buf, "NDF");
- }
+ sprintf (buf, "FPS %u %s", int (timecode_frames), (_session->timecode_drop_frames() ? "D" : ""));
} else {
- // there is no drop frame alternative
- buf[0] = '\0';
+ sprintf (buf, "%.2f %s", timecode_frames, (_session->timecode_drop_frames() ? "D" : ""));
}
- if (timecode_lower_info_label->get_text() != buf) {
- timecode_lower_info_label->set_text (buf);
- }
+ _right_layout->set_text (buf);
}
}
char buf[16];
Timecode::BBT_Time BBT;
+ if (_off) {
+ _layout->set_text ("--|--|--");
+ if (_left_layout) {
+ _left_layout->set_text ("");
+ _right_layout->set_text ("");
+ }
+ return;
+ }
+
/* handle a common case */
if (is_duration) {
if (when == 0) {
_session->tempo_map().bbt_time (when, BBT);
}
- sprintf (buf, "%0*" PRIu32, field_length[Bars], BBT.bars);
- if (force || _text_cells[Bars]->get_text () != buf) {
- bbt->set_text (Bars, buf);
- _text_cells[Bars]->set_text (buf);
- }
- sprintf (buf, "%0*" PRIu32, field_length[Beats], BBT.beats);
- if (force || _text_cells[Beats]->get_text () != buf) {
- bbt->set_text (Beats, buf);
- }
- sprintf (buf, "%0*" PRIu32, field_length[Ticks], BBT.ticks);
- if (force || _text_cells[Ticks]->get_text () != buf) {
- bbt->set_text (Ticks, buf);
- }
-
- if (bbt_upper_info_label) {
+ snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%04" PRIu32, BBT.bars, BBT.beats, BBT.ticks);
+ _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());
- if (bbt_lower_info_label->get_text() != buf) {
- bbt_lower_info_label->set_text (buf);
- }
+ _left_layout->set_text (buf);
+
sprintf (buf, "%g|%g", m.meter().beats_per_bar(), m.meter().note_divisor());
- if (bbt_upper_info_label->get_text() != buf) {
- bbt_upper_info_label->set_text (buf);
- }
+ _right_layout->set_text (buf);
}
}
_session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_configuration_changed, this, _1), gui_context());
- XMLProperty* prop;
+ const XMLProperty* prop;
XMLNode* node = _session->extra_xml (X_("ClockModes"));
AudioClock::Mode amode;
if (node) {
- if ((prop = node->property (_name)) != 0) {
- amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
- set_mode (amode);
+ for (XMLNodeList::const_iterator i = node->children().begin(); i != node->children().end(); ++i) {
+ if ((prop = (*i)->property (X_("name"))) && prop->value() == _name) {
+
+ if ((prop = (*i)->property (X_("mode"))) != 0) {
+ amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
+ set_mode (amode);
+ }
+ if ((prop = (*i)->property (X_("on"))) != 0) {
+ set_off (!string_is_affirmative (prop->value()));
+ }
+ break;
+ }
}
}
}
}
-void
-AudioClock::edit_next_field ()
-{
- /* move on to the next field.
- */
-
- switch (editing_field) {
-
- /* Timecode */
-
- case Timecode_Hours:
- editing_field = Timecode_Minutes;
- timecode->start_editing (Timecode_Minutes);
- break;
- case Timecode_Minutes:
- editing_field = Timecode_Seconds;
- timecode->start_editing (Timecode_Seconds);
- break;
- case Timecode_Seconds:
- editing_field = Timecode_Frames;
- timecode->start_editing (Timecode_Frames);
- break;
- case Timecode_Frames:
- end_edit ();
- break;
-
- /* Min:Sec */
-
- case MS_Hours:
- editing_field = MS_Minutes;
- minsec->start_editing (MS_Minutes);
- break;
- case MS_Minutes:
- editing_field = MS_Seconds;
- minsec->start_editing (MS_Seconds);
- break;
- case MS_Seconds:
- editing_field = MS_Milliseconds;
- minsec->start_editing (MS_Milliseconds);
- break;
- case MS_Milliseconds:
- end_edit ();
- break;
-
- /* BBT */
-
- case Bars:
- editing_field = Beats;
- bbt->start_editing (Beats);
- break;
- case Beats:
- editing_field = Ticks;
- bbt->start_editing (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)
{
+ if (!editing) {
+ return false;
+ }
+
/* return true for keys that we MIGHT use
at release
*/
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;
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
- } else {
- return false;
- }
+ case GDK_minus:
+ case GDK_KP_Subtract:
+ end_edit_relative (false);
+ return true;
+ break;
+
+ case GDK_plus:
+ case GDK_KP_Add:
+ 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;
return false;
}
- if (!move_on) {
-
- if (key_entry_state == 0) {
-
- /* initialize with a fresh new string */
+ if (input_string.length() >= insert_max) {
+ /* eat the key event, but do no nothing with it */
+ return true;
+ }
- if (editing_field != AudioFrames) {
- for (uint32_t xn = 0; xn < field_length[editing_field] - 1; ++xn) {
- new_text += '0';
+ input_string.insert (input_string.begin(), new_char);
+
+ string::reverse_iterator ri;
+ vector<int> insert_at;
+ int highlight_length;
+
+ /* merge with pre-edit-string into edit string */
+
+ switch (_mode) {
+ case Frames:
+ edit_string = input_string;
+ highlight_length = edit_string.length();
+ break;
+
+ default:
+ edit_string = pre_edit_string;
+
+ /* backup through the original string, till we have
+ * enough digits locations to put all the digits from
+ * the input string.
+ */
+
+ for (ri = edit_string.rbegin(); ri != edit_string.rend(); ++ri) {
+ if (isdigit (*ri)) {
+ insert_at.push_back (edit_string.length() - (ri - edit_string.rbegin()) - 1);
+ if (insert_at.size() == input_string.length()) {
+ break;
}
- } else {
- new_text = "";
}
-
+ }
+
+ if (insert_at.size() != input_string.length()) {
+ error << "something went wrong " << endmsg;
} 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);
+ for (int i = input_string.length() - 1; i >= 0; --i) {
+ edit_string[insert_at[i]] = input_string[i];
}
+
+ highlight_length = edit_string.length() - insert_at.back();
}
-
- new_text += new_char;
-
- if (current_cet) {
- current_cet->set_text (editing_field, new_text);
- }
-
- _canonical_time_is_displayed = true;
- key_entry_state++;
- }
-
- if (key_entry_state == field_length[editing_field]) {
- move_on = true;
+
+ break;
}
+
+ if (edit_string != _layout->get_text()) {
+ show_edit_status (highlight_length);
+ _layout->set_text (edit_string);
+ queue_draw ();
+ }
- if (move_on) {
-
- if (key_entry_state) {
-
- /* if key_entry_state != then we edited the text
- */
-
- char buf[16];
+ return true;
+}
- 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);
- _text_cells[Bars]->set_text (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);
- _text_cells[Beats]->set_text (buf);
- _canonical_time_is_displayed = true;
- }
- break;
- default:
- break;
- }
+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 if (index < 13) {
+ return Timecode_Frames;
+ } else {
+ return Field (0);
+ }
+ break;
+ case BBT:
+ if (index < 5) {
+ return Bars;
+ } else if (index < 7) {
+ return Beats;
+ } else if (index < 12) {
+ return Ticks;
+ } else {
+ return Field (0);
+ }
+ break;
- ValueChanged(); /* EMIT_SIGNAL */
+ case MinSec:
+ if (index < 3) {
+ return Timecode_Hours;
+ } else if (index < 6) {
+ return MS_Minutes;
+ } else if (index < 9) {
+ return MS_Seconds;
+ } else if (index < 12) {
+ return MS_Milliseconds;
+ } else {
+ return Field (0);
}
-
- edit_next_field ();
- }
+ break;
- //if user hit Enter, lose focus
- switch (ev->keyval) {
- case GDK_Return:
- case GDK_KP_Enter:
- end_edit ();
+ case Frames:
+ return AudioFrames;
+ break;
}
-
- return true;
}
bool
-AudioClock::button_press (GdkEventButton *ev, uint32_t id)
+AudioClock::on_button_press_event (GdkEventButton *ev)
{
- Field field = (Field) id;
-
switch (ev->button) {
case 1:
- editing_field = field;
- current_cet->start_editing (field);
-
- Keyboard::magic_widget_grab_focus ();
-
- /* 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;
+ if (editable) {
+ dragging = true;
+ /* make absolutely sure that the pointer is grabbed */
+ gdk_pointer_grab(ev->window,false ,
+ GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
+ NULL,NULL,ev->time);
+ drag_accum = 0;
+ drag_start_y = ev->y;
+ drag_y = ev->y;
+
+ int index;
+ int trailing;
+
+ if (_layout->xy_to_index (ev->x * PANGO_SCALE, ev->y * PANGO_SCALE, index, trailing)) {
+ drag_field = index_to_field (index);
+ } else {
+ drag_field = Field (0);
+ }
+ }
break;
default:
}
bool
-AudioClock::button_release (GdkEventButton *ev, uint32_t id)
+AudioClock::on_button_release_event (GdkEventButton *ev)
{
- 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
- return true;
- }
- }
+ if (editable) {
+ 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
+ return true;
+ } else {
+ if (ev->button == 1) {
+ start_edit ();
+ }
+ }
- if (!editable) {
- if (ops_menu == 0) {
- build_ops_menu ();
}
- ops_menu->popup (1, ev->time);
- return true;
}
if (Keyboard::is_context_menu_event (ev)) {
return true;
}
- return true;
+ return false;
}
bool
-AudioClock::scroll (GdkEventScroll *ev, uint32_t id)
+AudioClock::on_focus_out_event (GdkEventFocus* ev)
{
- Field field = (Field) id;
+ bool ret = CairoWidget::on_focus_out_event (ev);
- if (_session == 0) {
+ end_edit (false);
+
+ return ret;
+}
+
+bool
+AudioClock::on_scroll_event (GdkEventScroll *ev)
+{
+ int index;
+ int trailing;
+
+ if (_session == 0 || !editable) {
return false;
}
+ if (!_layout->xy_to_index (ev->x * PANGO_SCALE, ev->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);
- if (frames != 0) {
- if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
- frames *= 10;
- }
- set (current_time() + frames, true);
- ValueChanged (); /* EMIT_SIGNAL */
- }
- break;
-
+ frames = get_frame_step (f);
+ if (frames != 0) {
+ if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+ frames *= 10;
+ }
+ set (current_time() + frames, true);
+ ValueChanged (); /* EMIT_SIGNAL */
+ }
+ break;
+
case GDK_SCROLL_DOWN:
- frames = get_frames (field);
- if (frames != 0) {
- if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
- frames *= 10;
- }
-
- if ((double)current_time() - (double)frames < 0.0) {
- set (0, true);
- } else {
- set (current_time() - frames, true);
- }
-
- ValueChanged (); /* EMIT_SIGNAL */
- }
- break;
-
+ 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) {
+ 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) {
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 (trunc (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
{
- if (!_canonical_time_is_displayed) {
- return _canonical_time;
- }
+ return last_when;
+}
+framepos_t
+AudioClock::current_duration (framepos_t pos) const
+{
framepos_t ret = 0;
switch (_mode) {
case Timecode:
- ret = timecode_frame_from_display ();
+ ret = last_when;
break;
case BBT:
- ret = bbt_frame_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 ();
- break;
-
- case Off:
+ ret = last_when;
break;
}
return ret;
}
-framepos_t
-AudioClock::current_duration (framepos_t pos) const
+bool
+AudioClock::bbt_validate_edit (const string& str)
{
- framepos_t ret = 0;
-
- switch (_mode) {
- case Timecode:
- ret = timecode_frame_from_display ();
- break;
- case BBT:
- ret = bbt_frame_duration_from_display (pos);
- break;
-
- case MinSec:
- ret = minsec_frame_from_display ();
- break;
+ AnyTime any;
- case Frames:
- ret = audio_frame_from_display ();
- break;
+ sscanf (str.c_str(), "%" PRIu32 "|%" PRIu32 "|%" PRIu32, &any.bbt.bars, &any.bbt.beats, &any.bbt.ticks);
+
+ if (!is_duration && any.bbt.bars == 0) {
+ return false;
+ }
- case Off:
- break;
+ if (!is_duration && any.bbt.beats == 0) {
+ return false;
}
- return ret;
+ return true;
}
-void
-AudioClock::timecode_sanitize_display()
+bool
+AudioClock::timecode_validate_edit (const string& str)
{
- // Check Timecode fields for sanity, possibly adjusting values
- if (atoi (_text_cells[Timecode_Minutes]->get_text()) > 59) {
- _text_cells[Timecode_Minutes]->set_text("59");
- _canonical_time_is_displayed = true;
+ Timecode::Time TC;
+
+ if (sscanf (_layout->get_text().c_str(), "%" PRId32 ":%" PRId32 ":%" PRId32 ":%" PRId32,
+ &TC.hours, &TC.minutes, &TC.seconds, &TC.frames) != 4) {
+ return false;
}
- if (atoi (_text_cells[Timecode_Seconds]->get_text()) > 59) {
- _text_cells[Timecode_Seconds]->set_text("59");
- _canonical_time_is_displayed = true;
+ if (TC.minutes > 59 || TC.seconds > 59) {
+ return false;
}
- switch ((long)rint(_session->timecode_frames_per_second())) {
- case 24:
- if (atoi (_text_cells[Timecode_Frames]->get_text()) > 23) {
- _text_cells[Timecode_Frames]->set_text("23");
- _canonical_time_is_displayed = true;
- }
- break;
- case 25:
- if (atoi (_text_cells[Timecode_Frames]->get_text()) > 24) {
- _text_cells[Timecode_Frames]->set_text("24");
- _canonical_time_is_displayed = true;
- }
- break;
- case 30:
- if (atoi (_text_cells[Timecode_Frames]->get_text()) > 29) {
- _text_cells[Timecode_Frames]->set_text("29");
- _canonical_time_is_displayed = true;
- }
- break;
- default:
- break;
+ if (TC.frames > (long)rint(_session->timecode_frames_per_second()) - 1) {
+ 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)) {
- _text_cells[Timecode_Frames]->set_text("02");
- _canonical_time_is_displayed = true;
+ if (TC.minutes % 10 && TC.seconds == 0 && TC.frames < 2) {
+ 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 ());
- return i->second;
+ return true;
}
framepos_t
-AudioClock::timecode_frame_from_display () const
+AudioClock::frames_from_timecode_string (const string& str) const
{
if (_session == 0) {
return 0;
Timecode::Time TC;
framepos_t sample;
- TC.hours = atoi (label (Timecode_Hours)->get_text());
- TC.minutes = atoi (label (Timecode_Minutes)->get_text());
- TC.seconds = atoi (label (Timecode_Seconds)->get_text());
- TC.frames = atoi (label (Timecode_Frames)->get_text());
+ sscanf (str.c_str(), "%d:%d:%d:%d", &TC.hours, &TC.minutes, &TC.seconds, &TC.frames);
+
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 );
- }
-
- 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 );
- }
-
- 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 );
- }
-
- 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 (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 );
- }
-
- 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;
- }
-
- 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 );
- }
-
- 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_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 );
- }
-
- 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_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 );
- }
-
- 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_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 );
- }
-
- 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
-
-#endif
+
+ // timecode_tester ();
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();
+ sscanf (str.c_str(), "%d:%d:%d:%d", &hrs, &mins, &secs, &millisecs);
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());
+ sscanf (str.c_str(), "%" PRId32 "|%" PRId32 "|%" PRId32, &any.bbt.bars, &any.bbt.beats, &any.bbt.ticks);
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;
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());
+ sscanf (str.c_str(), "%" PRIu32 "|%" PRIu32 "|%" PRIu32, &bbt.bars, &bbt.beats, &bbt.ticks);
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
{
- return (framepos_t) atoi (label (AudioFrames)->get_text ());
+ framepos_t f;
+ sscanf (str.c_str(), "%" PRId64, &f);
+ return f;
}
void
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 (_("Off"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Off)));
if (editable && !is_duration && !_follows_playhead) {
ops_items.push_back (SeparatorElem());
_session->request_locate (current_time(), _session->transport_rolling ());
}
-void
-AudioClock::disconnect_signals ()
-{
- scroll_connection.disconnect ();
- button_press_connection.disconnect ();
- button_release_connection.disconnect ();
-}
-
-void
-AudioClock::connect_signals ()
-{
- disconnect_signals ();
-
- if (editable && current_cet) {
- scroll_connection = current_cet->scroll.connect (sigc::mem_fun (*this, &AudioClock::scroll));
- button_press_connection = current_cet->button_press.connect (sigc::mem_fun (*this, &AudioClock::button_press));
- button_release_connection = current_cet->button_release.connect (sigc::mem_fun (*this, &AudioClock::button_release));
- }
-}
-
void
AudioClock::set_mode (Mode m)
{
- /* slightly tricky: this is called from within the ARDOUR_UI
- constructor by some of its clock members. at that time
- the instance pointer is unset, so we have to be careful.
- the main idea is to drop keyboard focus in case we had
- started editing the clock and then we switch clock mode.
- */
-
- // clock_base.grab_focus ();
-
if (_mode == m) {
return;
}
- remove ();
_mode = m;
switch (_mode) {
case Timecode:
- current_cet = timecode;
- add (timecode_packer);
+ insert_max = 9; // 8 digits + sign [-]2:2:2:2
+ mode_based_info_ratio = 0.5;
break;
-
+
case BBT:
- current_cet = bbt;
- add (bbt_packer);
+ insert_max = 8; // 8 digits, 2|2|4
+ mode_based_info_ratio = 0.5;
break;
-
+
case MinSec:
- current_cet = minsec;
- add (minsec_packer);
+ insert_max = 9; // 7 digits 2:2:2.3
+ mode_based_info_ratio = 1.0;
break;
-
+
case Frames:
- current_cet = frames;
- add (frames_packer);
- break;
-
- case Off:
- current_cet = 0;
- add (off_hbox);
+ insert_max = INT_MAX;
+ mode_based_info_ratio = 1.0;
break;
}
- if (current_cet) {
- connect_signals ();
- } else {
- disconnect_signals ();
- }
-
- get_child()->show_all ();
-
set (last_when, true);
if (!is_transient) {
void
AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
{
- Alignment::on_style_changed (old_style);
- set_theme ();
+ CairoWidget::on_style_changed (old_style);
+ set_font ();
+ set_colors ();
}
void
is_duration = yn;
set (last_when, true, 0, 's');
}
+
+void
+AudioClock::set_off (bool yn)
+{
+ if (_off == yn) {
+ return;
+ }
+
+ _off = yn;
+
+ /* force a redraw. last_when will be preserved, but the clock text will
+ * change
+ */
+
+ set (last_when, true);
+}
+
+void
+AudioClock::focus ()
+{
+ start_edit ();
+}
+
+void
+AudioClock::set_draw_background (bool yn)
+{
+ _need_bg = yn;
+}
+