Skip to main content
Topic: JScript Panel script discussion/help (Read 75252 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

JScript Panel script discussion/help

Reply #50
Hi, i would like if somebody would post the most minimal scripts (wsh/jspanel) for the seekbar and volume. (maybe even other things if you have the will.)
so... solid colors, black on white, just the pure script, no @import .js stuff. so i can learn from that.

There are already minimal scripts here i know, but i find them slightly modified and its hard to modify/remove things i dont want. i want to start from the begining, thus the request.

also..
2.
i know how to make a square and circle with gr.Fill ... and all
but how do i make a triangle pointing this > direction. maybe you are already figured for what

3.
this is more advanced i guess and probably off topic.
is there a plugin/script/anything that gives foobar an ASCII visualisation, like the ones you can occasionaly spot in ncmpcpp on linux.

JScript Panel script discussion/help

Reply #51
1. #43 reply in this topic is my example of seekbar, though there still are some issues to solve...
2. You can use the polygon functions to draw triangles.
3. You mean the DOS-like interface? I guess you could make that with simply text drawing and on_key callbacks...

JScript Panel script discussion/help

Reply #52
Btw I think I've got it how to draw infusing shadows: by box blur...
That may be slow, but as I hate external images, that's affordable.
Those who remain at Pentium 4 and win xp don't deserve to enjoy my creations. Yup.

JScript Panel script discussion/help

Reply #53
Marc2003, I'm trying to combine AlbumArt sample with BoxBlur with no luck. Is it possible to do that albumart would be shown as blurry image?

JScript Panel script discussion/help

Reply #54
Insert this directly after var albumart = new _.albumart(0, 0, 0, 0);

Code: [Select]
albumart.metadb_changed = function () {
    if (panel.metadb) {
        this.img && this.img.Dispose();
        this.tooltip = "";
        this.path = "";
        var img = utils.GetAlbumArtV2(panel.metadb, this.id);
        if (img) {
            this.img = gdi.CreateImage(img.Width, img.Height);
            var g = this.img.GetGraphics();
            _.drawImage(g, img, 0, 0, img.Width, img.Height);
            this.img.ReleaseGraphics(g);
            this.img.BoxBlur(20, 2); //mess around with these values
            utils.GetAlbumArtAsync(window.ID, panel.metadb, this.id, true, false, true);
        }
        window.Repaint();
    }
}

JScript Panel script discussion/help

Reply #55
I just realised the above snippet will crash when there is no album art. This fixes it...

Code: [Select]
albumart.metadb_changed = function () {
    if (panel.metadb) {
        this.img && this.img.Dispose();
        this.tooltip = "";
        this.path = "";
        var img = utils.GetAlbumArtV2(panel.metadb, this.id);
        if (img) {
            this.img = gdi.CreateImage(img.Width, img.Height);
            var g = this.img.GetGraphics();
            _.drawImage(g, img, 0, 0, img.Width, img.Height);
            this.img.ReleaseGraphics(g);
            this.img.BoxBlur(20, 2); //mess around with these values
            utils.GetAlbumArtAsync(window.ID, panel.metadb, this.id, true, false, true);
        } else {
            this.img = null;
        }
        window.Repaint();
    }
}

JScript Panel script discussion/help

Reply #56
Marc2000, beautiful!!! Thanks a lot!!! This is the result:

JScript Panel script discussion/help

Reply #57
I'm using this code to love tracks with marc's button script
Code: [Select]
 fb.RunContextCommand("Last.fm/Last.fm Love Track '" + fb.TitleFormat("%title%").Eval() + "' By '" + fb.TitleFormat("%artist%").Eval() + "'");

When i click on it it freezes the whole foobar for like two seconds for it to love track  (not the playback ,but still very annoying- I can see this in the channel spectrum panel )
Is this a issue with Last.fm or what??

@marc
any chance including last.fm love/unlove part in your scripts(not playcount sync only love /unlove part)

JScript Panel script discussion/help

Reply #58
It looks like you're using foo_softplaylists so I guess that is the culprit? Surely you get the same delay when using the right click menu from the playlist??

As for me providing a script, not much chance of that. I simply can't be bothered with last.fm any more. FWIW, my old WSH panel mod scripts can still love/unlove tracks. It's just the server response is broken meaning the script doesn't update foo_customdb or display any message. If you check the WSH script thread, I've posted a hack to fix that. Of course you'll need a copy of the old script because I don't keep any of my old stuff.

JScript Panel script discussion/help

Reply #59
Ya same delay when using context menu  nothing to do then
I thought old script broked with new update to last.fm
Guess i can use it then

JScript Panel script discussion/help

Reply #60
Marc2003, can you show me a hint how to assign different font symbol to every element of PBOArray in PBOButton(Menu).txt sample? I'm trying to get rid of image icons at all.

JScript Panel script discussion/help

Reply #61
I want to have button to love/unlove based on rating
if loved -> rating =5
Unlove -> rating = 0
Code: [Select]
 buttons.buttons.love = new _.button(100, 0, 40, 40, {
        normal: _.tf("%rating%", panel.metadb) == 5 ? "buttons\\love_h.png" :"buttons\\love.png",
        hover :"buttons\\love_h.png"
    }, function() {

_.tf("%rating%", panel.metadb) == 5 ?fb.GetNowPlaying().UpdateFileInfoSimple("RATING",5,"RATING"): fb.GetNowPlaying().UpdateFileInfoSimple("RATING", 0, "RATING");
        
        


    }, "Love");

but it's not working
any idea why??

JScript Panel script discussion/help

Reply #62
@awx, use an array like this.

Code: [Select]
var symbols = ["a", "b", "c", "d", "e", "f", "g"];


Replace each letter with the character(s) from your font. Then inside your on_paint function, remove the code that draws the buttons and use gdi.DrawText with your custom font and this as the text

Code: [Select]
symbols[plman.PlaybackOrder]


@samithaj

Code: [Select]
panel.metadb.UpdateFileInfoSimple("RATING", panel.tf("%rating%") == 5 ? "" : 5);


Using double quotes deletes the tag. If you really want to write 0 then you can change it.

JScript Panel script discussion/help

Reply #63
@samithaj

Code: [Select]
panel.metadb.UpdateFileInfoSimple("RATING", panel.tf("%rating%") == 5 ? "" : 5);


Using double quotes deletes the tag. If you really want to write 0 then you can change it.

Thanks that worked
After updating to change the icon to love_h.png i used
Code: [Select]
 window.RepaintRect(buttons.buttons.love.x, buttons.buttons.love.y, buttons.buttons.love.w, buttons.buttons.love.h);

in the button's function
but it doesn't work, only after reloading the script it shows the updated icon image
sorry for all the stupid questions

JScript Panel script discussion/help

Reply #64
Presumably your code that creates the button is inside the on_metadb_changed callback? If not, it should be. The window.RepaintRect should be last line of code inside the callback, not inside the button function.

JScript Panel script discussion/help

Reply #65
Presumably your code that creates the button is inside the on_metadb_changed callback? If not, it should be. The window.RepaintRect should be last line of code inside the callback, not inside the button function.

worked after putting button inside the on_metadb_changed callback
Thanks again

JScript Panel script discussion/help

Reply #66
General question:

Is it possible to make a button in JScript with (switch to playlist) as menu?

Thx


Yes. If you browse samples that came with the component, take the MainMenuManager All-In-One.txt script and replace the menu function with this:

Code: [Select]
function menu() {
    var m = window.CreatePopupMenu();
    m.AppendMenuItem(MF_GRAYED, 0, "Switch to..."); //you wouldn't use an ID of 0 with a normal menu item but it's ok because this is greyed out.
    m.AppendMenuSeparator();
    for (var i = 0; i < plman.PlaylistCount; i++) {
        m.AppendMenuItem(MF_STRING, 1 + i, plman.GetPlaylistName(i).replace(/&/g, "&&"));
    }
    if (plman.ActivePlaylist > -1)
        m.CheckMenuRadioItem(1, plman.PlaylistCount + 1, plman.ActivePlaylist + 1);
    var idx = m.TrackPopupMenu(b.buttons.menu.x, b.buttons.menu.y);
    if (idx > 0)
        plman.ActivePlaylist = idx - 1;
    m.Dispose();
}

JScript Panel script discussion/help

Reply #67
General question:

Is it possible to make a button in JScript with (switch to playlist) as menu?

Thx


Yes. If you browse samples that came with the component, take the MainMenuManager All-In-One.txt script and replace the menu function with this:

Code: [Select]
function menu() {
    var m = window.CreatePopupMenu();
    m.AppendMenuItem(MF_GRAYED, 0, "Switch to..."); //you wouldn't use an ID of 0 with a normal menu item but it's ok because this is greyed out.
    m.AppendMenuSeparator();
    for (var i = 0; i < plman.PlaylistCount; i++) {
        m.AppendMenuItem(MF_STRING, 1 + i, plman.GetPlaylistName(i).replace(/&/g, "&&"));
    }
    if (plman.ActivePlaylist > -1)
        m.CheckMenuRadioItem(1, plman.PlaylistCount + 1, plman.ActivePlaylist + 1);
    var idx = m.TrackPopupMenu(b.buttons.menu.x, b.buttons.menu.y);
    if (idx > 0)
        plman.ActivePlaylist = idx - 1;
    m.Dispose();
}




Thank you working!!!! Great

JScript Panel script discussion/help

Reply #68
I'm not really sure why you removed the file. The error tells you exactly what to do:

Quote
"It appears the cached file has been corrupted. Use the right click menu>Force Update to try again."


If it's happening randomly (fixed by a forced update) then there isn't much I can do. If you can't get the bio of specific artist with multiple retries then I can take a look if you tell me what the artist is.

edit: If you reply, please do it in the script thread: https://www.hydrogenaud.io/forums/index.php?showtopic=110516


I had tried numerous times to update it, but that did not work so I tried removing the file to see if that would. As I mentioned in the other thread, other info (similar artist, other releases) does fetch fine.

This has happened with a few artists but the last 2 are

http://www.last.fm/music/This+Will+Destroy+You
http://www.last.fm/music/Maybeshewill

Thanks

JScript Panel script discussion/help

Reply #69
They both work fine for me so I blame your computer or internet connection.

Open js_marc2003\js\text.js in a text editor, go to line 338 and replace this...

Code: [Select]
            case "lastfm_bio":
                var content = _(_.getElementsByTagName(this.xmlhttp.responsetext, "div"))
                    .filter({"className" : "wiki-content"})
                    .map("innerHTML")
                    .stripTags()
                    .value();
                _.save(JSON.stringify([content]), f);
                this.artist = "";
                panel.item_focus_change();
                break;


with

Code: [Select]
            case "lastfm_bio":
                fb.ShowPopupMessage(this.xmlhttp.responsetext, 1);
                var content = _(_.getElementsByTagName(this.xmlhttp.responsetext, "div"))
                    .filter({"className" : "wiki-content"})
                    .map("innerHTML")
                    .value();
                fb.ShowPopupMessage(content, 2);
                content = _.stripTags(content);
                fb.ShowPopupMessage(content, 3);
                fb.ShowPopupMessage(JSON.stringify([content]), 4);
                break;


Delete the cached file and then let the script run. 4 popup windows should open at once and I'd like to see the contents of each one. Each window will be labelled with a number 1-4. Use something like pastebin for the first window because it should be a large chunk of html.

JScript Panel script discussion/help

Reply #70
They both work fine for me so I blame your computer or internet connection.

Delete the cached file and then let the script run. 4 popup windows should open at once and I'd like to see the contents of each one. Each window will be labelled with a number 1-4. Use something like pastebin for the first window because it should be a large chunk of html.


Damn computer 

Those other 3 windows did indeed show the bio.

HTML
https://copy.com/9Ui6X0t3qXJz9MKt

Window 2
https://copy.com/lQLIBInfZ1UKmijH

Window 3
https://copy.com/9N1lCTnCfoImIXA1

Window 4
https://copy.com/iGxONECt8hWOdFnf


Thanks

JScript Panel script discussion/help

Reply #71
Well if the bio is fine there, the only thing that can break it from that point onwards is the process of saving it to disk. All my scripts use the same _.save function though so I can't explain why it only seems to happen randomly in the bio script???

JScript Panel script discussion/help

Reply #72
Well if the bio is fine there, the only thing that can break it from that point onwards is the process of saving it to disk. All my scripts use the same _.save function though so I can't explain why it only seems to happen randomly in the bio script???


It does create a "bio.www.last.fm.json" file but it's empty. When I try to copy and paste from the actual bio, the file gets wiped once I play a song. I made the file "read only" but even that never gets loaded. However, if I choose another Last.fm site, it works  . Now I just need to brush up on my French or German or Italian or etc. 

Oh well, thanks for your time.

Cheers

JScript Panel script discussion/help

Reply #73
However, if I choose another Last.fm site, it works 


That really makes no sense at all.  But given your location says Canada, French should be no problem for you. 

JScript Panel script discussion/help

Reply #74
I have a panel for "playback button + status bar" within single panel.
The little buggy point is that the panel doesn't refresh when I resize foobar.
The buttons and status information stick to the initial postion even after I resized my foobar.
So,  I want to know if there is any method to refresh this panel whenever I change the foobar size.
Thank you for your help.
Code: [Select]
// ==PREPROCESSOR==
// @name "Playback Buttons"
// @author "marc2003"
// @import "%fb2k_profile_path%js_marc2003\js\lodash.min.js"
// @import "%fb2k_profile_path%js_marc2003\js\helpers.js"
// @import "%fb2k_profile_path%js_marc2003\js\panel.js"
// ==/PREPROCESSOR==

var panel = new _.panel("Playback Buttons", ["custom_background"]);
var buttons = new _.buttons();
var bs = 32;
var guifx_font = _.gdiFont(guifx.font, 8, 1);

var ww = window.Width;
var wh = window.Height;

var left_text_tf = "%playback_time%[ / %length%] :: %__bitrate% kbps %codec% [%codec_profile% ]";
var text_colour = _.RGB(40, 40, 40);

var show_volume = window.GetProperty("2K3.STATUS.SHOW.VOLUME", true);
var font = _.gdiFont("Segoe UI", 11);
var count = 0;
var right_text = "";
var right_text_width = 0;
refresh();

buttons.buttons.menu = new _.button(5, 5, bs, bs, {normal : "buttons\\menu.png"}, function () { _.menu(0, 16); }, "Menu");
buttons.buttons.stop = new _.button(ww/2-2*bs-15, 5, bs, bs, {normal : "buttons\\stop.png"}, function () { fb.Stop(); }, "Stop");
buttons.buttons.play = new _.button(ww/2-bs-5, 5, bs, bs, {normal : !fb.IsPlaying || fb.IsPaused ? "buttons\\play.png" : "buttons\\pause.png"}, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? "Play" : "Pause");
buttons.buttons.previous = new _.button(ww/2+5, 5, bs, bs, {normal : "buttons\\previous.png"}, function () { fb.Prev(); }, "Previous");
buttons.buttons.next = new _.button(ww/2+bs+15, 5, bs, bs, {normal : "buttons\\next.png"}, function () { fb.Next(); }, "Next");

buttons.update = function () {
this.buttons.play = new _.button(ww/2-bs-5, 5, bs, bs, {normal : !fb.IsPlaying || fb.IsPaused ? "buttons\\play.png" : "buttons\\pause.png"}, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? "Play" : "Pause");
window.RepaintRect(this.buttons.play.x, this.buttons.play.y, this.buttons.play.w, this.buttons.play.h);
}

function on_playlist_stop_after_current_changed() {
window.RepaintRect(buttons.buttons.stop.x, buttons.buttons.stop.y, buttons.buttons.stop.w, buttons.buttons.stop.h);
}

function on_size() {
panel.size();
window.MinHeight = 45;
window.MaxHeight = 45;
}

function on_paint(gr) {
panel.paint(gr);
buttons.paint(gr);
gr.SetTextRenderingHint(4);
if (fb.StopAfterCurrent)
gr.DrawString("", guifx_font, _.RGB(196, 30, 35), buttons.buttons.stop.x, buttons.buttons.stop.y + 1, buttons.buttons.stop.w, buttons.buttons.stop.h, SF_CENTRE);
if (fb.IsPlaying)
gr.GdiDrawText(_.tfe(left_text_tf), font, text_colour, 0, 2, ww - 55, font.Height, RIGHT);
if (count > 0)
gr.GdiDrawText(right_text, font, text_colour, 0, 22, ww - 5, font.Height, RIGHT);
if (show_volume)
gr.GdiDrawText(fb.Volume.toFixed(2) + " dB", font, text_colour, 0, 2, ww - 5, font.Height, RIGHT);
}

function on_playback_stop() {
buttons.update();
window.Repaint();
}

function on_playback_pause() {
buttons.update();
}

function on_playback_starting() {
buttons.update();
}

function on_mouse_move(x, y) {
buttons.move(x, y);
}

function on_mouse_leave() {
buttons.leave();
}

function on_mouse_lbtn_up(x, y) {
buttons.lbtn_up(x, y);
}

function on_mouse_rbtn_up(x, y) {
if (buttons.buttons.stop.trace(x, y)) {
var m = window.CreatePopupMenu();
m.AppendMenuItem(MF_STRING, 1, "Stop After Current");
m.CheckMenuItem(1, fb.StopAfterCurrent);
m.AppendMenuSeparator();
m.AppendMenuItem(MF_STRING, 2, "Configure...");
var idx = m.TrackPopupMenu(x, y);
if (idx == 1)
fb.StopAfterCurrent = !fb.StopAfterCurrent;
else if (idx == 2)
window.ShowConfigure();
m.Dispose();
return true;
} else {
return panel.rbtn_up(x, y);
}
}

function on_playback_time() {
window.Repaint();
}

function on_volume_change() {
window.Repaint();
}

function on_mouse_wheel(s) {
if (!show_volume)
return;
if (s == 1)
fb.VolumeUp();
else
fb.VolumeDown();
}

function on_mouse_lbtn_dblclk() {
fb.RunMainMenuCommand("View/Show now playing in playlist");
}

function on_mouse_rbtn_up(x, y) {
if (utils.IsKeyPressed(VK_SHIFT))
return false;
var m = window.CreatePopupMenu();
var c = fb.CreateContextMenuManager();
if (fb.IsPlaying) {
c.InitNowPlaying();
c.BuildMenu(m, 1, -1);
m.AppendMenuSeparator();
}
m.AppendMenuItem(MF_STRING, 10000, "Show volume");
m.CheckMenuItem(10000, show_volume);
m.AppendMenuSeparator();
m.AppendMenuItem(MF_STRING, 10001, "Configure...");
var idx = m.TrackPopupMenu(x, y);
switch (true) {
case idx == 0:
break;
case idx == 10000:
show_volume = !show_volume;
window.SetProperty("2K3.STATUS.SHOW.VOLUME", show_volume);
window.Repaint();
break;
case idx == 10001:
window.ShowConfigure();
break;
default:
c.ExecuteByID(idx - 1);
break;
}
m.Dispose();
c.Dispose();
return true;
}

function on_playlist_items_added(p) {
if (p == plman.ActivePlaylist)
refresh();
}

function on_playlist_items_removed(p) {
if (p == plman.ActivePlaylist)
refresh();
}

function on_playlist_switch() {
refresh();
}

function refresh() {
var items = plman.GetPlaylistItems(plman.ActivePlaylist);
count = items.Count;
right_text = count + (count == 1 ? " track :: " : " tracks :: ") + utils.FormatDuration(items.CalcTotalDuration()) + " :: " + utils.FormatFileSize(items.CalcTotalSize());
right_text_width = _.textWidth(right_text, font);
window.Repaint();
items.Dispose();
}

 
SimplePortal 1.0.0 RC1 © 2008-2018