Graphical User Interface Classes for SC3 (SwingOSC version)

Server.default=s=Server.local;

GUI classes for SC3 include Range and 2D sliders, drag and drop facilities, drop down lists, multisliders and many more... 

SwingOSC.default.boot;

To make a window

//The Rect(angle) takes the initial screen position and the window size
//as screenx,screeny, windowwidth, windowheight, where y is 0 at the bottom
(
var w;

w=JSCWindow("My Window", Rect(100,300,200,200)); 
//A 200 by 200 window appears at screen co-ordinates (100, 500)

w.front; //this line is need to make the window actually appear
)

Note that we count on the y axis from screen origin at bottom left, to the bottom left corner of the window.

We add controls to our window, defining any parameters of their use. We pass in the window we wish the control to appear in and use a Rect again to specify where in the window the control will appear and how large it is

(
var w, slid;

w=JSCWindow("My Window", Rect(100,500,200,200)); 
//A 200 by 200 window appears at screen co-ordinates (100, 500)

slid=JSCSlider(w,Rect(10,10,150,40)); //a basic slider object 

slid.action_({slid.value.postln;}); //this is the callback- the function is called whenever you move the slider

w.front;
)

Note how the default slider range is from 0.0 to 1.0

A ControlSpec is a helpful class which can be used to turn this into any desired range

(
var w, slid, cs;

w=JSCWindow("My Window", Rect(100,500,200,200)); 
//A 200 by 200 window appears at screen co-ordinates (100, 500)

slid=JSCSlider(w,Rect(10,10,150,40));

//arguments minimum value, maximum value, warp (mapping function), stepsize, starting value 
cs= ControlSpec(20, 20000, 'exp', 10, 1000); 

slid.action_({cs.map(slid.value).postln;}); //map to the desired range

w.front;
)

//Demo of using 2D-Slider for synthesis

(
SynthDef(\filterme,
{arg freq=1000, rq=0.5;
Out.ar(0, 
Pan2.ar(
BPF.ar(Impulse.ar(LFNoise0.kr(15,500,1000),0.1, WhiteNoise.ar(2)),freq,rq)
))
}).load(s)
)

(
var w, slid2d, syn;

w=JSCWindow("My Window", Rect(100,300,200,200)); 
slid2d= JSC2DSlider(w,Rect(5,5,175,175));

syn=Synth(\filterme);

slid2d.action_({
[slid2d.x, slid2d.y].postln;
syn.set(\freq,100+(10000*slid2d.y),\rq,0.01+(0.09*slid2d.x));  //I'm doing my own mapping here rather than use a ControlSpec
});

w.front;

w.onClose={syn.free;};
)

For further explorations:

For demos of Drag and Drop and other UI facilities open 

GUI examples.rtf		//in the Examples folder for SC

Document.open("Examples/GUI examples.rtf"); //on a Mac this will open it straight away

(
// create a GUI window with some NumberBoxes.
// You can control click on a control to drag its value to another control
var w, n, f, s;
w = JSCWindow("number box test", Rect(128, 64, 260, 80));
w.view.decorator = f = FlowLayout(w.view.bounds);

n = JSCNumberBox(w, Rect(0,0,80,24));
n.value = 123;

n = JSCNumberBox(w, Rect(0,0,80,24));
n.value = 456;

n = JSCDragBoth(w, Rect(0,0,80,24));
n.object = 789;

f.nextLine;

s = JSCSlider(w, Rect(0,0,240,24));

w.front;
)

There are also interesting help files for some other GUI objects:

[JSCMultiSliderView] //call the Help file

[JSCEnvelopeView] //not yet implemented but links to a possible substitute

and some media viewing objects

[JSCSoundFileView]

[JSCMovieView]

As well as screen drawing facilities using the JPen class

[JPen]