/*
Round Panner

Simple 3D autopan. (360 - Panner).

Pan	Fixed pan position (when Auto = 0)
Auto	Autopan rate (turn to left for anticlockwise, right for clockwise)
Mode	Stereo or Mono pan

Like all 3D processes the result depends on where you sit relative to the speakers,
and mono compatibility is not guaranteed.
This plugin must be used in a stereo channel or bus!
*/

slider1:0.5<0,1,0.00277777>pan
slider2:0.5<0,1,0.00087266>auto
slider3:1<0,1,1{mono,stereo}>mode

in_pin:L in
in_pin:R in
out_pin:L out
out_pin:R out

@init
twopi = 2*$pi;
fourpi = 4*$pi;
piradian = $pi*0.25;
phi = 0;
dphi = (5/srate);
hlfsqrt = sqrt(0.5);

@slider
fParam1 = slider1; //pan
fParam2 = slider2; //auto
fParam3 = slider3; //mode

phi = (twopi * (fParam1 - 0.5));

(fParam2 > 0.5) ? (
dphi = (20 * (fParam2 - 0.50) / srate);
):(
(fParam2 < 0.5) ? (
dphi = (-20 * (0.5 - fParam2) / srate);
):(
dphi = 0;
);
);

mode = fParam3;

@sample
mode == 0 ? (
a = (spl0 + spl1) * hlfsqrt;

c = (a * -sin((0.5 * phi) - piradian));
d = (a *  sin((0.5 * phi) + piradian));

phi = phi + dphi;

spl0 = c;
spl1 = d;

(phi < 0) ? (
phi = phi + fourpi;
):(
(phi > fourpi) ? (
phi = phi - fourpi;
);
);
);

mode == 1 ? (
a = spl0;
b = spl1;

c = a * cos(0.5 * phi) - b * sin(0.5 * phi);
d = b * cos(0.5 * phi) + a * sin(0.5 * phi);

phi = phi + dphi;

spl0 = c;
spl1 = d;

(phi < 0) ? (
phi = phi + fourpi;
):(
(phi > fourpi) ? (
phi = phi - fourpi;
);
);
);

@gfx 0 60
gfx_r=0; gfx_g=0.9; gfx_b=0; gfx_a=1;
gfx_setfont(1,"Arial", 16);

gfx_x =20; gfx_y =10;  gfx_printf("%.0f",(360 * (fParam1 - 0.5)) );
gfx_x =60; gfx_y =10;  gfx_printf("deg");
gfx_x =120; gfx_y =10;  gfx_printf("Pan");

gfx_x =20; gfx_y =30;  gfx_printf("%.0f",(57.296 * dphi * srate) );
gfx_x =60; gfx_y =30;  gfx_printf("deg/sec");
gfx_x =120; gfx_y =30;  gfx_printf("Auto");
