Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @name "VU Meter"
- // @version "1.0.1"
- // @author "VU Meter component/object by DRON, jscript by Br3tt aka Falstaff >> http://br3tt.deviantart.com"
- // @feature "dragdrop"
- // ==/PREPROCESSOR==
- // [Requirements]
- // * foobar2000 v1.1 or better >> http://foobar2000.org
- // * WSH panel Mod v1.5.3.1 or better >> http://code.google.com/p/foo-wsh-panel-mod/downloads/list
- // * VU Meter 2012-05-27 or better >> http://foobar2000.org.ru/forum/
- // * background image and needle image >> http://br3tt.free.fr/files/R/images.zip
- // [/Requirements]
- // Images Path + FileNames
- var img_dir = fb.ProfilePath + "themes\\fooRazor\\images\\";
- var bg = gdi.Image(img_dir+"vu_bg.png");
- var needle = gdi.Image(img_dir+"needle.png");
- var bg_img;
- // {{
- // Use with MenuManager()
- MF_STRING = 0x00000000;
- MF_SEPARATOR = 0x00000800;
- MF_GRAYED = 0x00000001;
- MF_DISABLED = 0x00000002;
- MF_POPUP = 0x00000010;
- // }}
- // {{
- // Used in window.GetColorCUI()
- ColorTypeCUI = {
- text: 0,
- selection_text: 1,
- inactive_selection_text: 2,
- background: 3,
- selection_background: 4,
- inactive_selection_background: 5,
- active_item_frame: 6
- };
- // }}
- // {{
- // Used in window.GetColorDUI()
- ColorTypeDUI = {
- text: 0,
- background: 1,
- highlight: 2,
- selection: 3
- };
- // }}
- function RGB(r, g, b) {
- return (0xff000000 | (r << 16) | (g << 8) | (b));
- };
- function RGBA(r, g, b, a) {
- return ((a << 24) | (r << 16) | (g << 8) | (b));
- };
- // window Properties
- var keepaspectratio = window.GetProperty("Keep Aspect Ratio", true);
- var layout = window.GetProperty("L+R Channels", false);
- // VUMeter Object
- VUMeter = new ActiveXObject("VUMeter");
- VUMeter.RegisterWindow(window.ID);
- //VUMeter.RegisterRect(window.ID,0,0,200,100);
- // Globals
- var vu_angle = 110;
- var g_instancetype = window.InstanceType;
- var ww = 0, wh = 0, true_ww = 0;
- var mouse_x, mouse_y;
- var g_textcolor = 0, g_textcolor_hl = 0;
- var g_backcolor = 0;
- var g_syscolor = 0;
- var COLOR_BTNFACE = 15;
- var g_tooltip = window.CreateTooltip();
- var tooltip_timer = false;
- function get_colors() {
- if (g_instancetype == 0) { // CUI
- g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
- g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
- g_textcolor_sel = window.GetColorCUI(ColorTypeCUI.selection_text);
- g_backcolor = window.GetColorCUI(ColorTypeCUI.background);
- } else if (g_instancetype == 1) { // DUI
- g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
- g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
- g_textcolor_sel = window.GetColorDUI(ColorTypeDUI.selection);
- g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
- } else {
- // None
- };
- g_syscolor = utils.GetSysColor(COLOR_BTNFACE);
- }
- get_colors();
- function on_size() {
- ww = window.Width;
- wh = window.Height;
- if(!ww || !wh) return true;
- bg_img && bg_img.Dispose();
- if(layout) {
- if(keepaspectratio) {
- if(wh != Math.floor(ww/4)) {
- window.MinHeight = Math.floor(ww/4);
- window.MaxHeight = Math.floor(ww/4);
- }
- } else {
- window.MinHeight = 0;
- window.MaxHeight = 0;
- }
- ww = Math.floor(ww / 2);
- } else {
- if(keepaspectratio) {
- if(wh != Math.floor(ww/2)) {
- window.MinHeight = Math.floor(ww/2);
- window.MaxHeight = Math.floor(ww/2);
- }
- } else {
- window.MinHeight = 0;
- window.MaxHeight = 0;
- }
- }
- bg_img = bg.Resize(ww, Math.round(ww/2), 7);
- true_ww = window.Width;
- };
- function on_paint(gr) {
- L = VUMeter.LeftLevel;
- R = VUMeter.RightLevel;
- LM = VUMeter.LeftPeak;
- RM = VUMeter.RightPeak;
- // Convert to Mono
- if(!layout) {
- L = (L + R) / 2;
- LM = (LM + RM) / 2;
- }
- // boundaries adjust
- var spectre_ratio = 1/1.5;
- if(L<=0) L = 0;
- if(R<=0) R = 0;
- if(L>=1.5) L = 1.5;
- if(R>=1.5) R = 1.5;
- L = L * spectre_ratio;
- R = R * spectre_ratio;
- // create draw area
- var wh2 = Math.round(ww / 2);
- var main_img = gdi.CreateImage(true_ww, wh2);
- var gb = main_img.GetGraphics();
- // fill bgcolor
- gb.FillSolidRect(0, 0, true_ww, wh2, g_syscolor);
- // Draw Peak
- if(layout) {
- // left peak
- gb.FillGradRect(7, 7, ww*LM-14, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
- // right peak
- gb.FillGradRect(ww+7, 7, ww*RM-14, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
- } else {
- // mono peak
- gb.FillGradRect(7, 7, ww*LM-14, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
- }
- if(layout) {
- gb.FillSolidRect(Math.floor(true_ww/2), 0, 2, wh2, g_backcolor);
- gb.FillSolidRect(true_ww-2, 0, 2, wh2, g_backcolor);
- }
- if(layout) {
- // left background image
- gb.DrawImage(bg_img, 0, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
- // right background image
- gb.DrawImage(bg_img, ww, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
- } else {
- // mono background image
- gb.DrawImage(bg_img, 0, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
- }
- var needle_padding = Math.round(wh2 * 0.15);
- if(layout) {
- // LEFT
- var theta = L * vu_angle;
- var ratio = (wh2-needle_padding)/150;
- var angle = theta - (vu_angle/2);
- gb.DrawImage(needle, Math.round((ww/2)-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, angle, 255);
- // RIGHT
- var theta = R * vu_angle;
- var ratio = (wh2-needle_padding)/150;
- var angle = theta - (vu_angle/2);
- gb.DrawImage(needle, Math.round((ww/2)+ww-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, angle, 255);
- } else {
- var theta = L * vu_angle;
- var ratio = (wh2-needle_padding)/150;
- var angle = theta - (vu_angle/2);
- gb.DrawImage(needle, Math.round((ww/2)-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, angle, 255);
- }
- // Release and Draw true panel graphics
- main_img.ReleaseGraphics(gb);
- gr.DrawImage(main_img, 0, 0, true_ww, wh, 0, 0, true_ww, wh2, 0, 255);
- main_img.Dispose();
- }
- function on_colors_changed() {
- get_colors();
- window.Repaint();
- }
- function on_mouse_wheel(step) {
- VUMeter.Offset = VUMeter.Offset + step;
- g_tooltip.Text = VUMeter.Offset + " dB";
- g_tooltip.Activate();
- tooltip_timer && window.ClearTimeout(tooltip_timer);
- tooltip_timer = window.SetTimeout(function() {
- g_tooltip.Text = "";
- g_tooltip.Deactivate();
- tooltip_timer && window.ClearTimeout(tooltip_timer);
- tooltip_timer = false;
- }, 2000);
- }
- function on_mouse_move(x, y) {
- mouse_x = x;
- mouse_y = y;
- }
- function on_mouse_leave() {
- g_tooltip.Text = "";
- g_tooltip.Deactivate();
- tooltip_timer && window.ClearTimeout(tooltip_timer);
- tooltip_timer = false;
- }
- function on_mouse_rbtn_down(x, y, mask) {
- var idx;
- var _menu = window.CreatePopupMenu();
- _menu.AppendMenuItem(MF_STRING, 100, "Left + Right Channels");
- _menu.CheckMenuItem(100, layout?1:0);
- _menu.AppendMenuItem(MF_STRING, 110, "Keep Aspect Ratio");
- _menu.CheckMenuItem(110, keepaspectratio?1:0);
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 900, "Properties");
- _menu.AppendMenuItem(MF_STRING, 910, "Configure...");
- idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 100:
- layout = !layout;
- window.SetProperty("L+R Channels", layout);
- on_size();
- break;
- case 110:
- keepaspectratio = !keepaspectratio;
- window.SetProperty("Keep Aspect Ratio", keepaspectratio);
- on_size();
- break;
- case 900:
- window.ShowProperties();
- break;
- case 910:
- window.ShowConfigure();
- break;
- default:
- };
- _menu.Dispose();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement