// This effect Copyright (C) 2004 and later Cockos Incorporated
// License: GPL - http://www.gnu.org/licenses/gpl.html
// fade fix/improvements thanks to dan mcmullen

desc: reverseness (reverses chunks)
slider1:500<0,4000,10>length (ms)
slider2:-6<-120,6,1>wet mix (dB)
slider3:-6<-120,6,1>dry mix (dB)
slider4:0.1<0,1>edge overlap (0..1.0)
slider5:0<0,1,1{off,on}>old compatible and clicky mode


@init
  pos=0;

@slider
  len=srate*slider1/1000; 
  wet=2 ^ (slider2/6); 
  dry=2 ^ (slider3/6); 
  nonclickymode = slider5 != 1;
  fadelen=len*min(slider4,nonclickymode?0.5:1.0)*0.5;
  freembuf(len*2);
  
@sample

s0=((len-pos)*2)[0];
s1=((len-pos)*2)[1];
(pos*2)[0]=spl0;
(pos*2)[1]=spl1;

pp=len-pos;
w2=pp<fadelen ? pp/fadelen : (pp > len-fadelen?(len-pp)/fadelen:1);

nonclickymode && w2 == 1 ?(
  pp= abs(len*0.5-pos);
  w2= pp<fadelen ? pp/fadelen : 1;
);

spl0=s0*wet*w2 + spl0*(dry + 1-w2);
spl1=s1*wet*w2 + spl1*(dry + 1-w2);

(pos+=1)>=len ? pos=0;
