mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-12 09:36:33 +01:00
VBAP rework (part III): fix position computation backend & GUI
This commit is contained in:
parent
431babc272
commit
dd4c0e040f
3 changed files with 71 additions and 87 deletions
|
|
@ -82,7 +82,7 @@ Panner2d::Panner2d (boost::shared_ptr<PannerShell> p, int32_t h)
|
||||||
drag_target = 0;
|
drag_target = 0;
|
||||||
set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
|
set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
|
||||||
|
|
||||||
handle_position_change ();
|
handle_position_change ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Panner2d::~Panner2d()
|
Panner2d::~Panner2d()
|
||||||
|
|
@ -206,7 +206,6 @@ Panner2d::handle_state_change ()
|
||||||
void
|
void
|
||||||
Panner2d::label_signals ()
|
Panner2d::label_signals ()
|
||||||
{
|
{
|
||||||
double w = panner_shell->pannable()->pan_width_control->get_value();
|
|
||||||
uint32_t sz = signals.size();
|
uint32_t sz = signals.size();
|
||||||
|
|
||||||
switch (sz) {
|
switch (sz) {
|
||||||
|
|
@ -218,23 +217,14 @@ Panner2d::label_signals ()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if (w >= 0.0) {
|
signals[0]->set_text ("L");
|
||||||
signals[0]->set_text ("R");
|
signals[1]->set_text ("R");
|
||||||
signals[1]->set_text ("L");
|
|
||||||
} else {
|
|
||||||
signals[0]->set_text ("L");
|
|
||||||
signals[1]->set_text ("R");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
for (uint32_t i = 0; i < sz; ++i) {
|
for (uint32_t i = 0; i < sz; ++i) {
|
||||||
char buf[64];
|
char buf[64];
|
||||||
if (w >= 0.0) {
|
snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
|
||||||
snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
|
|
||||||
} else {
|
|
||||||
snprintf (buf, sizeof (buf), "%" PRIu32, sz - i);
|
|
||||||
}
|
|
||||||
signals[i]->set_text (buf);
|
signals[i]->set_text (buf);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -247,7 +237,8 @@ Panner2d::handle_position_change ()
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
double w = panner_shell->pannable()->pan_width_control->get_value();
|
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) {
|
for (uint32_t i = 0; i < signals.size(); ++i) {
|
||||||
signals[i]->position = panner_shell->panner()->signal_position (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) {
|
if (need_move) {
|
||||||
CartesianVector cp (evx, evy, 0.0);
|
set<Evoral::Parameter> params = panner_shell->panner()->what_can_be_automated();
|
||||||
AngularVector av;
|
set<Evoral::Parameter>::iterator p = params.find(PanElevationAutomation);
|
||||||
|
|
||||||
/* canonicalize position and then clamp to the circle */
|
|
||||||
|
|
||||||
|
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);
|
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) {
|
if (drag_target == &position) {
|
||||||
double degree_fract = av.azi / 360.0;
|
double azi_fract = av.azi / 360.0;
|
||||||
panner_shell->panner()->set_position (degree_fract);
|
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;
|
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
|
void
|
||||||
Panner2d::clamp_to_circle (double& x, double& y)
|
Panner2d::clamp_to_circle (double& x, double& y)
|
||||||
{
|
{
|
||||||
double azi, ele;
|
double azi, ele;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
double l;
|
double l;
|
||||||
|
|
||||||
PBD::cartesian_to_spherical (x, y, z, azi, ele, l);
|
PBD::cartesian_to_spherical (x, y, z, azi, ele, l);
|
||||||
PBD::spherical_to_cartesian (azi, ele, 1.0, x, y, z);
|
PBD::spherical_to_cartesian (azi, ele, 1.0, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ class Panner2d : public Gtk::DrawingArea
|
||||||
and centered in the middle of our area
|
and centered in the middle of our area
|
||||||
*/
|
*/
|
||||||
void clamp_to_circle (double& x, double& y);
|
void clamp_to_circle (double& x, double& y);
|
||||||
|
void sphere_project (double& x, double& y, double& z);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Panner2dWindow : public ArdourWindow
|
class Panner2dWindow : public ArdourWindow
|
||||||
|
|
|
||||||
|
|
@ -118,70 +118,27 @@ VBAPanner::configure_io (ChanCount in, ChanCount /* ignored - we use Speakers */
|
||||||
void
|
void
|
||||||
VBAPanner::update ()
|
VBAPanner::update ()
|
||||||
{
|
{
|
||||||
/* recompute signal directions based on panner azimuth and, if relevant, width (diffusion) parameters)
|
/* recompute signal directions based on panner azimuth and, if relevant, width (diffusion) and elevation 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;
|
|
||||||
double elevation = _pannable->pan_elevation_control->get_value() * 90.0;
|
double elevation = _pannable->pan_elevation_control->get_value() * 90.0;
|
||||||
|
|
||||||
if (_signals.size() > 1) {
|
if (_signals.size() > 1) {
|
||||||
|
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) {
|
||||||
|
|
||||||
/* panner width control is [-1.0 .. 1.0]; we ignore sign, and map to [0 .. 360] degrees
|
Signal* signal = *s;
|
||||||
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;
|
int over = signal_direction;
|
||||||
|
over -= (signal_direction >= 0) ? 0 : 1;
|
||||||
|
signal_direction -= (double)over;
|
||||||
|
|
||||||
double min_dir = center - (w/2.0);
|
signal->direction = AngularVector (signal_direction * 360.0, elevation);
|
||||||
if (min_dir < 0) {
|
compute_gains (signal->desired_gains, signal->desired_outputs, signal->direction.azi, signal->direction.ele);
|
||||||
min_dir = 360.0 + min_dir; // its already negative
|
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) {
|
} 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 */
|
/* width has no role to play if there is only 1 signal: VBAP does not do "diffusion" of a single channel */
|
||||||
|
|
||||||
|
|
@ -520,7 +477,11 @@ void
|
||||||
VBAPanner::reset ()
|
VBAPanner::reset ()
|
||||||
{
|
{
|
||||||
set_position (0);
|
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);
|
set_elevation (0);
|
||||||
|
|
||||||
update ();
|
update ();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue