Advertisement
Guest User

Album Art*

a guest
Sep 14th, 2013
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "Album Art"
  3. // @author "Mire777"
  4. // @feature "v1.4"
  5. // @feature "watch-metadb"
  6. // ==/PREPROCESSOR==
  7.  
  8. var quality = window.GetProperty(" Quality", 7.5);
  9. var cut_edge = window.GetProperty(" Cut Edge", 0);
  10. var cycle = window.GetProperty(" Auto Cycle Image", 0);
  11.  
  12. function on_selection_changed() {
  13.     if  (cycle==1)
  14.     a.id = 0;
  15.     a.metadb_changed();
  16.     p.item_focus_change();
  17. }
  18.  
  19. function on_playlist_switch() {
  20.     if  (cycle==1)
  21.     a.id = 0;
  22.     a.metadb_changed();
  23.     p.item_focus_change();
  24. }
  25.  
  26. function on_playback_new_track() {
  27.     if  (cycle==1)
  28.     a.id = 0;
  29.     a.metadb_changed();
  30.     p.item_focus_change();
  31. }
  32.  
  33. function on_playback_dynamic_info_track() {
  34.     if  (cycle==1)
  35.     a.id = 0;
  36.     a.metadb_changed();
  37.     p.item_focus_change();
  38. }
  39.  
  40. function on_playback_stop() {
  41.     if  (cycle==1)
  42.     a.id = 0;
  43.     a.metadb_changed();
  44.     p.item_focus_change();
  45. }
  46.  
  47. function on_item_focus_change() {
  48.     if  (cycle==1)
  49.     a.id = 0;
  50.     a.metadb_changed();
  51.     p.item_focus_change();
  52. }
  53.  
  54. function on_mouse_leave() {
  55.     if (typeof b == "object") b.leave();
  56.     if (typeof r == "object") r.leave();
  57.     if (typeof li == "object") li.leave();
  58.     if (typeof s == "object") s.leave();
  59. }
  60.  
  61. function on_mouse_rbtn_up(x, y) {
  62.     p.rbtn_up(x, y);
  63.     return true;
  64. }
  65. function panel(name, features) {
  66.     this.item_focus_change = function() {
  67.         switch(this.selection_mode) {
  68.             case 0:
  69.                 this.metadb = fb.GetSelection();
  70.                 break;
  71.             case 1:
  72.                 this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  73.                 break;
  74.             case 2:
  75.                 this.metadb = fb.GetFocusItem();
  76.                 break;
  77.         }
  78.         if (this.metadb && typeof on_metadb_changed == "function") on_metadb_changed();
  79.     }
  80.  
  81. this.colors_changed = function() {
  82.         }
  83.    
  84.  
  85.  
  86. this.font_changed = function() {
  87.         }
  88.    
  89.    
  90.     this.size = function() {
  91.         this.w = window.Width;
  92.         this.h = window.Height;
  93.     }
  94.    
  95.     this.move = function(x, y) {
  96.         this.mx = x;
  97.         this.my = y;
  98.     }
  99.    
  100.  
  101.     this.rbtn_up = function(x, y) {
  102.         var MF_STRING = 0x00000000;
  103.         var _menu = window.CreatePopupMenu();
  104.         var q = window.CreatePopupMenu();
  105.         var MF_POPUP = 0x00000010;
  106.         var MF_GRAYED = 0x00000001;
  107.         var idx;
  108.         switch(true) {
  109.            
  110.             case typeof a == "object" && a.trace(x, y):
  111.                 _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  112.                  
  113.                  //Auto Cycle Image(menu)
  114.                  if (cycle==1) _menu.AppendMenuItem(MF_STRING, 5001, "Auto Cycle Image");
  115.                  else
  116.                  if (cycle==0) _menu.AppendMenuItem(MF_STRING, 5002, "Auto Cycle Image");
  117.                  _menu.CheckMenuItem(5001, cycle?1:0);
  118.                
  119.                 //Image Quality(menu)
  120.                 _menu.AppendMenuItem(MF_STRING | MF_POPUP, q.ID, "Image Quality");
  121.                 q.AppendMenuItem(MF_STRING, 5003, "High");
  122.                 q.AppendMenuItem(MF_STRING, 5004, "Cut");
  123.                 q.AppendMenuItem(MF_STRING, 5005, "Low");
  124.                 _menu.CheckMenuItem(5003, quality=="7" & cut_edge=="0");
  125.                 _menu.CheckMenuItem(5004, quality=="7" & cut_edge=="1");
  126.                 _menu.CheckMenuItem(5005, quality=="7.5" & cut_edge=="0");
  127.                
  128.                 //Main(menu)
  129.                 _menu.AppendMenuSeparator();
  130.                 if  (cycle==0) _menu.AppendMenuItem(MF_STRING, 2, "Front");
  131.                 if  (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 2, "Front");
  132.                 if  (cycle==0) _menu.AppendMenuItem(MF_STRING, 3, "Back");
  133.                 if  (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 3, "Back");
  134.                 if  (cycle==0) _menu.AppendMenuItem(MF_STRING, 4, "Disc");
  135.                 if  (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 4, "Disc");
  136.                 if  (cycle==0) _menu.AppendMenuItem(MF_STRING, 5, "Icon");
  137.                 if  (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 5, "Icon");
  138.                 if  (cycle==0) _menu.AppendMenuItem(MF_STRING, 6, "Artist");
  139.                 if  (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 6, "Artist");
  140.                 if  (cycle==0) _menu.CheckMenuRadioItem(2, 6, a.id + 2);
  141.                 _menu.AppendMenuSeparator();
  142.                 _menu.AppendMenuItem(MF_STRING, 16, "Top");
  143.                 _menu.AppendMenuItem(MF_STRING, 15, "Centre");
  144.                 _menu.AppendMenuItem(MF_STRING, 17, "Adjust");
  145.                 _menu.AppendMenuItem(MF_STRING, 18, "Stretch");
  146.                
  147.                 //_menu.AppendMenuSeparator();
  148.                 _menu.AppendMenuItem(MF_STRING, 5000, "Properties");
  149.                
  150.                
  151.                 _menu.CheckMenuRadioItem(15, 18, a.type == "crop" ? 15 : a.type == "crop top" ? 16 : a.type == "centre" ? 17 : 18);
  152.                 //_menu.AppendMenuSeparator();
  153.                 break;
  154.                 case typeof c == "object" && (!this.check_feature("now_playing") || np_cd) && c.trace(x, y):
  155.                 _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  156.                 //_menu.AppendMenuSeparator();
  157.                 break;
  158.                
  159.             }
  160.        
  161.         _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
  162.         idx = _menu.TrackPopupMenu(x, y);
  163.         switch(idx) {
  164.             case 1:
  165.                 on_item_focus_change();
  166.                 break;
  167.             case 2:
  168.             case 3:
  169.             case 4:
  170.             case 5:
  171.             case 6:
  172.                 a.id = idx - 2;
  173.                 window.SetProperty("artreader_id", a.id);
  174.                 on_item_focus_change();
  175.                 break;
  176.            
  177.             case 10:
  178.                 window.ShowConfigure();
  179.                 break;
  180.            
  181.             case 15:
  182.             case 16:
  183.             case 17:
  184.             case 18:
  185.                 a.type = idx == 15 ? "crop" : idx == 16 ? "crop top" : idx == 17 ? "centre" : "stretch";
  186.                 window.SetProperty("artreader_image_type", a.type);
  187.                 window.RepaintRect(a.x, a.y, a.w, a.h);
  188.                 break;
  189.             case 5000:
  190.             window.ShowProperties();
  191.             break;
  192.            
  193.             case 5001:
  194.             cycle = 0;
  195.            window.SetProperty(" Auto Cycle Image", 0);
  196.             break;
  197.            
  198.              case 5002:
  199.              cycle = 1;
  200.            window.SetProperty(" Auto Cycle Image", 1);
  201.             break;
  202.            
  203.             case 5003:
  204.             cut_edge = 0;
  205.             quality =  7;
  206.             window.SetProperty(" Cut Edge", 0);
  207.             window.SetProperty(" Quality", 7);
  208.             p.item_focus_change();
  209.             break;
  210.            
  211.             case 5004:
  212.             cut_edge = 1;
  213.             quality =  7;
  214.             window.SetProperty(" Cut Edge", 1);
  215.             window.SetProperty(" Quality", 7);
  216.             p.item_focus_change();
  217.             break;
  218.            
  219.             case 5005:
  220.             cut_edge = 0;
  221.             quality =  7.5;
  222.             window.SetProperty(" Cut Edge", 0);
  223.             window.SetProperty(" Quality", 7.5);
  224.             p.item_focus_change();
  225.             break;
  226.         }
  227.         _menu.Dispose();
  228.        
  229.     }
  230.    
  231.     this.features_init = function() {
  232.         for (i = 0; i < this.features.length; i++) {
  233.             switch(this.features[i]) {
  234.                    
  235.                     case "metadb":
  236.                     this.selection_mode = window.GetProperty("selection_mode", 1);
  237.                     this.metadb = fb.GetFocusItem();
  238.                     break;
  239.                 }
  240.         }
  241.    
  242. }
  243. this.check_feature = function(f) {
  244.         for (i = 0; i < this.features.length; i++) {
  245.             if (this.features[i] == f) return true;
  246.         }
  247.         return false;
  248.     }
  249.     this.tt = function(t) {
  250.         if (this.tooltip.Text == t) return;
  251.         this.tooltip.Text = t;
  252.         this.tooltip.Activate();
  253. }
  254.     this.ttd = function() {
  255.         this.tooltip.Text = "";
  256.         this.tooltip.Deactivate();
  257.     }
  258.     this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
  259.         if (!img) return;
  260.         gr.SetInterpolationMode(quality);  
  261.        
  262.             switch(type) {
  263.              case "crop":
  264.             case "crop top":
  265.                {
  266.                 var sr = img.Width / img.Height;
  267.                 var dr = width / height;
  268.                 if (sr < dr) {
  269.                     var r = img.Width / width;
  270.                     var ch = height * r;
  271.                     var sy = Math.round((img.Height - ch) / (type == "crop top" ? 1000 : 2));
  272.                     var cw = img.Width;
  273.                     var sx = 0;
  274.                 } else {
  275.                     var r = img.Height / height;
  276.                     var cw = width * r;
  277.                     var sx = Math.round((img.Width - cw) / 2);
  278.                     var ch = img.Height;
  279.                     var sy = 0;
  280.                 }
  281.                 if (cut_edge==0)
  282.                  {
  283.                 gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
  284.                 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  285.                  }
  286.                  else
  287.                  if (cut_edge==1)
  288.                  {
  289.                  gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
  290.                  if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);    
  291.                  }
  292.             }
  293.                 break;
  294.             case "stretch":
  295.                 //strech
  296.                  if (cut_edge==0)
  297.                  {
  298.                 gr.DrawImage(img, pos_x, pos_y, width, height, 0, 0, img.Width, img.Height, 0, alpha || 255);
  299.                 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  300.                  }
  301.                  else
  302.                  if (cut_edge==1)
  303.                  {
  304.                  gr.DrawImage(img, pos_x, pos_y, width, height, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
  305.                  if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  306.                  }
  307.                 break;
  308.             case "centre":
  309.             default:
  310.                 //adjust
  311.                 var s = Math.min(width / img.Width, height / img.Height);
  312.                 var nw = Math.round(img.Width * s);
  313.                 var nh = Math.round(img.Height * s);
  314.                 pos_x += Math.round((width - nw) / 2);
  315.                 pos_y += Math.round((height - nh) / 2);
  316.                
  317.                 if (cut_edge==0)
  318.                 {
  319.                 gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.Width, img.Height, 0, alpha || 255);              
  320.                 if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
  321.                 }
  322.               else
  323.                 if (cut_edge==1)
  324.               {
  325.               gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
  326.               if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
  327.             }
  328.                 break;
  329.         }
  330.     }
  331.        
  332.     this.name = name;
  333.     this.features = features;
  334.     this.dui = window.InstanceType;
  335.     this.tooltip = window.CreateTooltip();
  336.     this.w = 0;
  337.     this.h = 0;
  338.     this.mx = 0;
  339.     this.my = 0;
  340.     this.metadb = fb.GetFocusItem();
  341.     this.vb = new ActiveXObject("ScriptControl");
  342.     this.vb.Language = "VBScript";
  343.     this.artist = "";
  344.     this.artist_tf = "%artist%";
  345.     this.list_font_size = 11;
  346.     this.features_init();
  347.     this.colors_changed();
  348.     this.font_changed();
  349.     }
  350.  
  351. function artreader(x, y, w, h) {
  352.     this.draw = function(gr) {
  353.         if (!this.img) return;
  354.         p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
  355.     }
  356.     this.metadb_changed = function() {
  357.         if (!p.metadb) return;
  358.         this.img && this.img.Dispose();
  359.         this.path = "";
  360.         this.img = utils.GetAlbumArtV2(p.metadb, this.id);
  361.         //if 1+ image not found, then show front cover
  362.         if  (cycle==1)
  363.         if (!this.img) {
  364.         this.id++;
  365.         if (this.id < 4) this.id = 0;
  366.         else
  367.         if (this.id > 4) this.id = 0;
  368.        
  369.         //p.item_focus_change();
  370.    
  371.         //this.metadb_changed();
  372.         return;
  373.                        }
  374.        
  375.         window.RepaintRect(this.x, this.y, this.w, this.h);
  376.         utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
  377.     }
  378.     this.get_album_art_done = function(ip) {
  379.         this.path = ip;
  380.     }
  381.     this.trace = function(x, y) {
  382.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  383.     }
  384.     this.wheel = function(step) {
  385.         if (!this.trace(p.mx, p.my)) return false;
  386.         this.id -= step;
  387.         if (this.id < 0) this.id = 4;
  388.         if (this.id > 4) this.id = 0;
  389.         window.SetProperty("artreader_id", this.id);
  390.         this.metadb_changed();
  391.         return true;
  392.     }
  393.     this.move = function(x, y) {
  394.         if (this.trace(x, y)) {
  395.             // next line show picture size
  396.             //if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
  397.             //return true;
  398.         } else {
  399.             p.ttd();
  400.             return false;
  401.         }
  402.     }
  403.     this.x = x;
  404.     this.y = y;
  405.     this.w = w;
  406.     this.h = h;
  407.     this.id = window.GetProperty("artreader_id", 0);
  408.     this.img = null;
  409.     this.path = null;
  410.     this.type = window.GetProperty("artreader_image_type", "centre");
  411. }
  412. //Begin
  413. var p = new panel("Art Reader", ["metadb"]);
  414. var a = new artreader(0, 0, 100, 100);
  415.  
  416. on_item_focus_change();
  417.  
  418. function on_size() {
  419.     p.size();
  420.     a.w = p.w;
  421.     a.h = p.h;
  422. }
  423.  
  424. function on_paint(gr) {
  425.    
  426.     a.draw(gr);
  427.     if (!a.img) p.centre_tex;
  428. }
  429.  
  430. function on_metadb_changed() {
  431.     a.metadb_changed();
  432. }
  433.  
  434. function on_get_album_art_done(metadb, art_id, im, ip) {
  435.     a.get_album_art_done(ip);
  436. }
  437. function on_mouse_wheel(step) {
  438.     a.wheel(step);
  439.     p.item_focus_change();
  440. }
  441. //next line alow you to skroll images with mouse (front,back,artist..)
  442. function on_mouse_move(x, y) {
  443.     p.move(x, y);
  444.     a.move(x, y);
  445.     p.item_focus_change();
  446.    
  447. }
  448.  
  449.  
  450. //Auto Cycle Image
  451. var timer = window.CreateTimerInterval(15000);
  452. function on_timer() {
  453. if  (cycle==1)
  454. a.id++;
  455. if (a.id > 4) a.id = 0;
  456. a.metadb_changed();
  457. p.item_focus_change();
  458.                     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement