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

WSH Panel Mod script discussion/help

Reply #3075
How does the second line differ from the first in how a search is conducted? I could offer a guess but I already make myself look stupid on a regular basis without guessing lol.


only one of my various artist albums exists on allmusic and it's rather odd that it's not found if various artists is sent as part of the search. it is found if i omit it and search for the album title only.


like i said, i only have one example that uses Various Artists (most of my compilations are DJ mixes and i use the DJ name as the album artist)

artist: Various artists
album: Verve Remixed
original query: http://www.allmusic.com/search/albums/Verve Remixed Various artists finds no matches.

the modified query omits sending the artist if it is Various Artists

modified query: http://www.allmusic.com/search/albums/Verve Remixed gets the right match. obviously testing one album is hardly conclusive which is why i posted that bit of code for you to try yourself.

WSH Panel Mod script discussion/help

Reply #3076
Hi again. It's regarding marc2003's splendid Spectrogram Seekbar. I often find myself in need to check spectrograms with Audition you see, and this thing has possibilities to work as a quick and proper replacement.

Hence if you'll have time, could you please remove the seekbar and modify it so the pannel would a] go fullscreen and back on middle mouse key click for better view(like a default 'Spectrogram' component does) b] display spec of a file selected in the playlist, not the one that's playing(like 'Album Art Viewer' does) c] start processing only after LM click on WSH pannel. I hope you'll make it possible, with those features foobar becomes much more cozy.

Thanks in advance.

WSH Panel Mod script discussion/help

Reply #3077
a) not possible with WSH panel mod
b) i'm not changing the behaviour of my panel but you can display the images created by my seekbar. as they are just png files, you can configure the album art display in the main foobar preferences (file>preferences>display>album art). here you need to choose an album art type not in use like back or artist. then you need to configure it something like this....

Code: [Select]
c:\users\marc\appdata\roaming\foobar2000\spectrogram_cache\$crc32(%path%)channels 1 spectrogram -Y 130.png


or if running foobar in portable mode

Code: [Select]
E:\foobar2000\spectrogram_cache\$crc32(%path%)channels 1 spectrogram -Y 130.png


if you've changed the sox params in the seekbar script then you need to update the paths above.

you can then use my artreader panel to display them. right click and choose the right album art type and make sure to select Stretch as well. lastly, right click>Selection mode>follow selected track.

c) i'm not making that change.

WSH Panel Mod script discussion/help

Reply #3078
a) not possible with WSH panel mod


So then... Could you mod the panel itself? With the next update maybe?

b) i'm not changing the behaviour of my panel


Maybe you could just let foobar control it? Would that be possible? This way the end-user will be able to set it as he needs.

I don't really need B if I can't make it go fullscreen. Maybe there still is a way?

c) i'm not making that change.


I'm not asking you to change the thing entirely, just show a way how that could be achieved? (if that is achievable currently?)

WSH Panel Mod script discussion/help

Reply #3079
a) i have nothing to do with component development. that requires serious c++ skills which i do not have.
b) yeah you can do that with the default artwork panel or you can right click my artreader panel>selection mode>use display preferences.
c) i'm not making any changes to make it scan on demand. it takes less than a second on a normal length track so there is no point.

WSH Panel Mod script discussion/help

Reply #3080
Okay man, I hear you. Then how about making spectrogram open via default image viewer on middle mouse click?

WSH Panel Mod script discussion/help

Reply #3081
Heyho,
I was looking a long time for a Foobar skin I really liked, and I finally found this one: http://foo-nation.deviantart.com/#/art/Foo...-396911955?hf=1
I made a few adjustments of things I didnt like about it. I also disabled the Windows aero border completly, because it looks ugly with this skin. 
That opened up problems: I could not minimize, close or move the window the same as before.
I now move the window with the middle mouse button, which is fine.
I also added a button to fb.exit(); the window.

I minimize the window by pressing escape, but I'd much rather would like to have a button I can click on to minimize in some situations.
Is there a way to do that?

Any help would be very much appreciated

WSH Panel Mod script discussion/help

Reply #3082
Code: [Select]
fb.RunMainMenuCommand("View/Hide");

WSH Panel Mod script discussion/help

Reply #3083
Hi Marc.  In the past, I have used your scripts as a basis to create mine.  Among them, I have modified your script that downloads artist art from last.fm using the standalone art.exe.  Currently, I'm unable to download the artist images any more.  As far as I know, art.exe doesn't do its job:
Code: [Select]
"C:\Users\rol\AppData\Roaming\foobar2000\wsh_scripts\art.exe" "Fleetwood Mac" "D:\My Music\lastfm_artist_data\Fleetwood Mac" 10
artist:Fleetwood Mac

save_path:D:\My Music\lastfm_artist_data\Fleetwood Mac\

images:10 images
images to be fetched:

Then the exe returns immediately, without having downloaded anything.

Is it a new version of art.exe that works correctly?  If it's the case, where can I download it?  (I can't find it in your recent Samples archive.)
Or is it an alternative that doesn't need art.exe?  In the latter case, what script should I use?

Sorry if that question has already been answered.  I really can't search the numerous post of the whole thread.

WSH Panel Mod script discussion/help

Reply #3084
that stopped working months ago when last.fm shut down their artist images API feed.

i have a workaround in place. the thumbs script in my current pack downloads exactly the same images but it's quite a bit slower than the old method. if you use it, make sure you read the Help dialog on the right click menu as it explains a few things.

the code is bit of a mess so i just suggest using as it is rather than trying to pick it apart.

WSH Panel Mod script discussion/help

Reply #3085
OK, thanks.
I've also noticed changes in the last.fm behaviour, but I was not sure for the images.  Pity!  :-(

WSH Panel Mod script discussion/help

Reply #3086
i've just updated my allmusic review script.

as it doesn't always find what you're looking for, i've added a new option to the right click menu - Paste text from clipboard. if you find the review text manually or just want to add your text for albums that haven't been found, this is a quick way to save it. it will save/overwrite without prompting and the display will update immediately.

right click panel>Update script

full download: https://dl.dropboxusercontent.com/u/22801321/wsh/samples.zip


WSH Panel Mod script discussion/help

Reply #3087
so ive downloaded the latest samples package and opened the text for the spectrogram seekbar, ive installed the dependencies into *\sox\ and now im confused.. i see a whole mess of code, but no idea what to do with it. ive never used any scripts for foobar, only components or wsh panel (which is scripted, but i know where those scripts are located).. so, any chance someone could tell me what to do with the code thats found in spectrogram seekbar.txt ??

thx

WSH Panel Mod script discussion/help

Reply #3088
you need to check steps 1-5 of the bundled readme.pdf file.


WSH Panel Mod script discussion/help

Reply #3090
very nice indeed. im impressed. I spent a lot of time manually mapping all of these colors to the standard spectrogram panel that is used for DefaultUI, and took a very long time to do but now i have an intimate understanding of the color scheme and such. anyways, im curious how you did the mapping? is that something you did yourself or is that done by sox alone? the colors are pretty similar to audition, so i probably wouldnt change much anyways, but just curious if it's even possible.
thx for this great tool.. ill have to look through all of your others and surely ill find something else worth using. cheers

Edit: also, is there a way to add the axes and legend? I read about it in the sox documentation but it seems maybe you wrote it out?

WSH Panel Mod script discussion/help

Reply #3091
i automatically apply the -r command line option which gives the "raw" output without axes. doing this means i don't have to do any extra work making the progress marker/seekbar functionality fit the image. no matter how you resize the panel, the progress marker should always line up with what you see. if i was to consider allowing axes, i can no longer use the full width/height of the panel and i'd have to try and calculate the dimensions of just the spectrogram part of the image. if the borders were fixed size no matter what options you set, it may be possible to get it right but i've not tried it.

you can use most other SoX spectrogram options from the manual by right clicking the panel>SoX options.  the colours you're seeing are the default. -m, -h and -p let you tinker with them a bit but you don't get much control. check sox.pdf for more details.

WSH Panel Mod script discussion/help

Reply #3092
i automatically apply the -r command line option which gives the "raw" output without axes. doing this means i don't have to do any extra work making the progress marker/seekbar functionality fit the image. no matter how you resize the panel, the progress marker should always line up with what you see. if i was to consider allowing axes, i can no longer use the full width/height of the panel and i'd have to try and calculate the dimensions of just the spectrogram part of the image. if the borders were fixed size no matter what options you set, it may be possible to get it right but i've not tried it.

you can use most other SoX spectrogram options from the manual by right clicking the panel>SoX options.  the colours you're seeing are the default. -m, -h and -p let you tinker with them a bit but you don't get much control. check sox.pdf for more details.


i see now.. well, this is pure genius. I had always wished the default ui version would be a static spectrogram instead of scrolling throughout the track.. and this is exactly what i wanted.. its just like Audition! Thanks a lot for the work you put into this!

WSH Panel Mod script discussion/help

Reply #3093
May want to ask, is this Panel Mod allows us to drag&drop songs into the playlist between other existing songs but not add to last?

for example, I got a playlist like this:

1. A
2. B
3. C
4. D
5. E

If I drop new songs (lets call it Z) into this playlist, it will add to the last as 6th song in the playlist, like this:

1. A
2. B
3. C
4. D
5. E
6. Z <== new song

But what I want to do is I want to add the new song between 2nd and 3rd , like this

1. A
2. B
3. Z <== new song
4. C
5. D
6. E

I have searched long time for this in google, seems no one talk about this....

WSH Panel Mod script discussion/help

Reply #3094
it's not possible directly. the drag/drop function built-in to the component doesn't appear to accept any parameters.

it *might* be possible to hack something together yourself though. after the mouse button is released, you may be able to move the dropped tracks using plman.MovePlaylistSelection. i've never used these functions myself though so i can't be any more specific. maybe if falstaff/extremehunter read this, they might have some ideas as they have both coded their own WSH playlists.

WSH Panel Mod script discussion/help

Reply #3095
hkg196418

Code: [Select]
function on_playlist_items_added(playlist) {

    var selectionCount = plman.GetPlaylistSelectedItems(playlist).Count;
    var move = 2; // move items between 2 and 3
    //if(filesDropped)
    plman.MovePlaylistSelection(playlist, -plman.PlaylistItemCount(playlist) + move + selectionCount);

}

WSH Panel Mod script discussion/help

Reply #3096
just updated the thread to say i'm no longer supporting my discogs script. next month it will stop working because it will require user accounts and authorisation. i'm not messing about with that.


WSH Panel Mod script discussion/help

Reply #3097
First of all, i have no idea how foobar scripting works, i tried to copy & paste from other skins, always ends in trial & error.

\user-components\foo_uie_wsh_panel_mod\samples\MainMenuManager All-In-One.txt

Code: [Select]
// vi:set ft=javascript ff=dos ts=4 sts=4 sw=4 et:

// ==PREPROCESSOR==
// @name "MainMenuManager All-In-One"
// @author "YBStone"
// Modded by T.P Wang
// ==/PREPROCESSOR==

// Flags, used by Menu
var MF_SEPARATOR = 0x00000800;
var MF_ENABLED = 0x00000000;
var MF_GRAYED = 0x00000001;
var MF_DISABLED = 0x00000002;
var MF_UNCHECKED = 0x00000000;
var MF_CHECKED = 0x00000008;
var MF_STRING = 0x00000000;
var MF_POPUP = 0x00000010;
var MF_RIGHTJUSTIFY = 0x00004000;

function on_mouse_lbtn_up(x, y) {

    var basemenu = window.CreatePopupMenu();
    var contextman = fb.CreateContextMenuManager();

    contextman.InitNowPlaying();

    var child1 = window.CreatePopupMenu(); //File
    var child2 = window.CreatePopupMenu(); //Edit
    var child3 = window.CreatePopupMenu(); //View
    var child4 = window.CreatePopupMenu(); //Playback
    var child5 = window.CreatePopupMenu(); //Library
    var child6 = window.CreatePopupMenu(); //Help
    var child7 = window.CreatePopupMenu(); //Now playing

    var menuman1 = fb.CreateMainMenuManager();
    var menuman2 = fb.CreateMainMenuManager();
    var menuman3 = fb.CreateMainMenuManager();
    var menuman4 = fb.CreateMainMenuManager();
    var menuman5 = fb.CreateMainMenuManager();
    var menuman6 = fb.CreateMainMenuManager();

    child1.AppendTo(basemenu, MF_STRING, "File");
    child2.AppendTo(basemenu, MF_STRING, "Edit");
    child3.AppendTo(basemenu, MF_STRING, "View");
    child4.AppendTo(basemenu, MF_STRING, "Playback");
    child5.AppendTo(basemenu, MF_STRING, "Library");
    child6.AppendTo(basemenu, MF_STRING, "Help");
    child7.AppendTo(basemenu, MF_STRING, "Now Playing");

    menuman1.Init("file");
    menuman2.Init("edit");
    menuman3.Init("View");
    menuman4.Init("playback");
    menuman5.Init("library");
    menuman6.Init("help");

    menuman1.BuildMenu(child1, 1, 200);
    menuman2.BuildMenu(child2, 201, 200);
    menuman3.BuildMenu(child3, 401, 200);
    menuman4.BuildMenu(child4, 601, 300);
    menuman5.BuildMenu(child5, 901, 300);
    menuman6.BuildMenu(child6, 1201, 100);

    contextman.InitNowPlaying();
    contextman.BuildMenu(child7, 1301, -1);
    ret = 0;

    ret = basemenu.TrackPopupMenu(x, y);

    // fb.trace(ret);
    switch (true) {
    case(ret >= 1 && ret < 201):
        menuman1.ExecuteByID(ret - 1);
        break;

    case (ret >= 201 && ret < 401):
        menuman2.ExecuteByID(ret - 201);
        break;

    case (ret >= 401 && ret < 601):
        menuman3.ExecuteByID(ret - 401);
        break;

    case (ret >= 601 && ret < 901):
        menuman4.ExecuteByID(ret - 601);
        break;

    case (ret >= 901 && ret < 1201):
        menuman5.ExecuteByID(ret - 901);
        break;

    case (ret >= 1201 && ret < 1301):
        menuman6.ExecuteByID(ret - 1201);
        break;

    case (ret >= 1301):
        contextman.ExecuteByID(ret - 1301);
        break;
    }

    basemenu.Dispose();
    contextman.Dispose();
    menuman1.Dispose();
    menuman2.Dispose();
    menuman3.Dispose();
    menuman4.Dispose();
    menuman5.Dispose();
    menuman6.Dispose();
}


Above sample is 99% fine, the only problem is that whereever you click in the panel (blank space), the menu pops out. What i want is to have a clickable button with the following image (don't know why imagebam made it .jpg, it's actually a .png), meaning only a click on the image/button pops out the menu...



Workaround is to use WSH Panel Mod within a Panel Stack Splitter (imagebutton) and adjusting the size, but i'm not fond of this idea.

Anyone with the skills to help me out? btw is it possible to port above script to Panel Stack Splitter?

WSH Panel Mod script discussion/help

Reply #3098
First of all, i have no idea how foobar scripting works, i tried to copy & paste from other skins, always ends in trial & error.

\user-components\foo_uie_wsh_panel_mod\samples\MainMenuManager All-In-One.txt


Above sample is 99% fine, the only problem is that whereever you click in the panel (blank space), the menu pops out. What i want is to have a clickable button with the following image (don't know why imagebam made it .jpg, it's actually a .png), meaning only a click on the image/button pops out the menu...



Workaround is to use WSH Panel Mod within a Panel Stack Splitter (imagebutton) and adjusting the size, but i'm not fond of this idea.

Anyone with the skills to help me out? btw is it possible to port above script to Panel Stack Splitter?

I changed your script , so you can set your button image. Menu pops up -only on button left click.
Your buttons must be located in '[foobar main folder]\image'
Buttons must be named: menu1.png, menu2.png.

Edit this 295 line, to set 'button position' and 'image path':

//Button position
var top_margin = 5;
var left_margin = 5;
 
var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
var image_path = (image_path0 + "\\");

Paste this script:

Code: [Select]
// vi:set ft=javascript ff=dos ts=4 sts=4 sw=4 et:
// ==PREPROCESSOR==
// @name "MainMenuManager All-In-One"
// @author "YBStone"
// Modded by T.P Wang
// ==/PREPROCESSOR==

// Flags, used by Menu
var MF_SEPARATOR = 0x00000800;
var MF_ENABLED = 0x00000000;
var MF_GRAYED = 0x00000001;
var MF_DISABLED = 0x00000002;
var MF_UNCHECKED = 0x00000000;
var MF_CHECKED = 0x00000008;
var MF_STRING = 0x00000000;
var MF_POPUP = 0x00000010;
var MF_RIGHTJUSTIFY = 0x00004000;

function on_mouse_rbtn_up(x, y) {
up(x, y);
return true;
}

function up(x, y) {

    var basemenu = window.CreatePopupMenu();
    var contextman = fb.CreateContextMenuManager();
    contextman.InitNowPlaying();

    var child1 = window.CreatePopupMenu(); //File
    var child2 = window.CreatePopupMenu(); //Edit
    var child3 = window.CreatePopupMenu(); //View
    var child4 = window.CreatePopupMenu(); //Playback
    var child5 = window.CreatePopupMenu(); //Library
    var child6 = window.CreatePopupMenu(); //Help
    var child7 = window.CreatePopupMenu(); //Now playing

    var menuman1 = fb.CreateMainMenuManager();
    var menuman2 = fb.CreateMainMenuManager();
    var menuman3 = fb.CreateMainMenuManager();
    var menuman4 = fb.CreateMainMenuManager();
    var menuman5 = fb.CreateMainMenuManager();
    var menuman6 = fb.CreateMainMenuManager();

    child1.AppendTo(basemenu, MF_STRING, "File");
    child2.AppendTo(basemenu, MF_STRING, "Edit");
    child3.AppendTo(basemenu, MF_STRING, "View");
    child4.AppendTo(basemenu, MF_STRING, "Playback");
    child5.AppendTo(basemenu, MF_STRING, "Library");
    child6.AppendTo(basemenu, MF_STRING, "Help");
    child7.AppendTo(basemenu, MF_STRING, "Now Playing");

    menuman1.Init("file");
    menuman2.Init("edit");
    menuman3.Init("View");
    menuman4.Init("playback");
    menuman5.Init("library");
    menuman6.Init("help");

    menuman1.BuildMenu(child1, 1, 200);
    menuman2.BuildMenu(child2, 201, 200);
    menuman3.BuildMenu(child3, 401, 200);
    menuman4.BuildMenu(child4, 601, 300);
    menuman5.BuildMenu(child5, 901, 300);
    menuman6.BuildMenu(child6, 1201, 100);

    contextman.InitNowPlaying();
    contextman.BuildMenu(child7, 1301, -1);
    ret = 0;

    ret = basemenu.TrackPopupMenu(x, y);

    // fb.trace(ret);
    switch (true) {
    case(ret >= 1 && ret < 201):
        menuman1.ExecuteByID(ret - 1);
        break;

    case (ret >= 201 && ret < 401):
        menuman2.ExecuteByID(ret - 201);
        break;

    case (ret >= 401 && ret < 601):
        menuman3.ExecuteByID(ret - 401);
        break;

    case (ret >= 601 && ret < 901):
        menuman4.ExecuteByID(ret - 601);
        break;

    case (ret >= 901 && ret < 1201):
        menuman5.ExecuteByID(ret - 901);
        break;

    case (ret >= 1201 && ret < 1301):
        menuman6.ExecuteByID(ret - 1201);
        break;
   
    case (ret >= 1301):
        contextman.ExecuteByID(ret - 1301);
        break;
    }
   
    basemenu.Dispose();
    contextman.Dispose();
    menuman1.Dispose();
    menuman2.Dispose();
    menuman3.Dispose();
    menuman4.Dispose();
    menuman5.Dispose();
    menuman6.Dispose();
}

//Buttons---------------------------------------------------
 
var Buttons;
var g_tooltip = window.CreateTooltip();
var g_down = false;
 
var btn_down = null;
var cur_btn = null;
 
ButtonStates = {
        normal: 0,
        hover: 1,
        down: 2
}
 
function Button(x, y, w, h, img_src, func, tiptext)  {
        this.left = x;
        this.top = y;
        this.w = w;
        this.h = h;
        this.right = x + w;
        this.bottom = y + h;
        this.func = func;
        this.tiptext = tiptext;
        this.state = ButtonStates.normal;
        this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
        this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
        this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
        this.img = this.img_normal;
     
        this.alterImage = function(img_src) {
    this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
    this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
    this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
             
    this.changeState(this.state);
        }
     
    this.traceMouse = function (x, y) {
    var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
    if (b)
    g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
    else
    this.changeState(ButtonStates.normal);
    return b;
        }
     
    this.changeState = function (newstate) {
    if (newstate != this.state)
    window.RepaintRect(this.left, this.top, this.w, this.h);
    this.state = newstate;
    switch (this.state)
    {
    case ButtonStates.normal:
    this.img = this.img_normal;
    break;
                     
    case ButtonStates.hover:
    this.img = this.img_hover;
    break;
                     
    case ButtonStates.down:
    this.img = this.img_down;
    break;
                     
    default:
    this.img = null;
                }
        }
     
    this.draw = function (gr) {
    this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
        }
     
    this.onClick = function () {
    this.func && this.func(x,y);
        }
     
    this.onMouseIn = function() {
    g_tooltip.Text = this.tiptext;
    g_tooltip.Activate();
        }
     
    this.onMouseOut = function() {
    g_tooltip.Deactivate();
        }
}
 
function buttonsDraw(gr) {
    for (i in Buttons) {
    Buttons[i].draw(gr);
        }
}
 
function buttonsTraceMouse(x, y) {
        var btn = null;
        for (i in Buttons) {
    if (Buttons[i].traceMouse(x, y) && !btn)
    btn = Buttons[i];
        }
 
        return btn;
}
 
function on_mouse_move(x, y) {
        var btn = buttonsTraceMouse(x, y);
     
        if (btn != cur_btn) {
    cur_btn && cur_btn.onMouseOut();
    btn && btn.onMouseIn();
        }
     
        cur_btn = btn;
}
 
function on_mouse_lbtn_down(x, y) {
        g_down = true;
        btn_down = cur_btn;
 
        if (cur_btn) {
    cur_btn.changeState(ButtonStates.down);
        }
}
 
function on_mouse_lbtn_up(x, y) {
        if (cur_btn) {
    cur_btn.changeState(ButtonStates.hover);
    if( btn_down == cur_btn )
    cur_btn.onClick(x, y);
        }
        g_down = false;
}
 
function on_mouse_leave() {
        if (cur_btn) {
    cur_btn.changeState(ButtonStates.normal);
        }
}
 
function on_size() {
        ww = window.Width;
        wh = window.Height;
    window.Repaint();
}
 
//Background
this.dui = window.InstanceType;
function on_paint(gr) {
     
    if (this.dui) {
    col = window.GetColorDUI(1);
    gr.FillSolidRect(0, 0, ww, wh, col);
    }
    else
    {
    col = window.GetColorCUI(3);   
    }
 
        buttonsDraw(gr);
     
}
 
function RGB(r,g,b) {
return (0xff000000|(r<<16)|(g<<8)|(b));
}
 
function on_colors_changed() {
window.Repaint();
}
 
//Init Buttons--------------------------------------------
 
//Custom colour
var custom = RGB(255,255,255);
 
//Button width
var bw = 24;
 
//Button height
var bh = 20;
 
//Button position
var top_margin = 5;
var left_margin = 5;
 
var image_path0 = window.GetProperty("Button Path", fb.ProfilePath + "image");
var image_path = (image_path0 + "\\");
 
//These 2 lines of code lock the panel size.
//window.MinWidth = window.MaxWidth = 24;
//window.MinHeight = window.MaxHeight = 20;
 
 
Buttons = {
        but1: new Button(left_margin,top_margin,bw,bh, {normal: image_path + "menu1.png", hover: image_path + "menu2.png"}, function(){
    up(24, 17);
    }, "Menu")

}

function on_mouse_rbtn_up(x, y) {
return true;
}

WSH Panel Mod script discussion/help

Reply #3099
Hi there, I could need some help with understanding the whole WSH thing.

Sample: SimpleFollowCursor.txt
http://pastebin.com/25wFZUqb
Code: [Select]
// vi:set ft=javascript ff=dos ts=4 sts=4 sw=4 et:

// ==PREPROCESSOR==
// @name "SimpleFollowCursor"
// @author "T.P Wang"
// ==/PREPROCESSOR==

// This is a helper function, for generating flags in DrawString()/MeasureString()
// args: h_align, v_align, trimming, flags
function StringFormat() {
    var h_align = 0,
        v_align = 0,
        trimming = 0,
        flags = 0;
    switch (arguments.length) {
        // fall-thru
    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);
}

// h_align/v_align:
// [url=http://msdn.microsoft.com/en-us/library/ms534177(VS.85).aspx]http://msdn.microsoft.com/en-us/library/ms534177(VS.85).aspx[/url]
StringAlignment = {
    Near: 0,
    Center: 1,
    Far: 2
};

// trimming:
// [url=http://msdn.microsoft.com/en-us/library/ms534403(VS.85).aspx]http://msdn.microsoft.com/en-us/library/ms534403(VS.85).aspx[/url]
StringTrimming = {
    None: 0,
    Character: 1,
    Word: 2,
    EllipsisCharacter: 3,
    EllipsisWord: 4,
    EllipsisPath: 5
};

// flags, can be combined of:
// [url=http://msdn.microsoft.com/en-us/library/ms534181(VS.85).aspx]http://msdn.microsoft.com/en-us/library/ms534181(VS.85).aspx[/url]
StringFormatFlags = {
    DirectionRightToLeft: 0x00000001,
    DirectionVertical: 0x00000002,
    NoFitBlackBox: 0x00000004,
    DisplayFormatControl: 0x00000020,
    NoFontFallback: 0x00000400,
    MeasureTrailingSpaces: 0x00000800,
    NoWrap: 0x00001000,
    LineLimit: 0x00002000,
    NoClip: 0x00004000
};

function RGB(r, g, b) {
    return (0xff000000 | (r << 16) | (g << 8) | (b));
}


// APPLICATION - START
g_focus_metadb = fb.GetFocusItem();
g_font = gdi.Font("Tahoma", 12, 0);
g_tfo = fb.TitleFormat("%title%[ - %artist%][' ['%playback_time%']']\n$if(%ispaused%,' (Paused)')");
g_stringformat = StringFormat(StringAlignment.Center, StringAlignment.Center);

// Key point

function on_item_focus_change() {
    g_focus_metadb = fb.GetFocusItem();
    var info = g_focus_metadb.GetFileInfo();
    window.Repaint();
}

function on_paint(gr) {
    // Draw info
    if (g_focus_metadb) {
        gr.DrawString(g_tfo.EvalWithMetadb(g_focus_metadb), g_font, RGB(0, 0, 0), 0, 0, window.Width, window.Height, g_stringformat);
    }
}
// APPLICATION - END

First of all some basic JavaScript stuff...

Quote
29.  return ((h_align << 28) | (v_align << 24) | (trimming << 20) | flags);

65.  function RGB(r, g, b) {
66.    return (0xff000000 | (r << 16) | (g << 8) | (b));
67.  }
I'm not very familiar with all these bit shift operations. Could someone explain what's happening here like I'm 6?

Now the WSH part... (There is no real documentation of the API, just lists of available functions, variables, etc.)

Quote
on_paint(gr) {}
function on_paint(gr) is something like window.onload() in JS DOM, so everything within this function is only executed once, static. Am I right?
How can I manage to have dynamic output?

Quote
DrawString(str, IGdiFont, color, x, y, w, h, flags = 0);
flags... I'm really struggling with them

After looking at the script for a while and according to MSDN:
Quote
87.  gr.DrawString(g_tfo.EvalWithMetadb(g_focus_metadb), g_font, RGB(0, 0, 0), 0, 0, window.Width, window.Height, g_stringformat);
g_stringformat = StringFormat(StringAlignment.Center, StringAlignment.Center);
g_stringformat = StringFormat(1, 1);
=>
  h_align = 0,
  v_align = 1,
  trimming = 0,
  flags = 0;
=>
    return ((h_align << 28) | (v_align << 24) | (trimming << 20) | flags);


And that's where I get lost. Could somebody explain that too?

Quote
function on_playback_new_track() {}
function on_playback_dynamic_info_track() {}
What's the difference between those two?

My code so far (which is not working anyway)
Code: [Select]
var $tf = fb.TitleFormat("%artist% - %title%");
var $text = $tf.Eval();
// PAINT UI
var $textcolor = 0xff000000;
var $font = gdi.Font("Tahoma", 14, 1);
var $x = 0;
var $y = 0;
var $w = window.Width;
var $h = window.Height;
var $stringformat = 0;

function $upd() {
    $tf = fb.TitleFormat("%artist - %title%");
    window.Repaint();
    }

function on_playback_new_track() {
    $upd();
    }

function on_paint(gr) {
    gr.DrawString($text, $font, $textcolor, $x, $y, $w, $h, $stringformat);
    }

It only displays the Tag info once at code startup/initialize.
What am I doing wrong?

 
SimplePortal 1.0.0 RC1 © 2008-2019