1 SCLevelIndicator : SCView {
3 *paletteExample { arg parent, bounds;
4 ^this.new(parent, bounds).value_(0.7);
8 ^this.getProperty(\value)
11 this.setProperty(\value, val);
13 valueAction_ { arg val;
14 this.setPropertyWithAction(\value, val);
18 this.setProperty(\warning, val);
22 this.setProperty(\critical, val);
26 this.setProperty(\style, val);
30 this.setProperty(\numSteps, val);
34 this.setProperty(\image, image);
38 this.setProperty(\numTicks, ticks);
41 numMajorTicks_ {arg ticks;
42 this.setProperty(\numMajorTicks, ticks);
46 this.setProperty(\drawsPeak, bool);
50 this.setProperty(\peakLevel, val);
55 //EZLevelIndicator : EZGui {
57 // var <levelView, <numberView, <unitView, <>controlSpec,
58 // popUp=false, numSize,numberWidth,unitWidth, gap;
59 // var <>round = 0.001;
61 // *new { arg parent, bounds, label, controlSpec, action, initVal,
62 // initAction=false, labelWidth=60, numberWidth=45,
63 // unitWidth=0, labelHeight=20, layout=\horz, gap, margin;
65 // ^super.new.init(parent, bounds, label, controlSpec, action,
66 // initVal, initAction, labelWidth, numberWidth,
67 // unitWidth, labelHeight, layout, gap, margin)
70 // init { arg parentView, bounds, label, argControlSpec, argAction, initVal,
71 // initAction, labelWidth, argNumberWidth,argUnitWidth,
72 // labelHeight, argLayout, argGap, argMargin;
74 // var labelBounds, numBounds, unitBounds,levelBounds;
76 // // Set Margin and Gap
77 // this.prMakeMarginGap(parentView, argMargin, argGap);
79 // unitWidth = argUnitWidth;
80 // numberWidth = argNumberWidth;
82 // bounds.isNil.if{bounds = 350@20};
85 // // if no parent, then pop up window
86 // # view,bounds = this.prMakeView( parentView,bounds);
89 // labelSize=labelWidth@labelHeight;
90 // numSize = numberWidth@labelHeight;
92 // // calculate bounds of all subviews
93 // # labelBounds,numBounds,levelBounds, unitBounds
94 // = this.prSubViewBounds(innerBounds, label.notNil, unitWidth>0);
96 // // instert the views
97 // label.notNil.if{ //only add a label if desired
98 // labelView = GUI.staticText.new(view, labelBounds);
99 // labelView.string = label;
102 // (unitWidth>0).if{ //only add a unitLabel if desired
103 // unitView = GUI.staticText.new(view, unitBounds);
106 // numberView = GUI.numberBox.new(view, numBounds);
107 // levelView = SCLevelIndicator.new(view, levelBounds);
109 // // set view parameters and actions
111 // controlSpec = argControlSpec.asSpec;
112 // (unitWidth>0).if{unitView.string = " "++controlSpec.units.asString};
113 // initVal = initVal ? controlSpec.default;
114 // action = argAction;
116 // levelView.action = {
117 // this.valueAction_(controlSpec.map(levelView.value));
120 // if (controlSpec.step == 0) {
121 // levelView.step = (controlSpec.step / (controlSpec.maxval - controlSpec.minval));
124 // levelView.receiveDragHandler = { arg level;
125 // level.valueAction = controlSpec.unmap(GUI.view.currentDrag);
128 // levelView.beginDragAction = { arg level;
129 // controlSpec.map(level.value)
132 // numberView.action = { this.valueAction_(numberView.value) };
135 // this.valueAction_(initVal);
137 // this.value_(initVal);
139 // this.prSetViewParams;
144 // value = controlSpec.constrain(val);
145 // numberView.value = value.round(round);
146 // levelView.value = controlSpec.unmap(value);
149 // valueAction_ { arg val;
154 // doAction { action.value(this) }
156 // set { arg label, spec, argAction, initVal, initAction = false;
157 // labelView.notNil.if{labelView.string=label};
158 // controlSpec = spec.asSpec;
159 // action = argAction;
160 // initVal = initVal ? controlSpec.default;
162 // this.value = initVal;
165 // levelView.value = controlSpec.unmap(value);
166 // numberView.value = value.round(round);
171 // setColors{arg stringBackground,stringColor,levelBackground,numBackground,
172 // numStringColor,numNormalColor,numTypingColor,knobColor,background;
174 // stringBackground.notNil.if{
175 // labelView.notNil.if{labelView.background_(stringBackground)};
176 // unitView.notNil.if{unitView.background_(stringBackground)};};
177 // stringColor.notNil.if{
178 // labelView.notNil.if{labelView.stringColor_(stringColor)};
179 // unitView.notNil.if{unitView.stringColor_(stringColor)};};
180 // numBackground.notNil.if{
181 // numberView.background_(numBackground);};
182 // numNormalColor.notNil.if{
183 // numberView.normalColor_(numNormalColor);};
184 // numTypingColor.notNil.if{
185 // numberView.typingColor_(numTypingColor);};
186 // numStringColor.notNil.if{
187 // numberView.stringColor_(numStringColor);};
188 // levelBackground.notNil.if{
189 // levelView.background_(levelBackground);};
190 // knobColor.notNil.if{
191 // levelView.knobColor_(knobColor);};
192 // background.notNil.if{
193 // view.background=background;};
194 // numberView.refresh;
199 // labelView.notNil.if{labelView.font=font};
200 // unitView.notNil.if{unitView.font=font};
201 // numberView.font=font;
204 // ///////Private methods ///////
206 // prSetViewParams{ // sets resize and alignment for different layouts
210 // labelView.notNil.if{
211 // labelView.resize_(2);
212 // unitView.notNil.if{unitView.resize_(3)};
213 // numberView.resize_(3);
215 // unitView.notNil.if{
216 // unitView.resize_(2);
217 // numberView.resize_(1);
219 // numberView.resize_(2);
222 // levelView.resize_(5);
223 // popUp.if{view.resize_(2)};
226 // labelView.notNil.if{labelView.resize_(2)};
227 // unitView.notNil.if{unitView.resize_(8)};
228 // numberView.resize_(8);
229 // levelView.resize_(5);
230 // popUp.if{view.resize_(4)};
233 // labelView.notNil.if{labelView.resize_(4).align_(\right)};
234 // unitView.notNil.if{unitView.resize_(6)};
235 // numberView.resize_(6);
236 // levelView.resize_(5);
237 // popUp.if{view.resize_(2)};
242 // prSubViewBounds{arg rect, hasLabel, hasUnit; // calculate subview bounds
243 // var numBounds,labelBounds,levelBounds, unitBounds;
244 // var gap1, gap2, gap3, tmp, labelH, unitH;
248 // labelH=labelSize.y;// needed for \vert
249 // unitH=labelSize.y; // needed for \vert
250 // hasUnit.not.if{ gap3 = 0@0; unitWidth = 0};
255 // hasLabel.if{ // with label
256 // unitBounds = (unitWidth@labelSize.y)
257 // .asRect.left_(rect.width-unitWidth);// view to right
258 // numBounds = (numSize.x@labelSize.y)
259 // .asRect.left_(rect.width-unitBounds.width-numberWidth-gap3.x); // view to right
260 // labelBounds = (labelSize.x@labelSize.y)
261 // .asRect.width_(numBounds.left-gap2.x); //adjust width
263 // labelBounds = (0@labelSize.y).asRect; //just a dummy
264 // numBounds = (numberWidth@labelSize.y).asRect; //view to left
266 // unitBounds = Rect (numBounds.width+gap3.x, 0,
267 // rect.width-numBounds.width-gap3.x,labelSize.y); //adjust to fit
269 // unitBounds = Rect (0, 0,0,0); //no unitView
270 // numBounds = (rect.width@labelSize.y).asRect; //view to left
274 // levelBounds = Rect( //adjust to fit
276 // labelSize.y+gap1.y,
278 // rect.height-numSize.y-gap1.y;
283 // hasLabel.not.if{ gap1 = 0@0; labelSize.x = 0 ;};
284 // hasLabel.not.if{labelH=0};
285 // labelBounds = (rect.width@labelH).asRect; // to top
286 // hasUnit.not.if{unitH=0};
287 // unitBounds = (rect.width@unitH)
288 // .asRect.top_(rect.height-labelSize.y); // to bottom
289 // numBounds = (rect.width@labelSize.y)
290 // .asRect.top_(rect.height-unitBounds.height-numSize.y-gap3.y); // to bottom
292 // levelBounds = Rect( //adjust to fit
294 // labelBounds.height+gap1.y,
296 // rect.height - labelBounds.height - unitBounds.height
297 // - numBounds.height - gap1.y - gap2.y - gap3.y
302 // hasLabel.not.if{ gap1 = 0@0; labelSize.x = 0 ;};
303 // labelSize.y = rect.height;
304 // labelBounds = (labelSize.x@labelSize.y).asRect; //to left
305 // unitBounds = (unitWidth@labelSize.y).asRect.left_(rect.width-unitWidth); // to right
306 // numBounds = (numSize.x@labelSize.y).asRect
307 // .left_(rect.width-unitBounds.width-numSize.x-gap3.x);// to right
308 // levelBounds = Rect( // adjust to fit
309 // labelBounds.width+gap1.x,
311 // rect.width - labelBounds.width - unitBounds.width
312 // - numBounds.width - gap1.x - gap2.x - gap3.x,
313 // labelBounds.height
318 // ^[labelBounds, numBounds, levelBounds, unitBounds].collect{arg v; v.moveBy(margin.x,margin.y)}
325 // var window, view, meters, resp, synth, func;
327 // window = Window.new(this.name ++ " Output Levels");
328 // view = VLayoutView(window, Rect(10,10,380,300) );
329 // meters = Array.fill( options.numOutputBusChannels, { arg i;
330 // SCLevelIndicator( view, Rect(0,0,75,20) ).warning_(0.9).critical_(1.0);
333 // resp = OSCresponder(this.addr, "/" ++ this.name ++ "OutputLevels", { |t, r, msg| {msg.copyToEnd(3).do({|val, i| meters[i].value = val.ampdb.linlin(-40, 0, 0, 1);}) }.defer;
336 // synth = SynthDef(this.name ++ "OutputLevels", {
339 // "/" ++ this.name ++ "OutputLevels",
340 // Amplitude.kr(In.ar(0, options.numOutputBusChannels), 0.2, 0.2);
342 // }).play(RootNode(this), nil, \addToTail);
345 // window.onClose_({synth.free; resp.remove; ServerTree.remove(func)});
347 // ServerTree.add(func);
352 // var window, view, meters, resp, synth, func;
354 // window = Window.new(this.name ++ " Input Levels");
355 // view = VLayoutView(window, Rect(10,10,380,300) );
356 // meters = Array.fill( options.numInputBusChannels, { arg i;
357 // SCLevelIndicator( view, Rect(0,0,75,20) ).warning_(0.9).critical_(1.0);
360 // resp = OSCresponder(this.addr, "/" ++ this.name ++ "InputLevels", { |t, r, msg| {msg.copyToEnd(3).do({|val, i| meters[i].value = val.ampdb.linlin(-40, 0, 0, 1);}) }.defer;
363 // synth = SynthDef(this.name ++ "InputLevels", {
366 // "/" ++ this.name ++ "InputLevels",
367 // Amplitude.kr(In.ar(NumOutputBuses.ir, options.numInputBusChannels), 0.2, 0.2);
369 // }).play(RootNode(this), nil, \addToHead);
372 // window.onClose_({synth.free; resp.remove; ServerTree.remove(func)});
374 // ServerTree.add(func);