VuView a gui view with a gauge


*new(parent, bounds);

bounds: a Rect(

distance from left,

distance from bottom,

width,

height

)

value: a number. Get or set the control's value.

needleColor: a Color. Get or set the control's needle color.


(

var txt, needleColors;

needleColors = [Color.black(0.8, 0.8), Color.red(1.0, 0.8)];

w = SCWindow("Meter", Rect(300,400,300,120));

w.view.decorator = FlowLayout(w.view.bounds);

w.front;

m = VuView(w, 120@80);

Knob(w, 32@32)

.action = {|v|

var mappedValue;

mappedValue = [0,1.2].asSpec.map(v.value);

m.needleColor = needleColors.at( (mappedValue > 1.0).binaryValue );

m.value = mappedValue;

txt.string = format("val: % dB", m.value.ampdb.round(0.01));

};

txt = SCStaticText(w, 200@14);

)


s.boot;

(

o = OSCresponderNode(s.addr,'/tr',{ arg time,responder,msg;

if (msg[1] == z.nodeID, {

{ m.value = \amp.asSpec.unmap(msg[3]) }.defer;

});

}).add;

)


(

SynthDef(\meter, {arg bus = 0, rate = 15, rel = 1;

var signal, amplitude;

signal = In.ar(bus,1);

amplitude = Amplitude.kr(signal, 0.01, rel);

SendTrig.kr(Impulse.kr(rate), 1200, amplitude);

}).send(s);

)


// start the meter synth

z = Synth.tail(1, "meter");

z.set(\rate, 15)

z.set(\rel, 0.1)

z.set(\rel, 2)



// a click synth

(

a = { arg amp=0.1;

Decay2.ar(Impulse.ar(1.0), 0.1, 0.4, SinOsc.ar(1200,0,amp))

}.play.play(addAction: \addToHead)

)

a.set(\amp, 0.5)

a.free


// read audio inputs

(

a = { arg amp=0.1;

AudioIn.ar([1,2]) * amp

}.play(addAction: \addToHead)

)

a.set(\amp, 1.0)

a.free



z.free; // free meter synth

o.remove; // remove responder


//

(

var txt;

w = SCWindow("Meter", Rect(300,400,300,120));

w.view.decorator = FlowLayout(w.view.bounds);

w.front;

m = VuView(w, 120@80);

k = Knob(w, 32@32)

       .action = {|v|

               m.value = \amp.asSpec.map(v.value);

               txt.string = format("val: % dB", m.value.ampdb.round(0.01));

       };

txt = SCStaticText(w, 200@14);

)


// needle color changes, evaluate a few times

(

var signal, needleColor;

signal = rrand(0.3, 1.6); // possibly distorted signal

if(signal> 1.0, {

       needleColor=Color.red(1.0, 0.8);

       format("Signal value distorted: %", signal).postln;

}, {

       needleColor=Color.black(0.8, 0.8);

});

m.needleColor_(needleColor); // doesn't update until VuView value changes

k.valueAction_(signal);

signal

)