2 summary:: Wrapper class for label and number box
3 categories:: GUI>EZ-GUI
4 related:: Classes/NumberBox
7 EZNumber is wrapper class which creates an (optional) link::Classes/StaticText::, and a link::Classes/NumberBox::.
9 subsection:: Some Important Issues Regarding NumberBox
10 If the parent is code::nil::, then EZNumber will create its own window. See link::Classes/EZGui:: more options.
12 subsection:: Scrolling and Arrow Keys
13 EZNumber 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 EZNumber. By default, the shift-key modifier will allow you to step by 100 x 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::.
19 The parent view or window. If the parent is nil, then EZNumber 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.
22 An instance of link::Classes/Rect:: or link::Classes/Point::. Default value is code::160@20::.
25 The label. Default value is code::nil::. If code::nil::, then no link::Classes/StaticText:: is created.
27 argument:: controlSpec
28 The link::Classes/ControlSpec:: for scaling the value.
31 A link::Classes/Function:: called when the value changes. The function is passed the EZNumber instance as its argument.
34 The value to initialize the slider and number box with. If code::nil::, then it uses the link::Classes/ControlSpec::'s default value.
37 A link::Classes/Boolean:: indicating whether the action function should be called when setting the initial value. The default is code::false::.
40 Number of pixels width for the label. The default is 60. In the code::\horz:: layout, if you specify the code::numberWidth::, then the code::labelWidth:: is ignored and is set to the code::bounds.width - unitWidth - numberWidth::.
42 argument:: numberWidth
43 Number of pixels width for the number box. The default is 45. In \line2 layout, numberWidth defaults to the bounds.width minus the unitWidth.
46 Number of pixels width for the unit label. The default is 0. If code::unitWidth:: is 0, then no code::unitLabel:: is created. In the code::\line2:: layout, if you specify the code::numberWidth::, then the code::unitWidth:: is ignored and is set to the code::bounds.width - unitWidth - numberWidth::.
48 argument:: labelHeight
52 code::\line2::, or code::\horz::. The default is code::\horz::; code::\line2:: is a two line version.
55 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.
58 A link::Classes/Point::. This will inset the bounds occupied by the subviews of view.
64 g = EZNumber(w, // parent
68 { |ez| (ez.value.asString ++" is the value of " ++ ez).postln }, // action
72 g.setColors(Color.grey,Color.white);
76 // Simplest version, no parent view, so a window is created
78 g = EZNumber(label:" test ", controlSpec: \amp.asSpec.step_(0.01) );
79 g.action_({ |ez| (ez.value.asString ++" is the value of " ++ ez).postln });
83 The contained views can be accessed via the EZNumber instance variables: code::labelView::, code::numberView::.
88 Returns the numberView
91 A function to be evaluated when the value changes. Te first argument will be the EZNumber.
93 An instance of link::Classes/Function:: or link::Classes/FunctionList::. Default value is nil.
96 The value of the slider
99 Rounds the values in the number box.
102 An instance of link::Classes/ControlSpec:: for scaling the values.
105 Gets/sets the list/menu to the index at value. Does not perform the action.
107 An link::Classes/Integer::.
110 Sets the value and performs the action at the index value and the global action.
112 An link::Classes/Integer::.
115 Performs the action at the current index and the global action.
118 Set the args after creation.
121 Sets/gets if the list is enabled.
123 An instance of link::Classes/Boolean::. Default is code::true::.
126 subsection:: Changing Appearance
129 argument:: stringBackground
130 An instance of link::Classes/Color::. The code::background:: of the label and unit views.
131 argument:: stringColor
132 An instance of link::Classes/Color::. The code::stringColor:: of the label and unit views.
133 argument:: numBackground
134 An instance of link::Classes/Color::. The code::background:: of the number view.
135 argument:: numStringColor
136 An instance of link::Classes/Color::. The code::stringColor:: of the number view.
137 argument:: numNormalColor
138 An instance of link::Classes/Color::. The code::normalColor:: of the number view.
139 argument:: numTypingColor
140 An instance of link::Classes/Color::. The code::typingColor:: of the number view.
141 argument:: background
142 An instance of link::Classes/Color::. The code::background:: of the enclosing view.
145 Set the link::Classes/Font:: used by all the views.
147 An instance of link::Classes/Font::.
155 g=EZNumber(w, 170@16," test ", \freq,unitWidth:30, numberWidth:60,layout:\horz);
156 g.setColors(Color.grey,Color.white);
160 // lots of numberviews on on view
163 w.view.decorator=FlowLayout(w.view.bounds);
164 w.view.decorator.gap=2@2;
167 g=EZNumber(w, 170@16," test ", \freq,unitWidth:30, numberWidth:60,layout:\horz);
168 g.setColors(Color.grey,Color.white, Color.grey(0.8));
173 // click these parentheses to see all features and layouts
177 m=2@2; //comment for no margin
183 g=EZNumber(nil, 170@20," freq ", \freq,unitWidth:30, numberWidth:60,layout:\horz,margin:m);
184 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
185 g.window.bounds = g.window.bounds.moveBy(-180,50);
189 g=EZNumber(nil, 170@20," freq ", \freq,unitWidth:0, numberWidth:60,layout:\horz,margin:m);
190 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
191 g.window.bounds = g.window.bounds.moveBy(-180, -20);
194 ( // no label, with unit. use window name as label
195 g=EZNumber(nil, 120@20,nil, \freq,unitWidth:30, numberWidth:60,layout:\horz,margin:m);
196 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
197 g.window.bounds = g.window.bounds.moveBy(-180, -90);
198 g.window.name="Freq";
202 ( // no units, no label; use window name as label;
203 g=EZNumber(nil, 120@20, nil, \freq,unitWidth:0, numberWidth:60,layout:\horz,margin:m);
204 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
205 g.window.bounds = g.window.bounds.moveBy(-180, -160);
206 g.window.name="Freq";
213 g=EZNumber(nil, 120@42," freq ", \freq,unitWidth:30, numberWidth:60,layout:\line2,margin:m);
214 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
215 g.window.bounds = g.window.bounds.moveBy(100,50);
218 ( // no unitView, with label
219 g=EZNumber(nil, 170@42," freq ", \freq,unitWidth:0, numberWidth:60,layout:\line2,margin:m);
220 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
221 g.window.bounds = g.window.bounds.moveBy(100, -50);
223 ( // no unitView, no label; use window name as label
224 g=EZNumber(nil, 170@20,nil, \freq,unitWidth:0, numberWidth:60,layout:\line2,margin:m);
225 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
226 g.window.bounds = g.window.bounds.moveBy(100,-150);
227 g.window.name="Freq";
240 var w, startButton, noteControl, cutoffControl, resonControl;
241 var balanceControl, ampControl;
242 var node, cmdPeriodFunc;
245 SynthDef("window-test", { arg note = 36, fc = 1000, rq = 0.25, bal=0, amp=0.4, gate = 1;
248 LFSaw.ar((note + {0.1.rand2}.dup).midicps, 0, 0.02)
250 x = RLPF.ar(x, fc, rq).softclip;
251 x = RLPF.ar(x, fc, rq, amp).softclip;
252 x = Balance2.ar(x[0], x[1], bal);
253 x = x * EnvGen.kr(Env.cutoff, gate, doneAction: 2);
255 }, [0.1, 0.1, 0.1, 0.1, 0.1, 0]
261 w = Window("another control panel", Rect(200, 400, 300, 180));
262 w.front; // make window visible and front window.
263 w.view.decorator = FlowLayout(w.view.bounds);
265 w.view.background = Color.rand;
267 // add a button to start and stop the sound.
268 startButton = Button(w, 75 @ 20);
269 startButton.states = [
270 ["Start", Color.black, Color.green],
271 ["Stop", Color.white, Color.red]
273 startButton.action = {|view|
274 if (view.value == 1) {
276 node = Synth( "window-test", [
277 "note", noteControl.value,
278 "fc", cutoffControl.value,
279 "rq", resonControl.value,
280 "bal", balanceControl.value,
281 "amp", ampControl.value.dbamp ]);
283 // set gate to zero to cause envelope to release
284 node.release; node = nil;
288 // create controls for all parameters
289 w.view.decorator.nextLine;
290 noteControl = EZNumber(w, 160 @ 20, "Note ", ControlSpec(24, 60, \lin, 1),
291 {|ez| node.set( "note", ez.value )}, 36);
293 w.view.decorator.nextLine;
294 cutoffControl = EZNumber(w, 160 @ 20, "Cutoff ", ControlSpec(200, 5000, \exp),
295 {|ez| node.set( "fc", ez.value )}, 1000);
297 w.view.decorator.nextLine;
298 resonControl = EZNumber(w, 160 @ 20, "Reson", ControlSpec(0.1, 0.7),
299 {|ez| node.set( "rq", ez.value )}, 0.2);
301 w.view.decorator.nextLine;
302 balanceControl = EZNumber(w, 160 @ 20, "Balance ", \bipolar,
303 {|ez| node.set( "bal", ez.value )}, 0);
305 w.view.decorator.nextLine;
306 ampControl = EZNumber(w, 160 @ 20, "Amp ", \db,
307 {|ez| node.set( "amp", ez.value.dbamp )}, -6);
310 // set start button to zero upon a cmd-period
311 cmdPeriodFunc = { startButton.value = 0; };
312 CmdPeriod.add(cmdPeriodFunc);
314 // stop the sound when window closes and remove cmdPeriodFunc.
316 node.free; node = nil;
317 CmdPeriod.remove(cmdPeriodFunc);