enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / audio_clock.cc
index 8de39d58f1d5100ffe4c52ebd21c25e6a51f1470..16b4151a81840a380c46cf45404ecafcfef46db6 100644 (file)
@@ -42,7 +42,7 @@
 #include "keyboard.h"
 #include "gui_thread.h"
 #include "ui_config.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace ARDOUR_UI_UTILS;
@@ -151,7 +151,7 @@ AudioClock::on_realize ()
        Gtk::Requisition req;
 
        CairoWidget::on_realize ();
-       
+
        set_clock_dimensions (req);
 
        first_width = req.width;
@@ -197,7 +197,6 @@ AudioClock::set_font (Pango::FontDescription 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);
@@ -313,11 +312,7 @@ AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
        double lw = layout_width * xscale;
        double lh = layout_height * yscale;
 
-       if (lw >= get_width()) {
-               cairo_move_to (cr, 0.0, (upper_height - lh) / 2.0);
-       } else {
-               cairo_move_to (cr, (get_width() - lw) / 2.0, (upper_height - lh) / 2.0);
-       }
+       cairo_move_to (cr, (get_width() - lw) / 2.0, (upper_height - lh) / 2.0);
 
        if (xscale != 1.0 || yscale != 1.0) {
                cairo_save (cr);
@@ -406,44 +401,42 @@ AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
        }
 
        if (editing) {
-               Pango::Rectangle cursor;
-
                if (!insert_map.empty()) {
 
+                       int xcenter = (get_width() - layout_width) /2;
+
                        if (input_string.length() < insert_map.size()) {
+                               Pango::Rectangle cursor;
 
-                               cursor = _layout->get_cursor_strong_pos (edit_string.length() - 1);
+                               if (input_string.empty()) {
+                                       /* nothing entered yet, put cursor at the end
+                                          of string
+                                       */
+                                       cursor = _layout->get_cursor_strong_pos (edit_string.length() - 1);
+                               } else {
+                                       cursor = _layout->get_cursor_strong_pos (insert_map[input_string.length()]);
+                               }
 
                                cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
-
                                cairo_rectangle (cr,
-                                                cursor.get_x()/PANGO_SCALE,
-                                                (upper_height - layout_height)/2.0,
-                                                em_width,
-                                                cursor.get_height()/PANGO_SCALE);
-                               cairo_stroke (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 {
-                       cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
-
-                       if (edit_string.empty()) {
-                               cairo_rectangle (cr,
-                                                get_width() - em_width,
-                                                (upper_height - layout_height)/2.0,
-                                                em_width, upper_height);
-                       } else {
-                               cursor = _layout->get_cursor_strong_pos (edit_string.length() - 1);
+                       if (input_string.empty()) {
+                               cairo_set_source_rgba (cr, cursor_r, cursor_g, cursor_b, cursor_a);
                                cairo_rectangle (cr,
-                                                cursor.get_x()/PANGO_SCALE,
-                                                (upper_height - layout_height)/2.0,
-                                                em_width, upper_height);
+                                                (get_width()/2.0),
+                                                (upper_height - layout_height)/2.0,
+                                                2.0, upper_height);
+                               cairo_fill (cr);
                        }
-                               
-                       cairo_stroke (cr);
                }
        }
 }
@@ -484,19 +477,8 @@ AudioClock::set_clock_dimensions (Gtk::Requisition& req)
                tmp->set_text (" 88:88:88,88 ");
        tmp->get_pixel_size (req.width, req.height);
 
-
        layout_height = req.height;
        layout_width = req.width;
-
-       /* get the figure width for the font. This doesn't have to super
-        * accurate since we only use it to measure the (roughly 1 character)
-        * offset from the position Pango tells us for the "cursor"
-        */
-
-       int ignore_height;
-
-       tmp->set_text ("8");
-       tmp->get_pixel_size (em_width, ignore_height);
 }
 
 void
@@ -525,15 +507,15 @@ AudioClock::on_size_request (Gtk::Requisition* req)
                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 (INFO_FONT_SIZE);
@@ -579,17 +561,17 @@ AudioClock::start_edit (Field f)
                        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 ();
 
                Keyboard::magic_widget_grab_focus ();
@@ -941,6 +923,12 @@ AudioClock::session_property_changed (const PropertyChange&)
        set (last_when, true);
 }
 
+void
+AudioClock::metric_position_changed ()
+{
+       set (last_when, true);
+}
+
 void
 AudioClock::session_configuration_changed (std::string p)
 {
@@ -1270,12 +1258,12 @@ AudioClock::set_bbt (framepos_t when, bool /*force*/)
                        BBT.beats = 0;
                        BBT.ticks = 0;
                } else {
-                       _session->tempo_map().bbt_time (when, BBT);
+                       BBT = _session->tempo_map().bbt_at_frame (when);
                        BBT.bars--;
                        BBT.beats--;
                }
        } else {
-               _session->tempo_map().bbt_time (when, BBT);
+               BBT = _session->tempo_map().bbt_at_frame (when);
        }
 
        if (negative) {
@@ -1299,7 +1287,7 @@ AudioClock::set_bbt (framepos_t when, bool /*force*/)
 
                TempoMetric m (_session->tempo_map().metric_at (pos));
 
-               sprintf (buf, "%-5.1f", m.tempo().beats_per_minute());
+               sprintf (buf, "%-5.3f", _session->tempo_map().tempo_at_frame (pos).beats_per_minute());
                _left_layout->set_markup (string_compose ("<span size=\"%1\">" TXTSPAN "%3</span> <span foreground=\"green\">%2</span></span>",
                                                          INFO_FONT_SIZE, buf, _("Tempo")));
 
@@ -1318,8 +1306,9 @@ AudioClock::set_session (Session *s)
 
                _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_configuration_changed, this, _1), gui_context());
                _session->tempo_map().PropertyChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_property_changed, this, _1), gui_context());
+               _session->tempo_map().MetricPositionChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::metric_position_changed, this), gui_context());
 
-               const XMLProperty* prop;
+               XMLProperty const * prop;
                XMLNode* node = _session->extra_xml (X_("ClockModes"));
                AudioClock::Mode amode;
 
@@ -1329,7 +1318,7 @@ AudioClock::set_session (Session *s)
 
                                        if ((prop = (*i)->property (X_("mode"))) != 0) {
                                                amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
-                                               set_mode (amode);
+                                               set_mode (amode, true);
                                        }
                                        if ((prop = (*i)->property (X_("on"))) != 0) {
                                                set_off (!string_is_affirmative (prop->value()));
@@ -2130,16 +2119,14 @@ AudioClock::build_ops_menu ()
        MenuList& ops_items = ops_menu->items();
        ops_menu->set_name ("ArdourContextMenu");
 
-       if (!Profile->get_sae()) {
-               ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode)));
-       }
-       ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT)));
-       ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec)));
-       ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames)));
+       ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode, false)));
+       ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT, false)));
+       ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec, false)));
+       ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames, false)));
 
        if (editable && !_off && !is_duration && !_follows_playhead) {
                ops_items.push_back (SeparatorElem());
-               ops_items.push_back (MenuElem (_("Set From Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
+               ops_items.push_back (MenuElem (_("Set from Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
                ops_items.push_back (MenuElem (_("Locate to This Time"), sigc::mem_fun(*this, &AudioClock::locate)));
        }
        ops_items.push_back (SeparatorElem());
@@ -2168,7 +2155,7 @@ AudioClock::locate ()
 }
 
 void
-AudioClock::set_mode (Mode m)
+AudioClock::set_mode (Mode m, bool noemit)
 {
        if (_mode == m) {
                return;
@@ -2242,11 +2229,11 @@ AudioClock::set_mode (Mode m)
 
        set (last_when, true);
 
-        if (!is_transient) {
-                ModeChanged (); /* EMIT SIGNAL (the static one)*/
-        }
+       if (!is_transient && !noemit) {
+               ModeChanged (); /* EMIT SIGNAL (the static one)*/
+       }
 
-        mode_changed (); /* EMIT SIGNAL (the member one) */
+       mode_changed (); /* EMIT SIGNAL (the member one) */
 }
 
 void