deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / GUI / osx / scide_scapp / SCLevelIndicator.sc
bloba64ff46346394ac9ecb26e1ed09a92d654e00777
1 SCLevelIndicator : SCView {
3         *paletteExample { arg parent, bounds;
4                 ^this.new(parent, bounds).value_(0.7);
5         }
7         value {
8                 ^this.getProperty(\value)
9         }
10         value_ { arg val;
11                 this.setProperty(\value, val);
12         }
13         valueAction_ { arg val;
14                 this.setPropertyWithAction(\value, val);
15         }
17         warning_ {arg val;
18                 this.setProperty(\warning, val);
19         }
21         critical_ {arg val;
22                 this.setProperty(\critical, val);
23         }
25         style_ {arg val;
26                 this.setProperty(\style, val);
27         }
29         numSteps_ {arg val;
30                 this.setProperty(\numSteps, val);
31         }
33         image_ {arg image;
34                 this.setProperty(\image, image);
35         }
37         numTicks_ {arg ticks;
38                 this.setProperty(\numTicks, ticks);
39         }
41         numMajorTicks_ {arg ticks;
42                 this.setProperty(\numMajorTicks, ticks);
43         }
45         drawsPeak_ {arg bool;
46                 this.setProperty(\drawsPeak, bool);
47         }
49         peakLevel_ { arg val;
50                 this.setProperty(\peakLevel, val);
51         }
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)
68 //      }
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;
81 //              layout=argLayout;
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;
100 //              };
102 //              (unitWidth>0).if{ //only add a unitLabel if desired
103 //                      unitView = GUI.staticText.new(view, unitBounds);
104 //              };
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));
118 //              };
120 //              if (controlSpec.step == 0) {
121 //                      levelView.step = (controlSpec.step / (controlSpec.maxval - controlSpec.minval));
122 //              };
124 //              levelView.receiveDragHandler = { arg level;
125 //                      level.valueAction = controlSpec.unmap(GUI.view.currentDrag);
126 //              };
128 //              levelView.beginDragAction = { arg level;
129 //                      controlSpec.map(level.value)
130 //              };
132 //              numberView.action = { this.valueAction_(numberView.value) };
134 //              if (initAction) {
135 //                      this.valueAction_(initVal);
136 //              }{
137 //                      this.value_(initVal);
138 //              };
139 //              this.prSetViewParams;
141 //      }
143 //      value_ { arg val;
144 //              value = controlSpec.constrain(val);
145 //              numberView.value = value.round(round);
146 //              levelView.value = controlSpec.unmap(value);
147 //      }
149 //      valueAction_ { arg val;
150 //              this.value_(val);
151 //              this.doAction;
152 //      }
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;
161 //              if (initAction) {
162 //                      this.value = initVal;
163 //              }{
164 //                      value = initVal;
165 //                      levelView.value = controlSpec.unmap(value);
166 //                      numberView.value = value.round(round);
167 //              };
168 //      }
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;
195 //      }
197 //      font_{ arg font;
199 //                      labelView.notNil.if{labelView.font=font};
200 //                      unitView.notNil.if{unitView.font=font};
201 //                      numberView.font=font;
202 //      }
204 //      ///////Private methods ///////
206 //      prSetViewParams{ // sets resize and alignment for different layouts
208 //              switch (layout,
209 //              \line2, {
210 //                      labelView.notNil.if{
211 //                              labelView.resize_(2);
212 //                              unitView.notNil.if{unitView.resize_(3)};
213 //                              numberView.resize_(3);
214 //                              }{
215 //                              unitView.notNil.if{
216 //                                      unitView.resize_(2);
217 //                                      numberView.resize_(1);
218 //                                      }{
219 //                                      numberView.resize_(2);
220 //                                      };
221 //                              };
222 //                      levelView.resize_(5);
223 //                      popUp.if{view.resize_(2)};
224 //              },
225 //              \vert, {
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)};
231 //              },
232 //              \horz, {
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)};
238 //              });
240 //      }
242 //      prSubViewBounds{arg rect, hasLabel, hasUnit;  // calculate subview bounds
243 //              var numBounds,labelBounds,levelBounds, unitBounds;
244 //              var gap1, gap2, gap3, tmp, labelH, unitH;
245 //              gap1 = gap.copy;
246 //              gap2 = gap.copy;
247 //              gap3 = gap.copy;
248 //              labelH=labelSize.y;//  needed for \vert
249 //              unitH=labelSize.y; //  needed for \vert
250 //              hasUnit.not.if{ gap3 = 0@0; unitWidth = 0};
252 //              switch (layout,
253 //                      \line2, {
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
262 //                              }{ // no label
263 //                              labelBounds = (0@labelSize.y).asRect; //just a dummy
264 //                              numBounds = (numberWidth@labelSize.y).asRect; //view to left
265 //                              (unitWidth>0).if{
266 //                                      unitBounds = Rect (numBounds.width+gap3.x, 0,
267 //                                              rect.width-numBounds.width-gap3.x,labelSize.y); //adjust to fit
268 //                                              }{
269 //                                      unitBounds = Rect (0, 0,0,0); //no unitView
270 //                                              numBounds = (rect.width@labelSize.y).asRect; //view to left
271 //                                              };
273 //                              };
274 //                              levelBounds = Rect( //adjust to fit
275 //                                              0,
276 //                                              labelSize.y+gap1.y,
277 //                                              rect.width,
278 //                                              rect.height-numSize.y-gap1.y;
279 //                                              );
280 //                              },
282 //                       \vert, {
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
293 //                                      0,
294 //                                      labelBounds.height+gap1.y,
295 //                                      rect.width,
296 //                                      rect.height - labelBounds.height - unitBounds.height
297 //                                                      - numBounds.height - gap1.y - gap2.y - gap3.y
298 //                                      );
299 //                              },
301 //                       \horz, {
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,
310 //                                      0,
311 //                                      rect.width - labelBounds.width - unitBounds.width
312 //                                                      - numBounds.width - gap1.x - gap2.x - gap3.x,
313 //                                      labelBounds.height
314 //                                      );
315 //              });
318 //              ^[labelBounds, numBounds, levelBounds, unitBounds].collect{arg v; v.moveBy(margin.x,margin.y)}
319 //      }
323 //+ Server {
324 //      meterOutput {
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);
331 //              });
332 //              window.front;
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;
334 //              }).add;
335 //              func = {
336 //                      synth = SynthDef(this.name ++ "OutputLevels", {
337 //                              SendReply.kr(
338 //                                      Impulse.kr(20),
339 //                                      "/" ++ this.name ++ "OutputLevels",
340 //                                      Amplitude.kr(In.ar(0, options.numOutputBusChannels), 0.2, 0.2);
341 //                              );
342 //                      }).play(RootNode(this), nil, \addToTail);
343 //              };
345 //              window.onClose_({synth.free; resp.remove; ServerTree.remove(func)});
347 //              ServerTree.add(func);
348 //              func.value;
349 //      }
351 //      meterInput {
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);
358 //              });
359 //              window.front;
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;
361 //              }).add;
362 //              func = {
363 //                      synth = SynthDef(this.name ++ "InputLevels", {
364 //                              SendReply.kr(
365 //                                      Impulse.kr(20),
366 //                                      "/" ++ this.name ++ "InputLevels",
367 //                                      Amplitude.kr(In.ar(NumOutputBuses.ir, options.numInputBusChannels), 0.2, 0.2);
368 //                              );
369 //                      }).play(RootNode(this), nil, \addToHead);
370 //              };
372 //              window.onClose_({synth.free; resp.remove; ServerTree.remove(func)});
374 //              ServerTree.add(func);
375 //              func.value;
376 //      }