2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <pbd/error.h>
34 #include <pbd/failed_constructor.h>
35 #include <pbd/xml++.h>
37 #include <ardour/session.h>
38 #include <ardour/panner.h>
39 #include <ardour/utils.h>
41 #include <ardour/mix.h>
45 #include <pbd/mathfix.h>
48 using namespace ARDOUR;
51 float Panner::current_automation_version_number = 1.0;
53 string EqualPowerStereoPanner::name = "Equal Power Stereo";
54 string Multi2dPanner::name = "Multiple (2D)";
56 /* this is a default mapper of control values to a pan position
57 others can be imagined.
60 static pan_t direct_control_to_pan (double fract) {
64 static double direct_pan_to_control (pan_t val) {
68 StreamPanner::StreamPanner (Panner& p)
70 _control (X_("panner"), *this)
74 parent.session().add_controllable (&_control);
81 StreamPanner::~StreamPanner ()
86 StreamPanner::PanControllable::set_value (float val)
88 panner.set_position (direct_control_to_pan (val));
92 StreamPanner::PanControllable::get_value (void) const
95 panner.get_effective_position (xpos);
96 return direct_pan_to_control (xpos);
100 StreamPanner::PanControllable::can_send_feedback () const
102 AutoState astate = panner.get_parent().automation_state ();
104 if ((astate == Play) || (astate == Touch && !panner.get_parent().touching())) {
112 StreamPanner::set_muted (bool yn)
121 StreamPanner::set_position (float xpos, bool link_call)
123 if (!link_call && parent.linked()) {
124 parent.set_position (xpos, *this);
136 StreamPanner::set_position (float xpos, float ypos, bool link_call)
138 if (!link_call && parent.linked()) {
139 parent.set_position (xpos, ypos, *this);
142 if (x != xpos || y != ypos) {
152 StreamPanner::set_position (float xpos, float ypos, float zpos, bool link_call)
154 if (!link_call && parent.linked()) {
155 parent.set_position (xpos, ypos, zpos, *this);
158 if (x != xpos || y != ypos || z != zpos) {
168 StreamPanner::set_state (const XMLNode& node)
170 const XMLProperty* prop;
171 XMLNodeConstIterator iter;
173 if ((prop = node.property (X_("muted")))) {
174 set_muted (prop->value() == "yes");
181 StreamPanner::add_state (XMLNode& node)
183 node.add_property (X_("muted"), (muted() ? "yes" : "no"));
186 /*---------------------------------------------------------------------- */
188 BaseStereoPanner::BaseStereoPanner (Panner& p)
189 : StreamPanner (p), _automation (0.0, 1.0, 0.5)
193 BaseStereoPanner::~BaseStereoPanner ()
198 BaseStereoPanner::snapshot (nframes_t now)
200 if (_automation.automation_state() == Write || _automation.automation_state() == Touch) {
201 _automation.rt_add (now, x);
206 BaseStereoPanner::transport_stopped (nframes_t frame)
208 _automation.reposition_for_rt_add (frame);
210 if (_automation.automation_state() != Off) {
211 set_position (_automation.eval (frame));
216 BaseStereoPanner::set_automation_style (AutoStyle style)
218 _automation.set_automation_style (style);
222 BaseStereoPanner::set_automation_state (AutoState state)
224 if (state != _automation.automation_state()) {
226 _automation.set_automation_state (state);
229 set_position (_automation.eval (parent.session().transport_frame()));
235 BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
249 if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
251 /* interpolate over 64 frames or nframes, whichever is smaller */
253 nframes_t limit = min ((nframes_t)64, nframes);
256 delta = -(delta / (float) (limit));
258 for (n = 0; n < limit; n++) {
259 left_interp = left_interp + delta;
260 left = left_interp + 0.9 * (left - left_interp);
261 dst[n] += src[n] * left * gain_coeff;
264 pan = left * gain_coeff;
266 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
273 if ((pan = (left * gain_coeff)) != 1.0f) {
277 Session::mix_buffers_with_gain(dst,src,nframes,pan);
279 /* mark that we wrote into the buffer */
287 Session::mix_buffers_no_gain(dst,src,nframes);
289 /* mark that we wrote into the buffer */
299 if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
301 /* interpolate over 64 frames or nframes, whichever is smaller */
303 nframes_t limit = min ((nframes_t)64, nframes);
306 delta = -(delta / (float) (limit));
308 for (n = 0; n < limit; n++) {
309 right_interp = right_interp + delta;
310 right = right_interp + 0.9 * (right - right_interp);
311 dst[n] += src[n] * right * gain_coeff;
314 pan = right * gain_coeff;
316 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
318 /* XXX it would be nice to mark the buffer as written to */
322 right = desired_right;
323 right_interp = right;
325 if ((pan = (right * gain_coeff)) != 1.0f) {
329 Session::mix_buffers_with_gain(dst,src,nframes,pan);
331 /* XXX it would be nice to mark the buffer as written to */
336 Session::mix_buffers_no_gain(dst,src,nframes);
338 /* XXX it would be nice to mark the buffer as written to */
343 /*---------------------------------------------------------------------- */
345 EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
346 : BaseStereoPanner (p)
351 right = desired_right;
353 right_interp = right;
356 EqualPowerStereoPanner::~EqualPowerStereoPanner ()
361 EqualPowerStereoPanner::update ()
363 /* it would be very nice to split this out into a virtual function
364 that can be accessed from BaseStereoPanner and used in distribute_automated().
366 but the place where its used in distribute_automated() is a tight inner loop,
367 and making "nframes" virtual function calls to compute values is an absurd
371 /* x == 0 => hard left
376 float panL = 1 - panR;
378 const float pan_law_attenuation = -3.0f;
379 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
381 desired_left = panL * (scale * panL + 1.0f - scale);
382 desired_right = panR * (scale * panR + 1.0f - scale);
388 EqualPowerStereoPanner::distribute_automated (Sample* src, Sample** obufs,
389 nframes_t start, nframes_t end, nframes_t nframes,
395 /* fetch positional data */
397 if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
400 distribute (src, obufs, 1.0, nframes);
405 /* store effective pan position. do this even if we are muted */
408 effective_x = buffers[0][nframes-1];
414 /* apply pan law to convert positional data into pan coefficients for
418 const float pan_law_attenuation = -3.0f;
419 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
421 for (nframes_t n = 0; n < nframes; ++n) {
423 float panR = buffers[0][n];
424 float panL = 1 - panR;
426 buffers[0][n] = panL * (scale * panL + 1.0f - scale);
427 buffers[1][n] = panR * (scale * panR + 1.0f - scale);
435 for (nframes_t n = 0; n < nframes; ++n) {
436 dst[n] += src[n] * pbuf[n];
439 /* XXX it would be nice to mark the buffer as written to */
446 for (nframes_t n = 0; n < nframes; ++n) {
447 dst[n] += src[n] * pbuf[n];
450 /* XXX it would be nice to mark the buffer as written to */
454 EqualPowerStereoPanner::factory (Panner& parent)
456 return new EqualPowerStereoPanner (parent);
460 EqualPowerStereoPanner::get_state (void)
466 EqualPowerStereoPanner::state (bool full_state)
468 XMLNode* root = new XMLNode ("StreamPanner");
470 LocaleGuard lg (X_("POSIX"));
472 snprintf (buf, sizeof (buf), "%.12g", x);
473 root->add_property (X_("x"), buf);
474 root->add_property (X_("type"), EqualPowerStereoPanner::name);
477 XMLNode* autonode = new XMLNode (X_("Automation"));
478 autonode->add_child_nocopy (_automation.get_state ());
479 root->add_child_nocopy (*autonode);
481 /* never store automation states other than off in a template */
482 snprintf (buf, sizeof (buf), "0x%x", ARDOUR::Off);
485 root->add_property (X_("automation-state"), buf);
486 snprintf (buf, sizeof (buf), "0x%x", _automation.automation_style());
487 root->add_property (X_("automation-style"), buf);
489 StreamPanner::add_state (*root);
490 root->add_child_nocopy (_control.get_state ());
496 EqualPowerStereoPanner::set_state (const XMLNode& node)
498 const XMLProperty* prop;
501 LocaleGuard lg (X_("POSIX"));
503 if ((prop = node.property (X_("x")))) {
504 pos = atof (prop->value().c_str());
505 set_position (pos, true);
508 StreamPanner::set_state (node);
510 for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
511 if ((*iter)->name() == X_("panner")) {
512 _control.set_state (**iter);
513 } else if ((*iter)->name() == X_("Automation")) {
514 _automation.set_state (*((*iter)->children().front()));
518 if ((prop = node.property (X_("automation-state")))) {
519 sscanf (prop->value().c_str(), "0x%x", &x);
520 _automation.set_automation_state ((AutoState) x);
523 set_position (_automation.eval (parent.session().transport_frame()));
527 if ((prop = node.property (X_("automation-style")))) {
528 sscanf (prop->value().c_str(), "0x%x", &x);
529 _automation.set_automation_style ((AutoStyle) x);
535 /*----------------------------------------------------------------------*/
537 Multi2dPanner::Multi2dPanner (Panner& p)
538 : StreamPanner (p), _automation (0.0, 1.0, 0.5) // XXX useless
543 Multi2dPanner::~Multi2dPanner ()
548 Multi2dPanner::snapshot (nframes_t now)
554 Multi2dPanner::transport_stopped (nframes_t frame)
560 Multi2dPanner::set_automation_style (AutoStyle style)
566 Multi2dPanner::set_automation_state (AutoState state)
572 Multi2dPanner::update ()
574 static const float BIAS = FLT_MIN;
576 uint32_t nouts = parent.outputs.size();
583 for (i = 0; i < nouts; i++) {
584 dsq[i] = ((x - parent.outputs[i].x) * (x - parent.outputs[i].x) + (y - parent.outputs[i].y) * (y - parent.outputs[i].y) + BIAS);
588 f += dsq[i] * dsq[i];
591 // terrible hack to support OSX < 10.3.9 builds
592 fr = (float) (1.0 / sqrt((double)f));
596 for (i = 0; i < nouts; ++i) {
597 parent.outputs[i].desired_pan = 1.0f - (dsq[i] * fr);
604 Multi2dPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
608 vector<Panner::Output>::iterator o;
616 for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
621 if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
623 /* interpolate over 64 frames or nframes, whichever is smaller */
625 nframes_t limit = min ((nframes_t)64, nframes);
628 delta = -(delta / (float) (limit));
630 for (n = 0; n < limit; n++) {
631 left_interp = left_interp + delta;
632 left = left_interp + 0.9 * (left - left_interp);
633 dst[n] += src[n] * left * gain_coeff;
636 pan = left * gain_coeff;
638 for (; n < nframes; ++n) {
639 dst[n] += src[n] * pan;
645 pan = (*o).desired_pan;
647 if ((pan *= gain_coeff) != 1.0f) {
651 for (nframes_t n = 0; n < nframes; ++n) {
652 dst[n] += src[n] * pan;
660 for (nframes_t n = 0; n < nframes; ++n) {
675 Multi2dPanner::distribute_automated (Sample* src, Sample** obufs,
676 nframes_t start, nframes_t end, nframes_t nframes,
689 Multi2dPanner::factory (Panner& p)
691 return new Multi2dPanner (p);
695 Multi2dPanner::get_state (void)
701 Multi2dPanner::state (bool full_state)
703 XMLNode* root = new XMLNode ("StreamPanner");
705 LocaleGuard lg (X_("POSIX"));
707 snprintf (buf, sizeof (buf), "%.12g", x);
708 root->add_property (X_("x"), buf);
709 snprintf (buf, sizeof (buf), "%.12g", y);
710 root->add_property (X_("y"), buf);
711 root->add_property (X_("type"), Multi2dPanner::name);
713 /* XXX no meaningful automation yet */
719 Multi2dPanner::set_state (const XMLNode& node)
721 const XMLProperty* prop;
723 LocaleGuard lg (X_("POSIX"));
728 if ((prop = node.property (X_("x")))) {
729 newx = atof (prop->value().c_str());
732 if ((prop = node.property (X_("y")))) {
733 newy = atof (prop->value().c_str());
736 if (x < 0 || y < 0) {
737 error << _("badly-formed positional data for Multi2dPanner - ignored")
742 set_position (newx, newy);
746 /*---------------------------------------------------------------------- */
748 Panner::Panner (string name, Session& s)
752 _link_direction = SameDirection;
761 Panner::set_linked (bool yn)
765 _session.set_dirty ();
766 LinkStateChanged (); /* EMIT SIGNAL */
771 Panner::set_link_direction (LinkDirection ld)
773 if (ld != _link_direction) {
774 _link_direction = ld;
775 _session.set_dirty ();
776 LinkStateChanged (); /* EMIT SIGNAL */
781 Panner::set_bypassed (bool yn)
783 if (yn != _bypassed) {
791 Panner::reset (uint32_t nouts, uint32_t npans)
794 bool changed = false;
796 if (nouts < 2 || (nouts == outputs.size() && npans == size())) {
819 fatal << _("programming error:")
820 << X_("Panner::reset() called with a single output")
827 outputs.push_back (Output (0, 0));
828 outputs.push_back (Output (1.0, 0));
830 for (n = 0; n < npans; ++n) {
831 push_back (new EqualPowerStereoPanner (*this));
836 outputs.push_back (Output (0.5, 0));
837 outputs.push_back (Output (0, 1.0));
838 outputs.push_back (Output (1.0, 1.0));
840 for (n = 0; n < npans; ++n) {
841 push_back (new Multi2dPanner (*this));
847 outputs.push_back (Output (0, 0));
848 outputs.push_back (Output (1.0, 0));
849 outputs.push_back (Output (1.0, 1.0));
850 outputs.push_back (Output (0, 1.0));
852 for (n = 0; n < npans; ++n) {
853 push_back (new Multi2dPanner (*this));
858 case 5: //square+offcenter center
859 outputs.push_back (Output (0, 0));
860 outputs.push_back (Output (1.0, 0));
861 outputs.push_back (Output (1.0, 1.0));
862 outputs.push_back (Output (0, 1.0));
863 outputs.push_back (Output (0.5, 0.75));
865 for (n = 0; n < npans; ++n) {
866 push_back (new Multi2dPanner (*this));
872 /* XXX horrible placement. FIXME */
873 for (n = 0; n < nouts; ++n) {
874 outputs.push_back (Output (0.1 * n, 0.1 * n));
877 for (n = 0; n < npans; ++n) {
878 push_back (new Multi2dPanner (*this));
884 for (iterator x = begin(); x != end(); ++x) {
888 /* force hard left/right panning in a common case: 2in/2out
891 if (npans == 2 && outputs.size() == 2) {
893 /* Do this only if we changed configuration, or our configuration
894 appears to be the default set up (center).
900 front()->get_position (left);
901 back()->get_position (right);
903 if (changed || ((left == 0.5) && (right == 0.5))) {
905 front()->set_position (0.0);
906 front()->automation().reset_default (0.0);
908 back()->set_position (1.0);
909 back()->automation().reset_default (1.0);
916 Changed (); /* EMIT SIGNAL */
923 Panner::remove (uint32_t which)
925 vector<StreamPanner*>::iterator i;
926 for (i = begin(); i != end() && which; ++i, --which);
937 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
941 vector<StreamPanner*>::clear ();
945 Panner::set_automation_style (AutoStyle style)
947 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
948 (*i)->set_automation_style (style);
950 _session.set_dirty ();
954 Panner::set_automation_state (AutoState state)
956 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
957 (*i)->set_automation_state (state);
959 _session.set_dirty ();
963 Panner::automation_state () const
966 return front()->automation().automation_state ();
973 Panner::automation_style () const
976 return front()->automation().automation_style ();
983 Panner::transport_stopped (nframes_t frame)
985 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
986 (*i)->transport_stopped (frame);
991 Panner::snapshot (nframes_t now)
993 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
994 (*i)->snapshot (now);
999 Panner::clear_automation ()
1001 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1002 (*i)->automation().clear ();
1004 _session.set_dirty ();
1010 StreamPanner* (*factory)(Panner&);
1013 PanPlugins pan_plugins[] = {
1014 { EqualPowerStereoPanner::name, 2, EqualPowerStereoPanner::factory },
1015 { Multi2dPanner::name, 3, Multi2dPanner::factory },
1016 { string (""), 0, 0 }
1020 Panner::get_state (void)
1022 return state (true);
1026 Panner::state (bool full)
1028 XMLNode* root = new XMLNode (X_("Panner"));
1031 root->add_property (X_("linked"), (_linked ? "yes" : "no"));
1032 snprintf (buf, sizeof (buf), "%d", _link_direction);
1033 root->add_property (X_("link_direction"), buf);
1034 root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
1036 /* add each output */
1038 for (vector<Panner::Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
1039 XMLNode* onode = new XMLNode (X_("Output"));
1040 snprintf (buf, sizeof (buf), "%.12g", (*o).x);
1041 onode->add_property (X_("x"), buf);
1042 snprintf (buf, sizeof (buf), "%.12g", (*o).y);
1043 onode->add_property (X_("y"), buf);
1044 root->add_child_nocopy (*onode);
1047 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1048 root->add_child_nocopy ((*i)->state (full));
1055 Panner::set_state (const XMLNode& node)
1058 XMLNodeConstIterator niter;
1059 const XMLProperty *prop;
1062 LocaleGuard lg (X_("POSIX"));
1067 if ((prop = node.property (X_("linked"))) != 0) {
1068 set_linked (prop->value() == "yes");
1072 if ((prop = node.property (X_("bypassed"))) != 0) {
1073 set_bypassed (prop->value() == "yes");
1076 if ((prop = node.property (X_("link_direction"))) != 0) {
1077 sscanf (prop->value().c_str(), "%d", &i);
1078 set_link_direction ((LinkDirection) (i));
1081 nlist = node.children();
1083 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1084 if ((*niter)->name() == X_("Output")) {
1088 prop = (*niter)->property (X_("x"));
1089 sscanf (prop->value().c_str(), "%g", &x);
1091 prop = (*niter)->property (X_("y"));
1092 sscanf (prop->value().c_str(), "%g", &y);
1094 outputs.push_back (Output (x, y));
1098 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1100 if ((*niter)->name() == X_("StreamPanner")) {
1102 if ((prop = (*niter)->property (X_("type")))) {
1104 for (i = 0; pan_plugins[i].factory; ++i) {
1105 if (prop->value() == pan_plugins[i].name) {
1108 /* note that we assume that all the stream panners
1109 are of the same type. pretty good
1110 assumption, but its still an assumption.
1113 sp = pan_plugins[i].factory (*this);
1115 if (sp->set_state (**niter) == 0) {
1124 if (!pan_plugins[i].factory) {
1125 error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
1131 error << _("panner plugin node has no type information!")
1145 Panner::touching () const
1147 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1148 if ((*i)->automation().touching ()) {
1157 Panner::set_position (float xpos, StreamPanner& orig)
1163 orig.get_position (xnow);
1164 xdelta = xpos - xnow;
1166 if (_link_direction == SameDirection) {
1168 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1170 (*i)->set_position (xpos, true);
1172 (*i)->get_position (xnow);
1173 xnew = min (1.0f, xnow + xdelta);
1174 xnew = max (0.0f, xnew);
1175 (*i)->set_position (xnew, true);
1181 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1183 (*i)->set_position (xpos, true);
1185 (*i)->get_position (xnow);
1186 xnew = min (1.0f, xnow - xdelta);
1187 xnew = max (0.0f, xnew);
1188 (*i)->set_position (xnew, true);
1195 Panner::set_position (float xpos, float ypos, StreamPanner& orig)
1198 float xdelta, ydelta;
1201 orig.get_position (xnow, ynow);
1202 xdelta = xpos - xnow;
1203 ydelta = ypos - ynow;
1205 if (_link_direction == SameDirection) {
1207 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1209 (*i)->set_position (xpos, ypos, true);
1211 (*i)->get_position (xnow, ynow);
1213 xnew = min (1.0f, xnow + xdelta);
1214 xnew = max (0.0f, xnew);
1216 ynew = min (1.0f, ynow + ydelta);
1217 ynew = max (0.0f, ynew);
1219 (*i)->set_position (xnew, ynew, true);
1225 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1227 (*i)->set_position (xpos, ypos, true);
1229 (*i)->get_position (xnow, ynow);
1231 xnew = min (1.0f, xnow - xdelta);
1232 xnew = max (0.0f, xnew);
1234 ynew = min (1.0f, ynow - ydelta);
1235 ynew = max (0.0f, ynew);
1237 (*i)->set_position (xnew, ynew, true);
1244 Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
1246 float xnow, ynow, znow;
1247 float xdelta, ydelta, zdelta;
1248 float xnew, ynew, znew;
1250 orig.get_position (xnow, ynow, znow);
1251 xdelta = xpos - xnow;
1252 ydelta = ypos - ynow;
1253 zdelta = zpos - znow;
1255 if (_link_direction == SameDirection) {
1257 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1259 (*i)->set_position (xpos, ypos, zpos, true);
1261 (*i)->get_position (xnow, ynow, znow);
1263 xnew = min (1.0f, xnow + xdelta);
1264 xnew = max (0.0f, xnew);
1266 ynew = min (1.0f, ynow + ydelta);
1267 ynew = max (0.0f, ynew);
1269 znew = min (1.0f, znow + zdelta);
1270 znew = max (0.0f, znew);
1272 (*i)->set_position (xnew, ynew, znew, true);
1278 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1280 (*i)->set_position (xpos, ypos, true);
1282 (*i)->get_position (xnow, ynow, znow);
1284 xnew = min (1.0f, xnow - xdelta);
1285 xnew = max (0.0f, xnew);
1287 ynew = min (1.0f, ynow - ydelta);
1288 ynew = max (0.0f, ynew);
1290 znew = min (1.0f, znow + zdelta);
1291 znew = max (0.0f, znew);
1293 (*i)->set_position (xnew, ynew, znew, true);