slider1:-120<-120,0,0.1>Threshold (dB)
slider2:0.01<0.01,10,0.01>Attack (ms)
slider3:50<10,1000,1>Release (ms)
slider4:50<10,1000,1>Env Decay (ms)
slider5:0<-24,24,0.1>Output (dB)

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

@init
gain = 1;
env = 0;

@slider
threshold = 10^(slider1/20);

attack = exp(-1/(slider2/1000*srate));
release = exp(-1/(slider3/1000*srate));
envelope_decay = exp(-1/(slider4/1000*srate));

vol = 10^(slider5/20);

@sample
inL = spl0;
inR = spl1;

det = max(abs(inL),abs(inR));
det += 0.000000000001;
env = det >= env ? det : det+envelope_decay*(env-det);
transfer_gain = env > threshold ? pow(env,0):0;
gain = transfer_gain > gain ? transfer_gain+attack*(gain-transfer_gain) : transfer_gain+release*(gain-transfer_gain);

spl0 = inL * gain * vol;
spl1 = inR * gain * vol;

@gfx 0 70
x = 40;
y = 40;

function draw_led(x,y,size)(
gfx_r=gfx_b=gfx_g=1; gfx_a=0.25;
gfx_circle(x, y,size,1,1);
gfx_r=gfx_b=gfx_g=0.8;
gfx_a=0.8;
gfx_arc(x, y,size-(size/5),1,4,1);
gfx_a=1;
);

// LEDs
draw_led(x+5, y-5,20);
draw_led(x+50, y-5,20);
draw_led(x+95, y-5,20);

gain>=0.99 ? (
gfx_g=1; gfx_b=gfx_r=0;
gfx_circle(x+5, y-5,15,1,1);
);
gain>0.1 && gain<0.99 ? (
gfx_r=1; gfx_b=0; gfx_g=1;
gfx_circle(x+50, y-5,15,1,1);
);
gain<=0.1 ? (
gfx_r=1; gfx_b=gfx_g=0;
gfx_circle(x+95, y-5,15,1,1);
);
