Advertisement
Guest User

Untitled

a guest
May 29th, 2012
433
0
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. function LevelToAngle(Level, MinAngle, MaxAngle) {
  16.     L = Level +(Level > 1 ? 0.1 : 0.19) * (Level - 1);
  17.     Angle = MinAngle + L * (MaxAngle - MinAngle) * 132 / 193;
  18.     return Math.min(Math.max(MinAngle, MaxAngle),
  19.       Math.max(Math.min(MinAngle, MaxAngle), Angle));
  20. };
  21.  
  22. // Images Path + FileNames
  23. var img_dir = fb.ProfilePath + "themes\\fooRazor\\images\\";
  24. var bg = gdi.Image(img_dir+"vu_bg.png");
  25. var needle = gdi.Image(img_dir+"needle.png");
  26. var bg_img;
  27.  
  28. // {{
  29. // Use with MenuManager()
  30. MF_STRING = 0x00000000;
  31. MF_SEPARATOR = 0x00000800;
  32. MF_GRAYED = 0x00000001;
  33. MF_DISABLED = 0x00000002;
  34. MF_POPUP = 0x00000010;
  35. // }}
  36.  
  37. // {{
  38. // Used in window.GetColorCUI()
  39. ColorTypeCUI = {
  40.     text: 0,
  41.     selection_text: 1,
  42.     inactive_selection_text: 2,
  43.     background: 3,
  44.     selection_background: 4,
  45.     inactive_selection_background: 5,
  46.     active_item_frame: 6
  47. };
  48. // }}
  49.  
  50. // {{
  51. // Used in window.GetColorDUI()
  52. ColorTypeDUI = {
  53.     text: 0,
  54.     background: 1,
  55.     highlight: 2,
  56.     selection: 3
  57. };
  58. // }}
  59.  
  60. function RGB(r, g, b) {
  61.     return (0xff000000 | (r << 16) | (g << 8) | (b));
  62. };
  63. function RGBA(r, g, b, a) {
  64.     return ((a << 24) | (r << 16) | (g << 8) | (b));
  65. };
  66.  
  67. // window Properties
  68. var keepaspectratio = window.GetProperty("Keep Aspect Ratio", true);
  69. var layout = window.GetProperty("L+R Channels", false);
  70.  
  71. // VUMeter Object
  72. VUMeter = new ActiveXObject("VUMeter");
  73. VUMeter.RegisterWindow(window.ID);
  74. //VUMeter.RegisterRect(window.ID,0,0,200,100);
  75.  
  76. // Globals
  77. var vu_angle2 = 110 / 2;
  78. var g_instancetype = window.InstanceType;
  79. var ww = 0, wh = 0, true_ww = 0;
  80. var mouse_x, mouse_y;
  81. var g_textcolor = 0, g_textcolor_hl = 0;
  82. var g_backcolor = 0;
  83. var g_syscolor = 0;
  84. var COLOR_BTNFACE = 15;
  85. var g_tooltip = window.CreateTooltip();
  86. var tooltip_timer = false;
  87.  
  88. function get_colors() {
  89.     if (g_instancetype == 0) { // CUI
  90.         g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
  91.         g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
  92.         g_textcolor_sel = window.GetColorCUI(ColorTypeCUI.selection_text);
  93.         g_backcolor = window.GetColorCUI(ColorTypeCUI.background);
  94.     } else if (g_instancetype == 1) { // DUI
  95.         g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
  96.         g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
  97.         g_textcolor_sel = window.GetColorDUI(ColorTypeDUI.selection);
  98.         g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
  99.     } else {
  100.         // None
  101.     };
  102.     g_syscolor = utils.GetSysColor(COLOR_BTNFACE);
  103. }
  104. get_colors();
  105.  
  106. function on_size() {
  107.     ww = window.Width;
  108.     wh = window.Height;
  109.    
  110.     if(!ww || !wh) return true;
  111.    
  112.     bg_img && bg_img.Dispose();
  113.    
  114.     if(layout) {
  115.         if(keepaspectratio) {
  116.             if(wh != Math.floor(ww/4)) {
  117.                 window.MinHeight = Math.floor(ww/4);
  118.                 window.MaxHeight = Math.floor(ww/4);
  119.             }
  120.         } else {
  121.             window.MinHeight = 0;
  122.             window.MaxHeight = 0;
  123.         }
  124.         ww = Math.floor(ww / 2);
  125.     } else {
  126.         if(keepaspectratio) {
  127.             if(wh != Math.floor(ww/2)) {
  128.                 window.MinHeight = Math.floor(ww/2);
  129.                 window.MaxHeight = Math.floor(ww/2);
  130.             }
  131.         } else {
  132.             window.MinHeight = 0;
  133.             window.MaxHeight = 0;
  134.         }
  135.     }
  136.  
  137.     bg_img = bg.Resize(ww, Math.round(ww/2), 7);
  138.     true_ww = window.Width;
  139.    
  140. };
  141.  
  142. function on_paint(gr) {
  143.     L = VUMeter.LeftLevel;
  144.     R = VUMeter.RightLevel;
  145.     LM = VUMeter.LeftPeak;
  146.     RM = VUMeter.RightPeak;
  147.    
  148.     // Convert to Mono
  149.     if(!layout) {
  150.         L = (L + R) / 2;
  151.         LM = (LM + RM) / 2;
  152.     }
  153.    
  154.     LA = LevelToAngle(L, -vu_angle2, +vu_angle2);
  155.     RA = LevelToAngle(R, -vu_angle2, +vu_angle2);
  156.     LP = Math.sin(LevelToAngle(LM, -vu_angle2, +vu_angle2) / 180 * Math.PI);
  157.     RP = Math.sin(LevelToAngle(RM, -vu_angle2, +vu_angle2) / 180 * Math.PI);
  158.    
  159.     // create draw area
  160.     var wh2 = Math.round(ww / 2);
  161.     var main_img = gdi.CreateImage(true_ww, wh2);
  162.     var gb = main_img.GetGraphics();
  163.    
  164.     // fill bgcolor
  165.     gb.FillSolidRect(0, 0, true_ww, wh2, g_syscolor);
  166.  
  167.     var ratio = 0.79;
  168.     // Draw Peak
  169.     if(layout) {
  170.         // left peak
  171.         gb.FillGradRect(7, 7, wh2+ratio*wh2*LP-7, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
  172.         // right peak
  173.         gb.FillGradRect(ww+7, 7, wh2+ratio*wh2*RP-7, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
  174.     } else {
  175.         // mono peak
  176.         gb.FillGradRect(7, 7, wh2+ratio*wh2*LP-7, wh2-14, 0, RGBA(0,255,0,150), RGBA(255,0,0,150), 1);
  177.     }
  178.     if(layout) {
  179.         gb.FillSolidRect(Math.floor(true_ww/2), 0, 2, wh2, g_backcolor);
  180.         gb.FillSolidRect(true_ww-2, 0, 2, wh2, g_backcolor);
  181.     }
  182.  
  183.     if(layout) {
  184.         // left background image
  185.         gb.DrawImage(bg_img, 0, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
  186.         // right background image
  187.         gb.DrawImage(bg_img, ww, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
  188.     } else {
  189.         // mono background image
  190.         gb.DrawImage(bg_img, 0, 0, bg_img.Width, bg_img.Height, 0, 0, bg_img.Width, bg_img.Height, 0, 255);
  191.     }
  192.  
  193.     var needle_padding = Math.round(wh2 * 0.15);
  194.    
  195.     if(layout) {
  196.         // LEFT
  197.         var ratio = (wh2-needle_padding)/150;
  198.         gb.DrawImage(needle, Math.round((ww/2)-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, LA, 255);
  199.        
  200.         // RIGHT
  201.         var ratio = (wh2-needle_padding)/150;
  202.         gb.DrawImage(needle, Math.round((ww/2)+ww-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, RA, 255);
  203.  
  204.     } else {
  205.         var ratio = (wh2-needle_padding)/150;
  206.         gb.DrawImage(needle, Math.round((ww/2)-(25*ratio/2)), needle_padding, 25*ratio, 300*ratio, 0, 0, 25, 300, LA, 255);
  207.     }
  208.    
  209.     // Release and Draw true panel graphics
  210.     main_img.ReleaseGraphics(gb);
  211.     gr.DrawImage(main_img, 0, 0, true_ww, wh, 0, 0, true_ww, wh2, 0, 255);
  212.     main_img.Dispose();
  213. }
  214.  
  215. function on_colors_changed() {
  216.     get_colors();
  217.     window.Repaint();
  218. }
  219.  
  220. function on_mouse_wheel(step) {
  221.     VUMeter.Offset = VUMeter.Offset + step;
  222.     g_tooltip.Text = VUMeter.Offset + " dB";
  223.     g_tooltip.Activate();
  224.     tooltip_timer && window.ClearTimeout(tooltip_timer);
  225.     tooltip_timer = window.SetTimeout(function() {
  226.         g_tooltip.Text = "";
  227.         g_tooltip.Deactivate();
  228.         tooltip_timer && window.ClearTimeout(tooltip_timer);
  229.         tooltip_timer = false;
  230.     }, 2000);
  231. }
  232.  
  233. function on_mouse_move(x, y) {
  234.     mouse_x = x;
  235.     mouse_y = y;
  236. }
  237.  
  238. function on_mouse_leave() {
  239.     g_tooltip.Text = "";
  240.     g_tooltip.Deactivate();
  241.     tooltip_timer && window.ClearTimeout(tooltip_timer);
  242.     tooltip_timer = false;
  243. }
  244.  
  245. function on_mouse_rbtn_down(x, y, mask) {
  246.     var idx;
  247.     var _menu = window.CreatePopupMenu();
  248.     _menu.AppendMenuItem(MF_STRING, 100, "Left + Right Channels");
  249.     _menu.CheckMenuItem(100, layout?1:0);
  250.     _menu.AppendMenuItem(MF_STRING, 110, "Keep Aspect Ratio");
  251.     _menu.CheckMenuItem(110, keepaspectratio?1:0);
  252.     _menu.AppendMenuSeparator();
  253.     _menu.AppendMenuItem(MF_STRING, 900, "Properties");
  254.     _menu.AppendMenuItem(MF_STRING, 910, "Configure...");
  255.     idx = _menu.TrackPopupMenu(x, y);
  256.     switch(idx) {
  257.         case 100:
  258.             layout = !layout;
  259.             window.SetProperty("L+R Channels", layout);
  260.             on_size();
  261.             break;
  262.         case 110:
  263.             keepaspectratio = !keepaspectratio;
  264.             window.SetProperty("Keep Aspect Ratio", keepaspectratio);
  265.             on_size();
  266.             break;
  267.         case 900:
  268.             window.ShowProperties();
  269.             break;
  270.         case 910:
  271.             window.ShowConfigure();
  272.             break;
  273.         default:
  274.     };
  275.     _menu.Dispose();
  276.     return true;
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement