-using namespace PBD;
-
-float Panner::current_automation_version_number = 1.0;
-
-string EqualPowerStereoPanner::name = "Equal Power Stereo";
-string Multi2dPanner::name = "Multiple (2D)";
-
-/* this is a default mapper of control values to a pan position
- others can be imagined.
-*/
-
-static pan_t direct_control_to_pan (double fract) {
- return fract;
-}
-
-
-//static double direct_pan_to_control (pan_t val) {
-// return val;
-//}
-
-StreamPanner::StreamPanner (Panner& p, Evoral::Parameter param)
- : parent (p)
-{
- assert(param.type() != NullAutomation);
-
- _muted = false;
-
- _control = boost::dynamic_pointer_cast<AutomationControl>( parent.control( param, true ) );
-
- x = 0.5;
- y = 0.5;
- z = 0.5;
-}
-
-StreamPanner::~StreamPanner ()
-{
-}
-
-void
-Panner::PanControllable::set_value (float val)
-{
- panner.streampanner(parameter().id()).set_position (direct_control_to_pan (val));
- AutomationControl::set_value(val);
-}
-
-float
-Panner::PanControllable::get_value (void) const
-{
- return AutomationControl::get_value();
-}
-
-void
-StreamPanner::set_muted (bool yn)
-{
- if (yn != _muted) {
- _muted = yn;
- StateChanged ();
- }
-}
-
-void
-StreamPanner::set_position (float xpos, bool link_call)
-{
- if (!link_call && parent.linked()) {
- parent.set_position (xpos, *this);
- }
-
- if (x != xpos) {
- x = xpos;
- update ();
- Changed ();
- _control->Changed ();
- }
-}
-
-void
-StreamPanner::set_position (float xpos, float ypos, bool link_call)
-{
- if (!link_call && parent.linked()) {
- parent.set_position (xpos, ypos, *this);
- }
-
- if (x != xpos || y != ypos) {
-
- x = xpos;
- y = ypos;
- update ();
- Changed ();
- }
-}
-
-void
-StreamPanner::set_position (float xpos, float ypos, float zpos, bool link_call)
-{
- if (!link_call && parent.linked()) {
- parent.set_position (xpos, ypos, zpos, *this);
- }
-
- if (x != xpos || y != ypos || z != zpos) {
- x = xpos;
- y = ypos;
- z = zpos;
- update ();
- Changed ();
- }
-}
-
-int
-StreamPanner::set_state (const XMLNode& node)
-{
- const XMLProperty* prop;
- XMLNodeConstIterator iter;
-
- if ((prop = node.property (X_("muted")))) {
- set_muted (prop->value() == "yes");
- }
-
- return 0;
-}
-
-void
-StreamPanner::add_state (XMLNode& node)
-{
- node.add_property (X_("muted"), (muted() ? "yes" : "no"));
-}
-
-/*---------------------------------------------------------------------- */
-
-BaseStereoPanner::BaseStereoPanner (Panner& p, Evoral::Parameter param)
- : StreamPanner (p, param)
-{
-}
-
-BaseStereoPanner::~BaseStereoPanner ()
-{
-}
-
-int
-BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
-{
- char line[128];
- LocaleGuard lg (X_("POSIX"));
-
- _control->list()->clear ();
-
- while (in.getline (line, sizeof (line), '\n')) {
- nframes_t when;
- double value;
-
- ++linecnt;
-
- if (strcmp (line, "end") == 0) {
- break;
- }
-
- if (sscanf (line, "%" PRIu32 " %lf", &when, &value) != 2) {
- warning << string_compose(_("badly formatted pan automation event record at line %1 of %2 (ignored) [%3]"), linecnt, path, line) << endmsg;
- continue;
- }
-
- _control->list()->fast_simple_add (when, value);
- }
-
- /* now that we are done loading */
-
- ((AutomationList*)_control->list().get())->StateChanged ();
-
- return 0;
-}
-
-void
-BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes)
-{
- assert(obufs.count().n_audio() == 2);
-
- pan_t delta;
- Sample* dst;
- pan_t pan;
-
- if (_muted) {
- return;
- }
-
- Sample* const src = srcbuf.data();
-
- /* LEFT */
-
- dst = obufs.get_audio(0).data();
-
- if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
-
- /* interpolate over 64 frames or nframes, whichever is smaller */
-
- nframes_t limit = min ((nframes_t)64, nframes);
- nframes_t n;
-
- delta = -(delta / (float) (limit));
-
- for (n = 0; n < limit; n++) {
- left_interp = left_interp + delta;
- left = left_interp + 0.9 * (left - left_interp);
- dst[n] += src[n] * left * gain_coeff;
- }
-
- pan = left * gain_coeff;
-
- mix_buffers_with_gain (dst+n,src+n,nframes-n,pan);
-
- } else {
-
- left = desired_left;
- left_interp = left;
-
- if ((pan = (left * gain_coeff)) != 1.0f) {
-
- if (pan != 0.0f) {
-
- mix_buffers_with_gain(dst,src,nframes,pan);
-
- /* mark that we wrote into the buffer */
-
- // obufs[0] = 0;
-
- }
-
- } else {
-
- mix_buffers_no_gain(dst,src,nframes);
-
- /* mark that we wrote into the buffer */
-
- // obufs[0] = 0;
- }
- }
-
- /* RIGHT */
-
- dst = obufs.get_audio(1).data();
-
- if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
-
- /* interpolate over 64 frames or nframes, whichever is smaller */
-
- nframes_t limit = min ((nframes_t)64, nframes);
- nframes_t n;
-
- delta = -(delta / (float) (limit));
-
- for (n = 0; n < limit; n++) {
- right_interp = right_interp + delta;
- right = right_interp + 0.9 * (right - right_interp);
- dst[n] += src[n] * right * gain_coeff;
- }
-
- pan = right * gain_coeff;
-
- mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
-
- /* XXX it would be nice to mark the buffer as written to */
-
- } else {
-
- right = desired_right;
- right_interp = right;
-
- if ((pan = (right * gain_coeff)) != 1.0f) {
-
- if (pan != 0.0f) {
-
- mix_buffers_with_gain(dst,src,nframes,pan);
-
- /* XXX it would be nice to mark the buffer as written to */
- }
-
- } else {
-
- mix_buffers_no_gain(dst,src,nframes);
-
- /* XXX it would be nice to mark the buffer as written to */
- }
- }
-}
-
-/*---------------------------------------------------------------------- */
-
-EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p, Evoral::Parameter param)
- : BaseStereoPanner (p, param)
-{
- update ();