Simple GUI

SuperCollider comes with a simple Qt GUI framework to create functional user interfaces with little effort. The comprehensive SuperCollider GUI Introduction includes many details on the use and customization of GUI elements.

This example usees a slider to control a parameter of a sine oscillator and a button to trigger a noise burst:

(
// a sine oscillator node with one parameter
var x = {|freq=100| Out.ar(0, SinOsc.ar(freq))}.play;

// create a window with width and position
var w = Window("Slider", Rect(128, 64, 800, 480));

// add a slider
var button = Button(w, Rect(400,50,200,200));

// add a slider
var slider = Slider(w, Rect(10,300,1000,100));

// the callback function on slider move
slider.action_({x.set(\freq, pow(slider.value,4) * 10000)});

button.mouseDownAction = {{Out.ar(0, EnvGen.ar(Env([1,0],[1],'lin'),doneAction:Done.freeSelf) * WhiteNoise.ar())}.play};
// same as button.mouseDownAction_(...)

w.fullScreen;
// "same effect as setting -visible to true"
w.front;

)

Exercises