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 (string_is_affirmative (prop->value()));
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 if (_automation.automation_state() != Off) {
209 set_position (_automation.eval (frame));
212 _automation.reposition_for_rt_add (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);
228 /* don't reset pan if we're moving to Off or Write mode;
229 if we're moving to Write, the user may have manually set up pans
230 that they don't want to lose */
231 if (state != Off && state != Write) {
232 set_position (_automation.eval (parent.session().transport_frame()));
238 BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
241 LocaleGuard lg (X_("POSIX"));
243 _automation.clear ();
245 while (in.getline (line, sizeof (line), '\n')) {
251 if (strcmp (line, "end") == 0) {
255 if (sscanf (line, "%" PRIu32 " %lf", &when, &value) != 2) {
256 warning << string_compose(_("badly formatted pan automation event record at line %1 of %2 (ignored) [%3]"), linecnt, path, line) << endmsg;
260 _automation.fast_simple_add (when, value);
263 /* now that we are done loading */
265 _automation.StateChanged ();
271 BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
285 if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
287 /* interpolate over 64 frames or nframes, whichever is smaller */
289 nframes_t limit = min ((nframes_t)64, nframes);
292 delta = -(delta / (float) (limit));
294 for (n = 0; n < limit; n++) {
295 left_interp = left_interp + delta;
296 left = left_interp + 0.9 * (left - left_interp);
297 dst[n] += src[n] * left * gain_coeff;
300 pan = left * gain_coeff;
302 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
309 if ((pan = (left * gain_coeff)) != 1.0f) {
313 Session::mix_buffers_with_gain(dst,src,nframes,pan);
315 /* mark that we wrote into the buffer */
323 Session::mix_buffers_no_gain(dst,src,nframes);
325 /* mark that we wrote into the buffer */
335 if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
337 /* interpolate over 64 frames or nframes, whichever is smaller */
339 nframes_t limit = min ((nframes_t)64, nframes);
342 delta = -(delta / (float) (limit));
344 for (n = 0; n < limit; n++) {
345 right_interp = right_interp + delta;
346 right = right_interp + 0.9 * (right - right_interp);
347 dst[n] += src[n] * right * gain_coeff;
350 pan = right * gain_coeff;
352 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
354 /* XXX it would be nice to mark the buffer as written to */
358 right = desired_right;
359 right_interp = right;
361 if ((pan = (right * gain_coeff)) != 1.0f) {
365 Session::mix_buffers_with_gain(dst,src,nframes,pan);
367 /* XXX it would be nice to mark the buffer as written to */
372 Session::mix_buffers_no_gain(dst,src,nframes);
374 /* XXX it would be nice to mark the buffer as written to */
379 /*---------------------------------------------------------------------- */
381 EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
382 : BaseStereoPanner (p)
387 right = desired_right;
389 right_interp = right;
392 EqualPowerStereoPanner::~EqualPowerStereoPanner ()
397 EqualPowerStereoPanner::update ()
399 /* it would be very nice to split this out into a virtual function
400 that can be accessed from BaseStereoPanner and used in distribute_automated().
402 but the place where its used in distribute_automated() is a tight inner loop,
403 and making "nframes" virtual function calls to compute values is an absurd
407 /* x == 0 => hard left
412 float panL = 1 - panR;
414 const float pan_law_attenuation = -3.0f;
415 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
417 desired_left = panL * (scale * panL + 1.0f - scale);
418 desired_right = panR * (scale * panR + 1.0f - scale);
424 EqualPowerStereoPanner::distribute_automated (Sample* src, Sample** obufs,
425 nframes_t start, nframes_t end, nframes_t nframes,
431 /* fetch positional data */
433 if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
436 distribute (src, obufs, 1.0, nframes);
441 /* store effective pan position. do this even if we are muted */
444 effective_x = buffers[0][nframes-1];
450 /* apply pan law to convert positional data into pan coefficients for
454 const float pan_law_attenuation = -3.0f;
455 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
457 for (nframes_t n = 0; n < nframes; ++n) {
459 float panR = buffers[0][n];
460 float panL = 1 - panR;
462 buffers[0][n] = panL * (scale * panL + 1.0f - scale);
463 buffers[1][n] = panR * (scale * panR + 1.0f - scale);
471 for (nframes_t n = 0; n < nframes; ++n) {
472 dst[n] += src[n] * pbuf[n];
475 /* XXX it would be nice to mark the buffer as written to */
482 for (nframes_t n = 0; n < nframes; ++n) {
483 dst[n] += src[n] * pbuf[n];
486 /* XXX it would be nice to mark the buffer as written to */
490 EqualPowerStereoPanner::factory (Panner& parent)
492 return new EqualPowerStereoPanner (parent);
496 EqualPowerStereoPanner::get_state (void)
502 EqualPowerStereoPanner::state (bool full_state)
504 XMLNode* root = new XMLNode ("StreamPanner");
506 LocaleGuard lg (X_("POSIX"));
508 snprintf (buf, sizeof (buf), "%.12g", x);
509 root->add_property (X_("x"), buf);
510 root->add_property (X_("type"), EqualPowerStereoPanner::name);
512 XMLNode* autonode = new XMLNode (X_("Automation"));
513 autonode->add_child_nocopy (_automation.state (full_state));
514 root->add_child_nocopy (*autonode);
516 StreamPanner::add_state (*root);
518 root->add_child_nocopy (_control.get_state ());
524 EqualPowerStereoPanner::set_state (const XMLNode& node)
526 const XMLProperty* prop;
528 LocaleGuard lg (X_("POSIX"));
530 if ((prop = node.property (X_("x")))) {
531 pos = atof (prop->value().c_str());
532 set_position (pos, true);
535 StreamPanner::set_state (node);
537 for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
539 if ((*iter)->name() == X_("controllable")) {
540 if ((prop = (*iter)->property("name")) != 0 && prop->value() == "panner") {
541 _control.set_state (**iter);
544 } else if ((*iter)->name() == X_("Automation")) {
546 _automation.set_state (*((*iter)->children().front()));
548 if (_automation.automation_state() != Off) {
549 set_position (_automation.eval (parent.session().transport_frame()));
557 /*----------------------------------------------------------------------*/
559 Multi2dPanner::Multi2dPanner (Panner& p)
560 : StreamPanner (p), _automation (0.0, 1.0, 0.5) // XXX useless
565 Multi2dPanner::~Multi2dPanner ()
570 Multi2dPanner::snapshot (nframes_t now)
576 Multi2dPanner::transport_stopped (nframes_t frame)
582 Multi2dPanner::set_automation_style (AutoStyle style)
588 Multi2dPanner::set_automation_state (AutoState state)
594 Multi2dPanner::update ()
596 static const float BIAS = FLT_MIN;
598 uint32_t nouts = parent.outputs.size();
605 for (i = 0; i < nouts; i++) {
606 dsq[i] = ((x - parent.outputs[i].x) * (x - parent.outputs[i].x) + (y - parent.outputs[i].y) * (y - parent.outputs[i].y) + BIAS);
610 f += dsq[i] * dsq[i];
613 // terrible hack to support OSX < 10.3.9 builds
614 fr = (float) (1.0 / sqrt((double)f));
618 for (i = 0; i < nouts; ++i) {
619 parent.outputs[i].desired_pan = 1.0f - (dsq[i] * fr);
626 Multi2dPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes)
630 vector<Panner::Output>::iterator o;
638 for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
643 if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
645 /* interpolate over 64 frames or nframes, whichever is smaller */
647 nframes_t limit = min ((nframes_t)64, nframes);
650 delta = -(delta / (float) (limit));
652 for (n = 0; n < limit; n++) {
653 left_interp = left_interp + delta;
654 left = left_interp + 0.9 * (left - left_interp);
655 dst[n] += src[n] * left * gain_coeff;
658 pan = left * gain_coeff;
659 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
664 pan = (*o).desired_pan;
666 if ((pan *= gain_coeff) != 1.0f) {
669 Session::mix_buffers_with_gain(dst,src,nframes,pan);
672 Session::mix_buffers_no_gain(dst,src,nframes);
684 Multi2dPanner::distribute_automated (Sample* src, Sample** obufs,
685 nframes_t start, nframes_t end, nframes_t nframes,
698 Multi2dPanner::factory (Panner& p)
700 return new Multi2dPanner (p);
704 Multi2dPanner::load (istream& in, string path, uint32_t& linecnt)
710 Multi2dPanner::get_state (void)
716 Multi2dPanner::state (bool full_state)
718 XMLNode* root = new XMLNode ("StreamPanner");
720 LocaleGuard lg (X_("POSIX"));
722 snprintf (buf, sizeof (buf), "%.12g", x);
723 root->add_property (X_("x"), buf);
724 snprintf (buf, sizeof (buf), "%.12g", y);
725 root->add_property (X_("y"), buf);
726 root->add_property (X_("type"), Multi2dPanner::name);
728 /* XXX no meaningful automation yet */
734 Multi2dPanner::set_state (const XMLNode& node)
736 const XMLProperty* prop;
738 LocaleGuard lg (X_("POSIX"));
743 if ((prop = node.property (X_("x")))) {
744 newx = atof (prop->value().c_str());
747 if ((prop = node.property (X_("y")))) {
748 newy = atof (prop->value().c_str());
751 if (x < 0 || y < 0) {
752 error << _("badly-formed positional data for Multi2dPanner - ignored")
757 set_position (newx, newy);
761 /*---------------------------------------------------------------------- */
763 Panner::Panner (string name, Session& s)
769 _link_direction = SameDirection;
778 Panner::set_linked (bool yn)
782 _session.set_dirty ();
783 LinkStateChanged (); /* EMIT SIGNAL */
788 Panner::set_link_direction (LinkDirection ld)
790 if (ld != _link_direction) {
791 _link_direction = ld;
792 _session.set_dirty ();
793 LinkStateChanged (); /* EMIT SIGNAL */
798 Panner::set_bypassed (bool yn)
800 if (yn != _bypassed) {
807 Panner::reset_to_default ()
809 vector<float> positions;
811 switch (outputs.size()) {
817 if (outputs.size() == 2) {
820 front()->set_position (0.5);
821 front()->automation().reset_default (0.5);
825 front()->set_position (0.0);
826 front()->automation().reset_default (0.0);
827 back()->set_position (1.0);
828 back()->automation().reset_default (1.0);
835 vector<Output>::iterator o;
838 for (o = outputs.begin(), p = begin(); o != outputs.end() && p != end(); ++o, ++p) {
839 (*p)->set_position ((*o).x, (*o).y);
844 Panner::reset_streampanner (uint32_t which)
846 if (which >= size() || which >= outputs.size()) {
850 switch (outputs.size()) {
858 /* stereo out, 1 stream, default = middle */
859 front()->set_position (0.5);
860 front()->automation().reset_default (0.5);
863 /* stereo out, 2 streams, default = hard left/right */
865 front()->set_position (0.0);
866 front()->automation().reset_default (0.0);
868 back()->set_position (1.0);
869 back()->automation().reset_default (1.0);
876 (*this)[which]->set_position (outputs[which].x, outputs[which].y);
881 Panner::reset (uint32_t nouts, uint32_t npans)
884 bool changed = false;
885 bool do_not_and_did_not_need_panning = ((nouts < 2) && (outputs.size() < 2));
887 /* if new and old config don't need panning, or if
888 the config hasn't changed, we're done.
891 if (do_not_and_did_not_need_panning ||
892 ((nouts == outputs.size()) && (npans == size()))) {
919 fatal << _("programming error:")
920 << X_("Panner::reset() called with a single output")
927 outputs.push_back (Output (0, 0));
928 outputs.push_back (Output (1.0, 0));
930 for (n = 0; n < npans; ++n) {
931 push_back (new EqualPowerStereoPanner (*this));
936 outputs.push_back (Output (0.5, 0));
937 outputs.push_back (Output (0, 1.0));
938 outputs.push_back (Output (1.0, 1.0));
940 for (n = 0; n < npans; ++n) {
941 push_back (new Multi2dPanner (*this));
947 outputs.push_back (Output (0, 0));
948 outputs.push_back (Output (1.0, 0));
949 outputs.push_back (Output (1.0, 1.0));
950 outputs.push_back (Output (0, 1.0));
952 for (n = 0; n < npans; ++n) {
953 push_back (new Multi2dPanner (*this));
958 case 5: //square+offcenter center
959 outputs.push_back (Output (0, 0));
960 outputs.push_back (Output (1.0, 0));
961 outputs.push_back (Output (1.0, 1.0));
962 outputs.push_back (Output (0, 1.0));
963 outputs.push_back (Output (0.5, 0.75));
965 for (n = 0; n < npans; ++n) {
966 push_back (new Multi2dPanner (*this));
972 /* XXX horrible placement. FIXME */
973 for (n = 0; n < nouts; ++n) {
974 outputs.push_back (Output (0.1 * n, 0.1 * n));
977 for (n = 0; n < npans; ++n) {
978 push_back (new Multi2dPanner (*this));
984 for (iterator x = begin(); x != end(); ++x) {
988 /* force hard left/right panning in a common case: 2in/2out
991 if (npans == 2 && outputs.size() == 2) {
993 /* Do this only if we changed configuration, or our configuration
994 appears to be the default set up (center).
1000 front()->get_position (left);
1001 back()->get_position (right);
1003 if (changed || ((left == 0.5) && (right == 0.5))) {
1005 front()->set_position (0.0);
1006 front()->automation().reset_default (0.0);
1008 back()->set_position (1.0);
1009 back()->automation().reset_default (1.0);
1017 Changed (); /* EMIT SIGNAL */
1024 Panner::remove (uint32_t which)
1026 vector<StreamPanner*>::iterator i;
1027 for (i = begin(); i != end() && which; ++i, --which);
1038 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1042 vector<StreamPanner*>::clear ();
1046 Panner::set_automation_style (AutoStyle style)
1048 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1049 (*i)->set_automation_style (style);
1051 _session.set_dirty ();
1055 Panner::set_automation_state (AutoState state)
1057 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1058 (*i)->set_automation_state (state);
1060 _session.set_dirty ();
1064 Panner::automation_state () const
1067 return front()->automation().automation_state ();
1074 Panner::automation_style () const
1077 return front()->automation().automation_style ();
1084 Panner::transport_stopped (nframes_t frame)
1086 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1087 (*i)->transport_stopped (frame);
1092 Panner::snapshot (nframes_t now)
1094 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1095 (*i)->snapshot (now);
1100 Panner::clear_automation ()
1102 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1103 (*i)->automation().clear ();
1105 _session.set_dirty ();
1111 StreamPanner* (*factory)(Panner&);
1114 PanPlugins pan_plugins[] = {
1115 { EqualPowerStereoPanner::name, 2, EqualPowerStereoPanner::factory },
1116 { Multi2dPanner::name, 3, Multi2dPanner::factory },
1117 { string (""), 0, 0 }
1121 Panner::get_state (void)
1123 return state (true);
1127 Panner::state (bool full)
1129 XMLNode* root = new XMLNode (X_("Panner"));
1132 root->add_property (X_("linked"), (_linked ? "yes" : "no"));
1133 root->add_property (X_("link_direction"), enum_2_string (_link_direction));
1134 root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
1136 /* add each output */
1138 for (vector<Panner::Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
1139 XMLNode* onode = new XMLNode (X_("Output"));
1140 snprintf (buf, sizeof (buf), "%.12g", (*o).x);
1141 onode->add_property (X_("x"), buf);
1142 snprintf (buf, sizeof (buf), "%.12g", (*o).y);
1143 onode->add_property (X_("y"), buf);
1144 root->add_child_nocopy (*onode);
1147 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1148 root->add_child_nocopy ((*i)->state (full));
1155 Panner::set_state (const XMLNode& node)
1158 XMLNodeConstIterator niter;
1159 const XMLProperty *prop;
1162 LocaleGuard lg (X_("POSIX"));
1167 if ((prop = node.property (X_("linked"))) != 0) {
1168 set_linked (string_is_affirmative (prop->value()));
1172 if ((prop = node.property (X_("bypassed"))) != 0) {
1173 set_bypassed (string_is_affirmative (prop->value()));
1176 if ((prop = node.property (X_("link_direction"))) != 0) {
1177 LinkDirection ld; /* here to provide type information */
1178 set_link_direction (LinkDirection (string_2_enum (prop->value(), ld)));
1181 nlist = node.children();
1183 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1184 if ((*niter)->name() == X_("Output")) {
1188 prop = (*niter)->property (X_("x"));
1189 sscanf (prop->value().c_str(), "%g", &x);
1191 prop = (*niter)->property (X_("y"));
1192 sscanf (prop->value().c_str(), "%g", &y);
1194 outputs.push_back (Output (x, y));
1198 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1200 if ((*niter)->name() == X_("StreamPanner")) {
1202 if ((prop = (*niter)->property (X_("type")))) {
1204 for (i = 0; pan_plugins[i].factory; ++i) {
1205 if (prop->value() == pan_plugins[i].name) {
1208 /* note that we assume that all the stream panners
1209 are of the same type. pretty good
1210 assumption, but its still an assumption.
1213 sp = pan_plugins[i].factory (*this);
1215 if (sp->set_state (**niter) == 0) {
1224 if (!pan_plugins[i].factory) {
1225 error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
1231 error << _("panner plugin node has no type information!")
1239 /* don't try to do old-school automation loading if it wasn't marked as existing */
1241 if ((prop = node.property (X_("automation")))) {
1243 /* automation path is relative */
1245 automation_path = Glib::build_filename(_session.automation_dir(), prop->value ());
1254 Panner::touching () const
1256 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1257 if ((*i)->automation().touching ()) {
1266 Panner::set_position (float xpos, StreamPanner& orig)
1272 orig.get_position (xnow);
1273 xdelta = xpos - xnow;
1275 if (_link_direction == SameDirection) {
1277 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1279 (*i)->set_position (xpos, true);
1281 (*i)->get_position (xnow);
1282 xnew = min (1.0f, xnow + xdelta);
1283 xnew = max (0.0f, xnew);
1284 (*i)->set_position (xnew, true);
1290 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1292 (*i)->set_position (xpos, true);
1294 (*i)->get_position (xnow);
1295 xnew = min (1.0f, xnow - xdelta);
1296 xnew = max (0.0f, xnew);
1297 (*i)->set_position (xnew, true);
1304 Panner::set_position (float xpos, float ypos, StreamPanner& orig)
1307 float xdelta, ydelta;
1310 orig.get_position (xnow, ynow);
1311 xdelta = xpos - xnow;
1312 ydelta = ypos - ynow;
1314 if (_link_direction == SameDirection) {
1316 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1318 (*i)->set_position (xpos, ypos, true);
1320 (*i)->get_position (xnow, ynow);
1322 xnew = min (1.0f, xnow + xdelta);
1323 xnew = max (0.0f, xnew);
1325 ynew = min (1.0f, ynow + ydelta);
1326 ynew = max (0.0f, ynew);
1328 (*i)->set_position (xnew, ynew, true);
1334 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1336 (*i)->set_position (xpos, ypos, true);
1338 (*i)->get_position (xnow, ynow);
1340 xnew = min (1.0f, xnow - xdelta);
1341 xnew = max (0.0f, xnew);
1343 ynew = min (1.0f, ynow - ydelta);
1344 ynew = max (0.0f, ynew);
1346 (*i)->set_position (xnew, ynew, true);
1353 Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
1355 float xnow, ynow, znow;
1356 float xdelta, ydelta, zdelta;
1357 float xnew, ynew, znew;
1359 orig.get_position (xnow, ynow, znow);
1360 xdelta = xpos - xnow;
1361 ydelta = ypos - ynow;
1362 zdelta = zpos - znow;
1364 if (_link_direction == SameDirection) {
1366 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1368 (*i)->set_position (xpos, ypos, zpos, true);
1370 (*i)->get_position (xnow, ynow, znow);
1372 xnew = min (1.0f, xnow + xdelta);
1373 xnew = max (0.0f, xnew);
1375 ynew = min (1.0f, ynow + ydelta);
1376 ynew = max (0.0f, ynew);
1378 znew = min (1.0f, znow + zdelta);
1379 znew = max (0.0f, znew);
1381 (*i)->set_position (xnew, ynew, znew, true);
1387 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1389 (*i)->set_position (xpos, ypos, true);
1391 (*i)->get_position (xnow, ynow, znow);
1393 xnew = min (1.0f, xnow - xdelta);
1394 xnew = max (0.0f, xnew);
1396 ynew = min (1.0f, ynow - ydelta);
1397 ynew = max (0.0f, ynew);
1399 znew = min (1.0f, znow + zdelta);
1400 znew = max (0.0f, znew);
1402 (*i)->set_position (xnew, ynew, znew, true);
1408 /* old school automation handling */
1411 Panner::set_name (string str)
1413 automation_path = Glib::build_filename(_session.automation_dir(),
1414 _session.snap_name() + "-pan-" + legalize_for_path (str) + ".automation");
1421 uint32_t linecnt = 0;
1424 LocaleGuard lg (X_("POSIX"));
1426 if (automation_path.length() == 0) {
1430 if (access (automation_path.c_str(), F_OK)) {
1434 ifstream in (automation_path.c_str());
1437 error << string_compose (_("cannot open pan automation file %1 (%2)"),
1438 automation_path, strerror (errno))
1445 while (in.getline (line, sizeof(line), '\n')) {
1447 if (++linecnt == 1) {
1448 if (memcmp (line, X_("version"), 7) == 0) {
1449 if (sscanf (line, "version %f", &version) != 1) {
1450 error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg;
1454 error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"),
1455 automation_path, line) << endmsg;
1462 if (strlen (line) == 0 || line[0] == '#') {
1466 if (strcmp (line, "begin") == 0) {
1469 error << string_compose (_("too many panner states found in pan automation file %1"),
1475 if ((*sp)->load (in, automation_path, linecnt)) {