#include <pangomm/layout.h>
#include "pbd/compose.h"
+#include "pbd/controllable.h"
#include "pbd/error.h"
#include "pbd/stacktrace.h"
#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"
, _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()
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;
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;
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);
//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
cairo_stroke (cr);
#endif
}
-
+
if (!flat) {
//knob shadow
cairo_save(cr);
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
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);
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);
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);
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
boost::shared_ptr<PBD::Controllable> 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);
}
//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) {
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;
}
if (ev->button != 1 && ev->button != 2) {
return false;
}
-
+
set_active_state (Gtkmm2ext::ExplicitActive);
_tooltip.start_drag();
add_modal_grab();
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<PBD::Controllable> c = binding_proxy.get_controllable();
if (!c) return false;
- c->set_value (c->normal());
+ c->set_value (c->normal(), Controllable::NoGroup);
return true;
}
void
ArdourKnob::set_controllable (boost::shared_ptr<Controllable> c)
{
- watch_connection.disconnect (); //stop watching the old controllable
+ watch_connection.disconnect (); //stop watching the old controllable
if (!c) return;
ArdourKnob::controllable_changed ()
{
boost::shared_ptr<PBD::Controllable> 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());
}
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)
KnobPersistentTooltip::KnobPersistentTooltip (Gtk::Widget* w)
- : PersistentTooltip (w, 3)
+ : PersistentTooltip (w, true, 3)
, _dragging (false)
{
}