13
0

VBAP rework (part III): fix position computation backend & GUI

This commit is contained in:
Robin Gareus 2014-01-11 23:30:01 +01:00
parent 7ac05ccfa5
commit 72cec05d46
3 changed files with 71 additions and 87 deletions

View File

@ -82,7 +82,7 @@ Panner2d::Panner2d (boost::shared_ptr<PannerShell> p, int32_t h)
drag_target = 0;
set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
handle_position_change ();
handle_position_change ();
}
Panner2d::~Panner2d()
@ -206,7 +206,6 @@ Panner2d::handle_state_change ()
void
Panner2d::label_signals ()
{
double w = panner_shell->pannable()->pan_width_control->get_value();
uint32_t sz = signals.size();
switch (sz) {
@ -218,23 +217,14 @@ Panner2d::label_signals ()
break;
case 2:
if (w >= 0.0) {
signals[0]->set_text ("R");
signals[1]->set_text ("L");
} else {
signals[0]->set_text ("L");
signals[1]->set_text ("R");
}
signals[0]->set_text ("L");
signals[1]->set_text ("R");
break;
default:
for (uint32_t i = 0; i < sz; ++i) {
char buf[64];
if (w >= 0.0) {
snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
} else {
snprintf (buf, sizeof (buf), "%" PRIu32, sz - i);
}
snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
signals[i]->set_text (buf);
}
break;
@ -247,7 +237,8 @@ Panner2d::handle_position_change ()
uint32_t n;
double w = panner_shell->pannable()->pan_width_control->get_value();
position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0, 0.0);
position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0,
panner_shell->pannable()->pan_elevation_control->get_value() * 90.0);
for (uint32_t i = 0; i < signals.size(); ++i) {
signals[i]->position = panner_shell->panner()->signal_position (i);
@ -693,22 +684,39 @@ Panner2d::handle_motion (gint evx, gint evy, GdkModifierType state)
}
if (need_move) {
CartesianVector cp (evx, evy, 0.0);
AngularVector av;
/* canonicalize position and then clamp to the circle */
set<Evoral::Parameter> params = panner_shell->panner()->what_can_be_automated();
set<Evoral::Parameter>::iterator p = params.find(PanElevationAutomation);
double y0 = 4.0;
if (height > large_size_threshold) {
y0 = 12.0;
}
CartesianVector cp (evx - 12.0, evy - y0, 0.0);
AngularVector av;
gtk_to_cart (cp);
clamp_to_circle (cp.x, cp.y);
/* generate an angular representation of the current mouse position */
if (p == params.end()) {
clamp_to_circle (cp.x, cp.y);
cp.angular (av);
if (drag_target == &position) {
double degree_fract = av.azi / 360.0;
panner_shell->panner()->set_position (degree_fract);
}
} else {
/* sphere projection */
sphere_project (cp.x, cp.y, cp.z);
cp.angular (av);
double r2d = 180.0 / M_PI;
av.azi = r2d * atan2(cp.y, cp.x);
av.ele = r2d * asin(cp.z);
if (drag_target == &position) {
double degree_fract = av.azi / 360.0;
panner_shell->panner()->set_position (degree_fract);
}
if (drag_target == &position) {
double azi_fract = av.azi / 360.0;
double ele_fract = av.ele / 90.0;
panner_shell->panner()->set_position (azi_fract);
panner_shell->panner()->set_elevation (ele_fract);
}
}
}
}
@ -761,13 +769,27 @@ Panner2d::gtk_to_cart (CartesianVector& c) const
c.y = (((diameter - c.y) / diameter) * 2.0) - 1.0;
}
void
Panner2d::sphere_project (double& x, double& y, double& z)
{
double r, r2;
r2 = x * x + y * y;
if (r2 < 1.0) {
z = sqrt (1.0 - r2);
} else {
r = sqrt (r2);
x = x / r;
y = y / r;
z = 0.0;
}
}
void
Panner2d::clamp_to_circle (double& x, double& y)
{
double azi, ele;
double z = 0.0;
double l;
double l;
PBD::cartesian_to_spherical (x, y, z, azi, ele, l);
PBD::spherical_to_cartesian (azi, ele, 1.0, x, y, z);
}

View File

@ -142,6 +142,7 @@ class Panner2d : public Gtk::DrawingArea
and centered in the middle of our area
*/
void clamp_to_circle (double& x, double& y);
void sphere_project (double& x, double& y, double& z);
};
class Panner2dWindow : public ArdourWindow

View File

@ -114,70 +114,27 @@ VBAPanner::configure_io (ChanCount in, ChanCount /* ignored - we use Speakers */
void
VBAPanner::update ()
{
/* recompute signal directions based on panner azimuth and, if relevant, width (diffusion) parameters)
*/
/* panner azimuth control is [0 .. 1.0] which we interpret as [0 .. 360] degrees
*/
double center = _pannable->pan_azimuth_control->get_value() * 360.0;
/* recompute signal directions based on panner azimuth and, if relevant, width (diffusion) and elevation parameters */
double elevation = _pannable->pan_elevation_control->get_value() * 90.0;
if (_signals.size() > 1) {
/* panner width control is [-1.0 .. 1.0]; we ignore sign, and map to [0 .. 360] degrees
so that a width of 1 corresponds to a signal equally present from all directions,
and a width of zero corresponds to a point source from the "center" (above) point
on the perimeter of the speaker array.
*/
double w = fabs (_pannable->pan_width_control->get_value()) * 360.0;
double w = (_pannable->pan_width_control->get_value());
double signal_direction = _pannable->pan_azimuth_control->get_value() - (w/2);
double grd_step_per_signal = w / (_signals.size() - 1);
for (vector<Signal*>::iterator s = _signals.begin(); s != _signals.end(); ++s) {
double min_dir = center - (w/2.0);
if (min_dir < 0) {
min_dir = 360.0 + min_dir; // its already negative
Signal* signal = *s;
int over = signal_direction;
over -= (signal_direction >= 0) ? 0 : 1;
signal_direction -= (double)over;
signal->direction = AngularVector (signal_direction * 360.0, elevation);
compute_gains (signal->desired_gains, signal->desired_outputs, signal->direction.azi, signal->direction.ele);
signal_direction += grd_step_per_signal;
}
min_dir = max (min (min_dir, 360.0), 0.0);
double max_dir = center + (w/2.0);
if (max_dir > 360.0) {
max_dir = max_dir - 360.0;
}
max_dir = max (min (max_dir, 360.0), 0.0);
if (max_dir < min_dir) {
swap (max_dir, min_dir);
}
double degree_step_per_signal = (max_dir - min_dir) / (_signals.size() - 1);
double signal_direction = min_dir;
if (w >= 0.0) {
/* positive width - normal order of signal spread */
for (vector<Signal*>::iterator s = _signals.begin(); s != _signals.end(); ++s) {
Signal* signal = *s;
signal->direction = AngularVector (signal_direction, elevation);
compute_gains (signal->desired_gains, signal->desired_outputs, signal->direction.azi, signal->direction.ele);
signal_direction += degree_step_per_signal;
}
} else {
/* inverted width - reverse order of signal spread */
for (vector<Signal*>::reverse_iterator s = _signals.rbegin(); s != _signals.rend(); ++s) {
Signal* signal = *s;
signal->direction = AngularVector (signal_direction, elevation);
compute_gains (signal->desired_gains, signal->desired_outputs, signal->direction.azi, signal->direction.ele);
signal_direction += degree_step_per_signal;
}
}
} else if (_signals.size() == 1) {
double center = _pannable->pan_azimuth_control->get_value() * 360.0;
/* width has no role to play if there is only 1 signal: VBAP does not do "diffusion" of a single channel */
@ -516,7 +473,11 @@ void
VBAPanner::reset ()
{
set_position (0);
set_width (1);
if (_signals.size() > 1) {
set_width (1.0 - (1.0 / (double)_signals.size()));
} else {
set_width (0);
}
set_elevation (0);
update ();