EZRanger wrapper class for label, rangeslider, number boxes, and unit display.
EZRanger(window, dimensions, label, spec, action, initVal, initAction, labelWidth, numberWidth)
EZRanger is a wrapper class for managing a label, a rangeslider, 2 number boxes, and a unit label.
w - the window containing the views.
dimensions - a Point giving the width and height of the combined views.
label - a String to name it
spec - the ControlSpec for the value.
action - a function called when the value changes.
The function is passed the EZRanger instance as its argument.
initVal - the value (two numbers) 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 60.
numberWidth - number of pixels width for the number box. default is 40.
unitWidth - number of pixels width for the unit label. default is 30.
The contained views can be accessed via the EZRanger instance variables:
labelView, loBox, rangeSlider, hiBox, unitView, or all together as views.
Another useful instance variable is round, the rounding precision for the number box display.
The default value for round is 0.001 .
// Examples:
(
w = GUI.window.new("EZRanger", Rect(400, 400, 400, 100)).front;
w.view.decorator_(FlowLayout(w.bounds.copy.moveTo(0, 0)));
r = EZRanger(w, 384@20, "test", \freq, { |ez| ez.value.postln }, [250, 4000]).round_(0.1);
)
r.lo_(40);
r.hi_(300);
r.value;
r.value_([300, 3000]);
r.valueAction_([200, 5000]);
r.spec.postcs;
r.enabled;
r.enabled_(false);
r.enabled_(true);
r.visible;
r.visible_(false);
r.visible_(true);
r.remove; w.refresh;
// layout option in two lines:
(
w = GUI.window.new("EZRanger2", Rect(400, 400, 400, 100)).front;
w.view.decorator_(FlowLayout(w.bounds.copy.moveTo(0, 0)));
EZRanger2(w, 190@40, label: "test2", spec: \freq, initVal: [2000, 6000], labelWidth: 40, numberWidth: 60, unitWidth: 20)
.round_(0.01);
EZRanger2(w, 190@40, label: "test3", spec: \freq, initVal: [200, 600], labelWidth: 40, numberWidth: 60, unitWidth: 20)
.round_(0.01);
)
( // example to explore a synthesis idea:
p = ProxySpace.push(s.boot);
q = q ? ();
q.freqRange = [200, 2000];
q.ampRange = [0.1, 1];
q.ringRange = [0.1, 10];
q.numRange = [3, 30];
q.soundfunc = { |dens=5|
Splay.ar(
Array.fill(exprand(q.numRange[0], q.numRange[1]).asInteger, {
Ringz.ar(
Dust.ar(dens),
exprand(q.freqRange[0], q.freqRange[1]),
exprand(q.ringRange[0], q.ringRange[1]),
exprand(q.ampRange[0], q.ampRange[1])
)
})
).distort
};
)
~plong.play;
~plong.fadeTime = 3;
~plong = q[\soundfunc];
(
w = GUI.window.new("cow herd").front;
w.view.decorator_(FlowLayout(w.bounds.copy.moveTo(0, 0)));
Spec.add(\ring, [0.03, 30, \exp]);
Spec.add(\num, [3, 30, \exp, 1]);
EZRanger(w, 390@20, "numRange", \num, { |sl| q.numRange = sl.value; }, q.numRange)
.round_(1);
EZRanger(w, 390@20, "freqRange", \freq, { |sl| q.freqRange = sl.value; }, q.freqRange)
.round_(0.1);
EZRanger(w, 390@20, "ringRange", \ring, { |sl| q.ringRange = sl.value; }, q.ringRange)
.round_(0.0001);
EZRanger(w, 390@20, "ampRange", \amp, { |sl| q.ampRange = sl.value; }, q.ampRange)
.round_(0.0001);
GUI.button.new(w, 190@20).states_([[\newSound]]).action_({ ~plong = q[\soundfunc] });
)