hack up the stereo panner

git-svn-id: svn://localhost/ardour2/branches/3.0@8140 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-12-01 16:12:04 +00:00
parent 5aed83d927
commit 079057717d
3 changed files with 192 additions and 106 deletions

View file

@ -383,6 +383,13 @@ PannerUI::setup_pan ()
_current_nouts = nouts; _current_nouts = nouts;
_current_npans = npans; _current_npans = npans;
panning_viewport.remove ();
delete twod_panner;
twod_panner = 0;
delete _stereo_panner;
_stereo_panner = 0;
if (nouts == 0 || nouts == 1) { if (nouts == 0 || nouts == 1) {
while (!pan_adjustments.empty()) { while (!pan_adjustments.empty()) {
@ -392,15 +399,10 @@ PannerUI::setup_pan ()
pan_adjustments.pop_back (); pan_adjustments.pop_back ();
} }
delete twod_panner;
twod_panner = 0;
/* stick something into the panning viewport so that it redraws */ /* stick something into the panning viewport so that it redraws */
EventBox* eb = manage (new EventBox()); EventBox* eb = manage (new EventBox());
panning_viewport.remove ();
panning_viewport.add (*eb); panning_viewport.add (*eb);
panning_viewport.show_all ();
} else if (nouts == 2) { } else if (nouts == 2) {
@ -413,8 +415,18 @@ PannerUI::setup_pan ()
pan_adjustments.pop_back (); pan_adjustments.pop_back ();
} }
delete twod_panner; if (npans == 2) {
twod_panner = 0;
/* add integrated 2in/2out panner GUI */
_stereo_panner = new StereoPanner (_panner->direction_control(),
_panner->width_control());
_stereo_panner->set_size_request (-1, 2 * pan_bar_height);
panning_viewport.add (*_stereo_panner);
} else {
/* N-in/2out - just use a set of single-channel panners */
while ((asz = pan_adjustments.size()) < npans) { while ((asz = pan_adjustments.size()) < npans) {
@ -476,28 +488,11 @@ PannerUI::setup_pan ()
automation state. automation state.
*/ */
update_pan_sensitive (); update_pan_sensitive ();
panning_viewport.remove ();
panning_viewport.add (pan_bar_packer); panning_viewport.add (pan_bar_packer);
panning_viewport.show_all (); }
if (npans == 2) {
/* add position and width controls */
if (_stereo_panner == 0) {
_stereo_panner = new StereoPanner (_panner->direction_control(),
_panner->width_control());
poswidth_box.pack_start (*_stereo_panner, true, true);
}
pan_vbox.pack_start (poswidth_box, false, false);
poswidth_box.show_all ();
cerr << "Packed poswidth and mde it visible\n";
} else {
if (_stereo_panner) {
pan_vbox.remove (poswidth_box);
cerr << "Hid poswidth\n";
}
}
} else { } else {
@ -519,10 +514,10 @@ PannerUI::setup_pan ()
/* and finally, add it to the panner frame */ /* and finally, add it to the panner frame */
panning_viewport.remove ();
panning_viewport.add (*twod_panner); panning_viewport.add (*twod_panner);
panning_viewport.show_all ();
} }
panning_viewport.show_all ();
} }
void void
@ -698,7 +693,12 @@ PannerUI::pan_value_changed (uint32_t which)
twod_panner->move_puck (which, _panner->streampanner(which).get_position()); twod_panner->move_puck (which, _panner->streampanner(which).get_position());
in_pan_update = false; in_pan_update = false;
} else if (_stereo_panner) {
/* its taken care of */
} else if (_panner->npanners() > 0 && which < _panner->npanners()) { } else if (_panner->npanners() > 0 && which < _panner->npanners()) {
AngularVector model = _panner->streampanner(which).get_position(); AngularVector model = _panner->streampanner(which).get_position();
double fract = pan_adjustments[which]->get_value(); double fract = pan_adjustments[which]->get_value();
AngularVector view (BaseStereoPanner::lr_fract_to_azimuth (fract), 0.0); AngularVector view (BaseStereoPanner::lr_fract_to_azimuth (fract), 0.0);

View file

@ -22,8 +22,10 @@
#include <cstring> #include <cstring>
#include "pbd/controllable.h" #include "pbd/controllable.h"
#include "pbd/compose.h"
#include "gtkmm2ext/gui_thread.h" #include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/gtk_ui.h"
#include "ardour/panner.h" #include "ardour/panner.h"
#include "stereo_panner.h" #include "stereo_panner.h"
@ -33,6 +35,10 @@
using namespace std; using namespace std;
using namespace Gtk; using namespace Gtk;
static const int pos_box_size = 10;
static const int lr_box_size = 18;
static const int step_down = 10;
StereoPanner::StereoPanner (boost::shared_ptr<PBD::Controllable> position, boost::shared_ptr<PBD::Controllable> width) StereoPanner::StereoPanner (boost::shared_ptr<PBD::Controllable> position, boost::shared_ptr<PBD::Controllable> width)
: position_control (position) : position_control (position)
, width_control (width) , width_control (width)
@ -41,10 +47,9 @@ StereoPanner::StereoPanner (boost::shared_ptr<PBD::Controllable> position, boost
, drag_start_x (0) , drag_start_x (0)
, last_drag_x (0) , last_drag_x (0)
{ {
set_size_request (-1, 15); 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());
position_control->Changed.connect (connections, invalidator(*this), boost::bind (&DrawingArea::queue_draw, this), gui_context()); set_tooltip ();
width_control->Changed.connect (connections, invalidator(*this), boost::bind (&DrawingArea::queue_draw, this), gui_context());
add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK|Gdk::POINTER_MOTION_MASK); add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK|Gdk::POINTER_MOTION_MASK);
} }
@ -53,6 +58,22 @@ StereoPanner::~StereoPanner ()
{ {
} }
void
StereoPanner::set_tooltip ()
{
Gtkmm2ext::UI::instance()->set_tip (this, string_compose (_("L:%1 R:%2 Width: %3%%"),
(int) floor (position_control->get_value() * 100.0),
(int) floor ((1.0 - position_control->get_value() * 100)),
(int) floor (width_control->get_value() * 100.0)).c_str());
}
void
StereoPanner::value_change ()
{
set_tooltip ();
queue_draw ();
}
bool bool
StereoPanner::on_expose_event (GdkEventExpose* ev) StereoPanner::on_expose_event (GdkEventExpose* ev)
{ {
@ -65,29 +86,91 @@ StereoPanner::on_expose_event (GdkEventExpose* ev)
int width, height; int width, height;
double pos = position_control->get_value (); /* 0..1 */ double pos = position_control->get_value (); /* 0..1 */
double swidth = width_control->get_value (); /* -1..+1 */ double swidth = width_control->get_value (); /* -1..+1 */
const int pos_box_size = 5; const int border_width = 1;
const int border = border_width * 2;
width = get_width(); width = get_width();
height = get_height (); height = get_height ();
/* background */
cairo_set_source_rgb (cr, 0.184, 0.172, 0.172);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
/* leave a border */
width -= border_width;
height -= border_width;
/* compute where the central box is */ /* compute where the central box is */
x1 = (int) floor (width * pos); x1 = (int) floor (width * pos); // center of widget
x1 -= pos_box_size/2; x2 = x1 - (int) floor ((fabs (swidth) * width)/2.0); // center, then back up half the swidth value
x1 -= pos_box_size/2; // center, then back up by half width of position box
cairo_set_source_rgb (cr, 255, 0, 0);
cairo_rectangle (cr, x1, 4, pos_box_size, pos_box_size);
cairo_fill (cr);
/* compute & draw the line through the box */ /* compute & draw the line through the box */
x2 = x1 - (int) floor ((fabs (swidth) * width)/2.0); // center, then back up half the swidth value cairo_set_line_width (cr, 2);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_set_source_rgb (cr, 0, 255, 0); cairo_move_to (cr, border + x2, 4+(pos_box_size/2)+step_down);
cairo_move_to (cr, x2, 4+(pos_box_size/2)); cairo_line_to (cr, border + x2, 4+(pos_box_size/2));
cairo_line_to (cr, x2 + floor ((fabs (swidth * width))), 4+(pos_box_size/2)); cairo_line_to (cr, border + x2 + floor ((fabs (swidth * width))), 4+(pos_box_size/2));
cairo_line_to (cr, border + x2 + floor ((fabs (swidth * width))), 4+(pos_box_size/2) + step_down);
cairo_stroke (cr); cairo_stroke (cr);
/* left box */
cairo_rectangle (cr,
border+ x2 - lr_box_size/2,
(lr_box_size/2)+step_down,
lr_box_size, lr_box_size);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_stroke_preserve (cr);
cairo_set_source_rgba (cr, 0.4509, 0.7686, 0.8627, 0.8);
cairo_fill (cr);
/* add text */
cairo_move_to (cr,
border + x2 - lr_box_size/2 + 4,
(lr_box_size/2) + step_down + 13);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_show_text (cr, "L");
/* right box */
cairo_rectangle (cr,
border + x2 + (int) floor ((fabs (swidth * width))) - lr_box_size/2,
(lr_box_size/2)+step_down,
lr_box_size, lr_box_size);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_stroke_preserve (cr);
cairo_set_source_rgba (cr, 0.4509, 0.7686, 0.8627, 0.8);
cairo_fill (cr);
/* add text */
cairo_move_to (cr,
border + x2 + (int) floor ((fabs (swidth * width))) - lr_box_size/2 + 4,
(lr_box_size/2)+step_down + 13);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_show_text (cr, "R");
/* draw the central box */
cairo_set_line_width (cr, 1);
cairo_rectangle (cr, border + x1, 4, pos_box_size, pos_box_size);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_stroke_preserve (cr);
cairo_set_source_rgba (cr, 0.4509, 0.7686, 0.8627, 0.8);
cairo_fill (cr);
/* done */
cairo_destroy (cr); cairo_destroy (cr);
return true; return true;
} }
@ -103,7 +186,7 @@ StereoPanner::on_button_press_event (GdkEventButton* ev)
int w = get_width(); int w = get_width();
double pos = position_control->get_value (); double pos = position_control->get_value ();
if ((ev->x >= (int) floor ((pos * w)-4)) && (ev->x <= (int) floor ((pos * w)+4))) { if ((ev->x >= (int) floor ((pos * w)-(pos_box_size/2))) && (ev->x <= (int) floor ((pos * w)+(pos_box_size/2)))) {
dragging_position = true; dragging_position = true;
} else { } else {
dragging_position = false; dragging_position = false;

View file

@ -49,6 +49,9 @@ class StereoPanner : public Gtk::DrawingArea
bool dragging_position; bool dragging_position;
int drag_start_x; int drag_start_x;
int last_drag_x; int last_drag_x;
void value_change ();
void set_tooltip ();
}; };
#endif /* __gtk_ardour_stereo_panner_h__ */ #endif /* __gtk_ardour_stereo_panner_h__ */