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.
32 #include <pbd/error.h>
33 #include <pbd/failed_constructor.h>
34 #include <pbd/xml++.h>
35 #include <pbd/enumwriter.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::load (istream& in, string path, uint32_t& linecnt)
238 LocaleGuard lg (X_("POSIX"));
240 _automation.clear ();
242 while (in.getline (line, sizeof (line), '\n')) {
248 if (strcmp (line, "end") == 0) {
252 if (sscanf (line, "%" PRIu32 " %lf", &when, &value) != 2) {
253 warning << string_compose(_("badly formatted pan automation event record at line %1 of %2 (ignored) [%3]"), linecnt, path, line) << endmsg;
257 _automation.fast_simple_add (when, value);
260 /* now that we are done loading */
262 _automation.StateChanged ();
268 BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
282 if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
284 /* interpolate over 64 frames or nframes, whichever is smaller */
286 nframes_t limit = min ((nframes_t)64, nframes);
289 delta = -(delta / (float) (limit));
291 for (n = 0; n < limit; n++) {
292 left_interp = left_interp + delta;
293 left = left_interp + 0.9 * (left - left_interp);
294 dst[n] += src[n] * left * gain_coeff;
297 pan = left * gain_coeff;
299 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
306 if ((pan = (left * gain_coeff)) != 1.0f) {
310 Session::mix_buffers_with_gain(dst,src,nframes,pan);
312 /* mark that we wrote into the buffer */
320 Session::mix_buffers_no_gain(dst,src,nframes);
322 /* mark that we wrote into the buffer */
332 if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
334 /* interpolate over 64 frames or nframes, whichever is smaller */
336 nframes_t limit = min ((nframes_t)64, nframes);
339 delta = -(delta / (float) (limit));
341 for (n = 0; n < limit; n++) {
342 right_interp = right_interp + delta;
343 right = right_interp + 0.9 * (right - right_interp);
344 dst[n] += src[n] * right * gain_coeff;
347 pan = right * gain_coeff;
349 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
351 /* XXX it would be nice to mark the buffer as written to */
355 right = desired_right;
356 right_interp = right;
358 if ((pan = (right * gain_coeff)) != 1.0f) {
362 Session::mix_buffers_with_gain(dst,src,nframes,pan);
364 /* XXX it would be nice to mark the buffer as written to */
369 Session::mix_buffers_no_gain(dst,src,nframes);
371 /* XXX it would be nice to mark the buffer as written to */
376 /*---------------------------------------------------------------------- */
378 EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
379 : BaseStereoPanner (p)
384 right = desired_right;
386 right_interp = right;
389 EqualPowerStereoPanner::~EqualPowerStereoPanner ()
394 EqualPowerStereoPanner::update ()
396 /* it would be very nice to split this out into a virtual function
397 that can be accessed from BaseStereoPanner and used in distribute_automated().
399 but the place where its used in distribute_automated() is a tight inner loop,
400 and making "nframes" virtual function calls to compute values is an absurd
404 /* x == 0 => hard left
409 float panL = 1 - panR;
411 const float pan_law_attenuation = -3.0f;
412 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
414 desired_left = panL * (scale * panL + 1.0f - scale);
415 desired_right = panR * (scale * panR + 1.0f - scale);
421 EqualPowerStereoPanner::distribute_automated (Sample* src, Sample** obufs,
422 nframes_t start, nframes_t end, nframes_t nframes,
428 /* fetch positional data */
430 if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
433 distribute (src, obufs, 1.0, nframes);
438 /* store effective pan position. do this even if we are muted */
441 effective_x = buffers[0][nframes-1];
447 /* apply pan law to convert positional data into pan coefficients for
451 const float pan_law_attenuation = -3.0f;
452 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
454 for (nframes_t n = 0; n < nframes; ++n) {
456 float panR = buffers[0][n];
457 float panL = 1 - panR;
459 buffers[0][n] = panL * (scale * panL + 1.0f - scale);
460 buffers[1][n] = panR * (scale * panR + 1.0f - scale);
468 for (nframes_t n = 0; n < nframes; ++n) {
469 dst[n] += src[n] * pbuf[n];
472 /* XXX it would be nice to mark the buffer as written to */
479 for (nframes_t n = 0; n < nframes; ++n) {
480 dst[n] += src[n] * pbuf[n];
483 /* XXX it would be nice to mark the buffer as written to */
487 EqualPowerStereoPanner::factory (Panner& parent)
489 return new EqualPowerStereoPanner (parent);
493 EqualPowerStereoPanner::get_state (void)
499 EqualPowerStereoPanner::state (bool full_state)
501 XMLNode* root = new XMLNode ("StreamPanner");
503 LocaleGuard lg (X_("POSIX"));
505 snprintf (buf, sizeof (buf), "%.12g", x);
506 root->add_property (X_("x"), buf);
507 root->add_property (X_("type"), EqualPowerStereoPanner::name);
509 XMLNode* autonode = new XMLNode (X_("Automation"));
510 autonode->add_child_nocopy (_automation.state (full_state));
511 root->add_child_nocopy (*autonode);
513 StreamPanner::add_state (*root);
515 root->add_child_nocopy (_control.get_state ());
521 EqualPowerStereoPanner::set_state (const XMLNode& node)
523 const XMLProperty* prop;
525 LocaleGuard lg (X_("POSIX"));
527 if ((prop = node.property (X_("x")))) {
528 pos = atof (prop->value().c_str());
529 set_position (pos, true);
532 StreamPanner::set_state (node);
534 for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
536 if ((*iter)->name() == X_("controllable")) {
537 if ((prop = (*iter)->property("name")) != 0 && prop->value() == "panner") {
538 _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;
656 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
661 pan = (*o).desired_pan;
663 if ((pan *= gain_coeff) != 1.0f) {
666 Session::mix_buffers_with_gain(dst,src,nframes,pan);
669 Session::mix_buffers_no_gain(dst,src,nframes);
681 Multi2dPanner::distribute_automated (Sample* src, Sample** obufs,
682 nframes_t start, nframes_t end, nframes_t nframes,
695 Multi2dPanner::factory (Panner& p)
697 return new Multi2dPanner (p);
701 Multi2dPanner::load (istream& in, string path, uint32_t& linecnt)
707 Multi2dPanner::get_state (void)
713 Multi2dPanner::state (bool full_state)
715 XMLNode* root = new XMLNode ("StreamPanner");
717 LocaleGuard lg (X_("POSIX"));
719 snprintf (buf, sizeof (buf), "%.12g", x);
720 root->add_property (X_("x"), buf);
721 snprintf (buf, sizeof (buf), "%.12g", y);
722 root->add_property (X_("y"), buf);
723 root->add_property (X_("type"), Multi2dPanner::name);
725 /* XXX no meaningful automation yet */
731 Multi2dPanner::set_state (const XMLNode& node)
733 const XMLProperty* prop;
735 LocaleGuard lg (X_("POSIX"));
740 if ((prop = node.property (X_("x")))) {
741 newx = atof (prop->value().c_str());
744 if ((prop = node.property (X_("y")))) {
745 newy = atof (prop->value().c_str());
748 if (x < 0 || y < 0) {
749 error << _("badly-formed positional data for Multi2dPanner - ignored")
754 set_position (newx, newy);
758 /*---------------------------------------------------------------------- */
760 Panner::Panner (string name, Session& s)
766 _link_direction = SameDirection;
775 Panner::set_linked (bool yn)
779 _session.set_dirty ();
780 LinkStateChanged (); /* EMIT SIGNAL */
785 Panner::set_link_direction (LinkDirection ld)
787 if (ld != _link_direction) {
788 _link_direction = ld;
789 _session.set_dirty ();
790 LinkStateChanged (); /* EMIT SIGNAL */
795 Panner::set_bypassed (bool yn)
797 if (yn != _bypassed) {
805 Panner::reset (uint32_t nouts, uint32_t npans)
808 bool changed = false;
810 if (nouts < 2 || (nouts == outputs.size() && npans == size())) {
833 fatal << _("programming error:")
834 << X_("Panner::reset() called with a single output")
841 outputs.push_back (Output (0, 0));
842 outputs.push_back (Output (1.0, 0));
844 for (n = 0; n < npans; ++n) {
845 push_back (new EqualPowerStereoPanner (*this));
850 outputs.push_back (Output (0.5, 0));
851 outputs.push_back (Output (0, 1.0));
852 outputs.push_back (Output (1.0, 1.0));
854 for (n = 0; n < npans; ++n) {
855 push_back (new Multi2dPanner (*this));
861 outputs.push_back (Output (0, 0));
862 outputs.push_back (Output (1.0, 0));
863 outputs.push_back (Output (1.0, 1.0));
864 outputs.push_back (Output (0, 1.0));
866 for (n = 0; n < npans; ++n) {
867 push_back (new Multi2dPanner (*this));
872 case 5: //square+offcenter center
873 outputs.push_back (Output (0, 0));
874 outputs.push_back (Output (1.0, 0));
875 outputs.push_back (Output (1.0, 1.0));
876 outputs.push_back (Output (0, 1.0));
877 outputs.push_back (Output (0.5, 0.75));
879 for (n = 0; n < npans; ++n) {
880 push_back (new Multi2dPanner (*this));
886 /* XXX horrible placement. FIXME */
887 for (n = 0; n < nouts; ++n) {
888 outputs.push_back (Output (0.1 * n, 0.1 * n));
891 for (n = 0; n < npans; ++n) {
892 push_back (new Multi2dPanner (*this));
898 for (iterator x = begin(); x != end(); ++x) {
902 /* force hard left/right panning in a common case: 2in/2out
905 if (npans == 2 && outputs.size() == 2) {
907 /* Do this only if we changed configuration, or our configuration
908 appears to be the default set up (center).
914 front()->get_position (left);
915 back()->get_position (right);
917 if (changed || ((left == 0.5) && (right == 0.5))) {
919 front()->set_position (0.0);
920 front()->automation().reset_default (0.0);
922 back()->set_position (1.0);
923 back()->automation().reset_default (1.0);
930 Changed (); /* EMIT SIGNAL */
937 Panner::remove (uint32_t which)
939 vector<StreamPanner*>::iterator i;
940 for (i = begin(); i != end() && which; ++i, --which);
951 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
955 vector<StreamPanner*>::clear ();
959 Panner::set_automation_style (AutoStyle style)
961 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
962 (*i)->set_automation_style (style);
964 _session.set_dirty ();
968 Panner::set_automation_state (AutoState state)
970 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
971 (*i)->set_automation_state (state);
973 _session.set_dirty ();
977 Panner::automation_state () const
980 return front()->automation().automation_state ();
987 Panner::automation_style () const
990 return front()->automation().automation_style ();
997 Panner::transport_stopped (nframes_t frame)
999 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1000 (*i)->transport_stopped (frame);
1005 Panner::snapshot (nframes_t now)
1007 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1008 (*i)->snapshot (now);
1013 Panner::clear_automation ()
1015 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1016 (*i)->automation().clear ();
1018 _session.set_dirty ();
1024 StreamPanner* (*factory)(Panner&);
1027 PanPlugins pan_plugins[] = {
1028 { EqualPowerStereoPanner::name, 2, EqualPowerStereoPanner::factory },
1029 { Multi2dPanner::name, 3, Multi2dPanner::factory },
1030 { string (""), 0, 0 }
1034 Panner::get_state (void)
1036 return state (true);
1040 Panner::state (bool full)
1042 XMLNode* root = new XMLNode (X_("Panner"));
1045 root->add_property (X_("linked"), (_linked ? "yes" : "no"));
1046 root->add_property (X_("link_direction"), enum_2_string (_link_direction));
1047 root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
1049 /* add each output */
1051 for (vector<Panner::Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
1052 XMLNode* onode = new XMLNode (X_("Output"));
1053 snprintf (buf, sizeof (buf), "%.12g", (*o).x);
1054 onode->add_property (X_("x"), buf);
1055 snprintf (buf, sizeof (buf), "%.12g", (*o).y);
1056 onode->add_property (X_("y"), buf);
1057 root->add_child_nocopy (*onode);
1060 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1061 root->add_child_nocopy ((*i)->state (full));
1068 Panner::set_state (const XMLNode& node)
1071 XMLNodeConstIterator niter;
1072 const XMLProperty *prop;
1075 LocaleGuard lg (X_("POSIX"));
1080 if ((prop = node.property (X_("linked"))) != 0) {
1081 set_linked (prop->value() == "yes");
1085 if ((prop = node.property (X_("bypassed"))) != 0) {
1086 set_bypassed (prop->value() == "yes");
1089 if ((prop = node.property (X_("link_direction"))) != 0) {
1090 LinkDirection ld; /* here to provide type information */
1091 set_link_direction (LinkDirection (string_2_enum (prop->value(), ld)));
1094 nlist = node.children();
1096 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1097 if ((*niter)->name() == X_("Output")) {
1101 prop = (*niter)->property (X_("x"));
1102 sscanf (prop->value().c_str(), "%g", &x);
1104 prop = (*niter)->property (X_("y"));
1105 sscanf (prop->value().c_str(), "%g", &y);
1107 outputs.push_back (Output (x, y));
1111 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1113 if ((*niter)->name() == X_("StreamPanner")) {
1115 if ((prop = (*niter)->property (X_("type")))) {
1117 for (i = 0; pan_plugins[i].factory; ++i) {
1118 if (prop->value() == pan_plugins[i].name) {
1121 /* note that we assume that all the stream panners
1122 are of the same type. pretty good
1123 assumption, but its still an assumption.
1126 sp = pan_plugins[i].factory (*this);
1128 if (sp->set_state (**niter) == 0) {
1137 if (!pan_plugins[i].factory) {
1138 error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
1144 error << _("panner plugin node has no type information!")
1152 /* don't try to do old-school automation loading if it wasn't marked as existing */
1154 if ((prop = node.property (X_("automation")))) {
1156 /* automation path is relative */
1158 automation_path = _session.automation_dir();
1159 automation_path += prop->value ();
1168 Panner::touching () const
1170 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1171 if ((*i)->automation().touching ()) {
1180 Panner::set_position (float xpos, StreamPanner& orig)
1186 orig.get_position (xnow);
1187 xdelta = xpos - xnow;
1189 if (_link_direction == SameDirection) {
1191 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1193 (*i)->set_position (xpos, true);
1195 (*i)->get_position (xnow);
1196 xnew = min (1.0f, xnow + xdelta);
1197 xnew = max (0.0f, xnew);
1198 (*i)->set_position (xnew, true);
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);
1218 Panner::set_position (float xpos, float ypos, StreamPanner& orig)
1221 float xdelta, ydelta;
1224 orig.get_position (xnow, ynow);
1225 xdelta = xpos - xnow;
1226 ydelta = ypos - ynow;
1228 if (_link_direction == SameDirection) {
1230 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1232 (*i)->set_position (xpos, ypos, true);
1234 (*i)->get_position (xnow, ynow);
1236 xnew = min (1.0f, xnow + xdelta);
1237 xnew = max (0.0f, xnew);
1239 ynew = min (1.0f, ynow + ydelta);
1240 ynew = max (0.0f, ynew);
1242 (*i)->set_position (xnew, ynew, true);
1248 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1250 (*i)->set_position (xpos, ypos, true);
1252 (*i)->get_position (xnow, ynow);
1254 xnew = min (1.0f, xnow - xdelta);
1255 xnew = max (0.0f, xnew);
1257 ynew = min (1.0f, ynow - ydelta);
1258 ynew = max (0.0f, ynew);
1260 (*i)->set_position (xnew, ynew, true);
1267 Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
1269 float xnow, ynow, znow;
1270 float xdelta, ydelta, zdelta;
1271 float xnew, ynew, znew;
1273 orig.get_position (xnow, ynow, znow);
1274 xdelta = xpos - xnow;
1275 ydelta = ypos - ynow;
1276 zdelta = zpos - znow;
1278 if (_link_direction == SameDirection) {
1280 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1282 (*i)->set_position (xpos, ypos, zpos, true);
1284 (*i)->get_position (xnow, ynow, znow);
1286 xnew = min (1.0f, xnow + xdelta);
1287 xnew = max (0.0f, xnew);
1289 ynew = min (1.0f, ynow + ydelta);
1290 ynew = max (0.0f, ynew);
1292 znew = min (1.0f, znow + zdelta);
1293 znew = max (0.0f, znew);
1295 (*i)->set_position (xnew, ynew, znew, true);
1301 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1303 (*i)->set_position (xpos, ypos, true);
1305 (*i)->get_position (xnow, ynow, znow);
1307 xnew = min (1.0f, xnow - xdelta);
1308 xnew = max (0.0f, xnew);
1310 ynew = min (1.0f, ynow - ydelta);
1311 ynew = max (0.0f, ynew);
1313 znew = min (1.0f, znow + zdelta);
1314 znew = max (0.0f, znew);
1316 (*i)->set_position (xnew, ynew, znew, true);
1322 /* old school automation handling */
1325 Panner::set_name (string str)
1327 automation_path = _session.automation_dir();
1328 automation_path += _session.snap_name();
1329 automation_path += "-pan-";
1330 automation_path += legalize_for_path (str);
1331 automation_path += ".automation";
1338 uint32_t linecnt = 0;
1341 LocaleGuard lg (X_("POSIX"));
1343 if (automation_path.length() == 0) {
1347 if (access (automation_path.c_str(), F_OK)) {
1351 ifstream in (automation_path.c_str());
1354 error << string_compose (_("cannot open pan automation file %1 (%2)"),
1355 automation_path, strerror (errno))
1362 while (in.getline (line, sizeof(line), '\n')) {
1364 if (++linecnt == 1) {
1365 if (memcmp (line, X_("version"), 7) == 0) {
1366 if (sscanf (line, "version %f", &version) != 1) {
1367 error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg;
1371 error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"),
1372 automation_path, line) << endmsg;
1379 if (strlen (line) == 0 || line[0] == '#') {
1383 if (strcmp (line, "begin") == 0) {
1386 error << string_compose (_("too many panner states found in pan automation file %1"),
1392 if ((*sp)->load (in, automation_path, linecnt)) {