switch from JACK_Slave to Engine_Slave
[ardour.git] / gtk2_ardour / audio_clock.cc
index 2b65b2ef6d03a95b0f7930f734e90062f6e1eb44..6680e95b1514cfce5113e0c1ac705064137b2066 100644 (file)
@@ -53,13 +53,14 @@ using Gtkmm2ext::Keyboard;
 
 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)
@@ -70,20 +71,21 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
        , 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)
+       , edit_is_negative (false)
        , editing_attr (0)
        , foreground_attr (0)
        , first_height (0)
        , first_width (0)
+       , style_resets_first (true)
        , layout_height (0)
        , layout_width (0)
        , info_height (0)
        , upper_height (0)
        , mode_based_info_ratio (1.0)
-       , corner_radius (9)
+       , corner_radius (4)
        , font_size (10240)
        , editing (false)
        , bbt_reference_time (-1)
@@ -92,7 +94,6 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
        , last_sdelta (0)
        , dragging (false)
        , drag_field (Field (0))
-
 {
        set_flags (CAN_FOCUS);
 
@@ -142,7 +143,15 @@ AudioClock::set_widget_name (const string& str)
 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 ();
 }
@@ -170,7 +179,7 @@ AudioClock::set_font ()
        /* 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));
 
@@ -190,6 +199,9 @@ AudioClock::set_font ()
 
        tmp->set_text ("8");
        tmp->get_pixel_size (em_width, ignore_height);
+
+       /* force redraw of markup with new font-size */
+       set (last_when, true);
 }
 
 void
@@ -278,7 +290,7 @@ AudioClock::render (cairo_t* cr)
                cairo_set_source_rgba (cr, bg_r, bg_g, bg_b, bg_a);
                if (corner_radius) {
                        if (_left_layout) {
-                               Gtkmm2ext::rounded_top_half_rectangle (cr, 0, 0, get_width() - corner_radius/2.0, upper_height, corner_radius);
+                               Gtkmm2ext::rounded_top_half_rectangle (cr, 0, 0, get_width(), upper_height, corner_radius);
                        } else {
                                Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), upper_height, corner_radius);
                        }
@@ -288,12 +300,7 @@ AudioClock::render (cairo_t* cr)
                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());
 
@@ -313,7 +320,7 @@ AudioClock::render (cairo_t* cr)
                                if (corner_radius) {
                                        Gtkmm2ext::rounded_bottom_half_rectangle (cr, 0, upper_height + separator_height,
                                                        left_rect_width + (separator_height == 0 ? corner_radius : 0),
-                                                       h - corner_radius/2.0, corner_radius);
+                                                       h, corner_radius);
                                } else {
                                        cairo_rectangle (cr, 0, upper_height + separator_height, left_rect_width, h);
                                }
@@ -327,8 +334,8 @@ AudioClock::render (cairo_t* cr)
                                if (corner_radius) {
                                        Gtkmm2ext::rounded_bottom_half_rectangle (cr, left_rect_width + separator_height,
                                                        upper_height + separator_height,
-                                                       get_width() - separator_height - left_rect_width - corner_radius/2.0,
-                                                       h - corner_radius/2.0, corner_radius);
+                                                       get_width() - separator_height - left_rect_width,
+                                                       h, corner_radius);
                                } else {
                                        cairo_rectangle (cr, left_rect_width + separator_height, upper_height + separator_height,
                                                         get_width() - separator_height - left_rect_width, h);
@@ -347,8 +354,9 @@ AudioClock::render (cairo_t* cr)
                                 */
                                int x, rw, rh;
                                _right_layout->get_pixel_size(rw, rh);
-                               x = get_width() - rw- separator_height - x_leading_padding;
+                               x = get_width() - rw - separator_height - x_leading_padding;
                                if (x < x_leading_padding + left_rect_width + separator_height) {
+                                       /* rather cut off the right end than overlap with the text on the left */
                                        x = x_leading_padding + left_rect_width + separator_height;
                                }
                                cairo_move_to (cr, x, upper_height + separator_height + ((h - info_height)/2.0));
@@ -374,7 +382,7 @@ AudioClock::render (cairo_t* cr)
        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;
@@ -389,18 +397,11 @@ AudioClock::render (cairo_t* cr)
                                }
 
                                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 */
@@ -409,17 +410,10 @@ AudioClock::render (cairo_t* cr)
                } 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);
                        }
                }
@@ -436,33 +430,11 @@ AudioClock::on_size_allocate (Gtk::Allocation& alloc)
        } 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;
@@ -477,46 +449,29 @@ AudioClock::on_size_request (Gtk::Requisition* req)
 
        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 (" 8888|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 (" 8888888888::,");
-       } else {
-               switch (_mode) {
-               case Timecode:
-                       tmp->set_text ("-88:88:88:88");
-                       break;
-               case BBT:
-                       tmp->set_text (" 8888|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;
+}
 
-       tmp->get_pixel_size (req->width, req->height);
+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.
+       */
 
-       layout_height = req->height;
-       layout_width = req->width;
+       if (first_width) {
+               req->width = first_width;
+               req->height = first_height;
+               return;
+       }
+
+       set_clock_dimensions (*req);
 
        /* now tackle height, for which we need to know the height of the lower
         * layout
@@ -524,9 +479,22 @@ AudioClock::on_size_request (Gtk::Requisition* req)
 
        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);
 
@@ -544,12 +512,6 @@ AudioClock::on_size_request (Gtk::Requisition* req)
                req->height += info_height;
                req->height += separator_height;
        }
-
-       req->height += corner_radius/2.0;
-       req->width += corner_radius/2.0;
-
-       first_height = req->height;
-       first_width = req->width;
 }
 
 void
@@ -567,26 +529,30 @@ AudioClock::show_edit_status (int length)
 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;
+       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
@@ -698,6 +664,7 @@ AudioClock::end_edit (bool modify)
        } else {
 
                editing = false;
+               edit_is_negative = false;
                _layout->set_attributes (normal_attributes);
                _layout->set_text (pre_edit_string);
        }
@@ -909,7 +876,7 @@ AudioClock::end_edit_relative (bool add)
                } else {
                        framepos_t c = current_time();
 
-                       if (c > frames) {
+                       if (c > frames || _negative_allowed) {
                                set (c - frames, true);
                        } else {
                                set (0, true);
@@ -923,9 +890,20 @@ AudioClock::end_edit_relative (bool add)
        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;
@@ -1018,28 +996,45 @@ AudioClock::set_slave_info ()
                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 LTC:
-               case MTC:
                case MIDIClock:
                        if (slave) {
-                               _left_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"green\">%2</span>",
-                                                       INFO_FONT_SIZE, dynamic_cast<TimecodeSlave*>(slave)->approximate_current_position()));
-                               _right_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\">" 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;
+               case LTC:
+               case MTC:
+                       if (slave) {
+                               bool matching;
+                               TimecodeSlave* tcslave;
+                               if ((tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
+                                       matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
+                                       _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span><span foreground=\"%3\">%4</span></span>",
+                                                                                 INFO_FONT_SIZE, sync_source_to_string(sync_src, true)[0], (matching?"green":"red"),
+                                                                                 dynamic_cast<TimecodeSlave*>(slave)->approximate_current_position()));
+                                       _right_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
+                                                                                  INFO_FONT_SIZE, slave->approximate_current_delta()));
+                               }
+                       } else {
+                               _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%2</span></span>",
                                                        INFO_FONT_SIZE, _("--pending--")));
                                _right_layout->set_text ("");
                        }
                        break;
                }
        } 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 ("");
        }
@@ -1052,7 +1047,7 @@ AudioClock::set_frames (framepos_t when, bool /*force*/)
        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 ("");
@@ -1084,18 +1079,18 @@ AudioClock::set_frames (framepos_t when, bool /*force*/)
                        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));
                }
        }
 }
@@ -1112,7 +1107,7 @@ AudioClock::set_minsec (framepos_t when, bool /*force*/)
        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 ("");
@@ -1153,7 +1148,7 @@ AudioClock::set_timecode (framepos_t when, bool /*force*/)
        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 ("");
@@ -1188,7 +1183,7 @@ AudioClock::set_bbt (framepos_t when, bool /*force*/)
        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 ("");
@@ -1237,13 +1232,13 @@ AudioClock::set_bbt (framepos_t when, bool /*force*/)
 
                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=\"green\">%2</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=\"green\">%2</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")));
        }
 }
 
@@ -1255,6 +1250,7 @@ AudioClock::set_session (Session *s)
        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"));
@@ -1336,12 +1332,18 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
 
        case GDK_minus:
        case GDK_KP_Subtract:
-               end_edit_relative (false);
+               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);
+               }
                return true;
                break;
 
        case GDK_plus:
-       case GDK_KP_Add:
                end_edit_relative (true);
                return true;
                break;
@@ -1402,6 +1404,16 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
                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 ();
@@ -1535,9 +1547,10 @@ AudioClock::on_button_press_event (GdkEventButton *ev)
                        /* the text has been centered vertically, so adjust
                         * x and y.
                         */
+                       int xcenter = (get_width() - layout_width) /2;
 
                        y = ev->y - ((upper_height - layout_height)/2);
-                       x = ev->x - layout_x_offset;
+                       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 */
@@ -1579,10 +1592,11 @@ AudioClock::on_button_release_event (GdkEventButton *ev)
 
                                        if (_edit_by_click_field) {
 
+                                               int xcenter = (get_width() - layout_width) /2;
                                                int index = 0;
                                                int trailing;
                                                int y = ev->y - ((upper_height - layout_height)/2);
-                                               int x = ev->x - layout_x_offset;
+                                               int x = ev->x - xcenter;
                                                Field f;
 
                                                if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
@@ -1649,8 +1663,9 @@ AudioClock::on_scroll_event (GdkEventScroll *ev)
         * x and y.
         */
 
+       int xcenter = (get_width() - layout_width) /2;
        y = ev->y - ((upper_height - layout_height)/2);
-       x = ev->x - layout_x_offset;
+       x = ev->x - xcenter;
 
        if (!_layout->xy_to_index (x * PANGO_SCALE, y * PANGO_SCALE, index, trailing)) {
                /* not in the main layout */
@@ -1680,7 +1695,7 @@ AudioClock::on_scroll_event (GdkEventScroll *ev)
                                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);
@@ -1868,9 +1883,23 @@ bool
 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 (hours < 0) {
+               TC.hours = hours * -1;
+               TC.negative = true;
+       } else {
+               TC.hours = hours;
+               TC.negative = false;
+       }
 
-       if (sscanf (_layout->get_text().c_str(), "%" PRId32 ":%" PRId32 ":%" PRId32 ":%" PRId32,
-                   &TC.hours, &TC.minutes, &TC.seconds, &TC.frames) != 4) {
+       if (TC.negative && !_negative_allowed) {
                return false;
        }
 
@@ -1916,18 +1945,23 @@ AudioClock::frames_from_timecode_string (const string& str) const
 
        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.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;
 }
@@ -1979,7 +2013,7 @@ framepos_t
 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;
        }
 
@@ -2064,7 +2098,6 @@ AudioClock::set_mode (Mode m)
                int ignored;
                _left_layout->set_text (" 1234567890");
                _left_layout->get_pixel_size (ignored, info_height);
-               info_height += 4;
 
                _left_layout->set_text ("");
                _right_layout->set_text ("");
@@ -2072,7 +2105,7 @@ AudioClock::set_mode (Mode m)
 
        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);
@@ -2097,7 +2130,7 @@ AudioClock::set_mode (Mode m)
                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);
@@ -2110,7 +2143,7 @@ AudioClock::set_mode (Mode m)
                break;
 
        case Frames:
-               mode_based_info_ratio = 0.5;
+               mode_based_info_ratio = 0.45;
                break;
        }
 
@@ -2120,13 +2153,6 @@ AudioClock::set_mode (Mode m)
                 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) */
 }
 
@@ -2140,8 +2166,10 @@ void
 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 ();
 }
@@ -2194,12 +2222,6 @@ AudioClock::set_corner_radius (double r)
        queue_resize ();
 }
 
-void
-AudioClock::set_fixed_width (bool yn)
-{
-       _fixed_width = yn;
-}
-
 void
 AudioClock::dpi_reset ()
 {
@@ -2209,3 +2231,9 @@ AudioClock::dpi_reset ()
        first_height = 0;
        queue_resize ();
 }
+
+void
+AudioClock::set_negative_allowed (bool yn)
+{
+       _negative_allowed = yn;
+}