3 summary:: a level indicator GUI widget
5 related:: Classes/RangeSlider
8 A level indicator view, suitable for use as a level or peak meter, etc.
18 Get or set the current level of the view.
21 A link::Classes/Float:: between 0 and 1.
23 returns:: A link::Classes/Float::
26 Set the warning threshold. Styles 0 and 2 (see link::#-style::) implement a warning display. If link::#-critical:: is > warning the view will turn yellow if link::#-value:: is > code::val::. If critical is <= warning the view will turn yellow if value is <= to code::val::. If link::#-drawsPeak:: is true warning will be displayed based on link::#-peakLevel:: rather than value.
29 A link::Classes/Float::.
33 a = LevelIndicator(w, Rect(10, 10, 20, 160));
36 a.warning = 0.6; a.critical = 0.9;
41 Set the warning threshold. Styles 0 and 2 (see link::#-style::) implement a critical display. If critical is > link::#-warning:: the view will turn red if link::#-value:: is > code::val::. If critical is <= warning the view will turn yellow if value is <= to code::val::. If link::#-drawsPeak:: is true critical will be displayed based on link::#-peakLevel:: rather than value.
44 A link::Classes/Float::.
48 a = LevelIndicator(w, Rect(10, 10, 20, 160));
53 a.warning = 0.6; a.critical = 0.9;
58 note:: Not yet implemented in Qt GUI ::
59 Sets the style of the view.
62 An link::Classes/Integer:: from 0 to 3. 0 = colored bar; 1 = graduated black lines; 2 = LED style (see link::#-numSteps::); 3 = LED style with custom image. (See link::#-image::.)
68 a = LevelIndicator(w, Rect(0, 0, 20, 200));
77 The number of steps used in styles 2 and 3. (See link::#-style::.)
80 An positive link::Classes/Integer::.
84 a = LevelIndicator(w, Rect(10, 10, 200, 20));
93 note:: Not yet implemented in Qt GUI ::
94 Sets the image used in style 3. See below for an example.
97 An link::Classes/Image::. The default image is the SC cube.
100 The number of ticks to display in the view's scale.
103 An link::Classes/Integer:: >= 0.
106 w = Window.new.front;
107 w.view.background = Color.black;
108 a = LevelIndicator(w, Rect(10, 10, 300, 30));
114 METHOD:: numMajorTicks
115 The number of ticks in the view's scale which will be large sized.
118 An link::Classes/Integer:: >= 0.
121 w = Window.new.front;
122 w.view.background = Color.black;
123 a = LevelIndicator(w, Rect(10, 10, 300, 30));
131 Determines whether the view draws a separate peak display. This can be useful for displaying both peak and RMS values. If drawsPeak is true link::#-warning:: and link::#-critical:: will be displayed based on link::#-peakLevel:: rather than value in link::#-style#styles:: 0 and 2.
134 A link::Classes/Boolean::. By default the peak is not drawn.
137 w = Window.new.front;
138 a = LevelIndicator(w, Rect(10, 10, 300, 30));
147 Sets the level of the peak display. (See link::#-drawsPeak::.)
150 A link::Classes/Float::.
153 w = Window.new.front;
154 a = LevelIndicator(w, Rect(10, 10, 20, 160));
166 GUI.cocoa; // just to be sure
168 // something to meter
170 b = Buffer.read(s, "sounds/a11wlk01.wav");
171 x = { var colum, noise, imp, delimp, mul = 1;
172 imp = Impulse.kr(10);
173 delimp = Delay1.kr(imp);
174 colum = PlayBuf.ar(1, b, BufRateScale.kr(b), loop: 1) * mul;
175 // measure rms and Peak
176 SendReply.kr(imp, '/levels', [Amplitude.kr(colum), K2A.ar(Peak.ar(colum, delimp).lag(0, 3))]);
181 // a window and responder
182 // default style is coloured / solid
184 w = Window.new.front;
185 a = LevelIndicator(w, Rect(10, 10, 20, 160));
186 o = OSCFunc({arg msg;
188 a.value = msg[3].ampdb.linlin(-40, 0, 0, 1);
189 a.peakLevel = msg[4].ampdb.linlin(-40, 0, 0, 1);
191 }, '/levels', s.addr);
192 w.onClose = {o.free; x.free};
195 // styles 0 and 2 support warning and critical levels
197 a.warning = -6.dbamp;
198 a.critical = -3.dbamp;
201 // optionally show peak level
208 // style 1 is black bars
211 // looks good with a background
212 a.background = Gradient(Color.red, Color.green, \v);
214 // all styles can have ticks
216 a.background = Color.clear;
217 a.numTicks = 11; // includes 0;
229 // style 3 is as 2, but with images
230 a.style = 3; // use default image
232 // make a custom image
234 j = Image.new(20,20);
237 lozenge = Rect(3, 3, 16, 16);
238 Pen.addOval(lozenge);
239 Pen.fillAxialGradient(1@1, 19@19, Color.new255(255, 165, 0), Color.new255(238, 232, 170));
241 Pen.strokeColor = Color.blue;
242 Pen.strokeOval(lozenge);
248 j = Image.openURL("http://bit.ly/uSMWwp");
251 a.bounds = Rect(10, 10, 380, 80);