2 summary:: A wrapper class for a label, a rangeslider, and numberboxes
3 categories:: GUI>EZ-GUI
4 related:: Classes/EZGui, Classes/StaticText, Classes/Slider, Classes/NumberBox
7 EZRanger 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 EZRanger will create its own window. See link::Classes/EZGui:: more options.
9 subsection:: Scrolling and Arrow Keys
10 EZRanger's number boxs scroll 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::s. 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.
17 The parent view or window. If the parent is nil, then EZRanger 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.
20 An instance of link::Classes/Rect:: or link::Classes/Point::. Default value is code::160@20::.
23 The label. Default value is code::nil::. If code::nil::, then no link::Classes/StaticText:: is created.
25 argument:: controlSpec
26 The link::Classes/ControlSpec:: for scaling the value.
29 A link::Classes/Function:: called when the value changes. The function is passed the EZRanger instance as its argument.
32 An inistance of link::Classes/Array:: code::[lo, hi]::. If code::nil::, then it uses the link::Classes/ControlSpec::'s default value.
35 A link::Classes/Boolean:: indicating whether the action function should be called when setting the initial value. The default is code::false::.
38 Number of pixels width for the label. default is 60.
40 argument:: numberWidth
41 Number of pixels width for the number box. default is 45.
44 Number of pixels width for the unit label. The default is 0. If 0, then no code::unitLabel:: is created.
46 argument:: labelHeight
50 code::\vert::, code::\line2::, or code::\horz::. The default is code::\horz::.
53 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.
56 A link::Classes/Point::. This will inset the bounds occupied by the subviews of view.
62 g = EZRanger(w, 400@16," test ", \freq, { |v| v.value.postln }, [50,2000], unitWidth:30)
65 // Simplest version, no parent view, so a window is created
67 EZRanger(nil, 400@16," test ", \freq, { |v| v.value.postln }, [50,2000])
70 The contained views can be accessed via the EZRanger instance variables: code::rangeSlider::, code::hiBox::, code::loBox::, code::unitView::, code::labelView::.
74 subsection:: Accessing Instance and Class Variables
77 The units label. Only appears if code::unitWidth:: was set to > 0.
80 An instance of ControlSpec for scaling the values.
84 The code::lo:: value link::Classes/NumberBox::.
87 Set/get a link::Classes/Function:: or link::Classes/FunctionList:: to be evaluated when the value changes. The first argument will be the EZRanger.
90 The link::Classes/RangeSlider:: link::Classes/View::
93 Set/get the low value.
96 Set/get the high value
99 The hi value link::Classes/NumberBox::.
102 Rounds the values in the number boxes.
105 subsection:: Doing Some Task (optional)
108 Performs the action at the current index and the global action.
111 Gets/sets the code::lo:: and code::hi:: values.
113 An instance of link::Classes/Array:: code:: [lo, hi] ::.
116 Sets the value and performs the action at the index value and the global action.
118 An instance of link::Classes/Array:: code:: [lo, hi] ::.
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:: sliderColor
128 An instance of link::Classes/Color::. The slider code::background::.
129 argument:: numBackground
130 An instance of link::Classes/Color::. The code::background:: 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 slider 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::.
152 g=EZRanger(w, 400@16," test ", \freq,{|v| v.value.postln},[50,2000],unitWidth:30);
153 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
156 // lots of range sliders on a view
159 w.view.decorator=FlowLayout(w.view.bounds);
160 w.view.decorator.gap=1@1;
163 g=EZRanger(w, 400@16," test ", \freq,{|v| v.value.postln},[50.rand,50+20000.rand],unitWidth:30)
164 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,Color.white, Color.white, Color.yellow)
165 .font_(Font("Helvetica",11));
172 /////////////////////////////////////////////////////////////////
173 ////////// click these parentheses to see all features and layouts
177 m=2@2; // comment for no margin
183 ( // all features, small font
184 g=EZRanger(nil, 400@16," freq ", \freq,
185 initVal:[100.rand,200+2000.rand],unitWidth:30, numberWidth:60,layout:\horz, margin:2@2);
186 g.setColors(Color.grey,Color.white, Color.grey(0.7),
187 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
188 knobColor: HiliteGradient(Color.grey, Color.white));
189 g.window.bounds = g.window.bounds.moveBy(-180,50);
190 g.font_(Font("Helvetica",10));
194 g=EZRanger(nil, 400@16," freq ", \freq,initVal:[100.rand,200+2000.rand],
195 unitWidth:0, numberWidth:60,layout:\horz, margin:2@2);
196 g.setColors(Color.grey,Color.white, Color.grey(0.7),
197 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
198 knobColor: HiliteGradient(Color.grey, Color.white));
199 g.window.bounds = g.window.bounds.moveBy(-180, -20);
200 g.font_(Font("Helvetica",10));
202 ( // no label, so use window name as label
203 g=EZRanger(nil, 400@16, nil, \freq,initVal:[100.rand,200+2000.rand],
204 unitWidth:0, numberWidth:60,layout:\horz, margin:2@2);
205 g.setColors(Color.grey,Color.white, Color.grey(0.7),
206 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
207 knobColor: HiliteGradient(Color.grey, Color.white));
208 g.window.bounds = g.window.bounds.moveBy(-180, -90);
209 g.window.name="Freq";
210 g.font_(Font("Helvetica",10));
217 g=EZRanger(nil, 300@42," freq ", \freq,initVal:[100.rand,200+2000.rand],
218 unitWidth:30, numberWidth:60,layout:\line2, margin:2@2);
219 g.setColors(Color.grey,Color.white, Color.grey(0.7),
220 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
221 knobColor: HiliteGradient(Color.grey, Color.white));
222 g.window.bounds = g.window.bounds.moveBy(-180,-160);
225 ( // no unitView, with label
226 g=EZRanger(nil, 300@42," freq ", \freq,initVal:[100.rand,200+2000.rand],
227 unitWidth:0, numberWidth:60,layout:\line2, margin:2@2);
228 g.setColors(Color.grey,Color.white, Color.grey(0.7),
229 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
230 knobColor: HiliteGradient(Color.grey, Color.white));
231 g.window.bounds = g.window.bounds.moveBy(-180,-260);
235 g=EZRanger(nil, 300@42,nil, \freq, initVal:[100.rand,200+2000.rand],
236 unitWidth:30, numberWidth:60,layout:\line2, margin:2@2);
237 g.setColors(Color.grey,Color.white, Color.grey(0.7),
238 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
239 knobColor: HiliteGradient(Color.grey, Color.white));
240 g.window.bounds = g.window.bounds.moveBy(-180,-360);
241 g.window.name="Freq";
244 ( // no label, so use window name as label
245 g=EZRanger(nil, 150@42,nil, \freq,initVal:[100.rand,200+2000.rand],
246 unitWidth:0, numberWidth:60,layout:\line2, margin:2@2);
247 g.setColors(Color.grey,Color.white, Color.grey(0.7),
248 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
249 knobColor: HiliteGradient(Color.grey, Color.white));
250 g.window.bounds = g.window.bounds.moveBy(-180,-460);
251 g.window.name="Freq";
257 ( // all features, small font
258 g=EZRanger(nil, 45@300," Vol ", \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
259 unitWidth:30, numberWidth:60,layout:\vert, margin:2@2);
260 g.setColors(Color.grey,Color.white, Color.grey(0.7),
261 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
262 knobColor: HiliteGradient(Color.grey, Color.white,\h));
263 g.window.bounds = g.window.bounds.moveBy(250,50);
264 g.font_(Font("Helvetica",9));
266 ( // no label, small font
267 g=EZRanger(nil, 45@300, nil, \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
268 unitWidth:30, numberWidth:60,layout:\vert, margin:2@2);
269 g.setColors(Color.grey,Color.white, Color.grey(0.7),
270 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
271 knobColor: HiliteGradient(Color.grey, Color.white,\h));
272 g.window.bounds = g.window.bounds.moveBy(310,50);
273 g.font_(Font("Helvetica",9));
275 ( // no Units small font
276 g=EZRanger(nil, 45@300, " Vol", \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
277 unitWidth:0, numberWidth:60,layout:\vert, margin:2@2);
278 g.setColors(Color.grey,Color.white, Color.grey(0.7),
279 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
280 knobColor: HiliteGradient(Color.grey, Color.white,\h));
281 g.window.bounds = g.window.bounds.moveBy(370,50);
282 g.font_(Font("Helvetica",9));
284 ( // no unitView, no units small font
285 g=EZRanger(nil, 45@300, nil, \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
286 unitWidth:0, numberWidth:60,layout:\vert, margin:2@2);
287 g.setColors(Color.grey,Color.white, Color.grey(0.7),
288 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
289 knobColor: HiliteGradient(Color.grey, Color.white,\h));
290 g.window.bounds = g.window.bounds.moveBy(430,50);
291 g.font_(Font("Helvetica",9));
301 ( // example to explore a synthesis idea:
302 p = ProxySpace.push(s.boot);
305 q.freqRange = [200, 2000];
306 q.ampRange = [0.1, 1];
307 q.ringRange = [0.1, 10];
308 q.numRange = [3, 30];
310 q.soundfunc = { |dens=5|
312 Array.fill(exprand(q.numRange[0], q.numRange[1]).asInteger, {
315 exprand(q.freqRange[0], q.freqRange[1]),
316 exprand(q.ringRange[0], q.ringRange[1]),
317 exprand(q.ampRange[0], q.ampRange[1])
326 ~plong = q[\soundfunc];
329 w = Window("cow herd").front;
330 w.view.decorator_(FlowLayout(w.bounds.copy.moveTo(0, 0)));
332 Spec.add(\ring, [0.03, 30, \exp]);
333 Spec.add(\num, [3, 30, \exp, 1]);
335 EZRanger(w, 390@20, "numRange", \num, { |sl| q.numRange = sl.value; }, labelWidth: 65)
338 EZRanger(w, 390@20, "freqRange", \freq, { |sl| q.freqRange = sl.value; }, q.freqRange, labelWidth: 65)
340 EZRanger(w, 390@20, "ringRange", \ring, { |sl| q.ringRange = sl.value; }, q.ringRange, labelWidth: 65)
342 EZRanger(w, 390@20, "ampRange", \amp, { |sl| q.ampRange = sl.value; }, q.ampRange, labelWidth: 65)
344 Button(w, 190@20).states_([[\newSound]]).action_({~plong = q[\soundfunc] });