SHARE
TWEET

WSH VU Meter v1.0.1

Br3tt May 28th, 2012 1,269 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "VU Meter"
  3. // @version "1.0.1"
  4. // @author "VU Meter component/object by DRON, jscript by Br3tt aka Falstaff >> http://br3tt.deviantart.com"
  5. // @feature "dragdrop"
  6. // ==/PREPROCESSOR==
  7.  
  8. // [Requirements]
  9. // * foobar2000 v1.1 or better  >> http://foobar2000.org
  10. // * WSH panel Mod v1.5.3.1 or better  >> http://code.google.com/p/foo-wsh-panel-mod/downloads/list
  11. // * VU Meter 2012-05-27 or better >> http://foobar2000.org.ru/forum/
  12. // * background image and needle image >> http://br3tt.free.fr/files/R/images.zip
  13. // [/Requirements]
  14.  
  15. // Images Path + FileNames
  16. var img_dir = fb.ProfilePath + "themes\\fooRazor\\images\\";
  17. var bg = gdi.Image(img_dir+"vu_bg.png");
  18. var needle = gdi.Image(img_dir+"needle.png");
  19. var bg_img;
  20.  
  21. // {{
  22. // Use with MenuManager()
  23. MF_STRING = 0x00000000;
  24. MF_SEPARATOR = 0x00000800;
  25. MF_GRAYED = 0x00000001;
  26. MF_DISABLED = 0x00000002;
  27. MF_POPUP = 0x00000010;
  28. // }}
  29.  
  30. // {{
  31. // Used in window.GetColorCUI()
  32. ColorTypeCUI = {
  33.     text: 0,
  34.     selection_text: 1,
  35.     inactive_selection_text: 2,
  36.     background: 3,
  37.     selection_background: 4,
  38.     inactive_selection_background: 5,
  39.     active_item_frame: 6
  40. };
  41. // }}
  42.  
  43. // {{
  44. // Used in window.GetColorDUI()
  45. ColorTypeDUI = {
  46.     text: 0,
  47.     background: 1,
  48.     highlight: 2,
  49.     selection: 3
  50. };
  51. // }}
  52.  
  53. function RGB(r, g, b) {
  54.     return (0xff000000 | (r << 16) | (g << 8) | (b));
  55. };
  56. function RGBA(r, g, b, a) {
  57.     return ((a << 24) | (r << 16) | (g << 8) | (b));
  58. };
  59.  
  60. // window Properties
  61. var keepaspectratio = window.GetProperty("Keep Aspect Ratio", true);
  62. var layout = window.GetProperty("L+R Channels", false);
  63.  
  64. // VUMeter Object
  65. VUMeter = new ActiveXObject("VUMeter");
  66. VUMeter.RegisterWindow(window.ID);
  67. //VUMeter.RegisterRect(window.ID,0,0,200,100);
  68.  
  69. // Globals
  70. var vu_angle = 110;
  71. var g_instancetype = window.InstanceType;
  72. var ww = 0, wh = 0, true_ww = 0;
  73. var mouse_x, mouse_y;
  74. var g_textcolor = 0, g_textcolor_hl = 0;
  75. var g_backcolor = 0;
  76. var g_syscolor = 0;
  77. var COLOR_BTNFACE = 15;
  78. var g_tooltip = window.CreateTooltip();
  79. var tooltip_timer = false;
  80.  
  81. function get_colors() {
  82.     if (g_instancetype == 0) { // CUI
  83.         g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
  84.         g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
  85.         g_textcolor_sel = window.GetColorCUI(ColorTypeCUI.selection_text);
  86.         g_backcolor = window.GetColorCUI(ColorTypeCUI.background);
  87.     } else if (g_instancetype == 1) { // DUI
  88.         g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
  89.         g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
  90.         g_textcolor_sel = window.GetColorDUI(ColorTypeDUI.selection);
  91.         g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
  92.     } else {
  93.         // None
  94.     };
  95.     g_syscolor = utils.GetSysColor(COLOR_BTNFACE);
  96. }
  97. get_colors();
  98.  
  99. function on_size() {
  100.     ww = window.Width;
  101.     wh = window.Height;
  102.    
  103.     if(!ww || !wh) return true;
  104.    
  105.     bg_img && bg_img.Dispose();
  106.    
  107.     if(layout) {
  108.         if(keepaspectratio) {
  109.             if(wh != Math.floor(ww/4)) {
  110.                 window.MinHeight = Math.floor(ww/4);
  111.                 window.MaxHeight = Math.floor(ww/4);
  112.             }
  113.         } else {
  114.             window.MinHeight = 0;
  115.             window.MaxHeight = 0;
  116.         }
  117.         ww = Math.floor(ww / 2);
  118.     } else {
  119.         if(keepaspectratio) {
  120.             if(wh != Math.floor(ww/2)) {
  121.                 window.MinHeight = Math.floor(ww/2);
  122.                 window.MaxHeight = Math.floor(ww/2);
  123.             }
  124.         } else {
  125.             window.MinHeight = 0;
  126.             window.MaxHeight = 0;
  127.         }
  128.     }
  129.  
  130.     bg_img = bg.Resize(ww, Math.round(ww/2), 7);
  131.     true_ww = window.Width;
  132.    
  133. };
  134.  
  135. function on_paint(gr) {
  136.     L = VUMeter.LeftLevel;
  137.     R = VUMeter.RightLevel;
  138.     LM = VUMeter.LeftPeak;
  139.     RM = VUMeter.RightPeak;
  140.    
  141.     // Convert to Mono
  142.     if(!layout) {
  143.         L = (L + R) / 2;
  144.         LM = (LM + RM) / 2;
  145.     }
  146.    
  147.     // boundaries adjust
  148.     var spectre_ratio = 1/1.5;
  149.     if(L<=0) L = 0;
  150.     if(R<=0) R = 0;
  151.     if(L>=1.5) L = 1.5;
  152.     if(R>=1.5) R = 1.5;
  153.     L = L * spectre_ratio;
  154.     R = R * spectre_ratio;
  155.      
  156.     // create draw area
  157.     var wh2 = Math.round(ww / 2);
  158.     var main_img = gdi.CreateImage(true_ww, wh2);
  159.     var gb = main_img.GetGraphics();
  160.    
  161.     // fill bgcolor
  162.     gb.FillSolidRect(0, 0, true_ww, wh2, g_syscolor);
  163.  
  164.     // Draw Peak
  165.     if(layout) {
  166.         // left peak
  167.         gb.FillGradRect(7, 7, ww*LM-14, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
  168.         // right peak
  169.         gb.FillGradRect(ww+7, 7, ww*RM-14, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
  170.     } else {
  171.         // mono peak
  172.         gb.FillGradRect(7, 7, ww*LM-14, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
  173.     }
  174.     if(layout) {
  175.         gb.FillSolidRect(Math.floor(true_ww/2), 0, 2, wh2, g_backcolor);
  176.         gb.FillSolidRect(true_ww-2, 0, 2, wh2, g_backcolor);
  177.     }
  178.  
  179.     if(layout) {
  180.         // left background image
  181.         gb.DrawImage(bg_img, 0, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
  182.         // right background image
  183.         gb.DrawImage(bg_img, ww, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
  184.     } else {
  185.         // mono background image
  186.         gb.DrawImage(bg_img, 0, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
  187.     }
  188.  
  189.     var needle_padding = Math.round(wh2 * 0.15);
  190.    
  191.     if(layout) {
  192.         // LEFT
  193.         var theta = L * vu_angle;
  194.         var ratio = (wh2-needle_padding)/150;
  195.         var angle = theta - (vu_angle/2);
  196.         gb.DrawImage(needle, Math.round((ww/2)-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, angle, 255);
  197.        
  198.         // RIGHT
  199.         var theta = R * vu_angle;
  200.         var ratio = (wh2-needle_padding)/150;
  201.         var angle = theta - (vu_angle/2);
  202.         gb.DrawImage(needle, Math.round((ww/2)+ww-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, angle, 255);
  203.  
  204.     } else {
  205.         var theta = L * vu_angle;
  206.         var ratio = (wh2-needle_padding)/150;
  207.         var angle = theta - (vu_angle/2);
  208.         gb.DrawImage(needle, Math.round((ww/2)-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, angle, 255);
  209.     }
  210.    
  211.     // Release and Draw true panel graphics
  212.     main_img.ReleaseGraphics(gb);
  213.     gr.DrawImage(main_img, 0, 0, true_ww, wh, 0, 0, true_ww, wh2, 0, 255);
  214.     main_img.Dispose();
  215. }
  216.  
  217. function on_colors_changed() {
  218.     get_colors();
  219.     window.Repaint();
  220. }
  221.  
  222. function on_mouse_wheel(step) {
  223.     VUMeter.Offset = VUMeter.Offset + step;
  224.     g_tooltip.Text = VUMeter.Offset + " dB";
  225.     g_tooltip.Activate();
  226.     tooltip_timer && window.ClearTimeout(tooltip_timer);
  227.     tooltip_timer = window.SetTimeout(function() {
  228.         g_tooltip.Text = "";
  229.         g_tooltip.Deactivate();
  230.         tooltip_timer && window.ClearTimeout(tooltip_timer);
  231.         tooltip_timer = false;
  232.     }, 2000);
  233. }
  234.  
  235. function on_mouse_move(x, y) {
  236.     mouse_x = x;
  237.     mouse_y = y;
  238. }
  239.  
  240. function on_mouse_leave() {
  241.     g_tooltip.Text = "";
  242.     g_tooltip.Deactivate();
  243.     tooltip_timer && window.ClearTimeout(tooltip_timer);
  244.     tooltip_timer = false;
  245. }
  246.  
  247. function on_mouse_rbtn_down(x, y, mask) {
  248.     var idx;
  249.     var _menu = window.CreatePopupMenu();
  250.     _menu.AppendMenuItem(MF_STRING, 100, "Left + Right Channels");
  251.     _menu.CheckMenuItem(100, layout?1:0);
  252.     _menu.AppendMenuItem(MF_STRING, 110, "Keep Aspect Ratio");
  253.     _menu.CheckMenuItem(110, keepaspectratio?1:0);
  254.     _menu.AppendMenuSeparator();
  255.     _menu.AppendMenuItem(MF_STRING, 900, "Properties");
  256.     _menu.AppendMenuItem(MF_STRING, 910, "Configure...");
  257.     idx = _menu.TrackPopupMenu(x, y);
  258.     switch(idx) {
  259.         case 100:
  260.             layout = !layout;
  261.             window.SetProperty("L+R Channels", layout);
  262.             on_size();
  263.             break;
  264.         case 110:
  265.             keepaspectratio = !keepaspectratio;
  266.             window.SetProperty("Keep Aspect Ratio", keepaspectratio);
  267.             on_size();
  268.             break;
  269.         case 900:
  270.             window.ShowProperties();
  271.             break;
  272.         case 910:
  273.             window.ShowConfigure();
  274.             break;
  275.         default:
  276.     };
  277.     _menu.Dispose();
  278.     return true;
  279. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top