EZSlider wrapper class for label, slider, number box

EZSlider(window, dimensions, label, controlSpec, action, initVal, initAction, labelWidth, numberWidth)

EZSlider is a wrapper class for managing a label, slider and number box.

window - the window containing the views.

dimensions - a Point giving the width and height of the combined views.

label - a String

controlSpec - the ControlSpec for the value.

action - a function called when the value changes. The function is passed the EZSlider instance as its argument.

initVal - the value to initialize the slider and number box with. If nil, then it uses the ControlSpec's default value.

initAction - a Boolean indicating whether the action function should be called when setting the initial value. The default is false.

labelWidth - number of pixels width for the label. default is 80.

numberWidth - number of pixels width for the number box. default is 80.

The contained views can be accessed via the EZSlider instance variables:

labelView, sliderView, numberView

Another useful instance variable is round, the rounding precision for the number box display. The default value for round is 0.001 .

see also EZNumber and EZRanger.

// Example:

(

w = GUI.window.new("EZSlider", Rect(20, 400, 440, 180));

w.front;

w.view.decorator = FlowLayout(w.view.bounds);

e = EZSlider(w, // window

400 @ 24, // dimensions

"Cutoff", // label

ControlSpec(200, 5000, \exp), // control spec

{|ez| ez.value.postln },// action

1000 // initVal

)

)

e.enabled;

e.enabled_(false);

e.enabled_(true);

e.visible;

e.visible_(false);

e.visible_(true);

e.remove; w.refresh;

// Another example

(

// start server

s.boot;

)

(

// define a synth

SynthDef("window-test", { arg note = 36, fc = 1000, rq = 0.25, bal=0, amp=0.4, gate = 1;

var x;

x = Mix.fill(4, {

LFSaw.ar((note + {0.1.rand2}.dup).midicps, 0, 0.02)

});

x = RLPF.ar(x, fc, rq).softclip;

x = RLPF.ar(x, fc, rq, amp).softclip;

x = Balance2.ar(x[0], x[1], bal);

x = x * EnvGen.kr(Env.cutoff, gate, doneAction: 2);

Out.ar(0, x);

}, [0.1, 0.1, 0.1, 0.1, 0.1, 0]

).load(s);

)

(

var w, startButton, noteControl, cutoffControl, resonControl;

var balanceControl, ampControl;

var node, cmdPeriodFunc;

// make the window

w = GUI.window.new("another control panel", Rect(20, 400, 440, 180));

w.front; // make window visible and front window.

w.view.decorator = FlowLayout(w.view.bounds);

w.view.background = HiliteGradient(Color.rand(0.0,1.0),Color.rand(0.0,1.0),

[\h,\v].choose, 100, rrand(0.1,0.9));

// add a button to start and stop the sound.

startButton = GUI.button.new(w, 75 @ 24);

startButton.states = [

["Start", Color.black, Color.green],

["Stop", Color.white, Color.red]

];

startButton.action = {|view|

if (view.value == 1) {

// start sound

node = Synth( "window-test", [

"note", noteControl.value,

"fc", cutoffControl.value,

"rq", resonControl.value,

"bal", balanceControl.value,

"amp", ampControl.value.dbamp ]);

} {

// set gate to zero to cause envelope to release

node.release; node = nil;

};

};

// create controls for all parameters

w.view.decorator.nextLine;

noteControl = EZSlider(w, 400 @ 24, "Note", ControlSpec(24, 60, \lin, 1),

{|ez| node.set( "note", ez.value )}, 36);

w.view.decorator.nextLine;

cutoffControl = EZSlider(w, 400 @ 24, "Cutoff", ControlSpec(200, 5000, \exp),

{|ez| node.set( "fc", ez.value )}, 1000);

w.view.decorator.nextLine;

resonControl = EZSlider(w, 400 @ 24, "Resonance", ControlSpec(0.1, 0.7),

{|ez| node.set( "rq", ez.value )}, 0.2);

w.view.decorator.nextLine;

balanceControl = EZSlider(w, 400 @ 24, "Balance", \bipolar,

{|ez| node.set( "bal", ez.value )}, 0);

w.view.decorator.nextLine;

ampControl = EZSlider(w, 400 @ 24, "Amp", \db,

{|ez| node.set( "amp", ez.value.dbamp )}, -6);

// set start button to zero upon a cmd-period

cmdPeriodFunc = { startButton.value = 0; };

CmdPeriod.add(cmdPeriodFunc);

// stop the sound when window closes and remove cmdPeriodFunc.

w.onClose = {

node.free; node = nil;

CmdPeriod.remove(cmdPeriodFunc);

};

)