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_npans = npans;
panning_viewport.remove ();
delete twod_panner;
twod_panner = 0;
delete _stereo_panner;
_stereo_panner = 0;
if (nouts == 0 || nouts == 1) {
while (!pan_adjustments.empty()) {
@ -392,15 +399,10 @@ PannerUI::setup_pan ()
pan_adjustments.pop_back ();
}
delete twod_panner;
twod_panner = 0;
/* stick something into the panning viewport so that it redraws */
EventBox* eb = manage (new EventBox());
panning_viewport.remove ();
panning_viewport.add (*eb);
panning_viewport.show_all ();
} else if (nouts == 2) {
@ -413,92 +415,85 @@ PannerUI::setup_pan ()
pan_adjustments.pop_back ();
}
delete twod_panner;
twod_panner = 0;
while ((asz = pan_adjustments.size()) < npans) {
float x, rx;
PannerBar* bc;
/* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
which serves as a default, otherwise use current value */
rx = _panner->pan_control( asz)->get_value();
if (npans == 1) {
x = 0.5;
} else if (asz == 0) {
x = 0.0;
} else if (asz == 1) {
x = 1.0;
} else {
x = rx;
}
pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
bc = new PannerBar (*pan_adjustments[asz],
boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
/* now set adjustment with current value of panner, then connect the signals */
pan_adjustments.back()->set_value(rx);
pan_adjustments.back()->signal_value_changed().connect (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
connect_to_pan_control (asz);
bc->set_name ("PanSlider");
bc->set_shadow_type (Gtk::SHADOW_NONE);
boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
if (asz) {
bc->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
boost::weak_ptr<AutomationControl> (ac)));
bc->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
boost::weak_ptr<AutomationControl>(ac)));
}
char buf[64];
snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
ARDOUR_UI::instance()->set_tip (bc->event_widget(), buf);
bc->event_widget().signal_button_release_event().connect
(sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
bc->set_size_request (-1, pan_bar_height);
bc->SpinnerActive.connect (sigc::mem_fun (*this, &PannerUI::bar_spinner_activate));
pan_bars.push_back (bc);
pan_bar_packer.pack_start (*bc, false, false);
}
/* now that we actually have the pan bars,
set their sensitivity based on current
automation state.
*/
update_pan_sensitive ();
panning_viewport.remove ();
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";
/* 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 {
if (_stereo_panner) {
pan_vbox.remove (poswidth_box);
cerr << "Hid poswidth\n";
/* N-in/2out - just use a set of single-channel panners */
while ((asz = pan_adjustments.size()) < npans) {
float x, rx;
PannerBar* bc;
/* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
which serves as a default, otherwise use current value */
rx = _panner->pan_control( asz)->get_value();
if (npans == 1) {
x = 0.5;
} else if (asz == 0) {
x = 0.0;
} else if (asz == 1) {
x = 1.0;
} else {
x = rx;
}
pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
bc = new PannerBar (*pan_adjustments[asz],
boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
/* now set adjustment with current value of panner, then connect the signals */
pan_adjustments.back()->set_value(rx);
pan_adjustments.back()->signal_value_changed().connect (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
connect_to_pan_control (asz);
bc->set_name ("PanSlider");
bc->set_shadow_type (Gtk::SHADOW_NONE);
boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
if (asz) {
bc->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
boost::weak_ptr<AutomationControl> (ac)));
bc->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
boost::weak_ptr<AutomationControl>(ac)));
}
char buf[64];
snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
ARDOUR_UI::instance()->set_tip (bc->event_widget(), buf);
bc->event_widget().signal_button_release_event().connect
(sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
bc->set_size_request (-1, pan_bar_height);
bc->SpinnerActive.connect (sigc::mem_fun (*this, &PannerUI::bar_spinner_activate));
pan_bars.push_back (bc);
pan_bar_packer.pack_start (*bc, false, false);
}
/* now that we actually have the pan bars,
set their sensitivity based on current
automation state.
*/
update_pan_sensitive ();
panning_viewport.add (pan_bar_packer);
}
} else {
if (!twod_panner) {
@ -519,10 +514,10 @@ PannerUI::setup_pan ()
/* and finally, add it to the panner frame */
panning_viewport.remove ();
panning_viewport.add (*twod_panner);
panning_viewport.show_all ();
}
panning_viewport.show_all ();
}
void
@ -698,7 +693,12 @@ PannerUI::pan_value_changed (uint32_t which)
twod_panner->move_puck (which, _panner->streampanner(which).get_position());
in_pan_update = false;
} else if (_stereo_panner) {
/* its taken care of */
} else if (_panner->npanners() > 0 && which < _panner->npanners()) {
AngularVector model = _panner->streampanner(which).get_position();
double fract = pan_adjustments[which]->get_value();
AngularVector view (BaseStereoPanner::lr_fract_to_azimuth (fract), 0.0);

View File

@ -22,8 +22,10 @@
#include <cstring>
#include "pbd/controllable.h"
#include "pbd/compose.h"
#include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/gtk_ui.h"
#include "ardour/panner.h"
#include "stereo_panner.h"
@ -33,6 +35,10 @@
using namespace std;
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)
: position_control (position)
, width_control (width)
@ -41,11 +47,10 @@ StereoPanner::StereoPanner (boost::shared_ptr<PBD::Controllable> position, boost
, drag_start_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());
set_tooltip ();
position_control->Changed.connect (connections, invalidator(*this), boost::bind (&DrawingArea::queue_draw, this), gui_context());
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);
}
@ -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
StereoPanner::on_expose_event (GdkEventExpose* ev)
{
@ -65,29 +86,91 @@ StereoPanner::on_expose_event (GdkEventExpose* ev)
int width, height;
double pos = position_control->get_value (); /* 0..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();
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 */
x1 = (int) floor (width * pos);
x1 -= pos_box_size/2;
cairo_set_source_rgb (cr, 255, 0, 0);
cairo_rectangle (cr, x1, 4, pos_box_size, pos_box_size);
cairo_fill (cr);
x1 = (int) floor (width * pos); // center of widget
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
/* 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_source_rgb (cr, 0, 255, 0);
cairo_move_to (cr, x2, 4+(pos_box_size/2));
cairo_line_to (cr, x2 + floor ((fabs (swidth * width))), 4+(pos_box_size/2));
cairo_set_line_width (cr, 2);
cairo_set_source_rgba (cr, 0.3137, 0.4431, 0.7843, 1.0);
cairo_move_to (cr, border + x2, 4+(pos_box_size/2)+step_down);
cairo_line_to (cr, border + x2, 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);
/* 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);
return true;
}
@ -103,7 +186,7 @@ StereoPanner::on_button_press_event (GdkEventButton* ev)
int w = get_width();
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;
} else {
dragging_position = false;

View File

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