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.
83 The code::lo:: value link::Classes/NumberBox::.
86 Set/get a link::Classes/Function:: or link::Classes/FunctionList:: to be evaluated when the value changes. The first argument will be the EZRanger.
89 The link::Classes/RangeSlider:: link::Classes/View::
92 Set/get the low value.
95 Set/get the high value
98 The hi value link::Classes/NumberBox::.
101 Rounds the values in the number boxes.
103 subsection:: Doing Some Task (optional)
106 Performs the action at the current index and the global action.
109 Gets/sets the code::lo:: and code::hi:: values.
111 An instance of link::Classes/Array:: code:: [lo, hi] ::.
114 Sets the value and performs the action at the index value and the global action.
116 An instance of link::Classes/Array:: code:: [lo, hi] ::.
118 subsection:: Changing Appearance
121 argument:: stringBackground
122 An instance of link::Classes/Color::. The code::background:: of the label and unit views.
123 argument:: stringColor
124 An instance of link::Classes/Color::. The code::stringColor:: of the label and unit views.
125 argument:: sliderColor
126 An instance of link::Classes/Color::. The slider code::background::.
127 argument:: numBackground
128 An instance of link::Classes/Color::. The code::background:: of the number view.
129 argument:: numStringColor
130 An instance of link::Classes/Color::. The code::stringColor:: of the number view.
131 argument:: numNormalColor
132 An instance of link::Classes/Color::. The code::normalColor:: of the number view.
133 argument:: numTypingColor
134 An instance of link::Classes/Color::. The code::typingColor:: of the number view.
136 An instance of link::Classes/Color::. The code::knobColor:: of the slider view.
137 argument:: background
138 An instance of link::Classes/Color::. The code::background:: of the enclosing view.
141 Set the Font used by all the views.
143 An instance of link::Classes/Font::.
150 g=EZRanger(w, 400@16," test ", \freq,{|v| v.value.postln},[50,2000],unitWidth:30);
151 g.setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey, Color.white, Color.yellow);
154 // lots of range sliders on a view
157 w.view.decorator=FlowLayout(w.view.bounds);
158 w.view.decorator.gap=1@1;
161 g=EZRanger(w, 400@16," test ", \freq,{|v| v.value.postln},[50.rand,50+20000.rand],unitWidth:30)
162 .setColors(Color.grey,Color.white, Color.grey(0.7),Color.grey,Color.white, Color.white, Color.yellow)
163 .font_(Font("Helvetica",11));
170 /////////////////////////////////////////////////////////////////
171 ////////// click these parentheses to see all features and layouts
175 m=2@2; // comment for no margin
181 ( // all features, small font
182 g=EZRanger(nil, 400@16," freq ", \freq,
183 initVal:[100.rand,200+2000.rand],unitWidth:30, numberWidth:60,layout:\horz, margin:2@2);
184 g.setColors(Color.grey,Color.white, Color.grey(0.7),
185 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
186 knobColor: HiliteGradient(Color.grey, Color.white));
187 g.window.bounds = g.window.bounds.moveBy(-180,50);
188 g.font_(Font("Helvetica",10));
192 g=EZRanger(nil, 400@16," freq ", \freq,initVal:[100.rand,200+2000.rand],
193 unitWidth:0, numberWidth:60,layout:\horz, margin:2@2);
194 g.setColors(Color.grey,Color.white, Color.grey(0.7),
195 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
196 knobColor: HiliteGradient(Color.grey, Color.white));
197 g.window.bounds = g.window.bounds.moveBy(-180, -20);
198 g.font_(Font("Helvetica",10));
200 ( // no label, so use window name as label
201 g=EZRanger(nil, 400@16, nil, \freq,initVal:[100.rand,200+2000.rand],
202 unitWidth:0, numberWidth:60,layout:\horz, margin:2@2);
203 g.setColors(Color.grey,Color.white, Color.grey(0.7),
204 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
205 knobColor: HiliteGradient(Color.grey, Color.white));
206 g.window.bounds = g.window.bounds.moveBy(-180, -90);
207 g.window.name="Freq";
208 g.font_(Font("Helvetica",10));
215 g=EZRanger(nil, 300@42," freq ", \freq,initVal:[100.rand,200+2000.rand],
216 unitWidth:30, numberWidth:60,layout:\line2, margin:2@2);
217 g.setColors(Color.grey,Color.white, Color.grey(0.7),
218 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
219 knobColor: HiliteGradient(Color.grey, Color.white));
220 g.window.bounds = g.window.bounds.moveBy(-180,-160);
223 ( // no unitView, with label
224 g=EZRanger(nil, 300@42," freq ", \freq,initVal:[100.rand,200+2000.rand],
225 unitWidth:0, numberWidth:60,layout:\line2, margin:2@2);
226 g.setColors(Color.grey,Color.white, Color.grey(0.7),
227 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
228 knobColor: HiliteGradient(Color.grey, Color.white));
229 g.window.bounds = g.window.bounds.moveBy(-180,-260);
233 g=EZRanger(nil, 300@42,nil, \freq, initVal:[100.rand,200+2000.rand],
234 unitWidth:30, numberWidth:60,layout:\line2, margin:2@2);
235 g.setColors(Color.grey,Color.white, Color.grey(0.7),
236 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
237 knobColor: HiliteGradient(Color.grey, Color.white));
238 g.window.bounds = g.window.bounds.moveBy(-180,-360);
239 g.window.name="Freq";
242 ( // no label, so use window name as label
243 g=EZRanger(nil, 150@42,nil, \freq,initVal:[100.rand,200+2000.rand],
244 unitWidth:0, numberWidth:60,layout:\line2, margin:2@2);
245 g.setColors(Color.grey,Color.white, Color.grey(0.7),
246 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
247 knobColor: HiliteGradient(Color.grey, Color.white));
248 g.window.bounds = g.window.bounds.moveBy(-180,-460);
249 g.window.name="Freq";
255 ( // all features, small font
256 g=EZRanger(nil, 45@300," Vol ", \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
257 unitWidth:30, numberWidth:60,layout:\vert, margin:2@2);
258 g.setColors(Color.grey,Color.white, Color.grey(0.7),
259 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
260 knobColor: HiliteGradient(Color.grey, Color.white,\h));
261 g.window.bounds = g.window.bounds.moveBy(250,50);
262 g.font_(Font("Helvetica",9));
264 ( // no label, small font
265 g=EZRanger(nil, 45@300, nil, \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
266 unitWidth:30, numberWidth:60,layout:\vert, margin:2@2);
267 g.setColors(Color.grey,Color.white, Color.grey(0.7),
268 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
269 knobColor: HiliteGradient(Color.grey, Color.white,\h));
270 g.window.bounds = g.window.bounds.moveBy(310,50);
271 g.font_(Font("Helvetica",9));
273 ( // no Units small font
274 g=EZRanger(nil, 45@300, " Vol", \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
275 unitWidth:0, numberWidth:60,layout:\vert, margin:2@2);
276 g.setColors(Color.grey,Color.white, Color.grey(0.7),
277 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
278 knobColor: HiliteGradient(Color.grey, Color.white,\h));
279 g.window.bounds = g.window.bounds.moveBy(370,50);
280 g.font_(Font("Helvetica",9));
282 ( // no unitView, no units small font
283 g=EZRanger(nil, 45@300, nil, \db.asSpec.step_(0.01),initVal:[-3-15.rand,-2.rand],
284 unitWidth:0, numberWidth:60,layout:\vert, margin:2@2);
285 g.setColors(Color.grey,Color.white, Color.grey(0.7),
286 Color.grey, Color.white, Color.yellow, background:Color.grey(0.7),
287 knobColor: HiliteGradient(Color.grey, Color.white,\h));
288 g.window.bounds = g.window.bounds.moveBy(430,50);
289 g.font_(Font("Helvetica",9));
299 ( // example to explore a synthesis idea:
300 p = ProxySpace.push(s.boot);
303 q.freqRange = [200, 2000];
304 q.ampRange = [0.1, 1];
305 q.ringRange = [0.1, 10];
306 q.numRange = [3, 30];
308 q.soundfunc = { |dens=5|
310 Array.fill(exprand(q.numRange[0], q.numRange[1]).asInteger, {
313 exprand(q.freqRange[0], q.freqRange[1]),
314 exprand(q.ringRange[0], q.ringRange[1]),
315 exprand(q.ampRange[0], q.ampRange[1])
324 ~plong = q[\soundfunc];
327 w = Window("cow herd").front;
328 w.view.decorator_(FlowLayout(w.bounds.copy.moveTo(0, 0)));
330 Spec.add(\ring, [0.03, 30, \exp]);
331 Spec.add(\num, [3, 30, \exp, 1]);
333 EZRanger(w, 390@20, "numRange", \num, { |sl| q.numRange = sl.value; }, labelWidth: 65)
336 EZRanger(w, 390@20, "freqRange", \freq, { |sl| q.freqRange = sl.value; }, q.freqRange, labelWidth: 65)
338 EZRanger(w, 390@20, "ringRange", \ring, { |sl| q.ringRange = sl.value; }, q.ringRange, labelWidth: 65)
340 EZRanger(w, 390@20, "ampRange", \amp, { |sl| q.ampRange = sl.value; }, q.ampRange, labelWidth: 65)
342 Button(w, 190@20).states_([[\newSound]]).action_({~plong = q[\soundfunc] });