sigc::signal<void> AudioClock::ModeChanged;
vector<AudioClock*> AudioClock::clocks;
-const double AudioClock::info_font_scale_factor = 0.5;
+const double AudioClock::info_font_scale_factor = 0.50;
const double AudioClock::separator_height = 0.0;
const double AudioClock::x_leading_padding = 6.0;
#define BBT_BAR_CHAR "|"
#define BBT_SCANF_FORMAT "%" PRIu32 "%*c%" PRIu32 "%*c%" PRIu32
-#define INFO_FONT_SIZE ((int)round(font_size * info_font_scale_factor))
+#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)
, editable (allow_edit)
, _follows_playhead (follows_playhead)
, _off (false)
- , _fixed_width (true)
- , layout_x_offset (0)
, em_width (0)
, _edit_by_click_field (false)
, _negative_allowed (false)
, 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 (9)
+ , corner_radius (4)
, font_size (10240)
, editing (false)
, bbt_reference_time (-1)
, last_sdelta (0)
, dragging (false)
, drag_field (Field (0))
-
{
set_flags (CAN_FOCUS);
void
AudioClock::on_realize ()
{
+ Gtk::Requisition req;
+
CairoWidget::on_realize ();
+
+ set_clock_dimensions (req);
+
+ first_width = req.width;
+ first_height = req.height;
+
set_font ();
set_colors ();
}
/* now a smaller version of the same font */
delete font_attr;
- font.set_size ((int) lrint (font_size * info_font_scale_factor));
+ font.set_size (INFO_FONT_SIZE);
font.set_weight (Pango::WEIGHT_NORMAL);
font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (font));
cairo_fill (cr);
}
- if (!_fixed_width) {
- cairo_move_to (cr, layout_x_offset, 0);
- } else {
- int xcenter = layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
- cairo_move_to (cr, layout_x_offset + xcenter, (upper_height - layout_height) / 2.0);
- }
+ cairo_move_to (cr, (get_width() - layout_width) / 2.0, (upper_height - layout_height) / 2.0);
pango_cairo_show_layout (cr, _layout->gobj());
if (editing) {
if (!insert_map.empty()) {
- int xcenter = layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+ int xcenter = (get_width() - layout_width) /2;
if (input_string.length() < insert_map.size()) {
Pango::Rectangle cursor;
}
cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
- if (!_fixed_width) {
- cairo_rectangle (cr,
- min (get_width() - 2.0,
- (double) cursor.get_x()/PANGO_SCALE + layout_x_offset + xcenter + em_width), 0,
- 2.0, cursor.get_height()/PANGO_SCALE);
- } else {
- cairo_rectangle (cr,
- min (get_width() - 2.0,
- (double) layout_x_offset + xcenter + cursor.get_x()/PANGO_SCALE + em_width),
- (upper_height - layout_height)/2.0,
- 2.0, cursor.get_height()/PANGO_SCALE);
- }
+ 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);
- if (!_fixed_width) {
- cairo_rectangle (cr,
- (get_width()/2.0),
- 0,
- 2.0, upper_height);
- } else {
- cairo_rectangle (cr,
- (get_width()/2.0),
- (upper_height - layout_height)/2.0,
- 2.0, upper_height);
- }
+ cairo_rectangle (cr,
+ (get_width()/2.0),
+ (upper_height - layout_height)/2.0,
+ 2.0, upper_height);
cairo_fill (cr);
}
}
} else {
upper_height = get_height();
}
-
- if (_fixed_width) {
- /* center display in available space
- * NB. this only works if the containing widget is not the
- * layout itself (eg. the session->property dialog)
- */
- layout_x_offset = (get_width() - layout_width)/2.0;
- } else {
- /* left justify */
- layout_x_offset = 0;
- }
}
void
-AudioClock::on_size_request (Gtk::Requisition* req)
+AudioClock::set_clock_dimensions (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;
- }
-
Glib::RefPtr<Pango::Layout> tmp;
Glib::RefPtr<Gtk::Style> style = get_style ();
Pango::FontDescription font;
tmp->set_font_description (font);
- if (_fixed_width) {
- int ignored;
- tmp->set_text ("-88:88:88:88");
- tmp->get_pixel_size (_mode_width[Timecode], ignored);
- tmp->set_text (" 88888|88|8888");
- tmp->get_pixel_size (_mode_width[BBT], ignored);
- tmp->set_text (" 88:88:88,888");
- tmp->get_pixel_size (_mode_width[MinSec], ignored);
- tmp->set_text (" 8888888888");
- tmp->get_pixel_size (_mode_width[Frames], ignored);
-
- /* this string is the longest thing we will ever display,
- it does not include the BBT bar char that may descend
- below the baseline.
- note; depending on BPM setting this may actually
- not be sufficient for 24h worth of BBT
- */
+ /* this string is the longest thing we will ever display */
+ tmp->set_text (" 88:88:88,888");
+ tmp->get_pixel_size (req.width, req.height);
- tmp->set_text (" 88888888888::,");
- } else {
- switch (_mode) {
- case Timecode:
- tmp->set_text ("-88:88:88:88");
- break;
- case BBT:
- tmp->set_text (" 88888|88|8888");
- break;
- case MinSec:
- tmp->set_text (" 88:88:88,888");
- break;
- case Frames:
- tmp->set_text (" 8888888888");
- break;
- }
- }
+ 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.
+ */
- tmp->get_pixel_size (req->width, req->height);
+ if (first_width) {
+ req->width = first_width;
+ req->height = first_height;
+ return;
+ }
- layout_height = req->height;
- layout_width = req->width;
+ 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();
+ }
+
+ tmp->set_font_description (font);
- font.set_size ((int) lrint (font.get_size() * info_font_scale_factor));
+ font.set_size (INFO_FONT_SIZE);
font.set_weight (Pango::WEIGHT_NORMAL);
tmp->set_font_description (font);
req->height += info_height;
req->height += separator_height;
}
-
- first_height = req->height;
- first_width = req->width;
}
void
void
AudioClock::start_edit (Field f)
{
- 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 (!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 ();
- if (f) {
- input_string = get_field (f);
- show_edit_status (merge_input_and_edit_string ());
- _layout->set_text (edit_string);
+ Keyboard::magic_widget_grab_focus ();
+ grab_focus ();
}
-
- queue_draw ();
-
- Keyboard::magic_widget_grab_focus ();
- grab_focus ();
}
string
break;
case Frames:
+ if (edit_string.length() < 1) {
+ edit_string = pre_edit_string;
+ }
break;
}
} else {
framepos_t c = current_time();
- if (c > frames) {
+ if (c > frames || _negative_allowed) {
set (c - frames, true);
} else {
set (0, true);
drop_focus ();
}
+void
+AudioClock::session_property_changed (const PropertyChange&)
+{
+ set (last_when, true);
+}
+
void
AudioClock::session_configuration_changed (std::string p)
{
+ if (_negative_allowed) {
+ /* session option editor clock */
+ return;
+ }
+
if (p == "sync-source" || p == "external-sync") {
set (current_time(), true);
return;
Slave* slave = _session->slave();
switch (sync_src) {
- case JACK:
- _left_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">%2</span>",
+ 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\" foreground=\"white\">%2</span>",
+ _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\" foreground=\"white\">%2</span>",
+ _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\" foreground=\"white\">%2</span>",
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
INFO_FONT_SIZE, _("--pending--")));
_right_layout->set_text ("");
}
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\"><span foreground=\"white\">%2</span><span foreground=\"%3\">%4</span></span>",
+ _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\" foreground=\"white\">%2</span>",
+ _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\" foreground=\"white\">%2</span>",
+ _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
INFO_FONT_SIZE, _("--pending--")));
_right_layout->set_text ("");
}
break;
}
} else {
- _left_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">INT/%2</span>",
+ _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 ("");
}
bool negative = false;
if (_off) {
- _layout->set_text ("\u2012\u2012\u2012\u2012\u2012\u2012\u2012\u2012\u2012\u2012");
+ _layout->set_text (" ----------");
if (_left_layout) {
_left_layout->set_text ("");
sprintf (buf, "%" PRId64 "Hz", rate);
}
- _left_layout->set_markup (string_compose ("<span size=\"%1\"><span foreground=\"white\">%2 </span><span foreground=\"green\">%3</span></span>",
+ _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) {
- _right_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">%2</span>",
- INFO_FONT_SIZE, _("pullup: \u2012")));
+ _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);
- _right_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"green\">%2</span>",
- INFO_FONT_SIZE, 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));
}
}
}
bool negative = false;
if (_off) {
- _layout->set_text ("\u2012\u2012:\u2012\u2012:\u2012\u2012.\u2012\u2012\u2012");
+ _layout->set_text (" --:--:--.---");
if (_left_layout) {
_left_layout->set_text ("");
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());
+ left -= (framecnt_t) floor ((double)(secs * _session->frame_rate()));
millisecs = floor (left * 1000.0 / (float) _session->frame_rate());
if (negative) {
bool negative = false;
if (_off) {
- _layout->set_text ("\u2012\u2012:\u2012\u2012:\u2012\u2012:\u2012\u2012");
+ _layout->set_text (" --:--:--:--");
if (_left_layout) {
_left_layout->set_text ("");
_right_layout->set_text ("");
bool negative = false;
if (_off) {
- _layout->set_text ("\u2012\u2012\u2012|\u2012\u2012|\u2012\u2012\u2012\u2012");
+ _layout->set_text (" ---|--|----");
if (_left_layout) {
_left_layout->set_text ("");
_right_layout->set_text ("");
TempoMetric m (_session->tempo_map().metric_at (pos));
- sprintf (buf, "%-5.2f", m.tempo().beats_per_minute());
- _left_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">Tmp <span foreground=\"green\">%2</span></span>",
- INFO_FONT_SIZE, buf));
+ sprintf (buf, "%-5.1f", m.tempo().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().divisions_per_bar(), m.meter().note_divisor());
- _right_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">Mtr <span foreground=\"green\">%2</span></span>",
- INFO_FONT_SIZE, buf));
+ _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());
const XMLProperty* prop;
XMLNode* node = _session->extra_xml (X_("ClockModes"));
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 {
end_edit_relative (false);
}
highlight_length = merge_input_and_edit_string ();
}
+ 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," ");
+ }
+ }
+
show_edit_status (highlight_length);
_layout->set_text (edit_string);
queue_draw ();
/* the text has been centered vertically, so adjust
* x and y.
*/
- int xcenter = !_fixed_width || layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+ int xcenter = (get_width() - layout_width) /2;
y = ev->y - ((upper_height - layout_height)/2);
- x = ev->x - layout_x_offset - xcenter;
+ 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 */
if (_edit_by_click_field) {
- int xcenter = !_fixed_width || layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+ 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 - layout_x_offset - xcenter;
+ int x = ev->x - xcenter;
Field f;
if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
* x and y.
*/
- int xcenter = !_fixed_width || layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+ int xcenter = (get_width() - layout_width) /2;
y = ev->y - ((upper_height - layout_height)/2);
- x = ev->x - layout_x_offset - xcenter;
+ x = ev->x - xcenter;
if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
/* not in the main layout */
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);
drag_y = ev->y;
- if (trunc (drag_accum) != 0) {
+ if (floor (drag_accum) != 0) {
framepos_t frames;
framepos_t pos;
AudioClock::timecode_validate_edit (const string&)
{
Timecode::Time TC;
+ int hours;
+ char ignored[2];
+
+ if (sscanf (_layout->get_text().c_str(), "%[- _]%" PRId32 ":%" PRId32 ":%" PRId32 "%[:;]%" PRId32,
+ ignored, &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 6) {
+ return false;
+ }
- if (sscanf (_layout->get_text().c_str(), "%" PRId32 ":%" PRId32 ":%" PRId32 ":%" PRId32,
- &TC.hours, &TC.minutes, &TC.seconds, &TC.frames) != 4) {
+ if (hours < 0) {
+ TC.hours = hours * -1;
+ TC.negative = true;
+ } else {
+ TC.hours = hours;
+ TC.negative = false;
+ }
+
+ if (TC.negative && !_negative_allowed) {
return false;
}
Timecode::Time TC;
framepos_t sample;
+ char ignored[2];
+ int hours;
- if (sscanf (str.c_str(), "%d:%d:%d:%d", &TC.hours, &TC.minutes, &TC.seconds, &TC.frames) != 4) {
+ 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.negative = edit_is_negative;
+ TC.hours = abs(hours);
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 */ );
// timecode_tester ();
+ if (edit_is_negative) {
+ sample = - sample;
+ }
return sample;
}
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;
}
switch (_mode) {
case Timecode:
- mode_based_info_ratio = 0.5;
+ mode_based_info_ratio = 0.6;
insert_map.push_back (11);
insert_map.push_back (10);
insert_map.push_back (8);
break;
case MinSec:
- mode_based_info_ratio = 0.5;
+ mode_based_info_ratio = 0.6;
insert_map.push_back (12);
insert_map.push_back (11);
insert_map.push_back (10);
break;
case Frames:
- mode_based_info_ratio = 0.5;
+ mode_based_info_ratio = 0.45;
break;
}
ModeChanged (); /* EMIT SIGNAL (the static one)*/
}
- if (!_fixed_width) {
- /* display is different, allow us to resize */
- first_width = 0;
- first_height = 0;
- queue_resize ();
- }
-
mode_changed (); /* EMIT SIGNAL (the member one) */
}
AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
{
CairoWidget::on_style_changed (old_style);
- first_width = 0;
- first_height = 0;
+
+ Gtk::Requisition req;
+ set_clock_dimensions (req);
+
set_font ();
set_colors ();
}
queue_resize ();
}
-void
-AudioClock::set_fixed_width (bool yn)
-{
- _fixed_width = yn;
-}
-
void
AudioClock::dpi_reset ()
{