+
+string
+Panner::value_as_string (double v)
+{
+ if (Panner::equivalent (v, 0.5)) {
+ return _("C");
+ } else if (equivalent (v, 0)) {
+ return _("L");
+ } else if (equivalent (v, 1)) {
+ return _("R");
+ } else if (v < 0.5) {
+ stringstream s;
+ s << fixed << setprecision (0) << _("L") << ((0.5 - v) * 200) << "%";
+ return s.str();
+ } else {
+ stringstream s;
+ s << fixed << setprecision (0) << _("R") << ((v -0.5) * 200) << "%";
+ return s.str ();
+ }
+
+ return "";
+}
+
+void
+Panner::setup_speakers (uint32_t nouts)
+{
+ switch (nouts) {
+ case 3:
+ /* top, bottom kind-of-left & bottom kind-of-right */
+ outputs.push_back (AngularVector (90.0, 0.0));
+ outputs.push_back (AngularVector (215.0, 0,0));
+ outputs.push_back (AngularVector (335.0, 0,0));
+ break;
+ case 4:
+ /* clockwise from top left */
+ outputs.push_back (AngularVector (135.0, 0.0));
+ outputs.push_back (AngularVector (45.0, 0.0));
+ outputs.push_back (AngularVector (335.0, 0.0));
+ outputs.push_back (AngularVector (215.0, 0.0));
+ break;
+
+ default:
+ {
+ double degree_step = 360.0 / nouts;
+ double deg;
+ uint32_t n;
+
+ /* even number of speakers? make sure the top two are either side of "top".
+ otherwise, just start at the "top" (90.0 degrees) and rotate around
+ */
+
+ if (nouts % 2) {
+ deg = 90.0 - degree_step;
+ } else {
+ deg = 90.0;
+ }
+ for (n = 0; n < nouts; ++n, deg += degree_step) {
+ outputs.push_back (Output (AngularVector (deg, 0.0)));
+ }
+ }
+ }
+
+ Speakers& speakers (_session.get_speakers());
+
+ speakers.clear_speakers ();
+
+ for (vector<Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
+ speakers.add_speaker ((*o).position);
+ }
+}
+
+void
+Panner::set_stereo_width (double val)
+{
+ boost::shared_ptr<AutomationControl> dc = direction_control();
+ if (dc) {
+ dc->set_value (val);
+ }
+}
+
+void
+Panner::set_stereo_position (double val)
+{
+ boost::shared_ptr<AutomationControl> wc = width_control();
+ if (wc) {
+ wc->set_value (val);
+ }
+}
+
+bool
+Panner::set_stereo_pan (double direction_as_lr_fract, double width)
+{
+ AngularVector p (BaseStereoPanner::lr_fract_to_azimuth (direction_as_lr_fract), 0.0);
+ /* width parameter ranges from -1..+1 with 0.0 at center. we want 0..+1 plus knowing
+ whether its "reversed" (i.e. left signal pans right and right signal pans left).
+ full width = 180 degrees
+ */
+ double spread = 2.0 * fabs(width/2.0) * 180.0;
+ double l_pos = p.azi + (spread/2.0); /* more left is "increasing degrees" */
+ double r_pos = p.azi - (spread/2.0); /* more right is "decreasing degrees" */
+ bool move_left = true;
+ bool move_right = true;
+ int l_index = 0;
+ int r_index = 1;
+
+ assert (_streampanners.size() > 1);
+
+ if (width < 0.0) {
+ swap (l_index, r_index);
+ }
+
+ l_pos = max (min (l_pos, 180.0), 0.0);
+ r_pos = max (min (r_pos, 180.0), 0.0);
+
+ /* if the new left position is less than or equal to 180 (hard left) and the left panner
+ is already there, we're not moving the left signal.
+ */
+
+ if (l_pos >= 180.0 &&_streampanners[l_index]->get_position().azi == 180.0) {
+ move_left = false;
+ }
+
+ /* if the new right position is less than or equal to zero (hard right) and the right panner
+ is already there, we're not moving the right signal.
+ */
+
+ if (r_pos <= 0.0 && _streampanners[r_index]->get_position().azi == 0.0) {
+ move_right = false;
+ }
+
+ if (move_left && move_right) {
+ _streampanners[l_index]->set_position (AngularVector (l_pos, 0.0));
+ _streampanners[r_index]->set_position (AngularVector (r_pos, 0.0));
+ }
+
+ return move_left && move_right;
+}
+
+void
+Panner::setup_meta_controls ()
+{
+ if (_streampanners.size() != 2 || outputs.size() != 2) {
+ return;
+ }
+
+ /* 2 signals to 2 outputs: provide "classic" controls for easier manipulation.
+
+ The ID numbers used here don't really matter that much, because Parameters are scoped by owner,
+ but they keep us out of the ordinary range of pan-related parameters.
+ */
+
+ Evoral::Parameter lr_param (PanAutomation, 0, 100);
+ Evoral::Parameter width_param (PanAutomation, 0, 200);
+ boost::shared_ptr<AutomationControl> dc = automation_control (lr_param);
+ boost::shared_ptr<AutomationControl> wc = automation_control (width_param);
+
+ if (dc) {
+ /* reset parent StreamPanner as the current one may have been deleted */
+ boost::shared_ptr<StreamPanner::PanControllable> p = boost::dynamic_pointer_cast<StreamPanner::PanControllable> (dc);
+ assert (p);
+ p->streampanner = _streampanners.front ();
+ } else {
+ dc.reset (new StreamPanner::PanControllable (_session, _("lr"), _streampanners.front(), lr_param));
+ add_control (dc);
+ }
+
+ if (wc) {
+ /* reset parent as above */
+ boost::shared_ptr<StreamPanner::PanControllable> p = boost::dynamic_pointer_cast<StreamPanner::PanControllable> (wc);
+ assert (p);
+ p->streampanner = _streampanners.front ();
+ } else {
+ wc.reset (new StreamPanner::PanControllable (_session, _("width"), _streampanners.front(), width_param));
+ add_control (wc);
+ }
+
+ dc->set_value (0.5);
+ wc->set_value (1.0); // full width
+}
+
+string
+Panner::describe_parameter (Evoral::Parameter param)
+{
+ if (param.type() == PanAutomation) {
+ switch (param.id()) {
+ case 100:
+ return "Pan:position";
+ case 200:
+ return "Pan:width";
+ default:
+ if (_streampanners.size() == 2) {
+ switch (param.id()) {
+ case 0:
+ return "Pan L";
+ default:
+ return "Pan R";
+ }
+ } else {
+ stringstream ss;
+ ss << "Pan " << param.id() + 1;
+ return ss.str ();
+ }
+ }
+ }
+
+ return Automatable::describe_parameter (param);
+}