Advertisement
ExtremeHunter

Album Art Mire777

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