#include "gtkmm2ext/gtk_ui.h"
#include "gtkmm2ext/keyboard.h"
+#include "ardour/pannable.h"
#include "ardour/panner.h"
#include "ardour_ui.h"
StereoPanner::ColorScheme StereoPanner::colors[3];
bool StereoPanner::have_colors = false;
-PBD::Signal0<void> StereoPanner::color_change;
-StereoPanner::StereoPanner (boost::shared_ptr<PBD::Controllable> position, boost::shared_ptr<PBD::Controllable> width)
- : position_control (position)
- , width_control (width)
+using namespace ARDOUR;
+
+StereoPanner::StereoPanner (boost::shared_ptr<Panner> panner)
+ : _panner (panner)
+ , position_control (_panner->pannable()->pan_azimuth_control)
+ , width_control (_panner->pannable()->pan_width_control)
, dragging (false)
, dragging_position (false)
, dragging_left (false)
, drag_start_x (0)
, last_drag_x (0)
, accumulated_delta (0)
+ , detented (false)
, drag_data_window (0)
, drag_data_label (0)
+ , position_binder (position_control)
+ , width_binder (width_control)
{
if (!have_colors) {
set_colors ();
position_control->Changed.connect (connections, invalidator(*this), boost::bind (&StereoPanner::value_change, this), gui_context());
width_control->Changed.connect (connections, invalidator(*this), boost::bind (&StereoPanner::value_change, this), gui_context());
- set_tooltip ();
set_flags (Gtk::CAN_FOCUS);
add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|
Gdk::SCROLL_MASK|
Gdk::POINTER_MOTION_MASK);
- color_change.connect (connections, invalidator (*this), boost::bind (&DrawingArea::queue_draw, this), gui_context());
+ ColorsChanged.connect (sigc::mem_fun (*this, &StereoPanner::color_handler));
}
StereoPanner::~StereoPanner ()
delete drag_data_window;
}
-void
-StereoPanner::set_tooltip ()
-{
- Gtkmm2ext::UI::instance()->set_tip (this,
- string_compose (_("0 -> set width to zero (mono)\n%1-uparrow -> set width to 100\n%1-downarrow -> set width to -100"),
-
- Keyboard::secondary_modifier_name()).c_str());
-}
-
-void
-StereoPanner::unset_tooltip ()
-{
- Gtkmm2ext::UI::instance()->set_tip (this, "");
-}
-
void
StereoPanner::set_drag_data ()
{
dragging_position = false;
dragging_left = false;
dragging_right = false;
+ dragging = false;
accumulated_delta = 0;
+ detented = false;
+
+ /* Let the binding proxies get first crack at the press event
+ */
if (ev->y < 20) {
- /* top section of widget is for position drags */
- dragging_position = true;
+ if (position_binder.button_press_handler (ev)) {
+ return true;
+ }
} else {
- /* lower section is for dragging width */
-
- double pos = position_control->get_value (); /* 0..1 */
- double swidth = width_control->get_value (); /* -1..+1 */
- double fswidth = fabs (swidth);
- int usable_width = get_width() - lr_box_size;
- double center = (lr_box_size/2.0) + (usable_width * pos);
- int left = lrint (center - (fswidth * usable_width / 2.0)); // center of leftmost box
- int right = lrint (center + (fswidth * usable_width / 2.0)); // center of rightmost box
- const int half_box = lr_box_size/2;
-
- if (ev->x >= (left - half_box) && ev->x < (left + half_box)) {
- dragging_left = true;
- } else if (ev->x >= (right - half_box) && ev->x < (right + half_box)) {
- dragging_right = true;
+ if (width_binder.button_press_handler (ev)) {
+ return true;
}
-
+ }
+
+ if (ev->button != 1) {
+ return false;
}
if (ev->type == GDK_2BUTTON_PRESS) {
- if (dragging_position) {
- int width = get_width();
- if (ev->x >= width/2 - 10 && ev->x <= width/2 + 10) {
- /* double click near center, reset position to center */
- position_control->set_value (0.5);
- } else {
- if (ev->x < width/2) {
- /* double click on left, collapse to hard left */
+ int width = get_width();
+
+ if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
+ /* handled by button release */
+ return true;
+ }
+
+ if (ev->y < 20) {
+
+ /* upper section: adjusts position, constrained by width */
+
+ const double w = width_control->get_value ();
+ const double max_pos = 1.0 - (w/2.0);
+ const double min_pos = w/2.0;
+
+ if (ev->x <= width/3) {
+ /* left side dbl click */
+ if (Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier)) {
+ /* 2ndary-double click on left, collapse to hard left */
width_control->set_value (0);
position_control->set_value (0);
} else {
- /* double click on right, collapse to hard right */
+ position_control->set_value (min_pos);
+ }
+ } else if (ev->x > 2*width/3) {
+ if (Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier)) {
+ /* 2ndary-double click on right, collapse to hard right */
width_control->set_value (0);
position_control->set_value (1.0);
+ } else {
+ position_control->set_value (max_pos);
}
+ } else {
+ position_control->set_value (0.5);
}
+
} else {
- if (dragging_left) {
- width_control->set_value (1.0); // reset width to 100%
- } else if (dragging_right) {
- width_control->set_value (-1.0); // reset width to inverted 100%
+
+ /* lower section: adjusts width, constrained by position */
+
+ const double p = position_control->get_value ();
+ const double max_width = 2.0 * min ((1.0 - p), p);
+
+ if (ev->x <= width/3) {
+ /* left side dbl click */
+ width_control->set_value (max_width); // reset width to 100%
+ } else if (ev->x > 2*width/3) {
+ /* right side dbl click */
+ width_control->set_value (-max_width); // reset width to inverted 100%
} else {
+ /* center dbl click */
width_control->set_value (0); // collapse width to 0%
}
-
}
dragging = false;
- } else {
+ } else if (ev->type == GDK_BUTTON_PRESS) {
+
+ if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
+ /* handled by button release */
+ return true;
+ }
+
+ if (ev->y < 20) {
+ /* top section of widget is for position drags */
+ dragging_position = true;
+ StartPositionGesture ();
+ } else {
+ /* lower section is for dragging width */
+
+ double pos = position_control->get_value (); /* 0..1 */
+ double swidth = width_control->get_value (); /* -1..+1 */
+ double fswidth = fabs (swidth);
+ int usable_width = get_width() - lr_box_size;
+ double center = (lr_box_size/2.0) + (usable_width * pos);
+ int left = lrint (center - (fswidth * usable_width / 2.0)); // center of leftmost box
+ int right = lrint (center + (fswidth * usable_width / 2.0)); // center of rightmost box
+ const int half_box = lr_box_size/2;
+
+ if (ev->x >= (left - half_box) && ev->x < (left + half_box)) {
+ if (swidth < 0.0) {
+ dragging_right = true;
+ } else {
+ dragging_left = true;
+ }
+ } else if (ev->x >= (right - half_box) && ev->x < (right + half_box)) {
+ if (swidth < 0.0) {
+ dragging_left = true;
+ } else {
+ dragging_right = true;
+ }
+ }
+ StartWidthGesture ();
+ }
+
dragging = true;
}
bool
StereoPanner::on_button_release_event (GdkEventButton* ev)
{
+ if (ev->button != 1) {
+ return false;
+ }
+
+ bool dp = dragging_position;
+
dragging = false;
dragging_position = false;
dragging_left = false;
dragging_right = false;
accumulated_delta = 0;
+ detented = false;
if (drag_data_window) {
drag_data_window->hide ();
}
-
- set_tooltip ();
+
+ if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
+ /* reset to default */
+ position_control->set_value (0.5);
+ width_control->set_value (1.0);
+ } else {
+ if (dp) {
+ StopPositionGesture ();
+ } else {
+ StopWidthGesture ();
+ }
+ }
return true;
}
/* move the window a little away from the mouse */
drag_data_window->move (ev->x_root+30, ev->y_root+30);
drag_data_window->present ();
- unset_tooltip ();
}
int w = get_width();
double delta = (ev->x - last_drag_x) / (double) w;
+ double current_width = width_control->get_value ();
if (dragging_left) {
delta = -delta;
/* maintain position as invariant as we change the width */
- double current_width = width_control->get_value ();
/* create a detent close to the center */
- if (fabs (current_width) < 0.1) {
+ if (!detented && fabs (current_width) < 0.02) {
+ detented = true;
+ /* snap to zero */
+ width_control->set_value (0);
+ }
+
+ if (detented) {
+
accumulated_delta += delta;
- /* in the detent - have we pulled far enough to escape ? */
- if (fabs (accumulated_delta) >= 0.1) {
+
+ /* have we pulled far enough to escape ? */
+
+ if (fabs (accumulated_delta) >= 0.025) {
width_control->set_value (current_width + accumulated_delta);
- accumulated_delta = 0;
- } else {
- /* snap to zero */
- width_control->set_value (0);
+ detented = false;
+ accumulated_delta = false;
}
+
} else {
width_control->set_value (current_width + delta);
}
colors[Normal].outline = ARDOUR_UI::config()->canvasvar_StereoPannerOutline.get();
colors[Normal].text = ARDOUR_UI::config()->canvasvar_StereoPannerText.get();
colors[Normal].background = ARDOUR_UI::config()->canvasvar_StereoPannerBackground.get();
+ colors[Normal].rule = ARDOUR_UI::config()->canvasvar_StereoPannerRule.get();
colors[Mono].fill = ARDOUR_UI::config()->canvasvar_StereoPannerMonoFill.get();
colors[Mono].outline = ARDOUR_UI::config()->canvasvar_StereoPannerMonoOutline.get();
colors[Mono].text = ARDOUR_UI::config()->canvasvar_StereoPannerMonoText.get();
colors[Mono].background = ARDOUR_UI::config()->canvasvar_StereoPannerMonoBackground.get();
+ colors[Mono].rule = ARDOUR_UI::config()->canvasvar_StereoPannerRule.get();
colors[Inverted].fill = ARDOUR_UI::config()->canvasvar_StereoPannerInvertedFill.get();
colors[Inverted].outline = ARDOUR_UI::config()->canvasvar_StereoPannerInvertedOutline.get();
colors[Inverted].text = ARDOUR_UI::config()->canvasvar_StereoPannerInvertedText.get();
colors[Inverted].background = ARDOUR_UI::config()->canvasvar_StereoPannerInvertedBackground.get();
+ colors[Inverted].rule = ARDOUR_UI::config()->canvasvar_StereoPannerRule.get();
+}
- color_change (); /* EMIT SIGNAL */
+void
+StereoPanner::color_handler ()
+{
+ set_colors ();
+ queue_draw ();
}