// -------------------------------------------------------------------------------------- // WSHtpc01 // Description: a fullscreen now-playing script for foo_uie_wsh_panel // Author: ojdo // Version: 0.3 // --------------------------------------------------------------------------------------- // HELPER FUNCTIONS var showArtistArt = true; var showArtistArtalways = false; var AlbumArtMaxSize = 300; function StringFormat() { var h_align = 0, v_align = 0, trimming = 0, flags = 0; switch (arguments.length) { // fall-through case 4: flags = arguments[3]; case 3: trimming = arguments[2]; case 2: v_align = arguments[1]; case 1: h_align = arguments[0]; break; default: return 0; } return ((h_align << 28) | (v_align << 24) | (trimming << 20) | flags); } 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)); } // INITIALIZATION var g_albumart = null, g_albumart_rot = null; var g_disc = null, g_disc_rot = null; var g_artist = null, g_artist_rot = null; var album_w=0, album_h=0, album_x=0, album_y=0; var artist_w, artist_h, artist_x, artist_y; var g_font_title = gdi.Font("Calibri", 36, 0); var g_font_album = gdi.Font("Calibri", 28, 0); var g_font_artist = gdi.Font("Calibri", 22, 0); var g_font_time = gdi.Font("Calibri", 14, 0); var g_font_misc = gdi.Font("Calibri", 16, 0); var g_color_title = RGB(255,255,255); var g_color_misc = RGB(99,99,99); var g_color_time = RGB(77,77,77); var g_stringformat = StringFormat(0, 0,4); var title, artist, album, rating, mood, tracknumber, discnumber, totaltracks, totaldiscs, infoline, pbtime; var ww = 0, wh = 0; // Window width, height var g_handle = null; // metadb handle variable for watching the currently played track AlbumArtId = { front: 0, back: 1, disc: 2, icon: 3, artist: 4 }; var PlaybackOrderText = new Array("Default", "Repeat (Playlist)", "Repeat (Track)", "Random", "Shuffle (tracks)", "Shuffle (albums)", "Shuffle (folders)"); // evoke callback function to initially paint the window on_playback_new_track(fb.GetNowPlaying()); // ----------------------------------------------------------------------- // DRAW CANVAS CONTENT function on_paint(gr) { gr.SetTextRenderingHint(5); // enable cleartype font rendering // Background gr.FillSolidRect(0, 0, ww, wh, RGB(0,0,0)); gr.FillGradRect(0, 0.7*wh, ww, 0.2*wh, 90,RGB(26,26,26), RGBA(77,77,77,0)); // Albumart: Calculations and reflection if(g_albumart) { var album_scale_w = Math.min(AlbumArtMaxSize,0.44*ww) / g_albumart.Width; var album_scale_h = Math.min(AlbumArtMaxSize,0.93*(0.75*wh)) / g_albumart.Height; var album_scale = Math.min(album_scale_w, album_scale_h); album_w = g_albumart.Width * album_scale; album_h = g_albumart.Height * album_scale; album_x = 0.47*ww-album_w; album_y = 0.75*wh-album_h; gr.DrawImage(g_albumart_rot, album_x, album_y+album_h, album_w, album_h, 0, 0, g_albumart.Width, g_albumart.Height); gr.FillGradRect(album_x,album_y+album_h,album_w,wh/6, 90, RGBA(0,0,0,128), RGB(0,0,0)); gr.FillSolidRect(album_x,album_y+album_h+wh/6,album_w,5*wh/6, RGB(0,0,0)); } // Rating and Mood rating && gr.FillGradRect(0.49*ww, 0.7*wh-15, rating/5*ww/2.2, 2, 0, RGB(32,16,0), RGB(96,48,0)); mood && gr.FillGradRect(0.49*ww, 0.7*wh-8, mood/3*ww/2.2, 2, 0, RGB(0, 32,0), RGB(0,96,0)); // Artist & Title title && gr.DrawString(title, g_font_title, g_color_title, 0.49*ww, 0.7*wh-125, 0.5*ww, 50, g_stringformat); album && gr.DrawString(album, g_font_album, g_color_title, 0.49*ww, 0.7*wh-125+43, 0.5*ww, 35, g_stringformat); artist && gr.DrawString(artist, g_font_artist, g_color_title, 0.49*ww, 0.7*wh-125+80, 0.5*ww, 30, g_stringformat); // Infoline infoline && gr.DrawString(infoline, g_font_misc, g_color_misc, 0.49*ww, 0.7*wh+5, ww/2.2, 60, g_stringformat); // Progress bar if (fb.PlaybackLength>0) { gr.FillGradRect(0,0.7*wh-1, fb.PlaybackTime/fb.PlaybackLength*ww, 2, 0, RGB(64,64,64),RGB(0,48,96)); gr.DrawString(fb.TitleFormat("%playback_time_remaining%").Eval(), g_font_time, g_color_time, (1-0.07-0.005)*ww, 0.7*wh+5, 0.07*ww, 20, StringFormat(2,0)); gr.DrawString(fb.TitleFormat("%playback_time%").Eval(), g_font_time, g_color_time, 0.005*ww, 0.7*wh+5, 0.07*ww, 20, StringFormat(0,0)); } // Albumart if (g_albumart) { gr.DrawImage(g_albumart, album_x, album_y, album_w, album_h, 0, 0, g_albumart.Width, g_albumart.Height); } // Artistart if (g_artist) { var artist_scale_w = Math.min(0.6*AlbumArtMaxSize,0.16*ww) / g_artist.Width; var artist_scale_h = Math.min(0.6*AlbumArtMaxSize,0.5*(0.75*wh)) / g_artist.Height; var artist_scale = Math.min(artist_scale_w, artist_scale_h); artist_w = g_artist.Width * artist_scale; artist_h = g_artist.Height * artist_scale; artist_x = album_x+album_w/2-artist_w/2; artist_y = 0.78*wh-artist_h; if(fb.PlaybackLength>0) { var pbratio = fb.PlaybackTime/fb.PlaybackLength; if(showArtistArtalways || pbratio < 0.1 || pbratio > 0.9) { gr.DrawImage(g_artist_rot, artist_x, artist_y+artist_h, artist_w, artist_h, 0, 0, g_artist.Width, g_artist.Height); gr.DrawImage(g_artist, artist_x, artist_y, artist_w, artist_h, 0, 0, g_artist.Width, g_artist.Height); gr.FillGradRect(artist_x,artist_y+artist_h,artist_w,wh/6, 90, RGBA(0,0,0,128), RGB(0,0,0)); gr.FillSolidRect(artist_x,artist_y+artist_h+wh/6,artist_w,5*wh/6, RGB(0,0,0)); } } } } // ----------------------------------------------------------------------- // CALLBACKS // ----------------------------------------------------------------------- // window size changed function on_size() { ww = window.Width; wh = window.Height; } // new track function on_playback_new_track(metadb) { if (metadb) { utils.GetAlbumArtAsync(window.ID, metadb, AlbumArtId.front); //utils.GetAlbumArtAsync(window.ID, metadb, AlbumArtId.disc); showArtistArt && utils.GetAlbumArtAsync(window.ID, metadb, AlbumArtId.artist); } g_albumart = null; g_albumart_rot = null; g_disc = null; g_disc_rot = null; g_artist = null; g_artist_rot = null; if (g_handle) {window.UnwatchMetadb();} g_handle = fb.GetNowPlaying(); if (g_handle) { on_metadb_changed(); // calls on_metadb_changed() window.WatchMetadb(g_handle); } } // tag content changed function on_metadb_changed() { rating = fb.TitleFormat("%rating%").Eval(); if(rating == "?") rating=-1; mood = fb.TitleFormat("%mood%").Eval(); if(mood == "?") mood=-1; var old_infoline = infoline; title = fb.TitleFormat("%title%").Eval(); artist = fb.TitleFormat("%artist%").Eval(); album = fb.TitleFormat("$if2(%album%,)").Eval(); date = fb.TitleFormat("$if2(%date%,n/a)").Eval(); tracknumber = fb.TitleFormat("$if(%tracknumber%,$num(%tracknumber%,1))").Eval(); totaltracks = fb.TitleFormat("$if(%totaltracks%,$num(%totaltracks%,1))").Eval(); discnumber = fb.TitleFormat("[%discnumber%]").Eval(); totaldiscs = fb.TitleFormat("[%totaldiscs%]").Eval(); infoline = fb.TitleFormat( "[%genre%]"+ "[' '%style%]"+ "[' '%publisher%]"+ "$if(%tracknumber%,' '# $num(%tracknumber%,1)$if(%totaltracks%,/$replace($num(%totaltracks%,1),0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉)))"+ "$ifgreater(%totaldiscs%,1,' 'CD %discnumber%/$replace($num(%totaldiscs%,1),0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉),)"+ "$if(%date%,' 'Y$replace(%date%,0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉))"+ "$if(%play_count%,' 'PC$replace(%play_count%,0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉))"+ "$if(%first_played%,' : 'FP$replace($date(%first_played%),0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉,-,.))"+ "$if(%last_played%,' → 'LP$replace($date(%last_played%),0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉,-,.))"+ "$if(%length%,' 'LEN$replace(%length%,0,₀,1,₁,2,₂,3,₃,4,₄,5,₅,6,₆,7,₇,8,₈,9,₉,:,.))" ).Eval() + " Order: "+PlaybackOrderText[fb.PlaybackOrder]; window.RepaintRect(0.49*ww,0.7*wh-15,ww/2,10); // calls on_paint() if(old_infoline != infoline) { window.RepaintRect(0.49*ww, 0.7*wh+5, ww/2.2, 65+1); } } // time (each second) and on seeking function on_playback_time(time) { window.RepaintRect(0,0.7*wh+5,0.1*ww,20); window.RepaintRect(0.9*ww,0.7*wh+5,0.1*ww,20); window.RepaintRect(0,0.7*wh-1,ww,3); if(g_artist) { window.RepaintRect(artist_x,artist_y,artist_w+1,2*artist_h+1); } } function on_playback_seek(time) { on_playback_time(time); } // playback order changed function on_playback_order_changed(new_order_index) { on_metadb_changed(); } // playback stopped function on_playback_stop(reason) { if(reason != 2) { // starting_another g_albumart = null; g_albumart_rot = null; g_disc = null; g_disc_rot = null; g_artist = null; g_artist_rot = null; title = ""; artist = ""; album = ""; rating=0; mood=0; infoline = ""; window.Repaint(); } } // album art retrieved function on_get_album_art_done(metadb, art_id, image) { if(image) { switch(art_id) { case AlbumArtId .front: g_albumart = image; g_albumart_rot = g_albumart.Clone(0, 0, g_albumart.Width, g_albumart.Height); g_albumart_rot.RotateFlip(6); break; case AlbumArtId.disc: g_disc = image; g_disc_rot = g_disc.Clone(0, 0, g_disc.Width, g_disc.Height); g_disc_rot.RotateFlip(6); break; case AlbumArtId.artist: g_artist = image; g_artist_rot = g_artist.Clone(0, 0, g_artist.Width, g_artist.Height); g_artist_rot.RotateFlip(6); break; } window.Repaint(); // calls on_paint() } } function on_mouse_lbtn_dblclk(x, y, mask) { on_playback_new_track(fb.GetNowPlaying()); } // EOF