 desc: RCInflator (Oxford Edition)
/*
JSFX Name: RCInflator
Author: RCJacH
Release Date: Aug 2021
Link:
  https://github.com/RCJacH/ReaScripts
  https://forum.cockos.com/showthread.php?t=256286
Version: 0.6
Reference:
  tviler
  sai'ke
  Sony Oxford
  samu4199
About:
  JSFX implementation of Sony Oxford Inflator algorithm,
  found on Gearspace.
Changelog:
 * v0.8 (2021-12-22)
    + corrected PDC_delay (thank you Bill)
  * v0.7 (2021-12-14)
    + added oversampling
  * v0.6 (2021-08-15)
    + Refactor integers to floats
    + Clip dry signal before summing
  * v0.5.4 (2021-08-15)
    + Match slider range and steps to the original
  * v0.5.3 (2021-08-15)
    + Applies second clipping before output gain
  * v0.5.2 (2021-08-13)
    + Applies in/output gain to dry signal
    + Refactor for less CPU usage
  * v0.5.1 (2021-08-13)
    * Fix unsymmetrical waveshaping
  * v0.5 (2021-08-13)
    + Refactor code
    + Add absolute clipping at 6dB.
    + Add waveshapeOvershoot
  * v0.4 (2021-08-13)
    + Accurate decibel to float conversion.
    + Wrap waveshaper above 0dB.
    + Refactor waveshaper into function.
  * v0.3 (2021-08-11)
    + Apply waveshaper symmetrically.
    * Fix sign Error.
  * v0.2 (2021-08-09)
    * Cleaned up code.
  * v0.1 (2021-02-06)
    + Initial alpha release.


   GUI by argee (2021-12-18)
   Revisions to original effect code:
   - removed assignments to 'curve'(slider3) and 'clip'(slider4) in slider definitions and moved them to doslidercode function
     this is to allow interchange of values between visible slider and graphical knobs
   - made original sliders invisible by adding '-' in front of name
   - added visible generic slider for keyboard input of values (optional, can be hidden if not needed)
*/

desc:RCInflator GUI

slider1:0<-6, 12, 0.01>-Input (dB)
slider2:100<0, 100, 0.1>-Effect (%)
slider3:0<-50, 50, 0.1>-Curve
slider4:<0,1,1{Off,On}>-Clip
slider5:0<-12, 0, 0.01>-Output (dB)
slider6:0<-50,100,0.01>Value for last touched knob
slider7:0.2<0,1,0.1>-backred
slider8:0.6<0,1,0.1>-backgreen
slider9:1<0,1,0.1>-backblue
slider10:0<0,3,1{1x,2x,4x,8x}>-oversampling
slider11:0.45<0,1,0.1>-backalpha


// slider6 can be hidden if you don't think you'll need it (add hyphen (-) at the front of the label name i.e. -Value...)


@init

pdc_bot_ch = 0; pdc_top_ch = 2;
pdc_delay = 42 * oversample;
oversample == 8 ? pdc_delay = 42 + 32;

/* begin oversampler code */


function os_os2()
 instance(  
    y42 y41 
    y40 y39 y38 y37 y36 y35 y34 y33 y32 y31 
    y30 y29 y28 y27 y26 y25 y24 y23 y22 y21  y1
    y20 y19  y18 y17 y16 y15 y14 y13 y12 y11  y0
    y10 y09 y08 y07 y06 y05 y04 y03 y02 y01  y00)
(
  y42 = y40; y41 = y39; y40 = y38; y39 = y37;
  y38 = y36; y37 = y35; y36 = y34; y35 = y33;
  y34 = y32; y33 = y31; y32 = y30; y31 = y29;
  y30 = y28; y29 = y27; y28 = y26; y27 = y25;
  y26 = y24; y25 = y23; y24 = y22; y23 = y21;
  y22 = y20; y21 = y19; y20 = y18; y19 = y17;
  y18 = y16; y17 = y15; y16 = y14; y15 = y13;
  y14 = y12; y13 = y11; y12 = y10; y11 = y09;
  y10 = y08; y09 = y07; y08 = y06; y07 = y05;
  y06 = y04; y05 = y03; y04 = y02; y03 = y1;
  y02 = y0;
);

function os_up2(x)
 instance(  
    y42 y41 
    y40 y39 y38 y37 y36 y35 y34 y33 y32 y31 
    y30 y29 y28 y27 y26 y25 y24 y23 y22 y21  y1
    y20 y19  y18 y17 y16 y15 y14 y13 y12 y11  y0
    y10 y09 y08 y07 y06 y05 y04 y03 y02 y01  y00
    x20 x19  x18 x17 x16 x15 x14 x13 x12 x11  x21
    x10 x09 x08 x07 x06 x05 x04 x03 x02 x01  x00)
(
  x21 = x20; x20 = x19; x19 = x18; x18 = x17; x17 = x16;
  x16 = x15; x15 = x14; x14 = x13; x13 = x12; x12 = x11; x11 = x10;
  x10 = x09; x09 = x08; x08 = x07; x07 = x06; x06 = x05;
  x05 = x04; x04 = x03; x03 = x02; x02 = x01; x01 = x00;
  x00 = x * 2;

  this.os_os2();

y1 = 
 0.000309 * (x00 + x21) +
-0.001048 * (x01 + x20) +
 0.002421 * (x02 + x19) +
-0.004709 * (x03 + x18) +
 0.008277 * (x04 + x17) +
-0.013636 * (x05 + x16) +
 0.021630 * (x06 + x15) +
-0.033952 * (x07 + x14) +
 0.054950 * (x08 + x13) +
-0.100673 * (x09 + x12) +
 0.316465 * (x10 + x11);

y0 = 0.5 * x10;

);

function os_down2()
 instance(  
    y42 y41 
    y40 y39 y38 y37 y36 y35 y34 y33 y32 y31 
    y30 y29 y28 y27 y26 y25 y24 y23 y22 y21  y1
    y20 y19  y18 y17 y16 y15 y14 y13 y12 y11  y0
    y10 y09 y08 y07 y06 y05 y04 y03 y02 y01  y00)
(
 0.000309 * (y0 + y42) +
-0.001048 * (y02 + y40) +
 0.002421 * (y04 + y38) +
-0.004709 * (y06 + y36) +
 0.008277 * (y08 + y34) +
-0.013636 * (y10 + y32) +
 0.021630 * (y12 + y30) +
-0.033952 * (y14 + y28) +
 0.054950 * (y16 + y26) +
-0.100673 * (y18 + y24) +
 0.316465 * (y20 + y22) +
 0.500000 * y21; 
);

//--------------------Quarterband filter (31 tap)

function os_os4()
 instance(  y30 y29 y28 y27 y26 y25 y24 y23 y22 y21 
    y20 y19  y18 y17 y16 y15 y14 y13 y12 y11
    y10  y9  y8  y7  y6  y5  y4  y3  y2  y1  y0)
(
  y30 = y26; y29 = y25; y28 = y24; y27 = y23;
  y26 = y22; y25 = y21; y24 = y20; y23 = y19;
  y22 = y18; y21 = y17; y20 = y16; y19 = y15;
  y18 = y14; y17 = y13; y16 = y12; y15 = y11;
  y14 = y10; y13 =  y9; y12 =  y8; y11 =  y7;
  y10 =  y6;  y9 =  y5;  y8 =  y4;  y7 =  y3;
   y6 =  y2;  y5 =  y1;  y4 =  y0;
);


function os_up4(x)
 instance( x0 x1 x2 x3 x4 x5 x6 x7 y0 y1 y2 y3 )
(
  x7 = x6; x6 = x5; x5 = x4; x4 = x3; x3 = x2; x2 = x1; x1 = x0;
  x0 = x * 4;

  this.os_os4();

  y3 =    -0.002469076374678*x0 
  + 0.007919578847318*x1 
  - 0.022350687252104*x2 
  + 0.070316075718208*x3 
  + 0.223473433718352*x4
  - 0.037513557645167*x5 
  + 0.013514259906394*x6 
  - 0.004334792589110*x7;

  y2 =    -0.004548665973301*(x0 + x7) 
  + 0.014707851640244*(x1 + x6) 
  - 0.040721602089144*(x2 + x5)
  + 0.154646454517718*(x3 + x4);

  y1 =    -0.004334792589110*x0 
  + 0.013514259906394*x1 
  - 0.037513557645167*x2 
  + 0.223473433718352*x3 
  + 0.070316075718208*x4
  - 0.022350687252104*x5 
  + 0.007919578847318*x6 
  - 0.002469076374678*x7;

  y0 = x3 * 0.25;
);

function os_down4()
 instance(  y30 y29 y28 y26 y25 y24 y22 y21 
    y20 y18 y17 y16 y15 y14 y13 y12 
    y10  y9  y8  y6  y5  y4  y2  y1  y0)
(
   -0.002469076374678*( y0+y30) 
  - 0.004548665973301*( y1+y29) 
  - 0.004334792589110*( y2+y28) 
  + 0.007919578847318*( y4+y26) 
  + 0.014707851640244*( y5+y25) 
  + 0.013514259906394*( y6+y24) 
  - 0.022350687252104*( y8+y22) 
  - 0.040721602089144*( y9+y21) 
  - 0.037513557645167*(y10+y20) 
  + 0.070316075718208*(y12+y18) 
  + 0.154646454517718*(y13+y17) 
  + 0.223473433718352*(y14+y16) 
  + 0.25*y15;
);



function os_reset4()
 instance(  y30 y29 y28 y27 y26 y25 y24 y23 y22 y21 
    y20 y19  y18 y17 y16 y15 y14 y13 y12 y11
    y10  y9  y8  y7  y6  y5  y4  y3  y2  y1  
     y0  x0  x1  x2  x3  x4  x5  x6  x7  x8 x9 )
(
 y30 = y29 = y28 = y27 = y26 = y25 = y24 = y23 = y22 = y21 =
 y20 = y19 = y17 = y16 = y15 = y14 = y13 = y12 = y11 = y10 =
  y9 = y8 = y7 = y6 = y5 = y4 = y3 = y2 = y1 = y0 =
  x0 = x1 = x2 = x3 = x4 = x5 = x6 = x7 = x8 = x9 = 0;
);


/* end oversampler code */

/*ADJUST THESE VALUES TO CHANGE THE DEFAULT COLOR OF THE INTERFACE - USE VALUES BETWEEN 0 AND 1
//=================================================================================
  backred = 0.2;
  backgreen = 0.6 ;
  backblue = 1;
  backalpha = 0.45;
//=================================================================================

// GRAPHICS AND MOUSE HANDLING FUNCTIONS FOR KNOBS
//======================================================
*/

function TestCtrl_at_Mouse(ctrlnum,minX, maxX, minY, maxY)
(
  mouse_x > minX && mouse_x < maxX && mouse_y > minY && mouse_y < maxY ?
  (ctrlnum):(
    knobdrag == 0 ? 0;
  );
);

function arc_knob(x,y,r,deg0,degf,rotation,arc_w,slideval,dec,ctrlnum,unit, inc, minval, maxval, defval)
local(i,density,l,rad0,radf)
(   
    knobdrag == 0 ? mouse_on = TestCtrl_at_Mouse(ctrlnum,x-r,x+r,y-r,y+r);

//knob outline
    gfx_a=1;
    mouse_on == ctrlnum ? gfx_r=gfx_b=gfx_g=1:(gfx_r=slider7+0.35;gfx_g=slider8+0.35;gfx_b=slider9+0.35;);
    gfx_circle(x,y,r-8,0,1);    

//knob circle
    gfx_x=x;gfx_y=y;
    gfx_circle(x,y,r-11,1,1);

    gfx_a=0.5;
    gfx_r=slider7;gfx_g=slider8;gfx_b=slider9;
    gfx_circle(x,y,r-22,1,1);

//knob position indicator
    gfx_a=1;
    gfx_r=slider7*.7;gfx_g=slider8*.7;gfx_b=slider9*.7;
    (deg0+rotation) ? rad0=(deg0+rotation)*(0.0174532925); 
    radf=((degf+rotation)*100)*(17.4532925)/100000;
    arc_w<=2?(density=1;l=1;); arc_w>2?(density=.5; l=2;);
    i=13;
      loop(arc_w*l,
        gfx_arc(x,y,(r)-i,rad0,radf,1);
        i+=density;
      );  

  gfx_r=slider7;gfx_g=slider8;gfx_b=slider9;
    
//knob value text with units
    gfx_setfont(1,"Arial",16,0);
    mouse_on == ctrlnum ? gfx_r=gfx_b=gfx_g=1:(gfx_r=gfx_g=gfx_b=0.8);

    gfx_x=x+r*.65;gfx_y=y-r;
    dec == 4 ? str = sprintf(#, "%.4f", slideval);
    dec == 3 ? str = sprintf(#, "%.3f", slideval);
    dec == 2 ? str = sprintf(#, "%.2f", slideval);
    dec == 1 ? str = sprintf(#, "%.1f", slideval);
    dec == 0 ? str = sprintf(#, "%.0f", slideval);
    gfx_drawstr(str);

    gfx_x=x+r-5;gfx_y=y-r+16;
    gfx_drawstr(unit);

//reset font and size for knob name text
    gfx_setfont(1,"Arial Bold",18,0);
    gfx_x=x; gfx_y=y+r;

//Mouse handling
    mouse_on == ctrlnum && setmouse_on == 0 && colorset == 0 ? (
      mouse_cap == 5 ? inc*=0.1;
      mouse_cap == 17? inc*=3;
      mouse_cap > 0 && mouse_cap != 2 ? (
        mouseclick = ctrlnum;
        mouse_y > saveY+2 ? slideval = Max(minval,slideval-inc);
        mouse_y < saveY-2 ? slideval = Min(maxval,slideval+inc);
        knobdrag = 1;
      );
      mouse_cap == 0 ? (
        mouse_wheel < 0? (slideval = Max(minval,slideval-inc);mouseclick = ctrlnum ;slider6 = slideval);
        mouse_wheel > 0? (slideval = Min(maxval,slideval+inc);mouseclick = ctrlnum ;slider6 = slideval);
        mouse_wheel = 0;
        knobdrag = 0;
      );
    mouse_cap == 2 ? (slideval = defval;slider6 = slideval);
    );
  
//Return slider value (to update the original slider)
    slideval;
);

//END OF GRAPHICS AND MOUSE HANDLING FUNCTIONS FOR KNOBS
//======================================================

// FOLLOWING CODE ORIGINALLY IN @slider, MOVED HERE SO IT CAN BE CALLED FROM @slider AND @gfx
// some minor changes (see comments below) necessary to allow interaction with the GUI

function doslidercode()(
slider6 != saveSL6 ? (
  mouseclick == 1 ? slider1 = max(min(slider6,12),-6);
  mouseclick == 2 ? slider2 = max(min(slider6,100),0);
  mouseclick == 3 ? slider3 = max(min(slider6,50),-50);
  mouseclick == 5 ? slider5 = max(min(slider6,0),-12);
  saveSL6 = slider6;
  );

oversample = 2^(slider10);
// thank you Bill!
//changed to correct pdc, determined empirically bt 12/21/2021
oversample == 1 ? (
  pdc_delay = 0;
);
oversample == 2 ? (
  pdc_delay = 20;
);
oversample == 4 ? (
  pdc_delay = 41   ;
);
oversample == 8 ? (
  pdc_delay = 27;
);

in_db = exp(0.11512925464970229 * slider1);
wet = slider2 * 0.01;
dry = 1.0 - wet;
dry2 = dry * 2.0;
out_db = exp(0.11512925464970229 * slider5);

curvepct = slider3 * 0.01;
// 1 + (curve + 50) / 100
curveA = 1.5 + curvepct;
// - curve / 50
curveB = -(curvepct + curvepct);
// (curve - 50) / 100
curveC = curvepct - 0.5;
// 1 / 16 - curve / 400 + curve ^ 2 / (4 * 10 ^ 4)
curveD = 0.0625 - curve * 0.0025 + (curve * curve) * 0.000025;

clip = slider4;

);

function process(in)
local(s, s_2, s_3, out)
global(curveA, curveB, curveC, curveD,
    clip, dry, dry2, in_db, out_db, wet)
(

  in *= in_db;
  s = abs(in);
  clip && s > 1.0 ? s = 1.0;
  s_2 = s * s;
  s_3 = s_2 * s;
  s = (s >= 2.0) ? (
    0.0
  ) : s > 1.0 ? (
    2.0 * s - s_2
  ) : (
    curveA * s + curveB * s_2 + curveC * s_3 - curveD * (s_2 - 2.0 * s_3 + s_2 * s_2)
  );

  out = sign(in) * s * wet + min(max(in * dry, -dry2), dry2);
  clip ? out = max(-1.0, min(1.0, out));
  out * out_db
  
);

@gfx 620 150
  gfx_a=1;

//Graphics for the Main Background
  gfx_r=slider7;gfx_g=slider8;gfx_b=slider9;gfx_a=slider11;
  gfx_rect(0,30,620,120);
  gfx_a=1;
  gfx_x=0;gfx_y=0;

//Banner text - expands as slider2 (Effect %) increases
  gfx_setfont(1,"Calibri",32,'b');
  gfx_x=10;gfx_y=-2;
  gfx_r=1;gfx_g=1;gfx_b=1; gfx_drawstr("RC ");

  gfx_r=slider7*1.2;gfx_g=slider8*1.2;gfx_b=slider9*1.2;
  gfx_drawstr("I");
  gfx_x+=slider2*0.06;
  gfx_drawstr("n");
  gfx_x+=slider2*0.1;
  gfx_drawstr("f");
  gfx_x+=slider2*0.15;
  gfx_drawstr("l");
  gfx_x+=slider2*0.2;
  gfx_drawstr("a");
  gfx_x+=slider2*0.25;
  gfx_drawstr("t");
  gfx_x+=slider2*0.3;
  gfx_drawstr("o");
  gfx_x+=slider2*0.35;
  gfx_drawstr("r");

  gfx_setfont(1,"Calibri",22,'b');
  gfx_x=500;gfx_y=+4;
  gfx_r=slider7*0.7;gfx_g=slider8*0.7;gfx_b=slider9*0.7;
  gfx_drawstr("Oxford Edition");

//End of Main Background graphics

//Knobs - call to arc_knob function - mouse handling and graphics - then draw knob name text
//function arc_knob(x,y,r,deg0,degf,rotation,arc_w,slideval,dec,ctrlnum,unit, hilite, inc, minval, maxval, defval)

  slider1 = new.arc_knob(180,80,38,-92,slider1*14.5,-40,6,slider1,3,1,"dB",0.2,-6,12,0); gfx_x-=19; gfx_drawstr("Input");
  slider2 = new.arc_knob(60,80,38,0,slider2*2.84,-140,6,slider2,1,2,"%",2,0,100,100); gfx_x-=27; gfx_drawstr("Effect %");
  slider3 = new.arc_knob(300,80,38,-145,slider3*2.85,0,6,slider3,1,3,"",1,-50,50,0); gfx_x-=21; gfx_drawstr("Curve");
  slider5 = new.arc_knob(545,80,38,-280,slider5*23,140,6,slider5,3,5,"dB",0.25,-12,0,0); gfx_x-=24; gfx_drawstr("Output");

//Clip Toggle Button - Mouse Handling and Graphics
  knobdrag == 0 ? mouse_on = TestCtrl_at_Mouse(4,380,400,65,105);

  mouse_on == 4 ? (
    mouseclick = 0;
    mouse_cap == 1 ? (
      done == 0 ? (
        slider4 = (slider4 == 0 ? 1 : 0);
        done = 1;
      );
    ):
    mouse_cap == 0 ? (
      mouse_wheel < 0? slider4 = 0;
      mouse_wheel > 0? slider4 = 1;
      mouse_wheel = 0;
      knobdrag = 0;
      done = 0
    ):
    mouse_cap == 2 && done == 0 ? (
      slider4 = 0;
      done = 1;
    );
 
  );
    
  gfx_r=gfx_b=gfx_g=0;
  gfx_rect(380,60,20,40);
  mouse_on == 4 ? gfx_r=gfx_b=gfx_g=1:(gfx_r=slider7+0.35;gfx_g=slider8+0.35;gfx_b=slider9+0.35;);
  gfx_rect(382,81-slider4*18,16,16);

  mouse_on == 4 ? gfx_r=gfx_b=gfx_g=1:(gfx_r=gfx_b=gfx_g=0.8);
  gfx_x = 375; gfx_y = 118;
  gfx_drawstr("Clip");

  gfx_setfont(1,"Arial",12,0);

  gfx_x = 383; gfx_y = 47;
  gfx_drawstr("On");

  gfx_x = 382; gfx_y = 102;
  gfx_drawstr("Off");

// End of Clip Toggle Button

//Oversampling Radio Buttons
  knobdrag == 0 ? mouse_on = TestCtrl_at_Mouse(6,440,485,45,100);

  mouse_on == 6 ? (
    mouseclick = 0;
     mouse_cap == 1 ? (
      done == 0 ? (
        slider10 = floor((mouse_y-40)/15);
        done = 1;
       );
    ):
    mouse_cap == 0 ? (
      mouse_wheel > 0? slider10 = Max(0,slider10-1);
      mouse_wheel < 0? slider10 = Min(3,slider10+1);
      mouse_wheel = 0;
      knobdrag = 0;
    ):
    mouse_cap == 2 ? (
      slider10 = 0;
    );
    done = 0
  );

  gfx_r=gfx_b=gfx_g=0;
  gfx_circle(450,50,5,1,1);
  gfx_circle(450,65,5,1,1);
  gfx_circle(450,80,5,1,1);
  gfx_circle(450,95,5,1,1);
  mouse_on == 6 ? gfx_r=gfx_g=gfx_b=1 : (gfx_r=slider7+0.35;gfx_g=slider8+0.35;gfx_b=slider9+0.35);
  gfx_circle(450,50+slider10*15;,3,1,1);

  mouse_on == 6 ? gfx_r=gfx_b=gfx_g=1:(gfx_r=gfx_g=gfx_b=0.8);
  gfx_setfont(1,"Arial",14,0);
  gfx_x=460; gfx_y=43; gfx_drawstr("1 x");
  gfx_x=460; gfx_y=58; gfx_drawstr("2 x");
  gfx_x=460; gfx_y=73; gfx_drawstr("4 x");
  gfx_x=460; gfx_y=88; gfx_drawstr("8 x");
    
  gfx_setfont(1,"Calibri",17,'b');
  gfx_x=450;gfx_y=105;
  gfx_drawstr("Over");  
  gfx_x=437;gfx_y=120;
  gfx_drawstr("Sampling");

//End of Oversampling Radio Buttons

//Color Settings Window Mouse handling and graphics
//toggle window on/off by clicking in header part of plugin window
  knobdrag == 0 ? (
    mouse_cap > 0 ? (
      mouse_on = TestCtrl_at_Mouse(6,0,550,0,30);
      mouse_on == 6? (
      doneset == 0 ? (
        colorset == 0 ? (
          colorset = 1;
          setmouse_on = 1;
         ): colorset = 0;
      );
      doneset = 1);
    ): doneset = 0;
  );

  colorset == 1 ? (      //if user has activated color settings
      setmouse_on = 0;
      setmouse_on = TestCtrl_at_Mouse(7,80,195,50,60);
      setmouse_on == 7 ? (
        mouse_cap > 0 ? (
         slider7 = Min((mouse_x - 80),110)/110;
          knobdrag = 1;
        ):knobdrag = 0;
      );
      setmouse_on = TestCtrl_at_Mouse(8,80,195,70,80);
      setmouse_on == 8 ? (
        mouse_cap > 0 ? (
          slider8 = Min((mouse_x - 80),110)/110;
          knobdrag = 1;
        ):knobdrag = 0;
      );
      setmouse_on = TestCtrl_at_Mouse(9,80,195,90,100);
      setmouse_on == 9 ? (
        mouse_cap > 0 ? (
          slider9 = Min((mouse_x - 80),110)/110;
          knobdrag = 1;
        ):knobdrag = 0;
      );
      setmouse_on = TestCtrl_at_Mouse(10,80,195,110,120);
      setmouse_on == 10 ? (
        mouse_cap > 0 ? (
          slider11 = Min((mouse_x - 80),110)/110;
          knobdrag = 1;
        ):knobdrag = 0;
      );

    gfx_setfont(1,"Arial",16,0);
    gfx_r=gfx_b=gfx_g=1;gfx_a=1;
    gfx_rect(20,40,220,90);
    gfx_r=gfx_b=gfx_g=0;
    gfx_rect(80,50,110,10);
    gfx_rect(80,70,110,10);
    gfx_rect(80,90,110,10);
    gfx_rect(80,110,110,10);

    gfx_r=1;gfx_g=0;gfx_b=0;
    gfx_rect(80,50,slider7*110,10);
    gfx_r=0;gfx_g=1;gfx_b=0;
    gfx_rect(80,70,slider8*110,10);
    gfx_r=0;gfx_g=0;gfx_b=1;
    gfx_rect(80,90,slider9*110,10);
    gfx_r=gfx_b=gfx_g=0.7;
    gfx_rect(80,110,slider11*110,10);

    gfx_r=1;gfx_b=gfx_g=0;
    gfx_x=30;gfx_y=46;
    gfx_drawstr("Red");
    gfx_x=200;  
    gfx_drawnumber(slider7,2);
    gfx_r=0;gfx_b=0;gfx_g=1;
    gfx_x=30;gfx_y=66;
    gfx_drawstr("Green");
    gfx_x=200;
    gfx_drawnumber(slider8,2);

    gfx_r=0;gfx_b=1;gfx_g=0;
    gfx_x=30;gfx_y=86;
    gfx_drawstr("Blue");
    gfx_x=200;
    gfx_drawnumber(slider9,2);
  
    gfx_r=gfx_b=gfx_g=0;
    gfx_x=30;gfx_y=106;
    gfx_drawstr("Alpha");
    gfx_x=200;
    gfx_drawnumber(slider11,2);
  );

//End of Color Settings Window

//Update visible slider value to current knob value (excluding clip on/off)
  mouse_on == 1 ? (slider6 = slider1);
  mouse_on == 2 ? (slider6 = slider2);
  mouse_on == 3 ? (slider6 = slider3);
  mouse_on == 5 ? (slider6 = slider5);

  doslidercode();

  saveX = mouse_x;
  saveY = mouse_y;

@slider
doslidercode();

@sample
oversample == 2 ? (

  os0.os_up2(spl0);
  os0.y1 = process(os0.y1);
  os0.y0 = process(os0.y0);
  spl0 = os0.os_down2();
  
  os1.os_up2(spl1);
  os1.y1 = process(os1.y1);
  os1.y0 = process(os1.y0);
  spl1 = os1.os_down2();

  ) :
  
oversample == 4 ? (

  os2.os_up2(spl0);
  os3.os_up2(spl1);

  os4.os_up2( os2.y1 );
  os5.os_up2( os2.y0 );

  os6.os_up2( os3.y1 );
  os7.os_up2( os3.y0 );

  os4.y1 = process(os4.y1);
  os4.y0 = process(os4.y0);
  os5.y1 = process(os5.y1);
  os5.y0 = process(os5.y0);

  os6.y1 = process(os6.y1);
  os6.y0 = process(os6.y0);
  os7.y1 = process(os7.y1);
  os7.y0 = process(os7.y0);
  
  os2.y1 = os4.os_down2();
  os2.y0 = os5.os_down2();
  os3.y1 = os6.os_down2();
  os3.y0 = os7.os_down2();

  spl0 = os2.os_down2();
  spl1 = os3.os_down2();
  
  ) : 

oversample == 8 ? (

  os8.os_up2(spl0);
  os9.os_up2(spl1);

  osA.os_up4(os8.y1);
  osB.os_up4(os8.y0);
  osC.os_up4(os9.y1);
  osD.os_up4(os9.y0);

  osA.y3 = process(osA.y3);
  osA.y2 = process(osA.y2);
  osA.y1 = process(osA.y1);
  osA.y0 = process(osA.y0);
  osB.y3 = process(osB.y3);
  osB.y2 = process(osB.y2);
  osB.y1 = process(osB.y1);
  osB.y0 = process(osB.y0);

  osC.y3 = process(osC.y3);
  osC.y2 = process(osC.y2);
  osC.y1 = process(osC.y1);
  osC.y0 = process(osC.y0);
  osD.y3 = process(osD.y3);
  osD.y2 = process(osD.y2);
  osD.y1 = process(osD.y1);
  osD.y0 = process(osD.y0);

  os8.y1 = osA.os_down4();
  os8.y0 = osB.os_down4();
  os9.y1 = osC.os_down4();
  os9.y0 = osD.os_down4();

  spl0 = os8.os_down2();
  spl1 = os9.os_down2();

  ) : (

spl0 = process(spl0);
spl1 = process(spl1);

);
