Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: DiamondSlider : custom unidimensionnal slider GUI.
name
code content
( // Custom unidimensionnal horizontal slider, licensed under GNU GPL v3 (<https://www.gnu.org/licenses/>). // Written by Simon Deplat (aka Dindoleon). // This is lovely with a touchscreen. var synth, win, window_size, margin = 3, slider, value, label, diamond_size, stroke_size, diamond_outline_size, diamond_color, font; window_size = [300, 50]; diamond_size = 10; diamond_outline_size = 15; stroke_size = 2; margin = 3; diamond_color = Color.new(0.2,0.5,0.9); font = Font.new( Font.availableFonts.choose, window_size[1]/2 ); value = 0; win = Window("Diamond Slider", Rect(0, 0, window_size[0], window_size[1]), false); win.background_( Color.black ); slider = UserView( win, Rect( margin, margin, window_size[0] - (margin*2), window_size[1] - (margin*2))); synth = {arg freq=110; SinOsc.ar(freq!2)}.play; slider.drawFunc = { Pen.width = stroke_size; Pen.strokeColor = Color.white; Pen.fillColor = Color.black; Pen.addRect(Rect(0,0, slider.bounds.width,slider.bounds.height)); Pen.draw(3); Pen.moveTo(((slider.bounds.width*value)-diamond_size) @ (slider.bounds.height/2)); Pen.lineTo(((slider.bounds.width*value)) @ ((slider.bounds.height/2)+diamond_size)); Pen.lineTo(((slider.bounds.width*value)+diamond_size) @ (slider.bounds.height/2)); Pen.lineTo(((slider.bounds.width*value)) @ ((slider.bounds.height/2)-diamond_size)); Pen.lineTo(((slider.bounds.width*value)-diamond_size) @ (slider.bounds.height/2)); Pen.fillColor = diamond_color; Pen.fill; Pen.moveTo( (0) @ (slider.bounds.height/2)); Pen.lineTo(((slider.bounds.width*value)-diamond_outline_size) @ ((slider.bounds.height/2))); Pen.moveTo(((slider.bounds.width*value)+diamond_outline_size) @ (slider.bounds.height/2)); Pen.lineTo(((slider.bounds.width)) @ ((slider.bounds.height/2))); Pen.moveTo(((slider.bounds.width*value)-diamond_outline_size) @ (slider.bounds.height/2)); Pen.lineTo(((slider.bounds.width*value)) @ ((slider.bounds.height/2)+diamond_outline_size)); Pen.lineTo(((slider.bounds.width*value)+diamond_outline_size) @ (slider.bounds.height/2)); Pen.lineTo(((slider.bounds.width*value)) @ ((slider.bounds.height/2)-diamond_outline_size)); Pen.lineTo(((slider.bounds.width*value)-diamond_outline_size) @ (slider.bounds.height/2)); Pen.strokeColor = diamond_color; Pen.stroke; }; label = StaticText(slider, Rect(50, 0, slider.bounds.width-50, slider.bounds.height)); label.background_(Color.new(0,0,0,0)); label.stringColor = Color.new(1,1,1,0.75); label.string = "Frequency: 110.0"; label.align(\center); label.font = font; slider.mouseDownAction = { |slider, x| value = (x).linlin(0,slider.bounds.width,0,1); synth.set(\freq, value.linexp( 0, 1, 110, 220)); label.string = "Frequency: " + value.linexp(0,1,110,220).trunc(0.01); slider.refresh }; slider.mouseMoveAction = slider.mouseDownAction; win.front; CmdPeriod.doOnce({Window.closeAll}); // Kill GUI and server sounds on < Ctrl + ^ + . > . win.onClose = { s.freeAll; Window.closeAll; }; )
code description
Custom unidimensionnal slider GUI I made for my touchscreen instrument. Presented here as a tuner, but can serve any control purpose.
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change