My old script "Peak meter" for WSH. Maybe useful for someone.
// ==PREPROCESSOR==
// @name "Peak meter"
// @author "kgena_ua"
// @version "06082017"
// ==/PREPROCESSOR==
function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
var font = gdi.Font("Arial",9,1);
var font2 = gdi.Font("Arial",11,0);
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
var ww = window.Width, wh = window.Height;
var on_mouse = false;
var color = [];
var combinedColor1 = [];
var combinedColor2 = [];
var separator;
var offset, w, offset_l, w_l;
var pos_x = 0, pos_y = 0;;
var VUMOffset_t, t_height, t_width;
var wheel = false;
var tooltip_timer;
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
}
function get_color(){
bgcolor = window.GetColorCUI(ColorTypeCUI.background);
c1 = window.GetColorCUI(ColorTypeCUI.text);
c2 = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
c3 = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
color1 = [ c3, c1 ];
color2 = [ c2, c3 ];
window.Repaint();
}
get_color();
function on_colors_changed(){
get_color();
}
var dll;
var is_dll = utils.CheckComponent("\\user-components\\foo_vis_vumeter\\foo_vis_vumeter");
if (is_dll) {dll = false} else {dll = true};
if (dll) {VUMeter = new ActiveXObject("VUMeter")};
if (dll) {VUMeter.RegisterWindow(window.ID)}; // do not use for transparent mode
function ToDB(Level){
return Math.round(2000*Math.log(Level)/Math.LN10)/100;
}
var db = [-25,-22.5,-20,-17.5,-15,-12.5,-10,-7.5,-5,-4.5,-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,3.5,4];
var db_l = [-92.5,-90,-87.5,-85,-82.5,-80,-77.5,-75,-72.5,-70,-67.5,-65,-62.5,-60,-57.5,-55,-52.5,-50,-47.5,-45,-42.5,-40,-37.5,-35,-32.5,-30,-27.5];
for (var i = 0; i <= db.length; i++) {
if (db[i] == 0) {separator = i};
}
var points = db.length;
var s1 = separator;
var s2 = points - s1;
var points_l = db_l.length;
for(var j = 0; j < s1; j++) {
combinedColor1.push(combineColors(color1[0], color1[1], j / s1));
}
for(var j = 0; j < s2; j++) {
combinedColor2.push(combineColors(color2[0], color2[1], j / s2));
}
color = combinedColor1.concat(combinedColor2);
var col = 0;
var ytext = 5;
var h = 2;
var hM = 5;
var yL = ytext + 15;
var yLM = yL + h + 4;
var hM_l = 1;
var yLM_l = yLM + hM + 4;
var yRM_l = yLM_l + hM_l + 1;
var yRM = yRM_l + hM_l + 4;
var yR = yRM + hM + 4;
var wL = 0, wR = 0;
var xLanim = 0, xRanim = 0;
var xL = 0, xR = 0;
var xLManim = 0, xRManim = 0;
var xLM = 0, xRM = 0;
var kLM = 0, kRM = 0;
var kLM2 = 0, kRM2 = 0;
var xLManim2 = 0, xRManim2 = 0;
var kL = 0, kR = 0;
var wLanim = 0, wRanim = 0;
var oldwL = 0, oldwR = 0;
function on_paint(gr) {
gr.FillSolidRect(0, 0, ww, wh, bgcolor);
if (panel_on && dll) {
L = VUMeter.LeftLevel;
R = VUMeter.RightLevel;
LM = VUMeter.LeftPeak;
RM = VUMeter.RightPeak;
}
if (panel_on && fb.IsPlaying && dll) {
for (var i = 0; i <= points_l; i++) {
if (ToDB(LM) > db_l[i]) gr.FillSolidRect(col + i * offset_l, yLM_l, w_l, hM_l, color[0]);
if (ToDB(RM) > db_l[i]) gr.FillSolidRect(col + i * offset_l, yRM_l, w_l, hM_l, color[0]);
}
for (var i = 0; i <= points; i++) {
if ((ToDB(L) > db[i] && ToDB(L) < db[i+1])) {wL = i * offset + offset / Math.abs(db[i + 1]-db[i]) * Math.abs(ToDB(L) - db[i]) }
if (ToDB(L) > db[i]) gr.FillSolidRect(col, yL, wL, h, color[1]);
if ((ToDB(R) > db[i] && ToDB(R) < db[i+1])) {wR = i * offset + offset / Math.abs(db[i + 1]-db[i]) * Math.abs(ToDB(R) - db[i]) }
if (ToDB(R) > db[i]) gr.FillSolidRect(col, yR, wR, h, color[1]);
if (xLanim <= wL) {xLanim = wL; kL = 0; wLanim = wL - oldwL < 1 ? wLanim : wL - oldwL + 10} else {oldwL = wL};
if (ToDB(L) > db[i]) gr.FillSolidRect(col + xLanim + 2, yL, wLanim <= 0 ? 2 : wLanim, h, color[1]);
if (xRanim <= wR) {xRanim = wR; kR = 0; wRanim = wR - oldwR < 1 ? wRanim : wR - oldwR + 10} else {oldwR = wR};
if (ToDB(R) > db[i]) gr.FillSolidRect(col + xRanim + 2, yR, wRanim <= 0 ? 2 : wRanim, h, color[1]);
var overL = col + xLanim + 2 + wLanim - ww - 10;
if (overL > 0) gr.FillSolidRect(ww - overL, yL - h - 1, ww - 10, h, color[10]);
var overR = col + xRanim + 2 + wRanim - ww - 10;
if (overR > 0) gr.FillSolidRect(ww - overR, yR + h + 1, ww - 10, h, color[10]);
if (ToDB(LM) > db[i]) gr.FillSolidRect(col + i * offset, yLM, w, hM, color[i]);
if (ToDB(RM) > db[i]) gr.FillSolidRect(col + i * offset, yRM, w, hM, color[i]);
if (ToDB(LM) > db[i] && ToDB(LM) < db[i+1]) {xLM = i * offset};
if (xLManim <= xLM) {xLManim = xLM; xLManim2 = xLM; kLM = 0; kLM2 = 0};
if (ToDB(LM) > db[i]) gr.FillSolidRect(col + xLManim + offset, yLM, w * 0.8, hM , color[Math.round(xLManim/offset)]);
if (ToDB(RM) > db[i] && ToDB(RM) < db[i+1]) {xRM = i * offset};
if (xRManim <= xRM) {xRManim = xRM; xRManim2 = xRM; kRM = 0; kRM2 = 0};
if (ToDB(RM) > db[i]) gr.FillSolidRect(col + xRManim + offset, yRM, w * 0.8, hM, color[Math.round(xRManim/offset)]);
if (ToDB(LM) > db[i]) gr.FillSolidRect(col + xLManim2 + offset + w, yLM, w * 0.3, hM, color[Math.round(xLManim/offset)]);
if (ToDB(RM) > db[i]) gr.FillSolidRect(col + xRManim2 + offset + w, yRM, w * 0.3, hM, color[Math.round(xRManim/offset)]);
}
anim();
}
for (var i = 0; i <= points; i++) {
var text_w = gr.CalcTextWidth(db[i], font);
if (i > 2) gr.GdiDrawText( db[i]% 2 == 0 ? db[i] : "" , font, color1[0], col + offset * i - text_w / 2, ytext, ww, wh);
}
gr.GdiDrawText( "db", font, color1[0], col, ytext, ww, wh);
VUMOffset_t = Math.round(VUMeter.Offset) + " db";
t_height = gr.CalcTextHeight(VUMOffset_t, font2) + 2;
t_width = gr.CalcTextWidth(VUMOffset_t, font2) + 10;
wheel && gr.FillSolidRect(pos_x - t_width, pos_y - t_height + 0, t_width, t_height, bgcolor);
wheel && gr.GdiDrawText(VUMOffset_t, font2, color2[0], pos_x - t_width, pos_y - t_height + 0, t_width, t_height, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_WORD_ELLIPSIS );
}
function anim() {
kLM = kLM + Math.pow(0.3, 2);
kRM = kRM + Math.pow(0.3, 2);
xLManim = xLManim - kLM;
xRManim = xRManim - kRM;
kLM2 = kLM2 + Math.pow(1.1, 2);
kRM2 = kRM2 + Math.pow(1.1, 2);
xLManim2 = xLManim2 + kLM2;
xRManim2 = xRManim2 + kRM2;
kL = kL + Math.pow(0.3, 2);
kR = kR + Math.pow(0.3, 2);
xLanim = xLanim - kL;
xRanim = xRanim - kR;
wLanim = wLanim - kL * 2; //2
wRanim = wRanim - kR * 2;
}
function on_size() {
ww = window.Width;
wh = window.Height;
offset = (ww - col) / points;
w = offset - 1;
offset_l = (ww - col) / points_l;
w_l = offset_l - 1;
}
function on_mouse_move(x,y) {
on_mouse = true;
pos_x = x <= t_width ? col + t_width : col + x;
pos_y = y <= t_height ? t_height : y;
window.SetCursor(32649);
window.Repaint();
}
function on_mouse_leave() {
on_mouse = false;
window.SetCursor(32512);
window.Repaint();
}
function on_mouse_wheel(step) {
wheel = true;
VUMeter.Offset = VUMeter.Offset + step;
window.Repaint();
tooltip_timer && window.ClearTimeout(tooltip_timer);
tooltip_timer = window.SetTimeout(function() {
wheel = false;
tooltip_timer && window.ClearTimeout(tooltip_timer);
tooltip_timer = false;
}, 2000);
}
function combineColors(c1, c2, f){ // When fraction is 0, result is 100% color1, when f is 1, result is 100% color2.
var c1 = toRGB(c1);
var c2 = toRGB(c2);
var r = Math.round(c1[0] + f * (c2[0] - c1[0]));
var g = Math.round(c1[1] + f * (c2[1] - c1[1]));
var b = Math.round(c1[2] + f * (c2[2] - c1[2]));
return (0xff000000 | (r << 16) | (g << 8) | (b));
}
function toRGB(d){ // convert back to RGB values
var d = d-0xff000000;
var r = d >> 16;
var g = d >> 8 & 0xFF;
var b = d & 0xFF;
return [r,g,b];
}
panel_on = true;
function on_notify_data(name, info) {
if (name == "panel vis") {
if (info == "Peak meter"){
panel_on = true;
} else {
panel_on = false;
}
}
}