2 summary:: Wrapper class for label, slider, number box
3 categories:: GUI>EZ-GUI
4 related:: Classes/Slider, Classes/NumberBox, Classes/StaticText, Classes/CompositeView, Classes/EZGui
7 EZSlider is wrapper class which creates an (optional) link::Classes/StaticText::, and a link::Classes/Slider:: plus a link::Classes/NumberBox::. If the parent is code::nil::, then EZSlider will create its own window. See link::Classes/EZGui:: more options.
9 subsection:: Scrolling and Arrow Keys
10 EZSlider's number box scrolls by default, using the step size of the link::Classes/ControlSpec::. If the controlSpec's step is set to 0, or is not set, then the the stepping and scrolling will be guessed according to the code::minval:: and code::maxval:: values of the spec on creation of the view. Unlike the step variable of a regular link::Classes/NumberBox::, code::controlSpec.step:: is also the smallest possible increment for the link::Classes/NumberBox::. By default, the shift-key modifier will allow you to step by 100x code::controlSpec.step::, while the ctrl-key will give you 10x code::controlSpec.step::. Since the alt-key would give you 0.1 of the minimum step, it is disabled by default, but you can change that by setting code::numberView.alt_step:: to any value you like. Accordingly you can customize the other modifiers to fit your needs. See link::Classes/NumberBox:: and link::Classes/Slider::. This also effects the arrow keys for the slider.
14 subsection:: Creation / Class Methods
18 The parent view or window. If the parent is code::nil::, then EZSlider will create its own link::Classes/Window::, and place it conveniently on the screen if the bounds are a link::Classes/Point::. If the bounds are a link::Classes/Rect::, then the link::Classes/Rect:: determines the window bounds.
21 An instance of link::Classes/Rect:: or link::Classes/Point::. Default value is code::160@20::.
24 The label. Default value is code::nil::. If code::nil::, then no link::Classes/StaticText:: is created.
26 argument:: controlSpec
27 The link::Classes/ControlSpec:: for scaling the value.
30 A link::Classes/Function:: called when the value changes. The function is passed the EZSlider instance as its argument.
33 The value to initialize the slider and number box with. If code::nil::, then it uses the link::Classes/ControlSpec::'s default value.
36 A link::Classes/Boolean:: indicating whether the action function should be called when setting the initial value. The default is false.
39 Number of pixels width for the label. The default is 60.
41 argument:: numberWidth
42 Number of pixels width for the number box. The default is 45.
45 Number of pixels width for the unit label. The default is 0. If 0, then no unitLabel is created.
47 argument:: labelHeight
51 code::\vert::, code::\line2::, or code::\horz::. The default is code::\horz::.
54 A link::Classes/Point::. By default, the view tries to get its parent's gap, otherwise it defaults to code::2@2::. Setting it overrides these.
57 A link::Classes/Point::. This will inset the bounds occupied by the subviews of view.
63 g = EZSlider( w, // parent
67 { |ez| (ez.value.asString ++" is the value of " ++ ez).postln } // action
69 g.setColors(Color.grey,Color.white)
72 // Simplest version, no parent view, so a window is created
74 g = EZSlider(label:" test ");
75 g.action_({ |ez| (ez.value.asString ++" is the value of " ++ ez).postln });
78 The contained views can be accessed via the EZSlider instance variables: code::labelView::, code::sliderView::, code::numberView::.
82 subsection:: Accessing Instance and Class Variables
85 Returns the numberView.
88 A link::Classes/Function:: or link::Classes/FunctionList:: to be evaluated when the value changes. The first argument will be the EZSlider.
91 The value of the slider.
94 Rounds the values in the number box.
97 An instance of ControlSpec for scaling the values.
100 Gets/sets the list/menu to the index at value. Does not perform the action.
102 An link::Classes/Integer::.
105 Sets the value and performs the action at the index value and the global action.
107 An link::Classes/Integer::.
110 Performs the action at the current index and the global action.
113 Set the args after creation. You can only set the label if it was not nil from the beginning.
116 Sets/gets it the component views are visible.
118 An instance of link::Classes/Boolean::. Default is code::true::.
120 subsection:: Changing Appearance
123 argument:: stringBackground
124 An instance of link::Classes/Color::. The code::background:: of the label and unit views.
125 argument:: stringColor
126 An instance of link::Classes/Color::. The code::stringColor:: of the label and unit views.
127 argument:: sliderBackground
128 An instance of link::Classes/Color::. The slider code::background::.
129 argument:: numBackground
130 An instance of link::Classes/Color::. The code::numColor:: of the number view.
131 argument:: numStringColor
132 An instance of link::Classes/Color::. The code::stringColor:: of the number view.
133 argument:: numNormalColor
134 An instance of link::Classes/Color::. The code::normalColor:: of the number view.
135 argument:: numTypingColor
136 An instance of link::Classes/Color::. The code::typingColor:: of the number view.
138 An instance of link::Classes/Color::. The code::knobColor:: of the knob view.
139 argument:: background
140 An instance of link::Classes/Color::. The code::background:: of the enclosing view.
143 Set the Font used by all the views.
145 An instance of link::Classes/Font::.
151 g=EZSlider(w, 400@16," test ", \freq,unitWidth:30, numberWidth:60,layout:\horz);
152 g.setColors(Color.grey,Color.white);
155 // lots of sliders on on view
158 w.view.decorator=FlowLayout(w.view.bounds);
159 w.view.decorator.gap=2@2;
162 EZSlider(w, 392@16," Freq ", \freq,unitWidth:30,initVal:6000.rand, numberWidth:60,layout:\horz)
163 .setColors(Color.grey,Color.white)
164 .font_(Font("Helvetica",11));
169 Window.closeAll // use this to close all the windows
171 /////////////////////////////////////////////////////////////////
172 ////////// click these parentheses to see all features and layouts
177 //m=2@2; // uncomment this for margin
182 ( // all features, small font
183 g=EZSlider(nil, 400@14," freq ", \freq,unitWidth:30, numberWidth:60,layout:\horz, margin: m);
184 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
185 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
186 g.window.bounds = g.window.bounds.moveBy(-180,50);
187 g.font_(Font("Helvetica",10));
191 g=EZSlider(nil, 400@16," freq ", \freq,unitWidth:0, numberWidth:60,layout:\horz, margin: m);
192 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
193 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
194 g.window.bounds = g.window.bounds.moveBy(-180, -20);
196 ( // no label, so use window name as label
197 g=EZSlider(nil, 400@16, nil, \freq,unitWidth:0, numberWidth:60,layout:\horz, margin: m);
198 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
199 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
200 g.window.bounds = g.window.bounds.moveBy(-180, -90);
201 g.window.name="Freq";
208 g=EZSlider(nil, 300@42," freq ", \freq,unitWidth:30, numberWidth:60,layout:\line2, margin: m);
209 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
210 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
211 g.window.bounds = g.window.bounds.moveBy(-180,-160);
214 ( // no unitView, with label
215 g=EZSlider(nil, 300@42," freq ", \freq,unitWidth:0, numberWidth:60,layout:\line2, margin: m);
216 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
217 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
218 g.window.bounds = g.window.bounds.moveBy(-180,-260);
222 g=EZSlider(nil, 300@42,nil, \freq, unitWidth:30, numberWidth:60,layout:\line2, margin: m);
223 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
224 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
225 g.window.bounds = g.window.bounds.moveBy(-180,-360);
226 g.window.name="Freq";
229 ( // no lablel, so use window name as label
230 g=EZSlider(nil, 150@42,nil, \freq,unitWidth:0, numberWidth:60,layout:\line2, margin: m);
231 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
232 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
233 g.window.bounds = g.window.bounds.moveBy(-180,-460);
234 g.window.name="Freq";
240 ( // all features, small font
241 g=EZSlider(nil, 45@300," Vol ", \db.asSpec.step_(0.01),unitWidth:30, numberWidth:60,layout:\vert, margin: m);
242 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
243 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
244 g.window.bounds = g.window.bounds.moveBy(250,50);
245 g.font_(Font("Helvetica",10));
247 ( // no label, small font
248 g=EZSlider(nil, 45@300, nil, \db.asSpec.step_(0.01),unitWidth:30, numberWidth:60,layout:\vert, margin: m);
249 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
250 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
251 g.window.bounds = g.window.bounds.moveBy(310,50);
252 g.font_(Font("Helvetica",10));
254 ( // no Units small font
255 g=EZSlider(nil, 45@300, " Vol", \db.asSpec.step_(0.01),unitWidth:0, numberWidth:60,layout:\vert, margin: m);
256 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
257 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
258 g.window.bounds = g.window.bounds.moveBy(370,50);
259 g.font_(Font("Helvetica",10));
261 ( // no unitView, no Units small font
262 g=EZSlider(nil, 45@300, nil, \db.asSpec.step_(0.01),unitWidth:0, numberWidth:60,layout:\vert, margin: m);
263 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,
264 Color.white, Color.yellow,nil,nil, Color.grey(0.7));
265 g.window.bounds = g.window.bounds.moveBy(430,50);
266 g.font_(Font("Helvetica",10));
274 ///////////////////////////////////////////////////////////////
275 ///////////////////////////////////////////////////////////////
283 var w, startButton, noteControl, cutoffControl, resonControl;
284 var balanceControl, ampControl;
285 var node, cmdPeriodFunc;
288 SynthDef("window-test", { arg note = 36, fc = 1000, rq = 0.25, bal=0, amp=0.4, gate = 1;
291 LFSaw.ar((note + {0.1.rand2}.dup).midicps, 0, 0.02)
293 x = RLPF.ar(x, fc, rq).softclip;
294 x = RLPF.ar(x, fc, rq, amp).softclip;
295 x = Balance2.ar(x[0], x[1], bal);
296 x = x * EnvGen.kr(Env.cutoff, gate, doneAction: 2);
298 }, [0.1, 0.1, 0.1, 0.1, 0.1, 0]
305 w = Window("another control panel", Rect(20, 400, 440, 180));
306 w.front; // make window visible and front window.
307 w.view.decorator = FlowLayout(w.view.bounds);
308 w.view.decorator.gap=2@2;
310 // add a button to start and stop the sound.
311 startButton = Button(w, 75 @ 20);
312 startButton.states = [
313 ["Start", Color.black, Color.green(0.7)],
314 ["Stop", Color.white, Color.red(0.7)]
316 startButton.action = {|view|
317 if (view.value == 1) {
319 node = Synth( "window-test", [
320 "note", noteControl.value,
321 "fc", cutoffControl.value,
322 "rq", resonControl.value,
323 "bal", balanceControl.value,
324 "amp", ampControl.value.dbamp ]);
326 // set gate to zero to cause envelope to release
327 node.release; node = nil;
331 // create controls for all parameters
332 w.view.decorator.nextLine;
333 noteControl = EZSlider(w, 430 @ 20, "Note ", ControlSpec(24, 60, \lin, 1, 36, \note),
334 {|ez| node.set( "note", ez.value )}, unitWidth:30)
335 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
337 w.view.decorator.nextLine;
338 cutoffControl = EZSlider(w, 430 @ 20, "Cutoff ", ControlSpec(200, 5000, \exp,0.01,1000,\Hz),
339 {|ez| node.set( "fc", ez.value )}, unitWidth:30)
340 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
342 w.view.decorator.nextLine;
343 resonControl = EZSlider(w, 430 @ 20, "Reson ", ControlSpec(0.1, 0.7,\lin,0.001,0.2,\rq),
344 {|ez| node.set( "rq", ez.value )}, unitWidth:30)
345 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
347 w.view.decorator.nextLine;
348 balanceControl = EZSlider(w, 430 @ 20, "Balance ", \bipolar,
349 {|ez| node.set( "bal", ez.value )}, unitWidth:30)
350 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
352 w.view.decorator.nextLine;
353 ampControl = EZSlider(w, 430 @ 20, "Amp ", \db,
354 {|ez| node.set( "amp", ez.value.dbamp )}, -6, unitWidth:30)
355 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
358 // set start button to zero upon a cmd-period
359 cmdPeriodFunc = { startButton.value = 0; };
360 CmdPeriod.add(cmdPeriodFunc);
362 // stop the sound when window closes and remove cmdPeriodFunc.
364 node.free; node = nil;
365 CmdPeriod.remove(cmdPeriodFunc);
373 // a variant of the above example so one can
374 // add new parameters and more views are created automatically
380 var w, startButton, sliders;
381 var node, cmdPeriodFunc;
385 SynthDef("window-test", { arg note = 36, fc = 1000, rq = 0.25, bal = 0, amp=0.4, width=0, gate = 1;
388 VarSaw.ar((note + {0.1.rand2}.dup).midicps, 0, width, 0.02)
390 x = RLPF.ar(x, fc, rq).softclip;
391 x = RLPF.ar(x, fc, rq, amp).softclip;
392 x = Balance2.ar(x[0], x[1], bal);
393 x = x * EnvGen.kr(Env.cutoff, gate, 5, doneAction: 2);
395 }, [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0]
399 params = ["note", "fc", "rq", "bal", "amp", "width"];
401 ControlSpec(24, 60, \lin, 1, 36, \note),
402 ControlSpec(200, 5000, \exp,0.01,1000,\Hz),
403 ControlSpec(0.1, 0.7,\lin,0.001,0.2,\rq),
404 ControlSpec(-1, 1, \lin, 0, 0, \pan),
405 ControlSpec(0.0001, 2, \exp, 0, 0.3, \vol), // db spec acts weird, so use self made one
406 ControlSpec(0, 1, \lin, 0, 0.3, \width),
410 w = Window("another control panel", Rect(20, 400, 440, 180));
411 w.front; // make window visible and front window.
412 w.view.decorator = FlowLayout(w.view.bounds);
413 w.view.decorator.gap=2@2;
416 // add a button to start and stop the sound.
417 startButton = Button(w, 75 @ 20);
418 startButton.states = [
419 ["Start", Color.black, Color.green(0.7)],
420 ["Stop", Color.white, Color.red(0.7)]
422 startButton.action = {|view|
424 if (view.value == 1) {
426 params.do { |param, i|
427 args = args.add(param);
428 args = args.add(sliders[i].value)
430 node = Synth("window-test", args.postcs);
432 // set gate to zero to cause envelope to release
433 node.release; node = nil;
437 // create controls for all parameters
438 w.view.decorator.nextLine;
439 sliders = params.collect { |param, i|
440 EZSlider(w, 430 @ 20, param, specs[i], {|ez| node.set( param, ez.value )})
441 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
443 // set start button to zero upon a cmd-period
444 cmdPeriodFunc = { startButton.value = 0; };
445 CmdPeriod.add(cmdPeriodFunc);
447 // stop the sound when window closes and remove cmdPeriodFunc.
449 node.free; node = nil;
450 CmdPeriod.remove(cmdPeriodFunc);