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.
20 #define __STDC_FORMAT_MACROS 1
35 #include <pbd/error.h>
36 #include <pbd/failed_constructor.h>
37 #include <pbd/xml++.h>
38 #include <pbd/enumwriter.h>
40 #include <ardour/session.h>
41 #include <ardour/panner.h>
42 #include <ardour/utils.h>
44 #include <ardour/runtime_functions.h>
45 #include <ardour/buffer_set.h>
49 #include <pbd/mathfix.h>
52 using namespace ARDOUR;
55 float Panner::current_automation_version_number = 1.0;
57 string EqualPowerStereoPanner::name = "Equal Power Stereo";
58 string Multi2dPanner::name = "Multiple (2D)";
60 /* this is a default mapper of control values to a pan position
61 others can be imagined.
64 static pan_t direct_control_to_pan (double fract) {
68 static double direct_pan_to_control (pan_t val) {
72 StreamPanner::StreamPanner (Panner& p)
74 _control (new PanControllable(p.session(), X_("panner"), *this))
78 parent.session().add_controllable (_control);
85 StreamPanner::~StreamPanner ()
90 StreamPanner::PanControllable::set_value (float val)
92 panner.set_position (direct_control_to_pan (val));
96 StreamPanner::PanControllable::get_value (void) const
99 panner.get_effective_position (xpos);
100 return direct_pan_to_control (xpos);
104 StreamPanner::PanControllable::can_send_feedback () const
106 AutoState astate = panner.get_parent().automation_state ();
108 if ((astate == Play) || (astate == Touch && !panner.get_parent().touching())) {
116 StreamPanner::set_muted (bool yn)
125 StreamPanner::set_position (float xpos, bool link_call)
127 if (!link_call && parent.linked()) {
128 parent.set_position (xpos, *this);
135 _control->Changed ();
140 StreamPanner::set_position (float xpos, float ypos, bool link_call)
142 if (!link_call && parent.linked()) {
143 parent.set_position (xpos, ypos, *this);
146 if (x != xpos || y != ypos) {
156 StreamPanner::set_position (float xpos, float ypos, float zpos, bool link_call)
158 if (!link_call && parent.linked()) {
159 parent.set_position (xpos, ypos, zpos, *this);
162 if (x != xpos || y != ypos || z != zpos) {
172 StreamPanner::set_state (const XMLNode& node)
174 const XMLProperty* prop;
175 XMLNodeConstIterator iter;
177 if ((prop = node.property (X_("muted")))) {
178 set_muted (prop->value() == "yes");
185 StreamPanner::add_state (XMLNode& node)
187 node.add_property (X_("muted"), (muted() ? "yes" : "no"));
190 /*---------------------------------------------------------------------- */
192 BaseStereoPanner::BaseStereoPanner (Panner& p)
197 BaseStereoPanner::~BaseStereoPanner ()
202 BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
205 LocaleGuard lg (X_("POSIX"));
207 _control->list()->clear ();
209 while (in.getline (line, sizeof (line), '\n')) {
215 if (strcmp (line, "end") == 0) {
219 if (sscanf (line, "%" PRIu32 " %lf", &when, &value) != 2) {
220 warning << string_compose(_("badly formatted pan automation event record at line %1 of %2 (ignored) [%3]"), linecnt, path, line) << endmsg;
224 _control->list()->fast_simple_add (when, value);
227 /* now that we are done loading */
229 _control->list()->StateChanged ();
235 BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes)
237 assert(obufs.count().n_audio() == 2);
247 Sample* const src = srcbuf.data();
251 dst = obufs.get_audio(0).data();
253 if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
255 /* interpolate over 64 frames or nframes, whichever is smaller */
257 nframes_t limit = min ((nframes_t)64, nframes);
260 delta = -(delta / (float) (limit));
262 for (n = 0; n < limit; n++) {
263 left_interp = left_interp + delta;
264 left = left_interp + 0.9 * (left - left_interp);
265 dst[n] += src[n] * left * gain_coeff;
268 pan = left * gain_coeff;
270 mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
277 if ((pan = (left * gain_coeff)) != 1.0f) {
281 mix_buffers_with_gain(dst,src,nframes,pan);
283 /* mark that we wrote into the buffer */
291 mix_buffers_no_gain(dst,src,nframes);
293 /* mark that we wrote into the buffer */
301 dst = obufs.get_audio(1).data();
303 if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
305 /* interpolate over 64 frames or nframes, whichever is smaller */
307 nframes_t limit = min ((nframes_t)64, nframes);
310 delta = -(delta / (float) (limit));
312 for (n = 0; n < limit; n++) {
313 right_interp = right_interp + delta;
314 right = right_interp + 0.9 * (right - right_interp);
315 dst[n] += src[n] * right * gain_coeff;
318 pan = right * gain_coeff;
320 mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
322 /* XXX it would be nice to mark the buffer as written to */
326 right = desired_right;
327 right_interp = right;
329 if ((pan = (right * gain_coeff)) != 1.0f) {
333 mix_buffers_with_gain(dst,src,nframes,pan);
335 /* XXX it would be nice to mark the buffer as written to */
340 mix_buffers_no_gain(dst,src,nframes);
342 /* XXX it would be nice to mark the buffer as written to */
347 /*---------------------------------------------------------------------- */
349 EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
350 : BaseStereoPanner (p)
355 right = desired_right;
357 right_interp = right;
360 EqualPowerStereoPanner::~EqualPowerStereoPanner ()
365 EqualPowerStereoPanner::update ()
367 /* it would be very nice to split this out into a virtual function
368 that can be accessed from BaseStereoPanner and used in distribute_automated().
370 but the place where its used in distribute_automated() is a tight inner loop,
371 and making "nframes" virtual function calls to compute values is an absurd
375 /* x == 0 => hard left
380 float panL = 1 - panR;
382 const float pan_law_attenuation = -3.0f;
383 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
385 desired_left = panL * (scale * panL + 1.0f - scale);
386 desired_right = panR * (scale * panR + 1.0f - scale);
392 EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& obufs,
393 nframes_t start, nframes_t end, nframes_t nframes,
396 assert(obufs.count().n_audio() == 2);
400 Sample* const src = srcbuf.data();
402 /* fetch positional data */
404 if (!_control->list()->curve().rt_safe_get_vector (start, end, buffers[0], nframes)) {
407 distribute (srcbuf, obufs, 1.0, nframes);
412 /* store effective pan position. do this even if we are muted */
415 effective_x = buffers[0][nframes-1];
421 /* apply pan law to convert positional data into pan coefficients for
425 const float pan_law_attenuation = -3.0f;
426 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
428 for (nframes_t n = 0; n < nframes; ++n) {
430 float panR = buffers[0][n];
431 float panL = 1 - panR;
433 buffers[0][n] = panL * (scale * panL + 1.0f - scale);
434 buffers[1][n] = panR * (scale * panR + 1.0f - scale);
439 dst = obufs.get_audio(0).data();
442 for (nframes_t n = 0; n < nframes; ++n) {
443 dst[n] += src[n] * pbuf[n];
446 /* XXX it would be nice to mark the buffer as written to */
450 dst = obufs.get_audio(1).data();
453 for (nframes_t n = 0; n < nframes; ++n) {
454 dst[n] += src[n] * pbuf[n];
457 /* XXX it would be nice to mark the buffer as written to */
461 EqualPowerStereoPanner::factory (Panner& parent)
463 return new EqualPowerStereoPanner (parent);
467 EqualPowerStereoPanner::get_state (void)
473 EqualPowerStereoPanner::state (bool full_state)
475 XMLNode* root = new XMLNode ("StreamPanner");
477 LocaleGuard lg (X_("POSIX"));
479 snprintf (buf, sizeof (buf), "%.12g", x);
480 root->add_property (X_("x"), buf);
481 root->add_property (X_("type"), EqualPowerStereoPanner::name);
483 XMLNode* autonode = new XMLNode (X_("Automation"));
484 autonode->add_child_nocopy (_control->list()->state (full_state));
485 root->add_child_nocopy (*autonode);
487 StreamPanner::add_state (*root);
489 root->add_child_nocopy (_control->get_state ());
495 EqualPowerStereoPanner::set_state (const XMLNode& node)
497 const XMLProperty* prop;
499 LocaleGuard lg (X_("POSIX"));
501 if ((prop = node.property (X_("x")))) {
502 pos = atof (prop->value().c_str());
503 set_position (pos, true);
506 StreamPanner::set_state (node);
508 for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
510 if ((*iter)->name() == X_("controllable")) {
511 if ((prop = (*iter)->property("name")) != 0 && prop->value() == "panner") {
512 _control->set_state (**iter);
515 } else if ((*iter)->name() == X_("Automation")) {
517 _control->list()->set_state (*((*iter)->children().front()));
519 if (_control->list()->automation_state() != Off) {
520 set_position (_control->list()->eval (parent.session().transport_frame()));
528 /*----------------------------------------------------------------------*/
530 Multi2dPanner::Multi2dPanner (Panner& p)
536 Multi2dPanner::~Multi2dPanner ()
541 Multi2dPanner::update ()
543 static const float BIAS = FLT_MIN;
545 uint32_t nouts = parent.outputs.size();
552 for (i = 0; i < nouts; i++) {
553 dsq[i] = ((x - parent.outputs[i].x) * (x - parent.outputs[i].x) + (y - parent.outputs[i].y) * (y - parent.outputs[i].y) + BIAS);
557 f += dsq[i] * dsq[i];
560 // terrible hack to support OSX < 10.3.9 builds
561 fr = (float) (1.0 / sqrt((double)f));
565 for (i = 0; i < nouts; ++i) {
566 parent.outputs[i].desired_pan = 1.0f - (dsq[i] * fr);
573 Multi2dPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes)
577 vector<Panner::Output>::iterator o;
584 Sample* const src = srcbuf.data();
587 for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
589 dst = obufs.get_audio(n).data();
592 if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
594 /* interpolate over 64 frames or nframes, whichever is smaller */
596 nframes_t limit = min ((nframes_t)64, nframes);
599 delta = -(delta / (float) (limit));
601 for (n = 0; n < limit; n++) {
602 left_interp = left_interp + delta;
603 left = left_interp + 0.9 * (left - left_interp);
604 dst[n] += src[n] * left * gain_coeff;
607 pan = left * gain_coeff;
608 mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
613 pan = (*o).desired_pan;
615 if ((pan *= gain_coeff) != 1.0f) {
618 mix_buffers_with_gain(dst,src,nframes,pan);
621 mix_buffers_no_gain(dst,src,nframes);
633 Multi2dPanner::distribute_automated (AudioBuffer& src, BufferSet& obufs,
634 nframes_t start, nframes_t end, nframes_t nframes,
647 Multi2dPanner::factory (Panner& p)
649 return new Multi2dPanner (p);
653 Multi2dPanner::load (istream& in, string path, uint32_t& linecnt)
659 Multi2dPanner::get_state (void)
665 Multi2dPanner::state (bool full_state)
667 XMLNode* root = new XMLNode ("StreamPanner");
669 LocaleGuard lg (X_("POSIX"));
671 snprintf (buf, sizeof (buf), "%.12g", x);
672 root->add_property (X_("x"), buf);
673 snprintf (buf, sizeof (buf), "%.12g", y);
674 root->add_property (X_("y"), buf);
675 root->add_property (X_("type"), Multi2dPanner::name);
677 /* XXX no meaningful automation yet */
683 Multi2dPanner::set_state (const XMLNode& node)
685 const XMLProperty* prop;
687 LocaleGuard lg (X_("POSIX"));
692 if ((prop = node.property (X_("x")))) {
693 newx = atof (prop->value().c_str());
696 if ((prop = node.property (X_("y")))) {
697 newy = atof (prop->value().c_str());
700 if (x < 0 || y < 0) {
701 error << _("badly-formed positional data for Multi2dPanner - ignored")
706 set_position (newx, newy);
710 /*---------------------------------------------------------------------- */
712 Panner::Panner (string name, Session& s)
718 _link_direction = SameDirection;
727 Panner::set_linked (bool yn)
731 _session.set_dirty ();
732 LinkStateChanged (); /* EMIT SIGNAL */
737 Panner::set_link_direction (LinkDirection ld)
739 if (ld != _link_direction) {
740 _link_direction = ld;
741 _session.set_dirty ();
742 LinkStateChanged (); /* EMIT SIGNAL */
747 Panner::set_bypassed (bool yn)
749 if (yn != _bypassed) {
757 Panner::reset (uint32_t nouts, uint32_t npans)
760 bool changed = false;
762 if (nouts < 2 || (nouts == outputs.size() && npans == size())) {
785 fatal << _("programming error:")
786 << X_("Panner::reset() called with a single output")
793 outputs.push_back (Output (0, 0));
794 outputs.push_back (Output (1.0, 0));
796 for (n = 0; n < npans; ++n) {
797 push_back (new EqualPowerStereoPanner (*this));
802 outputs.push_back (Output (0.5, 0));
803 outputs.push_back (Output (0, 1.0));
804 outputs.push_back (Output (1.0, 1.0));
806 for (n = 0; n < npans; ++n) {
807 push_back (new Multi2dPanner (*this));
813 outputs.push_back (Output (0, 0));
814 outputs.push_back (Output (1.0, 0));
815 outputs.push_back (Output (1.0, 1.0));
816 outputs.push_back (Output (0, 1.0));
818 for (n = 0; n < npans; ++n) {
819 push_back (new Multi2dPanner (*this));
824 case 5: //square+offcenter center
825 outputs.push_back (Output (0, 0));
826 outputs.push_back (Output (1.0, 0));
827 outputs.push_back (Output (1.0, 1.0));
828 outputs.push_back (Output (0, 1.0));
829 outputs.push_back (Output (0.5, 0.75));
831 for (n = 0; n < npans; ++n) {
832 push_back (new Multi2dPanner (*this));
838 /* XXX horrible placement. FIXME */
839 for (n = 0; n < nouts; ++n) {
840 outputs.push_back (Output (0.1 * n, 0.1 * n));
843 for (n = 0; n < npans; ++n) {
844 push_back (new Multi2dPanner (*this));
850 for (iterator x = begin(); x != end(); ++x) {
854 /* force hard left/right panning in a common case: 2in/2out
857 if (npans == 2 && outputs.size() == 2) {
859 /* Do this only if we changed configuration, or our configuration
860 appears to be the default set up (center).
866 front()->get_position (left);
867 back()->get_position (right);
869 if (changed || ((left == 0.5) && (right == 0.5))) {
871 front()->set_position (0.0);
872 front()->pan_control()->list()->reset_default (0.0);
874 back()->set_position (1.0);
875 back()->pan_control()->list()->reset_default (1.0);
882 Changed (); /* EMIT SIGNAL */
889 Panner::remove (uint32_t which)
891 vector<StreamPanner*>::iterator i;
892 for (i = begin(); i != end() && which; ++i, --which);
903 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
907 vector<StreamPanner*>::clear ();
911 Panner::set_automation_style (AutoStyle style)
913 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
914 (*i)->pan_control()->list()->set_automation_style (style);
916 _session.set_dirty ();
920 Panner::set_automation_state (AutoState state)
922 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
923 (*i)->pan_control()->list()->set_automation_state (state);
925 _session.set_dirty ();
929 Panner::automation_state () const
932 return front()->pan_control()->list()->automation_state ();
939 Panner::automation_style () const
942 return front()->pan_control()->list()->automation_style ();
949 Panner::transport_stopped (nframes_t frame)
951 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
952 (*i)->pan_control()->list()->reposition_for_rt_add (frame);
957 Panner::snapshot (nframes_t now)
959 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
960 boost::shared_ptr<AutomationList> list = (*i)->pan_control()->list();
961 if (list->automation_write())
962 list->rt_add(now, (*i)->pan_control()->get_value());
967 Panner::clear_automation ()
969 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
970 (*i)->pan_control()->list()->clear ();
972 _session.set_dirty ();
978 StreamPanner* (*factory)(Panner&);
981 PanPlugins pan_plugins[] = {
982 { EqualPowerStereoPanner::name, 2, EqualPowerStereoPanner::factory },
983 { Multi2dPanner::name, 3, Multi2dPanner::factory },
984 { string (""), 0, 0 }
988 Panner::get_state (void)
994 Panner::state (bool full)
996 XMLNode* root = new XMLNode (X_("Panner"));
999 root->add_property (X_("linked"), (_linked ? "yes" : "no"));
1000 root->add_property (X_("link_direction"), enum_2_string (_link_direction));
1001 root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
1003 /* add each output */
1005 for (vector<Panner::Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
1006 XMLNode* onode = new XMLNode (X_("Output"));
1007 snprintf (buf, sizeof (buf), "%.12g", (*o).x);
1008 onode->add_property (X_("x"), buf);
1009 snprintf (buf, sizeof (buf), "%.12g", (*o).y);
1010 onode->add_property (X_("y"), buf);
1011 root->add_child_nocopy (*onode);
1014 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1015 root->add_child_nocopy ((*i)->state (full));
1022 Panner::set_state (const XMLNode& node)
1025 XMLNodeConstIterator niter;
1026 const XMLProperty *prop;
1029 LocaleGuard lg (X_("POSIX"));
1034 if ((prop = node.property (X_("linked"))) != 0) {
1035 set_linked (prop->value() == "yes");
1039 if ((prop = node.property (X_("bypassed"))) != 0) {
1040 set_bypassed (prop->value() == "yes");
1043 if ((prop = node.property (X_("link_direction"))) != 0) {
1044 LinkDirection ld; /* here to provide type information */
1045 set_link_direction (LinkDirection (string_2_enum (prop->value(), ld)));
1048 nlist = node.children();
1050 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1051 if ((*niter)->name() == X_("Output")) {
1055 prop = (*niter)->property (X_("x"));
1056 sscanf (prop->value().c_str(), "%g", &x);
1058 prop = (*niter)->property (X_("y"));
1059 sscanf (prop->value().c_str(), "%g", &y);
1061 outputs.push_back (Output (x, y));
1065 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1067 if ((*niter)->name() == X_("StreamPanner")) {
1069 if ((prop = (*niter)->property (X_("type")))) {
1071 for (i = 0; pan_plugins[i].factory; ++i) {
1072 if (prop->value() == pan_plugins[i].name) {
1075 /* note that we assume that all the stream panners
1076 are of the same type. pretty good
1077 assumption, but its still an assumption.
1080 sp = pan_plugins[i].factory (*this);
1082 if (sp->set_state (**niter) == 0) {
1091 if (!pan_plugins[i].factory) {
1092 error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
1098 error << _("panner plugin node has no type information!")
1106 /* don't try to do old-school automation loading if it wasn't marked as existing */
1108 if ((prop = node.property (X_("automation")))) {
1110 /* automation path is relative */
1112 automation_path = _session.automation_dir();
1113 automation_path += prop->value ();
1122 Panner::touching () const
1124 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1125 if ((*i)->pan_control()->list()->touching ()) {
1134 Panner::set_position (float xpos, StreamPanner& orig)
1140 orig.get_position (xnow);
1141 xdelta = xpos - xnow;
1143 if (_link_direction == SameDirection) {
1145 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1147 (*i)->set_position (xpos, true);
1149 (*i)->get_position (xnow);
1150 xnew = min (1.0f, xnow + xdelta);
1151 xnew = max (0.0f, xnew);
1152 (*i)->set_position (xnew, true);
1158 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1160 (*i)->set_position (xpos, true);
1162 (*i)->get_position (xnow);
1163 xnew = min (1.0f, xnow - xdelta);
1164 xnew = max (0.0f, xnew);
1165 (*i)->set_position (xnew, true);
1172 Panner::set_position (float xpos, float ypos, StreamPanner& orig)
1175 float xdelta, ydelta;
1178 orig.get_position (xnow, ynow);
1179 xdelta = xpos - xnow;
1180 ydelta = ypos - ynow;
1182 if (_link_direction == SameDirection) {
1184 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1186 (*i)->set_position (xpos, ypos, true);
1188 (*i)->get_position (xnow, ynow);
1190 xnew = min (1.0f, xnow + xdelta);
1191 xnew = max (0.0f, xnew);
1193 ynew = min (1.0f, ynow + ydelta);
1194 ynew = max (0.0f, ynew);
1196 (*i)->set_position (xnew, ynew, true);
1202 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1204 (*i)->set_position (xpos, ypos, true);
1206 (*i)->get_position (xnow, ynow);
1208 xnew = min (1.0f, xnow - xdelta);
1209 xnew = max (0.0f, xnew);
1211 ynew = min (1.0f, ynow - ydelta);
1212 ynew = max (0.0f, ynew);
1214 (*i)->set_position (xnew, ynew, true);
1221 Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
1223 float xnow, ynow, znow;
1224 float xdelta, ydelta, zdelta;
1225 float xnew, ynew, znew;
1227 orig.get_position (xnow, ynow, znow);
1228 xdelta = xpos - xnow;
1229 ydelta = ypos - ynow;
1230 zdelta = zpos - znow;
1232 if (_link_direction == SameDirection) {
1234 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1236 (*i)->set_position (xpos, ypos, zpos, true);
1238 (*i)->get_position (xnow, ynow, znow);
1240 xnew = min (1.0f, xnow + xdelta);
1241 xnew = max (0.0f, xnew);
1243 ynew = min (1.0f, ynow + ydelta);
1244 ynew = max (0.0f, ynew);
1246 znew = min (1.0f, znow + zdelta);
1247 znew = max (0.0f, znew);
1249 (*i)->set_position (xnew, ynew, znew, true);
1255 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1257 (*i)->set_position (xpos, ypos, true);
1259 (*i)->get_position (xnow, ynow, znow);
1261 xnew = min (1.0f, xnow - xdelta);
1262 xnew = max (0.0f, xnew);
1264 ynew = min (1.0f, ynow - ydelta);
1265 ynew = max (0.0f, ynew);
1267 znew = min (1.0f, znow + zdelta);
1268 znew = max (0.0f, znew);
1270 (*i)->set_position (xnew, ynew, znew, true);
1277 Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes_t nframes, nframes_t offset, gain_t gain_coeff)
1279 if (outbufs.count().n_audio() == 0) {
1280 // Don't want to lose audio...
1281 assert(inbufs.count().n_audio() == 0);
1285 // We shouldn't be called in the first place...
1286 assert(!bypassed());
1290 if (outbufs.count().n_audio() == 1) {
1292 AudioBuffer& dst = outbufs.get_audio(0);
1294 if (gain_coeff == 0.0f) {
1296 /* only one output, and gain was zero, so make it silent */
1298 dst.silence(offset);
1300 } else if (gain_coeff == 1.0f){
1302 /* mix all buffers into the output */
1305 dst.read_from(inbufs.get_audio(0), nframes, offset);
1307 // accumulate starting with the second
1308 BufferSet::audio_iterator i = inbufs.audio_begin();
1309 for (++i; i != inbufs.audio_end(); ++i) {
1310 dst.accumulate_from(*i, nframes, offset);
1315 /* mix all buffers into the output, scaling them all by the gain */
1318 dst.read_from(inbufs.get_audio(0), nframes, offset);
1320 // accumulate (with gain) starting with the second
1321 BufferSet::audio_iterator i = inbufs.audio_begin();
1322 for (++i; i != inbufs.audio_end(); ++i) {
1323 dst.accumulate_with_gain_from(*i, nframes, offset, gain_coeff);
1331 /* the terrible silence ... */
1332 for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
1333 i->silence(nframes, offset);
1336 BufferSet::audio_iterator i = inbufs.audio_begin();
1338 for (iterator pan = begin(); pan != end() && i != inbufs.audio_end(); ++pan, ++i) {
1339 (*pan)->distribute (*i, outbufs, gain_coeff, nframes);
1344 Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
1346 if (outbufs.count().n_audio() == 0) {
1347 // Failing to deliver audio we were asked to deliver is a bug
1348 assert(inbufs.count().n_audio() == 0);
1352 // We shouldn't be called in the first place...
1353 assert(!bypassed());
1356 // If we shouldn't play automation defer to distribute_no_automation
1357 if ( !( automation_state() & Play ||
1358 ((automation_state() & Touch) && !touching()) ) ) {
1361 gain_t gain_coeff = 1.0;
1362 if (fabsf(_session.transport_speed()) > 1.5f) {
1363 gain_coeff = speed_quietning;
1366 distribute_no_automation(inbufs, outbufs, nframes, offset, gain_coeff);
1370 // Otherwise.. let the automation flow, baby
1372 if (outbufs.count().n_audio() == 1) {
1374 AudioBuffer& dst = outbufs.get_audio(0);
1376 // FIXME: apply gain automation?
1379 dst.read_from(inbufs.get_audio(0), nframes, offset);
1381 // accumulate starting with the second
1382 BufferSet::audio_iterator i = inbufs.audio_begin();
1383 for (++i; i != inbufs.audio_end(); ++i) {
1384 dst.accumulate_from(*i, nframes, offset);
1390 // More than 1 output, we should have 1 panner for each input
1391 assert(size() == inbufs.count().n_audio());
1393 /* the terrible silence ... */
1394 for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
1395 i->silence(nframes, offset);
1398 BufferSet::audio_iterator i = inbufs.audio_begin();
1399 for (iterator pan = begin(); pan != end(); ++pan, ++i) {
1400 (*pan)->distribute_automated (*i, outbufs, start_frame, end_frame, nframes, _session.pan_automation_buffer());
1404 /* old school automation handling */
1407 Panner::set_name (string str)
1409 automation_path = _session.automation_dir();
1410 automation_path += _session.snap_name();
1411 automation_path += "-pan-";
1412 automation_path += legalize_for_path (str);
1413 automation_path += ".automation";
1420 uint32_t linecnt = 0;
1423 LocaleGuard lg (X_("POSIX"));
1425 if (automation_path.length() == 0) {
1429 if (access (automation_path.c_str(), F_OK)) {
1433 ifstream in (automation_path.c_str());
1436 error << string_compose (_("cannot open pan automation file %1 (%2)"),
1437 automation_path, strerror (errno))
1444 while (in.getline (line, sizeof(line), '\n')) {
1446 if (++linecnt == 1) {
1447 if (memcmp (line, X_("version"), 7) == 0) {
1448 if (sscanf (line, "version %f", &version) != 1) {
1449 error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg;
1453 error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"),
1454 automation_path, line) << endmsg;
1461 if (strlen (line) == 0 || line[0] == '#') {
1465 if (strcmp (line, "begin") == 0) {
1468 error << string_compose (_("too many panner states found in pan automation file %1"),
1474 if ((*sp)->load (in, automation_path, linecnt)) {