{
   "labels" : [
      "gui",
      "slider",
      "module"
   ],
   "code" : "(\r\n/* Poussière module for SuperCollider, licensed under GNU GPL v3 (<https://www.gnu.org/licenses/>),\r\nPoussière means 'Dust' in French.\r\nWritten by Simon Deplat (aka Dindoleon).\r\nSee http://sccode.org/1-5aY for more informations.\r\n*/\r\n\r\nvar synth, synth_amount_range, win, window_size, slider, margin, value, knob_size, knob_outline_size, stroke_size, frame_color, frame_border_color, gradient_color, diamond_color, diamond_outline_color;\r\n\r\nwindow_size = [ 400, 300 ];\r\nknob_size = 8;\r\nknob_outline_size = 15;\r\nstroke_size = 2;\r\nmargin = 3;\r\n\r\nframe_color = Color.black;\r\nframe_border_color = Color.white;\r\ngradient_color = Color.white;\r\n//Diamond Colors are disabled in order to change its color on fly\r\n//diamond_color = Color.red;\r\n//diamond_outline_color = Color.red;\r\n\r\nvalue = [ 0, 1 ];\r\nsynth_amount_range = [ 0.5, 10000 ];\r\n\r\nsynth = SynthDef(\\poussiere, {\r\n\t|out = 0, freq = 440, amp = 0, amount = 0|\r\n\tvar snd;\r\n\tsnd = Dust2.ar(amount, 1);\r\n\tOut.ar(out, Pan2.ar(snd, 0, amp));\r\n}).play;\r\n\r\nwin = Window(\"Poussière\", Rect(0, 0, window_size[0], window_size[1]), false);\r\nwin.background_( frame_color );\r\nslider = UserView( win, Rect( margin, margin, window_size[0] - ( margin * 2 ), window_size[1] - ( margin * 2 ) ));\r\n\r\nslider.drawFunc = {\r\n\tPen.width = stroke_size;\r\n\tPen.addRect( Rect(0,0, slider.bounds.width,slider.bounds.height) );\r\n\tPen.fillAxialGradient( slider.bounds.leftBottom, slider.bounds.rightTop, Color.black, gradient_color );\r\n\tPen.moveTo( ( slider.bounds.width * value[0] - knob_size ) @ ( slider.bounds.height * value[1] ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] - knob_size ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] + knob_size ) @ (( slider.bounds.height * value[1] ) ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] + knob_size ) );\r\n\tPen.fillColor_( Color.new( 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))) ) ); // Here.\r\n\tPen.fill;\r\n\tPen.moveTo( 0 @ ( slider.bounds.height * value[1] ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] - knob_outline_size ) @ ( slider.bounds.height * value[1] ) );\r\n\tPen.moveTo( ( slider.bounds.width * value[0] ) @ 0 );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] - knob_outline_size ) );\r\n\tPen.moveTo( ( slider.bounds.width * value[0] + knob_outline_size ) @ (( slider.bounds.height * value[1] ) ) );\r\n\tPen.lineTo( slider.bounds.width @ (( slider.bounds.height * value[1] ) ) );\r\n\tPen.moveTo( ( slider.bounds.width * value[0] ) @ (( slider.bounds.height * value[1] + knob_outline_size ) ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] ) @  slider.bounds.height );\r\n\tPen.moveTo( ( slider.bounds.width * value[0] - knob_outline_size ) @ ( slider.bounds.height * value[1] ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] ) @ ( slider.bounds.height * value[1] - knob_outline_size ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] + knob_outline_size ) @ (( slider.bounds.height * value[1] ) ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] ) @ (( slider.bounds.height * value[1] + knob_outline_size ) ) );\r\n\tPen.lineTo( ( slider.bounds.width * value[0] - knob_outline_size ) @ ( slider.bounds.height * value[1] ) );\r\n\tPen.strokeColor_( Color.new( 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))), 1-((0.5*value[0])+(0.5*(1-value[1]))) ) ); // And here.\r\n\tPen.stroke;\r\n\tPen.addRect( Rect(0,0, slider.bounds.width,slider.bounds.height) );\r\n\tPen.strokeColor_( frame_border_color );\r\n\tPen.stroke;\r\n};\r\n\r\nslider.action = {\r\n\tsynth.set(\\amp, 1 - value[1]);\r\n\tsynth.set(\\amount, linexp(value[0], 0, 1, synth_amount_range[0], synth_amount_range[1]));\r\n\tslider.refresh\r\n};\r\n\r\nslider.mouseDownAction = { arg slider, x = 0.5, y = 0.5, m;\r\n\t([256, 0].includes(m)).if{\r\n\t\tvalue[0] = (x).linlin(0,slider.bounds.width,0,1);\r\n\t\tvalue[1] = (y).linlin(0,slider.bounds.height,0,1);\r\n\t\tslider.doAction};\r\n};\r\nslider.mouseMoveAction = slider.mouseDownAction;\r\nwin.front;\r\n)",
   "id" : "1-5aZ",
   "is_private" : null,
   "name" : "Poussière : standalone dust generator (uncommented version of luce)",
   "author" : "Dindoléon",
   "description" : "Dust2 synth controlled by a custom 2D slider (kind of simulates vinyl crackles). Actually an uncommented fork of the luce module. Easy to integrate and modify.",
   "ancestor_list" : []
}
