form caption("VU Meter") size(400, 300), colour(20, 20, 20), pluginID("def1")
button bounds(16, 8, 24, 15), colour:0("white"), colour:1("red"), text("", ""), channel("leftChannel")
gentable bounds(16, 24, 54, 202), tablenumber(1), amprange(0, 1, 1), zoom(-1), tablegridcolour(0,0,0,0) tablecolour("yellow", "green", "black"), identchannel("vuMeter")
button bounds(47, 8, 24, 15), colour:0("white"), colour:1("red"), text("", ""), channel("rightChannel")
image bounds(38, 16, 9, 214), colour(20, 20, 20)
rslider bounds(80, 128, 95, 91), channel("leftAmp"), range(0, 1.5, 0), text("Left")
rslider bounds(176, 128, 93, 90), channel("rightAmp"), range(0, 1.5, 0), text("Right")
-n -d -+rtmidi=NULL
; Initialize the global variables.
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
a1 rand 1
a2 rand 1
;get RMS values for left and right channels
;and attenuate using sliders
kLeft rms a1, 30
kLeft = (60-abs(dbamp(kLeft)))/60
kRight rms a2, 30
kRight = (60-abs(dbamp(kRight)))/60
kLeft = kLeft*chnget:k("leftAmp")
kRight = kRight*chnget:k("rightAmp")
;if RMS goes above .99 trigger the clipping indicator
if kLeft>.99 then
chnset k(1), "leftChannel"
printk 0.5, 99
endif
if kRight>1 then
chnset k(1), "rightChannel"
endif
;update our table 10 times a second with the
;current RMS for left and right channel
if metro(10) == 1 then
tablew kLeft, k(0), 1
tablew kRight*chnget:k("rightAmp"), k(1), 1
chnset "tablenumber(1)", "vuMeter"
endif
endin
;using a GEN02 with a size of 2 for a stereo vu meter table
f1 0 2 2 -80 0
i1 0 10000