add back definition of 2ndary clock delta text color
[ardour.git] / gtk2_ardour / audio_clock.cc
index 2aa68e02edefd9a5664def00fc617eb817b87cdd..2dfdf77272e3bf254cc3b2dc7ffd53f28340c894 100644 (file)
@@ -283,7 +283,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);
                        }
@@ -296,7 +296,7 @@ AudioClock::render (cairo_t* cr)
        if (!_fixed_width) {
                cairo_move_to (cr, layout_x_offset, 0);
        } else {
-               int xcenter = layout_x_offset > corner_radius/4.0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+               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);
        }
 
@@ -318,7 +318,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);
                                }
@@ -332,8 +332,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);
@@ -352,7 +352,7 @@ 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 - corner_radius/2.0;
+                               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;
@@ -380,7 +380,7 @@ AudioClock::render (cairo_t* cr)
        if (editing) {
                if (!insert_map.empty()) {
 
-                       int xcenter = layout_x_offset > corner_radius/4.0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+                       int xcenter = layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
 
                        if (input_string.length() < insert_map.size()) {
                                Pango::Rectangle cursor;
@@ -915,7 +915,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);
@@ -929,9 +929,20 @@ AudioClock::end_edit_relative (bool add)
        drop_focus ();
 }
 
+void
+AudioClock::session_property_changed (const PropertyChange& p)
+{
+       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;
@@ -1113,12 +1124,12 @@ AudioClock::set_frames (framepos_t when, bool /*force*/)
                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\"><span foreground=\"white\">%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\"><span foreground=\"white\">%2 </span><span foreground=\"green\">%3</span></span>",
+                                       INFO_FONT_SIZE, _("Pull"), buf));
                }
        }
 }
@@ -1261,11 +1272,11 @@ 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>",
+               _left_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">Tempo <span foreground=\"green\">%2</span></span>",
                                        INFO_FONT_SIZE, buf));
 
                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>",
+               _right_layout->set_markup (string_compose ("<span size=\"%1\" foreground=\"white\">Meter <span foreground=\"green\">%2</span></span>",
                                        INFO_FONT_SIZE, buf));
        }
 }
@@ -1278,6 +1289,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"));
@@ -1361,6 +1373,9 @@ AudioClock::on_key_press_event (GdkEventKey* ev)
        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);
                }
@@ -1428,6 +1443,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.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 ();
@@ -1561,7 +1586,7 @@ AudioClock::on_button_press_event (GdkEventButton *ev)
                        /* the text has been centered vertically, so adjust
                         * x and y.
                         */
-                       int xcenter = !_fixed_width || layout_x_offset > corner_radius/4.0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+                       int xcenter = !_fixed_width || layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
 
                        y = ev->y - ((upper_height - layout_height)/2);
                        x = ev->x - layout_x_offset - xcenter;
@@ -1606,7 +1631,7 @@ AudioClock::on_button_release_event (GdkEventButton *ev)
 
                                        if (_edit_by_click_field) {
 
-                                               int xcenter = !_fixed_width || layout_x_offset > corner_radius/4.0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+                                               int xcenter = !_fixed_width || layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
                                                int index = 0;
                                                int trailing;
                                                int y = ev->y - ((upper_height - layout_height)/2);
@@ -1677,7 +1702,7 @@ AudioClock::on_scroll_event (GdkEventScroll *ev)
         * x and y.
         */
 
-       int xcenter = !_fixed_width || layout_x_offset > corner_radius/4.0 ? 0 : (get_width() - _mode_width[_mode]) /2;
+       int xcenter = !_fixed_width || layout_x_offset > 0 ? 0 : (get_width() - _mode_width[_mode]) /2;
        y = ev->y - ((upper_height - layout_height)/2);
        x = ev->x - layout_x_offset - xcenter;
 
@@ -1709,7 +1734,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);
@@ -1897,9 +1922,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,
-                   &TC.hours, &TC.minutes, &TC.seconds, &TC.frames) != 4) {
+       if (sscanf (_layout->get_text().c_str(), "%" PRId32 ":%" PRId32 ":%" PRId32 "%[:;]%" PRId32,
+                   &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 5) {
+               return false;
+       }
+
+       if (hours < 0) {
+               TC.hours = hours * -1;
+               TC.negative = true;
+       } else {
+               TC.hours = hours;
+               TC.negative = false;
+       }
+
+       if (TC.negative && !_negative_allowed) {
                return false;
        }
 
@@ -1945,19 +1984,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", &hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 5) {
                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;
 }