2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <pbd/error.h>
34 #include <pbd/failed_constructor.h>
35 #include <pbd/xml++.h>
37 #include <ardour/session.h>
38 #include <ardour/panner.h>
39 #include <ardour/utils.h>
41 #include <ardour/mix.h>
42 #include <ardour/buffer_set.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)
80 StreamPanner::~StreamPanner ()
85 StreamPanner::PanControllable::set_value (float val)
87 panner.set_position (direct_control_to_pan (val));
91 StreamPanner::PanControllable::get_value (void) const
94 panner.get_effective_position (xpos);
95 return direct_pan_to_control (xpos);
99 StreamPanner::PanControllable::can_send_feedback () const
101 AutoState astate = panner.get_parent().automation_state ();
103 if ((astate == Play) || (astate == Touch && !panner.get_parent().touching())) {
111 StreamPanner::set_muted (bool yn)
120 StreamPanner::set_position (float xpos, bool link_call)
122 if (!link_call && parent.linked()) {
123 parent.set_position (xpos, *this);
135 StreamPanner::set_position (float xpos, float ypos, bool link_call)
137 if (!link_call && parent.linked()) {
138 parent.set_position (xpos, ypos, *this);
141 if (x != xpos || y != ypos) {
151 StreamPanner::set_position (float xpos, float ypos, float zpos, bool link_call)
153 if (!link_call && parent.linked()) {
154 parent.set_position (xpos, ypos, zpos, *this);
157 if (x != xpos || y != ypos || z != zpos) {
167 StreamPanner::set_state (const XMLNode& node)
169 const XMLProperty* prop;
170 XMLNodeConstIterator iter;
172 if ((prop = node.property (X_("muted")))) {
173 set_muted (prop->value() == "yes");
180 StreamPanner::add_state (XMLNode& node)
182 node.add_property (X_("muted"), (muted() ? "yes" : "no"));
185 /*---------------------------------------------------------------------- */
187 BaseStereoPanner::BaseStereoPanner (Panner& p)
188 : StreamPanner (p), _automation (0.0, 1.0, 0.5)
192 BaseStereoPanner::~BaseStereoPanner ()
197 BaseStereoPanner::snapshot (jack_nframes_t now)
199 if (_automation.automation_state() == Write || _automation.automation_state() == Touch) {
200 _automation.rt_add (now, x);
205 BaseStereoPanner::transport_stopped (jack_nframes_t frame)
207 _automation.reposition_for_rt_add (frame);
209 if (_automation.automation_state() != Off) {
211 if (_automation.automation_write()) {
212 _automation.save_state (_("automation write pass"));
215 set_position (_automation.eval (frame));
220 BaseStereoPanner::set_automation_style (AutoStyle style)
222 _automation.set_automation_style (style);
226 BaseStereoPanner::set_automation_state (AutoState state)
228 if (state != _automation.automation_state()) {
230 _automation.set_automation_state (state);
233 set_position (_automation.eval (parent.session().transport_frame()));
239 BaseStereoPanner::save (ostream& out) const
241 LocaleGuard lg (X_("POSIX"));
243 /* force a single format for numeric data to ease session interchange
244 across national boundaries.
247 out << "begin" << endl;
249 for (AutomationList::const_iterator i = _automation.const_begin(); i != _automation.const_end(); ++i) {
250 out << '\t' << (jack_nframes_t) floor ((*i)->when) << ' ' << (*i)->value << endl;
252 error << string_compose (_("error writing pan automation file (%s)"), strerror (errno)) << endmsg;
256 out << "end" << endl;
262 BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
265 LocaleGuard lg (X_("POSIX"));
267 _automation.clear ();
269 while (in.getline (line, sizeof (line), '\n')) {
275 if (strcmp (line, "end") == 0) {
279 if (sscanf (line, "%" PRIu32 " %lf", &when, &value) != 2) {
280 warning << string_compose(_("badly formatted pan automation event record at line %1 of %2 (ignored) [%3]"), linecnt, path, line) << endmsg;
284 _automation.add (when, value, true);
287 /* now that we are done loading */
289 _automation.save_state (_("loaded from disk"));
290 _automation.StateChanged (Change (0));
296 BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, jack_nframes_t nframes)
298 assert(obufs.count().get(DataType::AUDIO) == 2);
308 Sample* const src = srcbuf.data(nframes);
312 dst = obufs.get_audio(0).data(nframes);
314 if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
316 /* interpolate over 64 frames or nframes, whichever is smaller */
318 jack_nframes_t limit = min ((jack_nframes_t)64, nframes);
321 delta = -(delta / (float) (limit));
323 for (n = 0; n < limit; n++) {
324 left_interp = left_interp + delta;
325 left = left_interp + 0.9 * (left - left_interp);
326 dst[n] += src[n] * left * gain_coeff;
329 pan = left * gain_coeff;
331 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
338 if ((pan = (left * gain_coeff)) != 1.0f) {
342 Session::mix_buffers_with_gain(dst,src,nframes,pan);
344 /* mark that we wrote into the buffer */
352 Session::mix_buffers_no_gain(dst,src,nframes);
354 /* mark that we wrote into the buffer */
362 dst = obufs.get_audio(1).data(nframes);
364 if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
366 /* interpolate over 64 frames or nframes, whichever is smaller */
368 jack_nframes_t limit = min ((jack_nframes_t)64, nframes);
371 delta = -(delta / (float) (limit));
373 for (n = 0; n < limit; n++) {
374 right_interp = right_interp + delta;
375 right = right_interp + 0.9 * (right - right_interp);
376 dst[n] += src[n] * right * gain_coeff;
379 pan = right * gain_coeff;
381 Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
383 /* XXX it would be nice to mark the buffer as written to */
387 right = desired_right;
388 right_interp = right;
390 if ((pan = (right * gain_coeff)) != 1.0f) {
394 Session::mix_buffers_with_gain(dst,src,nframes,pan);
396 /* XXX it would be nice to mark the buffer as written to */
401 Session::mix_buffers_no_gain(dst,src,nframes);
403 /* XXX it would be nice to mark the buffer as written to */
408 /*---------------------------------------------------------------------- */
410 EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
411 : BaseStereoPanner (p)
416 right = desired_right;
418 right_interp = right;
421 EqualPowerStereoPanner::~EqualPowerStereoPanner ()
426 EqualPowerStereoPanner::update ()
428 /* it would be very nice to split this out into a virtual function
429 that can be accessed from BaseStereoPanner and used in distribute_automated().
431 but the place where its used in distribute_automated() is a tight inner loop,
432 and making "nframes" virtual function calls to compute values is an absurd
436 /* x == 0 => hard left
441 float panL = 1 - panR;
443 const float pan_law_attenuation = -3.0f;
444 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
446 desired_left = panL * (scale * panL + 1.0f - scale);
447 desired_right = panR * (scale * panR + 1.0f - scale);
453 EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& obufs,
454 jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes,
457 assert(obufs.count().get(DataType::AUDIO) == 2);
461 Sample* const src = srcbuf.data(nframes);
463 /* fetch positional data */
465 if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
468 distribute (srcbuf, obufs, 1.0, nframes);
473 /* store effective pan position. do this even if we are muted */
476 effective_x = buffers[0][nframes-1];
482 /* apply pan law to convert positional data into pan coefficients for
486 const float pan_law_attenuation = -3.0f;
487 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
489 for (jack_nframes_t n = 0; n < nframes; ++n) {
491 float panR = buffers[0][n];
492 float panL = 1 - panR;
494 buffers[0][n] = panL * (scale * panL + 1.0f - scale);
495 buffers[1][n] = panR * (scale * panR + 1.0f - scale);
500 dst = obufs.get_audio(0).data(nframes);
503 for (jack_nframes_t n = 0; n < nframes; ++n) {
504 dst[n] += src[n] * pbuf[n];
507 /* XXX it would be nice to mark the buffer as written to */
511 dst = obufs.get_audio(1).data(nframes);
514 for (jack_nframes_t n = 0; n < nframes; ++n) {
515 dst[n] += src[n] * pbuf[n];
518 /* XXX it would be nice to mark the buffer as written to */
522 EqualPowerStereoPanner::factory (Panner& parent)
524 return new EqualPowerStereoPanner (parent);
528 EqualPowerStereoPanner::get_state (void)
534 EqualPowerStereoPanner::state (bool full_state)
536 XMLNode* root = new XMLNode ("StreamPanner");
538 LocaleGuard lg (X_("POSIX"));
540 snprintf (buf, sizeof (buf), "%.12g", x);
541 root->add_property (X_("x"), buf);
542 root->add_property (X_("type"), EqualPowerStereoPanner::name);
544 snprintf (buf, sizeof (buf), "0x%x", _automation.automation_state());
546 /* never store automation states other than off in a template */
547 snprintf (buf, sizeof (buf), "0x%x", ARDOUR::Off);
549 root->add_property (X_("automation-state"), buf);
550 snprintf (buf, sizeof (buf), "0x%x", _automation.automation_style());
551 root->add_property (X_("automation-style"), buf);
553 StreamPanner::add_state (*root);
559 EqualPowerStereoPanner::set_state (const XMLNode& node)
561 const XMLProperty* prop;
564 LocaleGuard lg (X_("POSIX"));
566 if ((prop = node.property (X_("x")))) {
567 pos = atof (prop->value().c_str());
568 set_position (pos, true);
571 if ((prop = node.property (X_("automation-state")))) {
572 sscanf (prop->value().c_str(), "0x%x", &x);
573 _automation.set_automation_state ((AutoState) x);
576 set_position (_automation.eval (parent.session().transport_frame()));
580 if ((prop = node.property (X_("automation-style")))) {
581 sscanf (prop->value().c_str(), "0x%x", &x);
582 _automation.set_automation_style ((AutoStyle) x);
585 StreamPanner::set_state (node);
590 /*----------------------------------------------------------------------*/
592 Multi2dPanner::Multi2dPanner (Panner& p)
593 : StreamPanner (p), _automation (0.0, 1.0, 0.5) // XXX useless
598 Multi2dPanner::~Multi2dPanner ()
603 Multi2dPanner::snapshot (jack_nframes_t now)
609 Multi2dPanner::transport_stopped (jack_nframes_t frame)
615 Multi2dPanner::set_automation_style (AutoStyle style)
621 Multi2dPanner::set_automation_state (AutoState state)
627 Multi2dPanner::update ()
629 static const float BIAS = FLT_MIN;
631 uint32_t nouts = parent.outputs.size();
638 for (i = 0; i < nouts; i++) {
639 dsq[i] = ((x - parent.outputs[i].x) * (x - parent.outputs[i].x) + (y - parent.outputs[i].y) * (y - parent.outputs[i].y) + BIAS);
643 f += dsq[i] * dsq[i];
646 // terrible hack to support OSX < 10.3.9 builds
647 fr = (float) (1.0 / sqrt((double)f));
651 for (i = 0; i < nouts; ++i) {
652 parent.outputs[i].desired_pan = 1.0f - (dsq[i] * fr);
659 Multi2dPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, jack_nframes_t nframes)
663 vector<Panner::Output>::iterator o;
670 Sample* const src = srcbuf.data(nframes);
673 for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
675 dst = obufs.get_audio(n).data(nframes);
678 if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
680 /* interpolate over 64 frames or nframes, whichever is smaller */
682 jack_nframes_t limit = min ((jack_nframes_t)64, nframes);
685 delta = -(delta / (float) (limit));
687 for (n = 0; n < limit; n++) {
688 left_interp = left_interp + delta;
689 left = left_interp + 0.9 * (left - left_interp);
690 dst[n] += src[n] * left * gain_coeff;
693 pan = left * gain_coeff;
695 for (; n < nframes; ++n) {
696 dst[n] += src[n] * pan;
702 pan = (*o).desired_pan;
704 if ((pan *= gain_coeff) != 1.0f) {
708 for (jack_nframes_t n = 0; n < nframes; ++n) {
709 dst[n] += src[n] * pan;
717 for (jack_nframes_t n = 0; n < nframes; ++n) {
732 Multi2dPanner::distribute_automated (AudioBuffer& src, BufferSet& obufs,
733 jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes,
746 Multi2dPanner::factory (Panner& p)
748 return new Multi2dPanner (p);
752 Multi2dPanner::load (istream& in, string path, uint32_t& linecnt)
758 Multi2dPanner::save (ostream& out) const
764 Multi2dPanner::get_state (void)
770 Multi2dPanner::state (bool full_state)
772 XMLNode* root = new XMLNode ("StreamPanner");
774 LocaleGuard lg (X_("POSIX"));
776 snprintf (buf, sizeof (buf), "%.12g", x);
777 root->add_property (X_("x"), buf);
778 snprintf (buf, sizeof (buf), "%.12g", y);
779 root->add_property (X_("y"), buf);
780 root->add_property (X_("type"), Multi2dPanner::name);
786 Multi2dPanner::set_state (const XMLNode& node)
788 const XMLProperty* prop;
790 LocaleGuard lg (X_("POSIX"));
795 if ((prop = node.property (X_("x")))) {
796 newx = atof (prop->value().c_str());
799 if ((prop = node.property (X_("y")))) {
800 newy = atof (prop->value().c_str());
803 if (x < 0 || y < 0) {
804 error << _("badly-formed positional data for Multi2dPanner - ignored")
809 set_position (newx, newy);
813 /*---------------------------------------------------------------------- */
815 Panner::Panner (string name, Session& s)
820 _link_direction = SameDirection;
829 Panner::set_linked (bool yn)
833 _session.set_dirty ();
834 LinkStateChanged (); /* EMIT SIGNAL */
839 Panner::set_link_direction (LinkDirection ld)
841 if (ld != _link_direction) {
842 _link_direction = ld;
843 _session.set_dirty ();
844 LinkStateChanged (); /* EMIT SIGNAL */
849 Panner::set_name (string str)
851 automation_path = _session.automation_dir();
852 automation_path += _session.snap_name();
853 automation_path += "-pan-";
854 automation_path += legalize_for_path (str);
855 automation_path += ".automation";
860 Panner::set_bypassed (bool yn)
862 if (yn != _bypassed) {
870 Panner::reset (uint32_t nouts, uint32_t npans)
873 bool changed = false;
876 if (nouts < 2 || (nouts == outputs.size() && npans == size())) {
899 fatal << _("programming error:")
900 << X_("Panner::reset() called with a single output")
907 outputs.push_back (Output (0, 0));
908 outputs.push_back (Output (1.0, 0));
910 for (n = 0; n < npans; ++n) {
911 push_back (new EqualPowerStereoPanner (*this));
916 outputs.push_back (Output (0.5, 0));
917 outputs.push_back (Output (0, 1.0));
918 outputs.push_back (Output (1.0, 1.0));
920 for (n = 0; n < npans; ++n) {
921 push_back (new Multi2dPanner (*this));
927 outputs.push_back (Output (0, 0));
928 outputs.push_back (Output (1.0, 0));
929 outputs.push_back (Output (1.0, 1.0));
930 outputs.push_back (Output (0, 1.0));
932 for (n = 0; n < npans; ++n) {
933 push_back (new Multi2dPanner (*this));
938 case 5: //square+offcenter center
939 outputs.push_back (Output (0, 0));
940 outputs.push_back (Output (1.0, 0));
941 outputs.push_back (Output (1.0, 1.0));
942 outputs.push_back (Output (0, 1.0));
943 outputs.push_back (Output (0.5, 0.75));
945 for (n = 0; n < npans; ++n) {
946 push_back (new Multi2dPanner (*this));
952 /* XXX horrible placement. FIXME */
953 for (n = 0; n < nouts; ++n) {
954 outputs.push_back (Output (0.1 * n, 0.1 * n));
957 for (n = 0; n < npans; ++n) {
958 push_back (new Multi2dPanner (*this));
964 for (iterator x = begin(); x != end(); ++x) {
968 /* force hard left/right panning in a common case: 2in/2out
971 if (npans == 2 && outputs.size() == 2) {
973 /* Do this only if we changed configuration, or our configuration
974 appears to be the default set up (center).
980 front()->get_position (left);
981 back()->get_position (right);
983 if (changed || ((left == 0.5) && (right == 0.5))) {
985 front()->set_position (0.0);
986 front()->automation().reset_default (0.0);
988 back()->set_position (1.0);
989 back()->automation().reset_default (1.0);
996 Changed (); /* EMIT SIGNAL */
1003 Panner::remove (uint32_t which)
1005 vector<StreamPanner*>::iterator i;
1006 for (i = begin(); i != end() && which; ++i, --which);
1017 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1021 vector<StreamPanner*>::clear ();
1025 Panner::set_automation_style (AutoStyle style)
1027 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1028 (*i)->set_automation_style (style);
1030 _session.set_dirty ();
1034 Panner::set_automation_state (AutoState state)
1036 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1037 (*i)->set_automation_state (state);
1039 _session.set_dirty ();
1043 Panner::automation_state () const
1046 return front()->automation().automation_state ();
1053 Panner::automation_style () const
1056 return front()->automation().automation_style ();
1063 Panner::transport_stopped (jack_nframes_t frame)
1065 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1066 (*i)->transport_stopped (frame);
1071 Panner::snapshot (jack_nframes_t now)
1073 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1074 (*i)->snapshot (now);
1079 Panner::clear_automation ()
1081 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1082 (*i)->automation().clear ();
1084 _session.set_dirty ();
1088 Panner::save () const
1090 ofstream out (automation_path.c_str());
1093 error << string_compose (_("cannot open pan automation file \"%1\" for saving (%s)"), automation_path, strerror (errno))
1098 out << X_("version ") << current_automation_version_number << endl;
1100 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1101 if ((*i)->save (out)) {
1113 uint32_t linecnt = 0;
1116 LocaleGuard lg (X_("POSIX"));
1118 if (automation_path.length() == 0) {
1122 if (access (automation_path.c_str(), F_OK)) {
1126 ifstream in (automation_path.c_str());
1129 error << string_compose (_("cannot open pan automation file %1 (%2)"),
1130 automation_path, strerror (errno))
1137 while (in.getline (line, sizeof(line), '\n')) {
1139 if (++linecnt == 1) {
1140 if (memcmp (line, X_("version"), 7) == 0) {
1141 if (sscanf (line, "version %f", &version) != 1) {
1142 error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg;
1146 error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"),
1147 automation_path, line) << endmsg;
1151 if (version != current_automation_version_number) {
1152 error << string_compose(_("mismatched pan automation event file version (%1)"), version) << endmsg;
1159 if (strlen (line) == 0 || line[0] == '#') {
1163 if (strcmp (line, "begin") == 0) {
1166 error << string_compose (_("too many panner states found in pan automation file %1"),
1172 if ((*sp)->load (in, automation_path, linecnt)) {
1186 StreamPanner* (*factory)(Panner&);
1189 PanPlugins pan_plugins[] = {
1190 { EqualPowerStereoPanner::name, 2, EqualPowerStereoPanner::factory },
1191 { Multi2dPanner::name, 3, Multi2dPanner::factory },
1192 { string (""), 0, 0 }
1196 Panner::get_state (void)
1198 return state (true);
1202 Panner::state (bool full)
1204 XMLNode* root = new XMLNode (X_("Panner"));
1207 for (iterator p = begin(); p != end(); ++p) {
1208 root->add_child_nocopy ((*p)->state (full));
1211 root->add_property (X_("linked"), (_linked ? "yes" : "no"));
1212 snprintf (buf, sizeof (buf), "%d", _link_direction);
1213 root->add_property (X_("link_direction"), buf);
1214 root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
1216 /* add each output */
1218 for (vector<Panner::Output>::iterator o = outputs.begin(); o != outputs.end(); ++o) {
1219 XMLNode* onode = new XMLNode (X_("Output"));
1220 snprintf (buf, sizeof (buf), "%.12g", (*o).x);
1221 onode->add_property (X_("x"), buf);
1222 snprintf (buf, sizeof (buf), "%.12g", (*o).y);
1223 onode->add_property (X_("y"), buf);
1224 root->add_child_nocopy (*onode);
1229 root->add_property (X_("automation"), Glib::path_get_basename (automation_path));
1237 Panner::set_state (const XMLNode& node)
1240 XMLNodeConstIterator niter;
1241 const XMLProperty *prop;
1244 LocaleGuard lg (X_("POSIX"));
1249 if ((prop = node.property (X_("linked"))) != 0) {
1250 set_linked (prop->value() == "yes");
1254 if ((prop = node.property (X_("bypassed"))) != 0) {
1255 set_bypassed (prop->value() == "yes");
1258 if ((prop = node.property (X_("link_direction"))) != 0) {
1259 sscanf (prop->value().c_str(), "%d", &i);
1260 set_link_direction ((LinkDirection) (i));
1263 nlist = node.children();
1265 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1266 if ((*niter)->name() == X_("Output")) {
1270 prop = (*niter)->property (X_("x"));
1271 sscanf (prop->value().c_str(), "%g", &x);
1273 prop = (*niter)->property (X_("y"));
1274 sscanf (prop->value().c_str(), "%g", &y);
1276 outputs.push_back (Output (x, y));
1280 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1282 if ((*niter)->name() == X_("StreamPanner")) {
1284 if ((prop = (*niter)->property (X_("type")))) {
1286 for (i = 0; pan_plugins[i].factory; ++i) {
1287 if (prop->value() == pan_plugins[i].name) {
1290 /* note that we assume that all the stream panners
1291 are of the same type. pretty good
1292 assumption, but its still an assumption.
1295 sp = pan_plugins[i].factory (*this);
1297 if (sp->set_state (**niter) == 0) {
1306 if (!pan_plugins[i].factory) {
1307 error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
1313 error << _("panner plugin node has no type information!")
1321 /* don't try to load automation if it wasn't marked as existing */
1323 if ((prop = node.property (X_("automation")))) {
1325 /* automation path is relative */
1327 automation_path = _session.automation_dir();
1328 automation_path += prop->value ();
1337 Panner::touching () const
1339 for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
1340 if ((*i)->automation().touching ()) {
1349 Panner::set_position (float xpos, StreamPanner& orig)
1355 orig.get_position (xnow);
1356 xdelta = xpos - xnow;
1358 if (_link_direction == SameDirection) {
1360 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1362 (*i)->set_position (xpos, true);
1364 (*i)->get_position (xnow);
1365 xnew = min (1.0f, xnow + xdelta);
1366 xnew = max (0.0f, xnew);
1367 (*i)->set_position (xnew, true);
1373 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1375 (*i)->set_position (xpos, true);
1377 (*i)->get_position (xnow);
1378 xnew = min (1.0f, xnow - xdelta);
1379 xnew = max (0.0f, xnew);
1380 (*i)->set_position (xnew, true);
1387 Panner::set_position (float xpos, float ypos, StreamPanner& orig)
1390 float xdelta, ydelta;
1393 orig.get_position (xnow, ynow);
1394 xdelta = xpos - xnow;
1395 ydelta = ypos - ynow;
1397 if (_link_direction == SameDirection) {
1399 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1401 (*i)->set_position (xpos, ypos, true);
1403 (*i)->get_position (xnow, ynow);
1405 xnew = min (1.0f, xnow + xdelta);
1406 xnew = max (0.0f, xnew);
1408 ynew = min (1.0f, ynow + ydelta);
1409 ynew = max (0.0f, ynew);
1411 (*i)->set_position (xnew, ynew, true);
1417 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1419 (*i)->set_position (xpos, ypos, true);
1421 (*i)->get_position (xnow, ynow);
1423 xnew = min (1.0f, xnow - xdelta);
1424 xnew = max (0.0f, xnew);
1426 ynew = min (1.0f, ynow - ydelta);
1427 ynew = max (0.0f, ynew);
1429 (*i)->set_position (xnew, ynew, true);
1436 Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
1438 float xnow, ynow, znow;
1439 float xdelta, ydelta, zdelta;
1440 float xnew, ynew, znew;
1442 orig.get_position (xnow, ynow, znow);
1443 xdelta = xpos - xnow;
1444 ydelta = ypos - ynow;
1445 zdelta = zpos - znow;
1447 if (_link_direction == SameDirection) {
1449 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1451 (*i)->set_position (xpos, ypos, zpos, true);
1453 (*i)->get_position (xnow, ynow, znow);
1455 xnew = min (1.0f, xnow + xdelta);
1456 xnew = max (0.0f, xnew);
1458 ynew = min (1.0f, ynow + ydelta);
1459 ynew = max (0.0f, ynew);
1461 znew = min (1.0f, znow + zdelta);
1462 znew = max (0.0f, znew);
1464 (*i)->set_position (xnew, ynew, znew, true);
1470 for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
1472 (*i)->set_position (xpos, ypos, true);
1474 (*i)->get_position (xnow, ynow, znow);
1476 xnew = min (1.0f, xnow - xdelta);
1477 xnew = max (0.0f, xnew);
1479 ynew = min (1.0f, ynow - ydelta);
1480 ynew = max (0.0f, ynew);
1482 znew = min (1.0f, znow + zdelta);
1483 znew = max (0.0f, znew);
1485 (*i)->set_position (xnew, ynew, znew, true);
1492 Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff)
1494 if (outbufs.count().get(DataType::AUDIO) == 0) {
1495 // Don't want to lose audio...
1496 assert(inbufs.count().get(DataType::AUDIO) == 0);
1500 // We shouldn't be called in the first place...
1501 assert(!bypassed());
1505 if (outbufs.count().get(DataType::AUDIO) == 1) {
1507 AudioBuffer& dst = outbufs.get_audio(0);
1509 if (gain_coeff == 0.0f) {
1511 /* only one output, and gain was zero, so make it silent */
1513 dst.silence(offset);
1515 } else if (gain_coeff == 1.0f){
1517 /* mix all buffers into the output */
1520 dst.read_from(inbufs.get_audio(0), nframes, offset);
1522 // accumulate starting with the second
1523 BufferSet::audio_iterator i = inbufs.audio_begin();
1524 for (++i; i != inbufs.audio_end(); ++i) {
1525 dst.accumulate_from(*i, nframes, offset);
1528 //audio_output(0)->mark_silence (false); // FIXME
1532 /* mix all buffers into the output, scaling them all by the gain */
1535 dst.read_from(inbufs.get_audio(0), nframes, offset);
1537 // accumulate (with gain) starting with the second
1538 BufferSet::audio_iterator i = inbufs.audio_begin();
1539 for (++i; i != inbufs.audio_end(); ++i) {
1540 dst.accumulate_with_gain_from(*i, nframes, offset, gain_coeff);
1543 //audio_output(0)->mark_silence (false); // FIXME
1549 // More than 1 output, we should have 1 panner for each input
1550 assert(size() == inbufs.count().get(DataType::AUDIO));
1552 /* the terrible silence ... */
1553 for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
1554 i->silence(nframes, offset);
1557 BufferSet::audio_iterator i = inbufs.audio_begin();
1558 for (iterator pan = begin(); pan != end(); ++pan, ++i) {
1559 (*pan)->distribute (*i, outbufs, gain_coeff, nframes);
1564 Panner::distribute_automated (BufferSet& inbufs, BufferSet& outbufs, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset)
1566 if (outbufs.count().get(DataType::AUDIO) == 0) {
1567 // Don't want to lose audio...
1568 assert(inbufs.count().get(DataType::AUDIO) == 0);
1572 // We shouldn't be called in the first place...
1573 assert(!bypassed());
1577 if (outbufs.count().get(DataType::AUDIO) == 1) {
1579 AudioBuffer& dst = outbufs.get_audio(0);
1581 // FIXME: apply gain automation?
1584 dst.read_from(inbufs.get_audio(0), nframes, offset);
1586 // accumulate starting with the second
1587 BufferSet::audio_iterator i = inbufs.audio_begin();
1588 for (++i; i != inbufs.audio_end(); ++i) {
1589 dst.accumulate_from(*i, nframes, offset);
1592 //audio_output(0)->mark_silence (false); // FIXME
1597 // More than 1 output, we should have 1 panner for each input
1598 assert(size() == inbufs.count().get(DataType::AUDIO));
1600 /* the terrible silence ... */
1601 for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
1602 i->silence(nframes, offset);
1605 BufferSet::audio_iterator i = inbufs.audio_begin();
1606 for (iterator pan = begin(); pan != end(); ++pan, ++i) {
1607 (*pan)->distribute_automated (*i, outbufs, start_frame, end_frame, nframes, _session.pan_automation_buffer());