// ==PREPROCESSOR==
// @name "Status Bar / Mod"
// @author "marc2003 / ghstchldrn"
// @import "%fb2k_component_path%helpers.txt"
// @import "%fb2k_component_path%samples\js\lodash.min.js"
// @import "%fb2k_component_path%samples\js\common.js"
// @import "%fb2k_component_path%samples\js\volume.js"
// ==/PREPROCESSOR==
var left_text_playing = fb.TitleFormat("$if(%ispaused%,Paused...,Playing $replace(%codec%,Musepack,MPC,Vorbis,OGG,Monkey$char(39)s Audio,APE,aac,AAC,opus,OPUS,Opus,OPUS)[ · %bitrate% kbps][ · %__bitspersample%-bit][ · %samplerate% Hz][ · $caps(%channels%)][ · %length%][ – Playing $if2($info(video_codec),$if($or(%fy_title%,$strstr($info(@),fy+)),$replace($trim($substr(%video_file_stats%,$strchr(%video_file_stats%,|),$if2($strstr(%video_file_stats%, | aac),99))),| ,, |,, , $char(183) ,vp,VP,h,H.,av,AV,fps, fps,kbps, kbps)))])");
var right_text_playing = fb.TitleFormat("$puts(path,$if2($info(@),%path%))$puts(s,$if($strstr($get(path),fy+),12,$if($strstr($get(path),https),9,$if($strcmp($left($get(path),3),www),0,8))))$puts(domain,$left($substr($get(path),$get(s),999),$sub($strchr($substr($get(path),$get(s),999),/),1)))$if($or($strstr($get(path),http),$strstr($get(path),www)),From $char(91)$get(domain)$char(93),From $left(%path%,3))[$if(%__hdcd%, · HDCD %__hdcd_gain% '('Peak: $caps(%__hdcd_peak_extend%)')',)][ · Album %replaygain_album_gain%][ · Track %replaygain_track_gain%]");
var left_text_stopped = '';
var right_text_stopped = '';
var left_text_status = 'Stopped. ';
var properties = {
sl_count : new _p('Show Selection Count', true),
sl_duration : new _p('Show Selection Duration', true),
sl_size : new _p('Show Selection Size', true),
pl_name : new _p('Show Playlist Name', true),
pl_count : new _p('Show Playlist Count', true),
pl_duration : new _p('Show Playlist Duration', true),
pl_size : new _p('Show Playlist Size', true),
background : new _p('Custom Colour Background', RGB(51, 51, 51)),
text : new _p('Custom Colour Text', RGB(240, 240, 240))
};
var ww = 0;
var wh = 0;
var font = CreateFontString('Segoe UI Symbol', 9);
get_selection();
get_playlist();
function get_selection() {
var tmp = [];
var sl_items = fb.GetSelection(0);
var sl_count = sl_items.Count;
if (properties.sl_count.enabled) {
tmp.push(sl_count == 0 ? 'None' : sl_count + (sl_count == 1 ? ' Track' : ' Tracks'));
}
if (properties.sl_duration.enabled) {
tmp.push(utils.FormatDuration(sl_items.CalcTotalDuration()));
}
if (properties.sl_size.enabled) {
tmp.push(utils.FormatFileSize(sl_items.CalcTotalSize()));
}
sl_items.Dispose();
left_text_stopped = (properties.sl_count.enabled || properties.sl_duration.enabled || properties.sl_size.enabled ? 'Selection: ' : '') + tmp.join(' · ');
window.Repaint();
}
function get_playlist() {
var tmp = [];
var ap = plman.ActivePlaylist;
if (ap >= 0 && ap < plman.PlaylistCount) {
var pl_items = plman.GetPlaylistItems(ap);
var pl_count = pl_items.Count;
if (properties.pl_count.enabled) {
tmp.push(pl_count + (pl_count == 1 ? ' Track' : ' Tracks'));
}
if (properties.pl_duration.enabled) {
tmp.push(utils.FormatDuration(pl_items.CalcTotalDuration()));
}
if (properties.pl_size.enabled) {
tmp.push(utils.FormatFileSize(pl_items.CalcTotalSize()));
}
if (properties.pl_name.enabled) {
var str = plman.IsPlaylistLocked(ap) ? '🔒 ' : '';
str += plman.GetPlaylistName(ap);
tmp.push(str);
}
pl_items.Dispose();
}
right_text_stopped = (properties.pl_count.enabled || properties.pl_duration.enabled || properties.pl_size.enabled || properties.pl_name.enabled ? 'Playlist: ' : '') + tmp.join(' · ');
window.Repaint();
}
function on_mouse_lbtn_dblclk() {
fb.RunMainMenuCommand('View/Show now playing in playlist');
}
function on_mouse_rbtn_up(x, y) {
var menu = window.CreatePopupMenu();
var sub = window.CreatePopupMenu();
var colour_menu = window.CreatePopupMenu();
var context = fb.CreateContextMenuManager();
if (fb.IsPlaying) {
context.InitNowPlaying();
context.BuildMenu(sub, 1);
sub.AppendTo(menu, MF_STRING, 'Now playing');
menu.AppendMenuSeparator();
}
menu.AppendMenuItem(MF_STRING, 9000, 'Show selection count');
menu.CheckMenuItem(9000, properties.sl_count.enabled);
menu.AppendMenuItem(MF_STRING, 9001, 'Show selection duration');
menu.CheckMenuItem(9001, properties.sl_duration.enabled);
menu.AppendMenuItem(MF_STRING, 9002, 'Show selection size');
menu.CheckMenuItem(9002, properties.sl_size.enabled);
menu.AppendMenuSeparator();
menu.AppendMenuItem(MF_STRING, 10000, 'Show playlist name');
menu.CheckMenuItem(10000, properties.pl_name.enabled);
menu.AppendMenuItem(MF_STRING, 10001, 'Show playlist count');
menu.CheckMenuItem(10001, properties.pl_count.enabled);
menu.AppendMenuItem(MF_STRING, 10002, 'Show playlist duration');
menu.CheckMenuItem(10002, properties.pl_duration.enabled);
menu.AppendMenuItem(MF_STRING, 10003, 'Show playlist size');
menu.CheckMenuItem(10003, properties.pl_size.enabled);
menu.AppendMenuSeparator();
colour_menu.AppendMenuItem(MF_STRING, 10004, 'Background...');
colour_menu.AppendMenuItem(MF_STRING, 10005, 'Text...');
colour_menu.AppendTo(menu, MF_STRING, 'Colours');
menu.AppendMenuSeparator();
menu.AppendMenuItem(MF_STRING, 10010, 'Configure...');
var idx = menu.TrackPopupMenu(x, y);
menu.Dispose();
switch (idx) {
case 0:
break;
case 9000:
properties.sl_count.toggle();
get_selection();
break;
case 9001:
properties.sl_duration.toggle();
get_selection();
break;
case 9002:
properties.sl_size.toggle();
get_selection();
break;
case 10000:
properties.pl_name.toggle();
get_playlist();
break;
case 10001:
properties.pl_count.toggle();
get_playlist();
break;
case 10002:
properties.pl_duration.toggle();
get_playlist();
break;
case 10003:
properties.pl_size.toggle();
get_playlist();
break;
case 10004:
properties.background.value = utils.ColourPicker(properties.background.value);
window.Repaint();
break;
case 10005:
properties.text.value = utils.ColourPicker(properties.text.value);
window.Repaint();
break;
case 10010:
window.ShowConfigure();
break;
default:
context.ExecuteByID(idx - 1);
break;
}
context.Dispose();
return true;
}
function on_mouse_wheel(s) {
if (s < 0) fb.VolumeDown();
else fb.VolumeUp();
}
function on_mouse_mbtn_up() {
fb.VolumeMute();
}
function on_volume_change() {
window.Repaint();
}
function on_paint(gr) {
gr.Clear(properties.background.value);
if (fb.IsPlaying) {
gr.WriteText(left_text_playing.Eval(), font, this.properties.text.value, 5, 0, ww - 200 - utils.CalcTextWidth(right_text_playing.Eval(), 'Segoe UI', 9), 21, DWRITE_TEXT_ALIGNMENT_LEADING, DWRITE_PARAGRAPH_ALIGNMENT_NEAR, DWRITE_WORD_WRAPPING_NO_WRAP, DWRITE_TRIMMING_GRANULARITY_CHARACTER);
}
else {
gr.WriteText(left_text_status + left_text_stopped, font, this.properties.text.value, 5, 0, ww - 200 - utils.CalcTextWidth(right_text_stopped, 'Segoe UI', 9), 21, DWRITE_TEXT_ALIGNMENT_LEADING, DWRITE_PARAGRAPH_ALIGNMENT_NEAR, DWRITE_WORD_WRAPPING_NO_WRAP, DWRITE_TRIMMING_GRANULARITY_CHARACTER);
}
if (fb.IsPlaying) {
gr.WriteText(right_text_playing.Eval(), font, this.properties.text.value, 0, 0, ww - 130, 21, DWRITE_TEXT_ALIGNMENT_TRAILING);
}
else if (plman.ActivePlaylist > -1 && plman.ActivePlaylist < plman.PlaylistCount) {
gr.WriteText(right_text_stopped, font, this.properties.text.value, 0, 0, ww - 130, 21, DWRITE_TEXT_ALIGNMENT_TRAILING);
}
gr.WriteText(fb.Volume.toFixed(2) < -60.00 ? 'Muted' : fb.Volume.toFixed(2) + ' dB', font, this.properties.text.value, 0, 0, ww - 5, 21, DWRITE_TEXT_ALIGNMENT_TRAILING);
}
function on_playback_new_track() {
window.Repaint();
}
function on_playback_starting() {
left_text_status = 'Starting... ';
window.Repaint();
}
function on_playback_stop() {
left_text_status = 'Stopped. ';
window.Repaint();
}
function on_playback_pause() {
window.Repaint();
}
function on_playback_time() {
window.Repaint();
}
function on_playlist_items_added(p) {
if (p == plman.ActivePlaylist) {
get_playlist();
}
}
function on_playlist_items_removed(p) {
if (p == plman.ActivePlaylist) {
get_playlist();
}
}
function on_playlist_switch() {
get_playlist();
}
function on_playlists_changed() {
if (properties.pl_name.enabled) {
get_playlist();
}
}
function on_selection_changed() {
if (properties.sl_count.enabled || properties.sl_duration.enabled || properties.sl_size.enabled) {
get_selection();
}
}
function on_size() {
ww = window.Width;
wh = window.Height;
}