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>
36 #include <pbd/enumwriter.h>
38 #include <ardour/session.h>
39 #include <ardour/panner.h>
40 #include <ardour/utils.h>
42 #include <ardour/mix.h>
46 #include <pbd/mathfix.h>
49 using namespace ARDOUR;
52 float Panner::current_automation_version_number = 1.0;
54 string EqualPowerStereoPanner::name = "Equal Power Stereo";
55 string Multi2dPanner::name = "Multiple (2D)";
57 /* this is a default mapper of control values to a pan position
58 others can be imagined.
61 static pan_t direct_control_to_pan (double fract) {
65 static double direct_pan_to_control (pan_t val) {
69 StreamPanner::StreamPanner (Panner& p)
71 _control (X_("panner"), *this)
75 parent.session().add_controllable (&_control);
82 StreamPanner::~StreamPanner ()
87 StreamPanner::PanControllable::set_value (float val)
89 panner.set_position (direct_control_to_pan (val));
93 StreamPanner::PanControllable::get_value (void) const
96 panner.get_effective_position (xpos);
97 return direct_pan_to_control (xpos);
101 StreamPanner::PanControllable::can_send_feedback () const
103 AutoState astate = panner.get_parent().automation_state ();
105 if ((astate == Play) || (astate == Touch && !panner.get_parent().touching())) {
113 StreamPanner::set_muted (bool yn)
122 StreamPanner::set_position (float xpos, bool link_call)
124 if (!link_call && parent.linked()) {
125 parent.set_position (xpos, *this);
137 StreamPanner::set_position (float xpos, float ypos, bool link_call)
139 if (!link_call && parent.linked()) {
140 parent.set_position (xpos, ypos, *this);
143 if (x != xpos || y != ypos) {
153 StreamPanner::set_position (float xpos, float ypos, float zpos, bool link_call)
155 if (!link_call && parent.linked()) {
156 parent.set_position (xpos, ypos, zpos, *this);
159 if (x != xpos || y != ypos || z != zpos) {
169 StreamPanner::set_state (const XMLNode& node)
171 const XMLProperty* prop;
172 XMLNodeConstIterator iter;
174 if ((prop = node.property (X_("muted")))) {
175 set_muted (prop->value() == "yes");
182 StreamPanner::add_state (XMLNode& node)
184 node.add_property (X_("muted"), (muted() ? "yes" : "no"));
187 /*---------------------------------------------------------------------- */
189 BaseStereoPanner::BaseStereoPanner (Panner& p)
190 : StreamPanner (p), _automation (0.0, 1.0, 0.5)
194 BaseStereoPanner::~BaseStereoPanner ()
199 BaseStereoPanner::snapshot (nframes_t now)
201 if (_automation.automation_state() == Write || _automation.automation_state() == Touch) {
202 _automation.rt_add (now, x);
207 BaseStereoPanner::transport_stopped (nframes_t frame)
209 _automation.reposition_for_rt_add (frame);
211 if (_automation.automation_state() != Off) {
212 set_position (_automation.eval (frame));
217 BaseStereoPanner::set_automation_style (AutoStyle style)
219 _automation.set_automation_style (style);
223 BaseStereoPanner::set_automation_state (AutoState state)
225 if (state != _automation.automation_state()) {
227 _automation.set_automation_state (state);
230 set_position (_automation.eval (parent.session().transport_frame()));
236 BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
239 LocaleGuard lg (X_("POSIX"));
241 _automation.clear ();
243 while (in.getline (line, sizeof (line), '\n')) {
249 if (strcmp (line, "end") == 0) {
253 if (sscanf (line, "%" PRIu32 " %lf", &when, &value) != 2) {
254 warning << string_compose(_("badly formatted pan automation event record at line %1 of %2 (ignored) [%3]"), linecnt, path, line) << endmsg;
258 _automation.fast_simple_add (when, value);
261 /* now that we are done loading */
263 _automation.StateChanged ();
269 BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
283 if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
285 /* interpolate over 64 frames or nframes, whichever is smaller */
287 nframes_t limit = min ((nframes_t)64, nframes);
290 delta = -(delta / (float) (limit));
292 for (n = 0; n < limit; n++) {
293 left_interp = left_interp + delta;
294 left = left_interp + 0.9 * (left - left_interp);
295 dst[n] += src[n] * left * gain_coeff;
298 pan = left * gain_coeff;
300 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
307 if ((pan = (left * gain_coeff)) != 1.0f) {
311 Session::mix_buffers_with_gain(dst,src,nframes,pan);
313 /* mark that we wrote into the buffer */
321 Session::mix_buffers_no_gain(dst,src,nframes);
323 /* mark that we wrote into the buffer */
333 if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
335 /* interpolate over 64 frames or nframes, whichever is smaller */
337 nframes_t limit = min ((nframes_t)64, nframes);
340 delta = -(delta / (float) (limit));
342 for (n = 0; n < limit; n++) {
343 right_interp = right_interp + delta;
344 right = right_interp + 0.9 * (right - right_interp);
345 dst[n] += src[n] * right * gain_coeff;
348 pan = right * gain_coeff;
350 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
352 /* XXX it would be nice to mark the buffer as written to */
356 right = desired_right;
357 right_interp = right;
359 if ((pan = (right * gain_coeff)) != 1.0f) {
363 Session::mix_buffers_with_gain(dst,src,nframes,pan);
365 /* XXX it would be nice to mark the buffer as written to */
370 Session::mix_buffers_no_gain(dst,src,nframes);
372 /* XXX it would be nice to mark the buffer as written to */
377 /*---------------------------------------------------------------------- */
379 EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
380 : BaseStereoPanner (p)
385 right = desired_right;
387 right_interp = right;
390 EqualPowerStereoPanner::~EqualPowerStereoPanner ()
395 EqualPowerStereoPanner::update ()
397 /* it would be very nice to split this out into a virtual function
398 that can be accessed from BaseStereoPanner and used in distribute_automated().
400 but the place where its used in distribute_automated() is a tight inner loop,
401 and making "nframes" virtual function calls to compute values is an absurd
405 /* x == 0 => hard left
410 float panL = 1 - panR;
412 const float pan_law_attenuation = -3.0f;
413 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
415 desired_left = panL * (scale * panL + 1.0f - scale);
416 desired_right = panR * (scale * panR + 1.0f - scale);
422 EqualPowerStereoPanner::distribute_automated (Sample* src, Sample** obufs,
423 nframes_t start, nframes_t end, nframes_t nframes,
429 /* fetch positional data */
431 if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
434 distribute (src, obufs, 1.0, nframes);
439 /* store effective pan position. do this even if we are muted */
442 effective_x = buffers[0][nframes-1];
448 /* apply pan law to convert positional data into pan coefficients for
452 const float pan_law_attenuation = -3.0f;
453 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
455 for (nframes_t n = 0; n < nframes; ++n) {
457 float panR = buffers[0][n];
458 float panL = 1 - panR;
460 buffers[0][n] = panL * (scale * panL + 1.0f - scale);
461 buffers[1][n] = panR * (scale * panR + 1.0f - scale);
469 for (nframes_t n = 0; n < nframes; ++n) {
470 dst[n] += src[n] * pbuf[n];
473 /* XXX it would be nice to mark the buffer as written to */
480 for (nframes_t n = 0; n < nframes; ++n) {
481 dst[n] += src[n] * pbuf[n];
484 /* XXX it would be nice to mark the buffer as written to */
488 EqualPowerStereoPanner::factory (Panner& parent)
490 return new EqualPowerStereoPanner (parent);
494 EqualPowerStereoPanner::get_state (void)
500 EqualPowerStereoPanner::state (bool full_state)
502 XMLNode* root = new XMLNode ("StreamPanner");
504 LocaleGuard lg (X_("POSIX"));
506 snprintf (buf, sizeof (buf), "%.12g", x);
507 root->add_property (X_("x"), buf);
508 root->add_property (X_("type"), EqualPowerStereoPanner::name);
510 XMLNode* autonode = new XMLNode (X_("Automation"));
511 autonode->add_child_nocopy (_automation.state (full_state));
512 root->add_child_nocopy (*autonode);
514 StreamPanner::add_state (*root);
516 root->add_child_nocopy (_control.get_state ());
522 EqualPowerStereoPanner::set_state (const XMLNode& node)
524 const XMLProperty* prop;
526 LocaleGuard lg (X_("POSIX"));
528 if ((prop = node.property (X_("x")))) {
529 pos = atof (prop->value().c_str());
530 set_position (pos, true);
533 StreamPanner::set_state (node);
535 for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
537 if ((*iter)->name() == X_("panner")) {
539 _control.set_state (**iter);
541 } else if ((*iter)->name() == X_("Automation")) {
543 _automation.set_state (*((*iter)->children().front()));
545 if (_automation.automation_state() != Off) {
546 set_position (_automation.eval (parent.session().transport_frame()));
554 /*----------------------------------------------------------------------*/
556 Multi2dPanner::Multi2dPanner (Panner& p)
557 : StreamPanner (p), _automation (0.0, 1.0, 0.5) // XXX useless
562 Multi2dPanner::~Multi2dPanner ()
567 Multi2dPanner::snapshot (nframes_t now)
573 Multi2dPanner::transport_stopped (nframes_t frame)
579 Multi2dPanner::set_automation_style (AutoStyle style)
585 Multi2dPanner::set_automation_state (AutoState state)
591 Multi2dPanner::update ()
593 static const float BIAS = FLT_MIN;
595 uint32_t nouts = parent.outputs.size();
602 for (i = 0; i < nouts; i++) {
603 dsq[i] = ((x - parent.outputs[i].x) * (x - parent.outputs[i].x) + (y - parent.outputs[i].y) * (y - parent.outputs[i].y) + BIAS);
607 f += dsq[i] * dsq[i];
610 // terrible hack to support OSX < 10.3.9 builds
611 fr = (float) (1.0 / sqrt((double)f));
615 for (i = 0; i < nouts; ++i) {
616 parent.outputs[i].desired_pan = 1.0f - (dsq[i] * fr);
623 Multi2dPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
627 vector<Panner::Output>::iterator o;
635 for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
640 if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
642 /* interpolate over 64 frames or nframes, whichever is smaller */
644 nframes_t limit = min ((nframes_t)64, nframes);
647 delta = -(delta / (float) (limit));
649 for (n = 0; n < limit; n++) {
650 left_interp = left_interp + delta;
651 left = left_interp + 0.9 * (left - left_interp);
652 dst[n] += src[n] * left * gain_coeff;
655 pan = left * gain_coeff;
657 for (; n < nframes; ++n) {
658 dst[n] += src[n] * pan;
664 pan = (*o).desired_pan;
666 if ((pan *= gain_coeff) != 1.0f) {
670 for (nframes_t n = 0; n < nframes; ++n) {
671 dst[n] += src[n] * pan;
679 for (nframes_t n = 0; n < nframes; ++n) {
694 Multi2dPanner::distribute_automated (Sample* src, Sample** obufs,
695 nframes_t start, nframes_t end, nframes_t nframes,
708 Multi2dPanner::factory (Panner& p)
710 return new Multi2dPanner (p);
714 Multi2dPanner::load (istream& in, string path, uint32_t& linecnt)
720 Multi2dPanner::get_state (void)
726 Multi2dPanner::state (bool full_state)
728 XMLNode* root = new XMLNode ("StreamPanner");
730 LocaleGuard lg (X_("POSIX"));
732 snprintf (buf, sizeof (buf), "%.12g", x);
733 root->add_property (X_("x"), buf);
734 snprintf (buf, sizeof (buf), "%.12g", y);
735 root->add_property (X_("y"), buf);
736 root->add_property (X_("type"), Multi2dPanner::name);
738 /* XXX no meaningful automation yet */
744 Multi2dPanner::set_state (const XMLNode& node)
746 const XMLProperty* prop;
748 LocaleGuard lg (X_("POSIX"));
753 if ((prop = node.property (X_("x")))) {
754 newx = atof (prop->value().c_str());
757 if ((prop = node.property (X_("y")))) {
758 newy = atof (prop->value().c_str());
761 if (x < 0 || y < 0) {
762 error << _("badly-formed positional data for Multi2dPanner - ignored")
767 set_position (newx, newy);
771 /*---------------------------------------------------------------------- */
773 Panner::Panner (string name, Session& s)
779 _link_direction = SameDirection;
788 Panner::set_linked (bool yn)
792 _session.set_dirty ();
793 LinkStateChanged (); /* EMIT SIGNAL */
798 Panner::set_link_direction (LinkDirection ld)
800 if (ld != _link_direction) {
801 _link_direction = ld;
802 _session.set_dirty ();
803 LinkStateChanged (); /* EMIT SIGNAL */
808 Panner::set_bypassed (bool yn)
810 if (yn != _bypassed) {
818 Panner::reset (uint32_t nouts, uint32_t npans)
821 bool changed = false;
823 if (nouts < 2 || (nouts == outputs.size() && npans == size())) {
846 fatal << _("programming error:")
847 << X_("Panner::reset() called with a single output")
854 outputs.push_back (Output (0, 0));
855 outputs.push_back (Output (1.0, 0));
857 for (n = 0; n < npans; ++n) {
858 push_back (new EqualPowerStereoPanner (*this));
863 outputs.push_back (Output (0.5, 0));
864 outputs.push_back (Output (0, 1.0));
865 outputs.push_back (Output (1.0, 1.0));
867 for (n = 0; n < npans; ++n) {
868 push_back (new Multi2dPanner (*this));
874 outputs.push_back (Output (0, 0));
875 outputs.push_back (Output (1.0, 0));
876 outputs.push_back (Output (1.0, 1.0));
877 outputs.push_back (Output (0, 1.0));
879 for (n = 0; n < npans; ++n) {
880 push_back (new Multi2dPanner (*this));
885 case 5: //square+offcenter center
886 outputs.push_back (Output (0, 0));
887 outputs.push_back (Output (1.0, 0));
888 outputs.push_back (Output (1.0, 1.0));
889 outputs.push_back (Output (0, 1.0));
890 outputs.push_back (Output (0.5, 0.75));
892 for (n = 0; n < npans; ++n) {
893 push_back (new Multi2dPanner (*this));
899 /* XXX horrible placement. FIXME */
900 for (n = 0; n < nouts; ++n) {
901 outputs.push_back (Output (0.1 * n, 0.1 * n));
904 for (n = 0; n < npans; ++n) {
905 push_back (new Multi2dPanner (*this));
911 for (iterator x = begin(); x != end(); ++x) {
915 /* force hard left/right panning in a common case: 2in/2out
918 if (npans == 2 && outputs.size() == 2) {
920 /* Do this only if we changed configuration, or our configuration
921 appears to be the default set up (center).
927 front()->get_position (left);
928 back()->get_position (right);
930 if (changed || ((left == 0.5) && (right == 0.5))) {
932 front()->set_position (0.0);
933 front()->automation().reset_default (0.0);
935 back()->set_position (1.0);
936 back()->automation().reset_default (1.0);
943 Changed (); /* EMIT SIGNAL */
950 Panner::remove (uint32_t which)
952 vector<StreamPanner*>::iterator i;
953 for (i = begin(); i != end() && which; ++i, --which);
964 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
968 vector<StreamPanner*>::clear ();
972 Panner::set_automation_style (AutoStyle style)
974 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
975 (*i)->set_automation_style (style);
977 _session.set_dirty ();
981 Panner::set_automation_state (AutoState state)
983 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
984 (*i)->set_automation_state (state);
986 _session.set_dirty ();
990 Panner::automation_state () const
993 return front()->automation().automation_state ();
1000 Panner::automation_style () const
1003 return front()->automation().automation_style ();
1010 Panner::transport_stopped (nframes_t frame)
1012 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1013 (*i)->transport_stopped (frame);
1018 Panner::snapshot (nframes_t now)
1020 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1021 (*i)->snapshot (now);
1026 Panner::clear_automation ()
1028 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1029 (*i)->automation().clear ();
1031 _session.set_dirty ();
1037 StreamPanner* (*factory)(Panner&);
1040 PanPlugins pan_plugins[] = {
1041 { EqualPowerStereoPanner::name, 2, EqualPowerStereoPanner::factory },
1042 { Multi2dPanner::name, 3, Multi2dPanner::factory },
1043 { string (""), 0, 0 }
1047 Panner::get_state (void)
1049 return state (true);
1053 Panner::state (bool full)
1055 XMLNode* root = new XMLNode (X_("Panner"));
1058 root->add_property (X_("linked"), (_linked ? "yes" : "no"));
1059 root->add_property (X_("link_direction"), enum_2_string (_link_direction));
1060 root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
1062 /* add each output */
1064 for (vector<Panner::Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
1065 XMLNode* onode = new XMLNode (X_("Output"));
1066 snprintf (buf, sizeof (buf), "%.12g", (*o).x);
1067 onode->add_property (X_("x"), buf);
1068 snprintf (buf, sizeof (buf), "%.12g", (*o).y);
1069 onode->add_property (X_("y"), buf);
1070 root->add_child_nocopy (*onode);
1073 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1074 root->add_child_nocopy ((*i)->state (full));
1081 Panner::set_state (const XMLNode& node)
1084 XMLNodeConstIterator niter;
1085 const XMLProperty *prop;
1088 LocaleGuard lg (X_("POSIX"));
1093 if ((prop = node.property (X_("linked"))) != 0) {
1094 set_linked (prop->value() == "yes");
1098 if ((prop = node.property (X_("bypassed"))) != 0) {
1099 set_bypassed (prop->value() == "yes");
1102 if ((prop = node.property (X_("link_direction"))) != 0) {
1103 LinkDirection ld; /* here to provide type information */
1104 set_link_direction (LinkDirection (string_2_enum (prop->value(), ld)));
1107 nlist = node.children();
1109 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1110 if ((*niter)->name() == X_("Output")) {
1114 prop = (*niter)->property (X_("x"));
1115 sscanf (prop->value().c_str(), "%g", &x);
1117 prop = (*niter)->property (X_("y"));
1118 sscanf (prop->value().c_str(), "%g", &y);
1120 outputs.push_back (Output (x, y));
1124 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1126 if ((*niter)->name() == X_("StreamPanner")) {
1128 if ((prop = (*niter)->property (X_("type")))) {
1130 for (i = 0; pan_plugins[i].factory; ++i) {
1131 if (prop->value() == pan_plugins[i].name) {
1134 /* note that we assume that all the stream panners
1135 are of the same type. pretty good
1136 assumption, but its still an assumption.
1139 sp = pan_plugins[i].factory (*this);
1141 if (sp->set_state (**niter) == 0) {
1150 if (!pan_plugins[i].factory) {
1151 error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
1157 error << _("panner plugin node has no type information!")
1165 /* don't try to do old-school automation loading if it wasn't marked as existing */
1167 if ((prop = node.property (X_("automation")))) {
1169 /* automation path is relative */
1171 automation_path = _session.automation_dir();
1172 automation_path += prop->value ();
1181 Panner::touching () const
1183 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1184 if ((*i)->automation().touching ()) {
1193 Panner::set_position (float xpos, StreamPanner& orig)
1199 orig.get_position (xnow);
1200 xdelta = xpos - xnow;
1202 if (_link_direction == SameDirection) {
1204 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1206 (*i)->set_position (xpos, true);
1208 (*i)->get_position (xnow);
1209 xnew = min (1.0f, xnow + xdelta);
1210 xnew = max (0.0f, xnew);
1211 (*i)->set_position (xnew, true);
1217 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1219 (*i)->set_position (xpos, true);
1221 (*i)->get_position (xnow);
1222 xnew = min (1.0f, xnow - xdelta);
1223 xnew = max (0.0f, xnew);
1224 (*i)->set_position (xnew, true);
1231 Panner::set_position (float xpos, float ypos, StreamPanner& orig)
1234 float xdelta, ydelta;
1237 orig.get_position (xnow, ynow);
1238 xdelta = xpos - xnow;
1239 ydelta = ypos - ynow;
1241 if (_link_direction == SameDirection) {
1243 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1245 (*i)->set_position (xpos, ypos, true);
1247 (*i)->get_position (xnow, ynow);
1249 xnew = min (1.0f, xnow + xdelta);
1250 xnew = max (0.0f, xnew);
1252 ynew = min (1.0f, ynow + ydelta);
1253 ynew = max (0.0f, ynew);
1255 (*i)->set_position (xnew, ynew, true);
1261 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1263 (*i)->set_position (xpos, ypos, true);
1265 (*i)->get_position (xnow, ynow);
1267 xnew = min (1.0f, xnow - xdelta);
1268 xnew = max (0.0f, xnew);
1270 ynew = min (1.0f, ynow - ydelta);
1271 ynew = max (0.0f, ynew);
1273 (*i)->set_position (xnew, ynew, true);
1280 Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
1282 float xnow, ynow, znow;
1283 float xdelta, ydelta, zdelta;
1284 float xnew, ynew, znew;
1286 orig.get_position (xnow, ynow, znow);
1287 xdelta = xpos - xnow;
1288 ydelta = ypos - ynow;
1289 zdelta = zpos - znow;
1291 if (_link_direction == SameDirection) {
1293 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1295 (*i)->set_position (xpos, ypos, zpos, true);
1297 (*i)->get_position (xnow, ynow, znow);
1299 xnew = min (1.0f, xnow + xdelta);
1300 xnew = max (0.0f, xnew);
1302 ynew = min (1.0f, ynow + ydelta);
1303 ynew = max (0.0f, ynew);
1305 znew = min (1.0f, znow + zdelta);
1306 znew = max (0.0f, znew);
1308 (*i)->set_position (xnew, ynew, znew, true);
1314 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1316 (*i)->set_position (xpos, ypos, true);
1318 (*i)->get_position (xnow, ynow, znow);
1320 xnew = min (1.0f, xnow - xdelta);
1321 xnew = max (0.0f, xnew);
1323 ynew = min (1.0f, ynow - ydelta);
1324 ynew = max (0.0f, ynew);
1326 znew = min (1.0f, znow + zdelta);
1327 znew = max (0.0f, znew);
1329 (*i)->set_position (xnew, ynew, znew, true);
1335 /* old school automation handling */
1338 Panner::set_name (string str)
1340 automation_path = _session.automation_dir();
1341 automation_path += _session.snap_name();
1342 automation_path += "-pan-";
1343 automation_path += legalize_for_path (str);
1344 automation_path += ".automation";
1351 uint32_t linecnt = 0;
1354 LocaleGuard lg (X_("POSIX"));
1356 if (automation_path.length() == 0) {
1360 if (access (automation_path.c_str(), F_OK)) {
1364 ifstream in (automation_path.c_str());
1367 error << string_compose (_("cannot open pan automation file %1 (%2)"),
1368 automation_path, strerror (errno))
1375 while (in.getline (line, sizeof(line), '\n')) {
1377 if (++linecnt == 1) {
1378 if (memcmp (line, X_("version"), 7) == 0) {
1379 if (sscanf (line, "version %f", &version) != 1) {
1380 error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg;
1384 error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"),
1385 automation_path, line) << endmsg;
1392 if (strlen (line) == 0 || line[0] == '#') {
1396 if (strcmp (line, "begin") == 0) {
1399 error << string_compose (_("too many panner states found in pan automation file %1"),
1405 if ((*sp)->load (in, automation_path, linecnt)) {