Fix playhead smoothing when auditioning.
[ardour.git] / gtk2_ardour / shuttle_control.cc
index 70293cd20ed9feab9d7eaba269bb43778c45dda5..c18bacc20f3f474960dc99b72fe41ba2cc00dfa1 100644 (file)
 #include "ardour/rc_configuration.h"
 #include "ardour/session.h"
 
+#include "gtkmm2ext/colors.h"
 #include "gtkmm2ext/keyboard.h"
 #include "gtkmm2ext/gui_thread.h"
-#include "gtkmm2ext/cairocell.h"
 #include "gtkmm2ext/utils.h"
 #include "gtkmm2ext/rgb_macros.h"
 
+#include "widgets/tooltips.h"
+
 #include "actions.h"
 #include "rgb_macros.h"
 #include "shuttle_control.h"
-#include "tooltips.h"
 
 #include "pbd/i18n.h"
 
 using namespace Gtk;
 using namespace Gtkmm2ext;
 using namespace ARDOUR;
-using namespace ARDOUR_UI_UTILS;
+using namespace ArdourWidgets;
 using std::min;
 using std::max;
 
@@ -55,16 +56,13 @@ gboolean qt (gboolean, gint, gint, gboolean, Gtk::Tooltip*, gpointer)
 ShuttleControl::ShuttleControl ()
        : _controllable (new ShuttleControllable (*this))
        , binding_proxy (_controllable)
-       , text_color (0)
 {
-
-       Pango::AttrFontDesc* font_attr;
-       font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (UIConfiguration::instance().get_NormalFont()));
-       text_attributes.change (*font_attr);
-       delete font_attr;
-
-       _text = Pango::Layout::create (get_pango_context());
-       _text->set_attributes (text_attributes);
+       _info_button.set_layout_font (UIConfiguration::instance().get_NormalFont());
+       _info_button.set_sizing_text (S_("LogestShuttle|< +00 st"));
+       _info_button.set_name ("shuttle text");
+       _info_button.set_sensitive (false);
+       _info_button.set_visual_state (Gtkmm2ext::NoVisualState);
+       _info_button.set_elements (ArdourButton::Text);
 
        set_tooltip (*this, _("Shuttle speed control (Context-click for options)"));
 
@@ -85,13 +83,7 @@ ShuttleControl::ShuttleControl ()
        add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::POINTER_MOTION_MASK|Gdk::SCROLL_MASK);
        set_name (X_("ShuttleControl"));
 
-       int tw, th, h;
        ensure_style ();
-       _text->set_text ("@Sp");
-       _text->get_pixel_size (tw, th);
-       h = (int) ceil(th * BASELINESTRETCH + 1.0);
-       if ((h - th) & 1) { ++h; }
-       set_size_request (85, h);
 
        shuttle_max_speed = Config->get_shuttle_max_speed();
 
@@ -116,7 +108,6 @@ ShuttleControl::~ShuttleControl ()
 {
        cairo_pattern_destroy (pattern);
        cairo_pattern_destroy (shine_pattern);
-       delete text_color;
 }
 
 void
@@ -163,7 +154,7 @@ ShuttleControl::on_size_allocate (Gtk::Allocation& alloc)
 void
 ShuttleControl::map_transport_state ()
 {
-       float speed = _session->transport_speed ();
+       float speed = _session->actual_speed ();
 
        if ( (fabsf( speed - last_speed_displayed) < 0.005f) // dead-zone
             && !( speed == 1.f && last_speed_displayed != 1.f)
@@ -262,16 +253,6 @@ ShuttleControl::build_shuttle_context_menu ()
        items.push_back (MenuElem (_("Reset to 100%"), sigc::mem_fun (*this, &ShuttleControl::reset_speed)));
 }
 
-void
-ShuttleControl::show_shuttle_context_menu ()
-{
-       if (shuttle_context_menu == 0) {
-               build_shuttle_context_menu ();
-       }
-
-       shuttle_context_menu->popup (1, gtk_get_current_event_time());
-}
-
 void
 ShuttleControl::reset_speed ()
 {
@@ -302,7 +283,10 @@ ShuttleControl::on_button_press_event (GdkEventButton* ev)
        }
 
        if (Keyboard::is_context_menu_event (ev)) {
-               show_shuttle_context_menu ();
+               if (shuttle_context_menu == 0) {
+                       build_shuttle_context_menu ();
+               }
+               shuttle_context_menu->popup (ev->button, ev->time);
                return true;
        }
 
@@ -315,7 +299,7 @@ ShuttleControl::on_button_press_event (GdkEventButton* ev)
                } else {
                        add_modal_grab ();
                        shuttle_grabbed = true;
-                       shuttle_speed_on_grab = _session->transport_speed ();
+                       shuttle_speed_on_grab = _session->actual_speed ();
                        requested_speed = shuttle_speed_on_grab;
                        mouse_shuttle (ev->x, true);
                        gdk_pointer_grab(ev->window,false,
@@ -576,29 +560,17 @@ ShuttleControl::set_colors ()
        int r, g, b, a;
 
        uint32_t bg_color = UIConfiguration::instance().color (X_("shuttle bg"));
-       uint32_t text = UIConfiguration::instance().color (X_("shuttle text"));
 
        UINT_TO_RGBA (bg_color, &r, &g, &b, &a);
        bg_r = r/255.0;
        bg_g = g/255.0;
        bg_b = b/255.0;
-
-       UINT_TO_RGBA (text, &r, &g, &b, &a);
-
-       /* rescale for Pango colors ... sigh */
-
-       r = lrint (r * 65535.0);
-       g = lrint (g * 65535.0);
-       b = lrint (b * 65535.0);
-
-       delete text_color;
-       text_color = new Pango::AttrColor (Pango::Attribute::create_attr_foreground (r, g, b));
-       text_attributes.change (*text_color);
 }
 
 void
-ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
+ShuttleControl::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
 {
+       cairo_t* cr = ctx->cobj();
        // center slider line
        float yc = get_height() / 2;
        float lw = 3;
@@ -607,6 +579,10 @@ ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
        cairo_move_to (cr, lw, yc);
        cairo_line_to (cr, get_width () - lw, yc);
        cairo_set_source_rgb (cr, bg_r, bg_g, bg_b);
+       if (UIConfiguration::instance().get_widget_prelight() && _hovering) {
+               cairo_stroke_preserve (cr);
+               cairo_set_source_rgba (cr, 1, 1, 1, 0.15);
+       }
        cairo_stroke (cr);
 
        float speed = 0.0;
@@ -614,7 +590,7 @@ ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
        char buf[32];
 
        if (_session) {
-               speed = _session->transport_speed ();
+               speed = _session->actual_speed ();
                acutal_speed = speed;
                if (shuttle_grabbed) {
                        speed = requested_speed;
@@ -631,14 +607,23 @@ ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
        cairo_set_source_rgba (cr, 0, 0, 0, 1);
        cairo_fill(cr);
        rounded_rectangle (cr, x + 1, 1, marker_size - 2, get_height() - 2, 3.5);
-       cairo_set_source (cr, pattern);
+       if (_flat_buttons) {
+               uint32_t col = UIConfiguration::instance().color ("shuttle");
+               Gtkmm2ext::set_source_rgba (cr, col);
+       } else {
+               cairo_set_source (cr, pattern);
+       }
+       if (UIConfiguration::instance().get_widget_prelight() && _hovering) {
+               cairo_fill_preserve (cr);
+               cairo_set_source_rgba (cr, 1, 1, 1, 0.15);
+       }
        cairo_fill(cr);
 
        /* text */
        if (acutal_speed != 0) {
                if (Config->get_shuttle_units() == Percentage) {
                        if (acutal_speed == 1.0) {
-                               snprintf (buf, sizeof (buf), "%s", _("Playing"));
+                               snprintf (buf, sizeof (buf), "%s", _("Play"));
                        } else {
                                if (acutal_speed < 0.0) {
                                        snprintf (buf, sizeof (buf), "< %.1f%%", -acutal_speed * 100.f);
@@ -650,23 +635,20 @@ ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
                        bool reversed;
                        int semi = speed_as_semitones (acutal_speed, reversed);
                        if (reversed) {
-                               snprintf (buf, sizeof (buf), _("< %+2d semi"), semi);
+                               snprintf (buf, sizeof (buf), _("< %+2d st"), semi);
                        } else {
-                               snprintf (buf, sizeof (buf), _("> %+2d semi"), semi);
+                               snprintf (buf, sizeof (buf), _("> %+2d st"), semi);
                        }
                }
        } else {
-               snprintf (buf, sizeof (buf), "%s", _("Stopped"));
+               snprintf (buf, sizeof (buf), "%s", _("Stop"));
        }
 
        last_speed_displayed = acutal_speed;
 
-       int tw, th;
-       _text->set_text (buf);
-       _text->get_pixel_size (tw, th);
-       cairo_move_to (cr, 0.5 * (get_width() - tw), 0.5 * (get_height() - th));
-       pango_cairo_show_layout (cr, _text->gobj());
+       _info_button.set_text (buf);
 
+#if 0
        if (UIConfiguration::instance().get_widget_prelight()) {
                if (_hovering) {
                        rounded_rectangle (cr, 0, 0, get_width(), get_height(), 3.5);
@@ -674,15 +656,7 @@ ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
                        cairo_fill (cr);
                }
        }
-}
-
-void
-ShuttleControl::shuttle_unit_clicked ()
-{
-       if (shuttle_unit_menu == 0) {
-               shuttle_unit_menu = dynamic_cast<Menu*> (ActionManager::get_widget ("/ShuttleUnitPopup"));
-       }
-       shuttle_unit_menu->popup (1, gtk_get_current_event_time());
+#endif
 }
 
 void
@@ -725,7 +699,7 @@ ShuttleControl::parameter_changed (std::string p)
                         */
                        if (_session) {
                                if (_session->transport_rolling()) {
-                                       if (_session->transport_speed() == 1.0) {
+                                       if (_session->actual_speed() == 1.0) {
                                                queue_draw ();
                                        } else {
                                                /* reset current speed and