X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fardour_knob.cc;h=8cea0f4a4d3a4dc5eb81cf83b8b0c2efa4a072bd;hb=eeb20bc392c1aae0545010c6fcf2c7096bb9c650;hp=bfc3c88057ed5ab90e0f21a2d7ebc9b9d7bd7119;hpb=9a4f205b6ef6fec779833ea56a3202c058317ddd;p=ardour.git diff --git a/gtk2_ardour/ardour_knob.cc b/gtk2_ardour/ardour_knob.cc index bfc3c88057..8cea0f4a4d 100644 --- a/gtk2_ardour/ardour_knob.cc +++ b/gtk2_ardour/ardour_knob.cc @@ -24,6 +24,7 @@ #include #include "pbd/compose.h" +#include "pbd/controllable.h" #include "pbd/error.h" #include "pbd/stacktrace.h" @@ -35,8 +36,8 @@ #include "ardour/rc_configuration.h" // for widget prelight preference #include "ardour_knob.h" -#include "ardour_ui.h" -#include "global_signals.h" +#include "timers.h" +#include "ui_config.h" #include "canvas/colors.h" #include "canvas/utils.h" @@ -65,7 +66,10 @@ ArdourKnob::ArdourKnob (Element e, Flags flags) , _flags (flags) , _tooltip (this) { - ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ArdourKnob::color_handler)); + UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourKnob::color_handler)); + + // watch automation :( + Timers::rapid_connect (sigc::mem_fun (*this, &ArdourKnob::controllable_changed)); } ArdourKnob::~ArdourKnob() @@ -76,13 +80,13 @@ void ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) { cairo_pattern_t* shade_pattern; - + float width = get_width(); float height = get_height(); - + const float scale = min(width, height); const float pointer_thickness = 3.0 * (scale/80); //(if the knob is 80 pixels wide, we want a 3-pix line on it) - + const float start_angle = ((180 - 65) * G_PI) / 180; const float end_angle = ((360 + 65) * G_PI) / 180; @@ -93,25 +97,25 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) const float value_angle = start_angle + (_val * (end_angle - start_angle)); const float zero_angle = start_angle + (zero * (end_angle - start_angle)); - + float value_x = cos (value_angle); float value_y = sin (value_angle); float xc = 0.5 + width/ 2.0; float yc = 0.5 + height/ 2.0; - + cairo_translate (cr, xc, yc); //after this, everything is based on the center of the knob //get the knob color from the theme - ArdourCanvas::Color knob_color = ARDOUR_UI::config()->color (string_compose ("%1", get_name())); + ArdourCanvas::Color knob_color = UIConfiguration::instance().color (string_compose ("%1", get_name())); float center_radius = 0.48*scale; float border_width = 0.8; - + bool arc = (_elements & Arc)==Arc; bool bevel = (_elements & Bevel)==Bevel; bool flat = _flat_buttons; - + if ( arc ) { center_radius = scale*0.33; @@ -119,7 +123,7 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) float outer_progress_radius = scale*0.48; float progress_width = (outer_progress_radius-inner_progress_radius); float progress_radius = inner_progress_radius + progress_width/2.0; - + //dark arc background cairo_set_source_rgb (cr, 0.3, 0.3, 0.3 ); cairo_set_line_width (cr, progress_width); @@ -128,10 +132,10 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) //look up the arc colors from the config double red_start, green_start, blue_start, unused; - ArdourCanvas::Color arc_start_color = ARDOUR_UI::config()->color ( string_compose ("%1: arc start", get_name())); + ArdourCanvas::Color arc_start_color = UIConfiguration::instance().color ( string_compose ("%1: arc start", get_name())); ArdourCanvas::color_to_rgba( arc_start_color, red_start, green_start, blue_start, unused ); double red_end, green_end, blue_end; - ArdourCanvas::Color arc_end_color = ARDOUR_UI::config()->color ( string_compose ("%1: arc end", get_name()) ); + ArdourCanvas::Color arc_end_color = UIConfiguration::instance().color ( string_compose ("%1: arc end", get_name()) ); ArdourCanvas::color_to_rgba( arc_end_color, red_end, green_end, blue_end, unused ); //vary the arc color over the travel of the knob @@ -181,7 +185,7 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) cairo_stroke (cr); #endif } - + if (!flat) { //knob shadow cairo_save(cr); @@ -195,8 +199,8 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) ArdourCanvas::set_source_rgba(cr, knob_color); cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); cairo_fill (cr); - - //gradient + + //gradient if (bevel) { //knob gradient shade_pattern = cairo_pattern_create_linear (0.0, -yc, 0.0, yc); //note we have to offset the gradient from our centerpoint @@ -213,7 +217,7 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) ArdourCanvas::set_source_rgb_a (cr, knob_color, 0.5 ); cairo_arc (cr, 0, 0, center_radius-pointer_thickness, 0, 2.0*G_PI); cairo_fill (cr); - } else { + } else { //radial gradient shade_pattern = cairo_pattern_create_radial ( -center_radius, -center_radius, 1, -center_radius, -center_radius, center_radius*2.5 ); //note we have to offset the gradient from our centerpoint cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.2); @@ -223,21 +227,21 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) cairo_fill (cr); cairo_pattern_destroy (shade_pattern); } - + } else { //inner circle ArdourCanvas::set_source_rgba(cr, knob_color); cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); cairo_fill (cr); } - + //black knob border cairo_set_line_width (cr, border_width); cairo_set_source_rgba (cr, 0,0,0, 1 ); cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); cairo_stroke (cr); - + //line shadow if (!flat) { cairo_save(cr); @@ -250,7 +254,7 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) cairo_stroke (cr); cairo_restore(cr); } - + //line cairo_set_source_rgba (cr, 1,1,1, 1 ); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); @@ -260,13 +264,13 @@ ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) cairo_stroke (cr); //highlight if grabbed or if mouse is hovering over me - if (_tooltip.dragging() || (_hovering && ARDOUR_UI::config()->get_widget_prelight() ) ) { + if (_tooltip.dragging() || (_hovering && UIConfiguration::instance().get_widget_prelight() ) ) { cairo_set_source_rgba (cr, 1,1,1, 0.12 ); cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); cairo_fill (cr); } - - cairo_identity_matrix(cr); + + cairo_identity_matrix(cr); } void @@ -301,11 +305,11 @@ ArdourKnob::on_scroll_event (GdkEventScroll* ev) boost::shared_ptr c = binding_proxy.get_controllable(); if (c) { float val = c->get_interface(); - + if ( ev->direction == GDK_SCROLL_UP ) val += scale; else - val -= scale; + val -= scale; c->set_interface(val); } @@ -327,7 +331,7 @@ ArdourKnob::on_motion_notify_event (GdkEventMotion *ev) //scale the adjustment based on keyboard modifiers & GUI size - const float ui_scale = max (1.f, ARDOUR_UI::ui_scale); + const float ui_scale = max (1.f, UIConfiguration::instance().get_ui_scale()); float scale = 0.0025 / ui_scale; if (ev->state & Keyboard::GainFineScaleModifier) { @@ -361,15 +365,14 @@ ArdourKnob::on_motion_notify_event (GdkEventMotion *ev) delta = tozero + remain; _dead_zone_delta = 0; } else { - c->set_value (c->normal()); - val = _normal; + c->set_value (c->normal(), Controllable::NoGroup); _dead_zone_delta = remain / px_deadzone; return true; } } if (fabsf (rintf((val - _normal) / scale) + _dead_zone_delta) < 1) { - c->set_value (c->normal()); + c->set_value (c->normal(), Controllable::NoGroup); _dead_zone_delta += delta / px_deadzone; return true; } @@ -405,7 +408,7 @@ ArdourKnob::on_button_press_event (GdkEventButton *ev) if (ev->button != 1 && ev->button != 2) { return false; } - + set_active_state (Gtkmm2ext::ExplicitActive); _tooltip.start_drag(); add_modal_grab(); @@ -427,7 +430,7 @@ ArdourKnob::on_button_release_event (GdkEventButton *ev) if ( (_grabbed_y == ev->y && _grabbed_x == ev->x) && Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) { //no move, shift-click sets to default boost::shared_ptr c = binding_proxy.get_controllable(); if (!c) return false; - c->set_value (c->normal()); + c->set_value (c->normal(), Controllable::NoGroup); return true; } @@ -451,7 +454,7 @@ ArdourKnob::on_size_allocate (Allocation& alloc) void ArdourKnob::set_controllable (boost::shared_ptr c) { - watch_connection.disconnect (); //stop watching the old controllable + watch_connection.disconnect (); //stop watching the old controllable if (!c) return; @@ -468,10 +471,16 @@ void ArdourKnob::controllable_changed () { boost::shared_ptr c = binding_proxy.get_controllable(); + if (!c) return; + + float val = c->get_interface(); + val = min( max(0.0f, val), 1.0f); // clamp - _val = c->get_interface(); //% of knob travel - _val = min( max(0.0f, _val), 1.0f); //range check + if (val == _val) { + return; + } + _val = val; if (!_tooltip_prefix.empty()) { _tooltip.set_tip (_tooltip_prefix + c->get_user_string()); } @@ -497,14 +506,14 @@ ArdourKnob::set_active_state (Gtkmm2ext::ActiveState s) if (_active_state != s) CairoWidget::set_active_state (s); } - + void ArdourKnob::set_visual_state (Gtkmm2ext::VisualState s) { if (_visual_state != s) CairoWidget::set_visual_state (s); } - + bool ArdourKnob::on_focus_in_event (GdkEventFocus* ev) @@ -554,7 +563,7 @@ ArdourKnob::add_elements (Element e) KnobPersistentTooltip::KnobPersistentTooltip (Gtk::Widget* w) - : PersistentTooltip (w, 3) + : PersistentTooltip (w, true, 3) , _dragging (false) { }