slider1:0<0,100,1>Shape (%)
slider2:0<0,3,1{Type 1 (atan - soft),Type 2 (tanh - hard),Type 3 (soft),Type 4 (hard)}>Mode
slider3:0<-48,0,0.1>Output (dB)
slider4:25<20,250,5>Size (ms)

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

@init
function tanh(x)
(
x = exp(2*x);
(x - 1) / (x + 1);
);

histbuf=1000000;
histpos=0;

@slider
shape=max(min(slider1+1,100),1);
mode=slider2;
output=10^(slider3/20);

mode == 2 ? (
shape=max(min(slider1+2,102),2);
);
mode == 3 ? (
shape=max(min((slider1*0.01),0.99),0);
);

size=slider4;
histsize=size/1000*srate|0;

@sample
in0=min(max(spl0,-1),1);
in1=min(max(spl1,-1),1);

mode == 0 ? (
spl0=atan(in0*shape)/atan(shape);
spl1=atan(in1*shape)/atan(shape);
);
mode == 1 ? (
spl0=tanh(in0*shape)/tanh(shape);
spl1=tanh(in1*shape)/tanh(shape);
);
mode == 2 ? (
spl0=in0*(abs(in0)+shape)/(in0^2+(shape-1)*abs(in0)+1);
spl1=in1*(abs(in1)+shape)/(in1^2+(shape-1)*abs(in1)+1);
);
mode == 3 ? (
spl0=in0*(1+(2*shape/(1-shape)))/((2*shape/(1-shape))*abs(in0)+1);
spl1=in1*(1+(2*shape/(1-shape)))/((2*shape/(1-shape))*abs(in1)+1);
);

spl0*=output;
spl1*=output;

histbuf[histpos]=spl0;
histbuf[histpos+histsize]=spl1;

histpos+=1;
histpos >= histsize ? histpos=0;

@gfx 0 101
gfxSize=min(gfx_w,gfx_h);

gfx_r=gfx_g=gfx_b=0; gfx_a=1;
gfx_x=gfx_y=0;
gfx_rectto(gfx_w,gfx_h);

gfx_r=gfx_g=gfx_b=0.8; gfx_a=1;
gfx_x=gfxSize/2;
gfx_y=0;
gfx_lineto(gfxSize/2,gfxSize,0);
gfx_x=0;
gfx_y=gfxSize/2;
gfx_lineto(gfxSize,gfxSize/2,0);

gfx_r=0.5; gfx_g=1; gfx_b=0; gfx_a=1;
gfx_x=0;
gfx_y=gfxSize;
x = -1;
while(

mode == 0 ? (
y = -(atan(x*shape)/atan(shape));
);
mode == 1 ? (
y = -(tanh(x*shape)/tanh(shape));
);
mode == 2 ? (
y = -(x*(abs(x)+shape)/(x^2+(shape-1)*abs(x)+1));
);
mode == 3 ? (
y = -(x*(1+(2*shape/(1-shape)))/((2*shape/(1-shape))*abs(x)+1));
);

gfx_lineto(x*gfxSize/2+gfxSize/2,y*gfxSize/2+gfxSize/2,1);
(x+=0.001) <= 1;
);
gfx_lineto(gfxSize-1,0,1);

offs=histpos;
gscale=gfxSize/histsize;
gbuf=histbuf;
gscale2=gfxSize/2;

gfx_r=0; gfx_g=1; gfx_b=1; gfx_a=0.5;

ga=0;
loop(histsize,
gv=gbuf[offs];
offs+=1;
offs>=histsize?offs=0;
gx=ga*gscale;
gy=gfxSize/2 - gv*gscale2;
ga ? gfx_lineto(gx,gy,0) : ( gfx_x=gx; gfx_y=gy; );
ga+=1;
);

gbuf+=histsize;
