X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fshuttle_control.cc;h=88159fe0209b2b943121e3bcd3c37bb78525cca4;hb=04416e2d1df3cc8d9f014765e5ca5ce818b7b4d7;hp=3a0572cd69ec17fdd9043db2b1d1bf790213e930;hpb=7c7afd08b92151746dd25f275d28c0c00306a6be;p=ardour.git diff --git a/gtk2_ardour/shuttle_control.cc b/gtk2_ardour/shuttle_control.cc index 3a0572cd69..88159fe020 100644 --- a/gtk2_ardour/shuttle_control.cc +++ b/gtk2_ardour/shuttle_control.cc @@ -29,6 +29,7 @@ #include "gtkmm2ext/gui_thread.h" #include "ardour_ui.h" +#include "rgb_macros.h" #include "shuttle_control.h" #include "i18n.h" @@ -66,7 +67,7 @@ ShuttleControl::ShuttleControl () set_size_request (100, 15); set_name (X_("ShuttleControl")); - Config->ParameterChanged.connect (parameter_connection, MISSING_INVALIDATOR, ui_bind (&ShuttleControl::parameter_changed, this, _1), gui_context()); + Config->ParameterChanged.connect (parameter_connection, MISSING_INVALIDATOR, boost::bind (&ShuttleControl::parameter_changed, this, _1), gui_context()); /* gtkmm 2.4: the C++ wrapper doesn't work */ g_signal_connect ((GObject*) gobj(), "query-tooltip", G_CALLBACK (qt), NULL); @@ -100,11 +101,16 @@ ShuttleControl::on_size_allocate (Gtk::Allocation& alloc) } pattern = cairo_pattern_create_linear (0, 0, alloc.get_width(), alloc.get_height()); - + /* add 3 color stops */ + uint32_t col = ARDOUR_UI::config()->canvasvar_Shuttle.get(); + + int r,b,g,a; + UINT_TO_RGBA(col, &r, &g, &b, &a); + cairo_pattern_add_color_stop_rgb (pattern, 0.0, 0, 0, 0); - cairo_pattern_add_color_stop_rgb (pattern, 0.5, 0.0, 0.0, 1.0); + cairo_pattern_add_color_stop_rgb (pattern, 0.5, r/255.0, g/255.0, b/255.0); cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0, 0, 0); DrawingArea::on_size_allocate (alloc); @@ -144,7 +150,7 @@ ShuttleControl::build_shuttle_context_menu () Menu* units_menu = manage (new Menu); MenuList& units_items = units_menu->items(); RadioMenuItem::Group units_group; - + units_items.push_back (RadioMenuElem (units_group, _("Percent"), sigc::bind (sigc::mem_fun (*this, &ShuttleControl::set_shuttle_units), Percentage))); if (Config->get_shuttle_units() == Percentage) { static_cast(&units_items.back())->set_active(); @@ -154,7 +160,7 @@ ShuttleControl::build_shuttle_context_menu () static_cast(&units_items.back())->set_active(); } items.push_back (MenuElem (_("Units"), *units_menu)); - + Menu* style_menu = manage (new Menu); MenuList& style_items = style_menu->items(); RadioMenuItem::Group style_group; @@ -167,7 +173,7 @@ ShuttleControl::build_shuttle_context_menu () if (Config->get_shuttle_behaviour() == Wheel) { static_cast(&style_items.back())->set_active(); } - + items.push_back (MenuElem (_("Mode"), *style_menu)); RadioMenuItem::Group speed_group; @@ -198,7 +204,7 @@ ShuttleControl::build_shuttle_context_menu () } items.push_back (MenuElem (_("Maximum speed"), *speed_menu)); - + } void @@ -272,8 +278,8 @@ ShuttleControl::on_button_release_event (GdkEventButton* ev) case 2: if (_session->transport_rolling()) { - _session->request_transport_speed (1.0); - } + _session->request_transport_speed (1.0, Config->get_shuttle_behaviour() == Wheel); + } return true; case 3: @@ -298,20 +304,42 @@ ShuttleControl::on_scroll_event (GdkEventScroll* ev) return true; } + bool semis = (Config->get_shuttle_units() == Semitones); + switch (ev->direction) { case GDK_SCROLL_UP: case GDK_SCROLL_RIGHT: - shuttle_fract += 0.005; + if (semis) { + if (shuttle_fract == 0) { + shuttle_fract = semitones_as_fract (1, false); + } else { + bool rev; + int st = fract_as_semitones (shuttle_fract, rev); + shuttle_fract = semitones_as_fract (st + 1, rev); + } + } else { + shuttle_fract += 0.00125; + } break; case GDK_SCROLL_DOWN: case GDK_SCROLL_LEFT: - shuttle_fract -= 0.005; + if (semis) { + if (shuttle_fract == 0) { + shuttle_fract = semitones_as_fract (1, true); + } else { + bool rev; + int st = fract_as_semitones (shuttle_fract, rev); + shuttle_fract = semitones_as_fract (st - 1, rev); + } + } else { + shuttle_fract -= 0.00125; + } break; default: return false; } - - if (Config->get_shuttle_units() == Semitones) { + + if (semis) { float lower_side_of_dead_zone = semitones_as_fract (-24, true); float upper_side_of_dead_zone = semitones_as_fract (-24, false); @@ -365,7 +393,7 @@ ShuttleControl::mouse_shuttle (double x, bool force) } /* compute shuttle fract as expressing how far between the center - and the edge we are. positive values indicate we are right of + and the edge we are. positive values indicate we are right of center, negative values indicate left of center */ @@ -393,7 +421,7 @@ ShuttleControl::speed_as_semitones (float speed, bool& reverse) reverse = false; return (int) round (12.0 * fast_log2 (speed)); } -} +} float ShuttleControl::semitones_as_speed (int semi, bool reverse) @@ -451,17 +479,17 @@ ShuttleControl::use_shuttle_fract (bool force) speed = shuttle_max_speed * shuttle_fract; } - _session->request_transport_speed_nonzero (speed); + _session->request_transport_speed_nonzero (speed, true); } bool -ShuttleControl::on_expose_event (GdkEventExpose* event) +ShuttleControl::on_expose_event (GdkEventExpose*) { cairo_text_extents_t extents; Glib::RefPtr win (get_window()); Glib::RefPtr style (get_style()); - cairo_t* cr = gdk_cairo_create (win->gobj()); + cairo_t* cr = gdk_cairo_create (win->gobj()); cairo_set_source (cr, pattern); cairo_rectangle (cr, 0.0, 0.0, get_width(), get_height()); @@ -494,7 +522,7 @@ ShuttleControl::on_expose_event (GdkEventExpose* event) if (Config->get_shuttle_units() == Percentage) { if (speed == 1.0) { - snprintf (buf, sizeof (buf), _("Playing")); + snprintf (buf, sizeof (buf), "%s", _("Playing")); } else { if (speed < 0.0) { snprintf (buf, sizeof (buf), "<<< %d%%", (int) round (-speed * 100)); @@ -516,7 +544,7 @@ ShuttleControl::on_expose_event (GdkEventExpose* event) } } else { - snprintf (buf, sizeof (buf), _("Stopped")); + snprintf (buf, sizeof (buf), "%s", _("Stopped")); } last_speed_displayed = speed; @@ -531,10 +559,10 @@ ShuttleControl::on_expose_event (GdkEventExpose* event) switch (Config->get_shuttle_behaviour()) { case Sprung: - snprintf (buf, sizeof (buf), _("Sprung")); + snprintf (buf, sizeof (buf), "%s", _("Sprung")); break; case Wheel: - snprintf (buf, sizeof (buf), _("Wheel")); + snprintf (buf, sizeof (buf), "%s", _("Wheel")); break; } @@ -576,24 +604,18 @@ ShuttleControl::update_speed_display () queue_draw (); } } - + ShuttleControl::ShuttleControllable::ShuttleControllable (ShuttleControl& s) - : PBD::Controllable (X_("Shuttle")) + : PBD::Controllable (X_("Shuttle")) , sc (s) { } -void -ShuttleControl::ShuttleControllable::set_id (const std::string& str) -{ - _id = str; -} - void ShuttleControl::ShuttleControllable::set_value (double val) { double fract; - + if (val == 0.5) { fract = 0.0; } else { @@ -607,7 +629,7 @@ ShuttleControl::ShuttleControllable::set_value (double val) sc.set_shuttle_fract (fract); } -double +double ShuttleControl::ShuttleControllable::get_value () const { return sc.get_shuttle_fract (); @@ -626,6 +648,9 @@ ShuttleControl::parameter_changed (std::string p) if (_session->transport_speed() == 1.0) { queue_draw (); } else { + /* reset current speed and + revert to 1.0 as the default + */ _session->request_transport_speed (1.0); /* redraw when speed changes */ } @@ -639,7 +664,7 @@ ShuttleControl::parameter_changed (std::string p) queue_draw (); break; } - + } else if (p == "shuttle-units") { queue_draw (); }