Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: WSH Panel Mod (Read 814860 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

WSH Panel Mod

Reply #925
Nevertheless i've made those two toolbars to replace foobar's standard ones :
Volume :
Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }
var g_font = gdi.Font("Tahoma", 12, 0);
var g_drag = 0;
var ww = 100;
var hofset = 5;
var wh = 12;
function on_paint(gr){
    var vofset = (window.Height-wh)/2;
    var grad = Math.pow((100+fb.Volume)/100,2);
    var i = 0;
    while (i < ww+1) {
        var col = (grad<=0)  ? RGB(168,168,168) : (i<=grad*ww) ? RGB(32+128*i/ww,164*(1-i/ww),32*(1-i/ww)) :  RGB(168,168,168);
        gr.FillSolidRect(hofset+1+i,vofset,4,wh, col);
        i = i +5;   
    }
    gr.DrawRect(hofset,vofset, i, wh, 1.0, RGB(192,192,192));
}
function on_mouse_lbtn_down(x,y){
    g_drag = 1;
}
function on_mouse_lbtn_up(x,y){
    on_mouse_move(x,y);
    g_drag = 0;
}
function on_mouse_move(x,y){
    if(g_drag){
        var v = (x-hofset)/ww;
        v = (v<0) ? 0 : (v<1) ? v : 1;
        v = 100 * (Math.pow(v,1/2) - 1);
        fb.Volume = v;
    }   
}
function on_mouse_wheel(delta){
    if(delta>0)
        fb.VolumeUp();
    else
        fb.VolumeDown();
}
function on_volume_change(val){
    window.Repaint();
}
function on_playback_time(time){
window.Repaint();
}
//EOF


Seekbar:
Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }
var g_font = gdi.Font("Tahoma", 12, 0);
var g_drag = 0;
var ww = 270;
var hofset = 10;
var wh = 12;
function on_paint(gr){
var vofset = (window.Height-wh)/2;
var length = fb.PlaybackLength;
var grad = 0;
if (length > 0) {
grad = fb.PlaybackTime/fb.PlaybackLength;}

var i = 0;
while (i < ww+1) {

var col = (grad<=0)  ? RGB(168,168,168) : (i<=grad*ww) ? RGB(0,32+48*(1-i/ww),96+64*(1-i/ww)) :  RGB(128+48*(1-i/ww),128+48*(1-i/ww),128+48*(1-i/ww));
gr.FillSolidRect(hofset+1+i,vofset,4,wh, col);
i = i +5;
}
gr.DrawRect(hofset,vofset, i, wh, 1.0, RGB(192,192,192));
}
function on_mouse_lbtn_down(x,y){
g_drag = 1;
}
function on_mouse_lbtn_up(x,y){
on_mouse_move(x,y);
g_drag = 0;
}
function on_mouse_move(x,y){
if(g_drag){
var v = (x-hofset)/ww;
v = (v<0) ? 0 : (v<1) ? v : 1;
fb.PlaybackTime = fb.PlaybackLength * v;



}

}
function on_mouse_wheel(delta){
if(delta>0)
fb.PlaybackTime = fb.PlaybackTime + delta;
else
fb.PlaybackTime = fb.PlaybackTime + delta;
}
function on_playback_new_track(info){
window.Repaint();
}
function on_playback_stop(){
window.Repaint();
}
function on_playback_seek(time){
window.Repaint();
}
function on_playback_time(time){
window.Repaint();
}



how can i change the background color of the seekbar (CUI)?

regard

WSH Panel Mod

Reply #926
Is it possible to give verbose names to the WSH Panel GUI ID?

WSH Panel Mod (GUID: "my panel name"): initliased in 5 ms
instead of
WSH Panel Mod (GUID: 179D50A2-0F18-422F-97C9-6760D953EB02): initliased in 5 ms
?
would be helpful!

WSH Panel Mod

Reply #927
Is it possible to give verbose names to the WSH Panel GUI ID?

WSH Panel Mod (GUID: "my panel name"): initliased in 5 ms
instead of
WSH Panel Mod (GUID: 179D50A2-0F18-422F-97C9-6760D953EB02): initliased in 5 ms
?
would be helpful!

you can use window.ID to retrieve the specified WSH panel ID~
mad messy misanthropist morbid mused

 

WSH Panel Mod

Reply #929
why? in the Oxford Dictionary the "-ise"and "isation" are sorted in British English....

"Initialised" is a word.  "Initliased" is not.  This whole discussion was started to correct a spelling mistake, but some people incorrectly thought it was a British vs. American English argument.

WSH Panel Mod

Reply #930
In Preferences: WSH Panel Mod
Code: [Select]
Name: api.vbscript
Value: $(dir.component)interface.api


Is there a value for %fb_profile_path% to use in the editor properties? Because my *.api files are located in %fb_profile_path%\user-components\foo_uie_wsh_panel_mod

WSH Panel Mod

Reply #931
Problem with Meta values of internet radios:

Open an internet radio, for example http://209.9.238.4:9178/

In F2K (not WSH), when it is not playing, "%title% contains the name of the radio, in my example, "Stellar Attraction - Progressive Rock Heaven (Yes, Pink Floyd, Genesis, ELP, Jethro Tull et al)", and %artist% is undefined.  When the radio is playing, %title% and %artist% contain the title and artist names of the currently playing track.

In WSH, this code gives always the name of the radio:
Code: [Select]
metadb = fb.GetNowPlaying();
fb.trace(fb.TitleFormat("%title%").EvalWithMetadb(metadb));
metadb.Dispose();

and %artist% is always undefined.

I have also tried to use IFbFileInfo.MetaValue(), but the result is identical.

I have the same problem with Last.fm radios.

I need to retrieve the artist and title names when a radio is playing.  Is it possible?  Have I missed something?

WSH Panel Mod

Reply #932
@r0lZ


This is all discussed before! Search the topic.

change this line fb.trace(fb.TitleFormat("%title%").Eval());


WSH Panel Mod

Reply #933
Thanks!

I had tried to search the answer myself, but the problem with large thread such as this one is that you have to know the answer to find it!  ;-)

BTW, now I know how to do it, but I still doesn't understand the exact difference between Eval() and EvalWithMetadb(handle_to_now_playing_metadb)
The only thing I've found on that subject is this:
PS:
The Eval() method is applied to now playing metadb handle, implicitly.

Can you please explain exactly what Eval() and Eval(force) are supposed to do?

WSH Panel Mod

Reply #934
Copy this code to wsh panel and then try to select tracks on your playlist when foobar is playing and when stopped, you'll see the differences.




Code: [Select]
function RGB(r, g, b) {
return (0xff000000 | (r << 16) | (g << 8) | (b));
}
 
    var g_font = gdi.font("Tahoma", 16, 0);
 
    var text1 = fb.TitleFormat("[%tracknumber%. ][%title%][ - %artist%]");
    var text2 = fb.TitleFormat("[%tracknumber%. ][%title%][ - %artist%]");
    var text3 = fb.TitleFormat("[%tracknumber%. ][%title%][ - %artist%]");

 
  function on_paint (gr) {
     
   
    var metadb = fb.GetFocusItem(); 
 
gr.GdiDrawText("Eval(true)    "+text1.Eval(true), g_font, RGB(0,0,0), 20, 20, ww, 20, 0);
gr.GdiDrawText("Eval(false)    "+text2.Eval(false), g_font, RGB(0,0,0), 20, 50, ww, 20, 0);
if(metadb)
gr.GdiDrawText("EvalWithMetadb(metadb)    "+text3.EvalWithMetadb(metadb), g_font, RGB(0,0,0), 20, 80, ww, 20, 0);


}
function on_size() {

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

}

function on_playback_new_track() {
// Called when new track titles has been changed
    window.Repaint();
}

function on_playback_dynamic_info_track() {
// Called when stream track titles has been changed
    window.Repaint();
}

function on_item_focus_change() {
// Called when playlist focus has been changed
    window.Repaint();
}
function on_playback_stop(reason) {
    if (reason != 2)
    window.Repaint();
    }

WSH Panel Mod

Reply #935
Huge thanks!  I really appreciate your help.

I had already tested the behaviour of Eval() and EvalWithMetadb() (with matadb created with GetNowPlaying, GetFocusItem and GetSelection).  But I did my test on a playlist containing only local files, so my opinion was that Eval(true) is equivalent of EvalWithMetadb(now_playing_db).  I know now that it is different.  But it's that difference that I still don't understand clearly.

My misunderstanding does not come from WSH, but probably from my ignorance of the way the meta values are handled by F2K and the streaming protocols.  I don't understand why two similar functions, both accessing the same meta field in the stream (for example %title%) can return a different string.  I suppose that there are two kinds of meta data, "static" (always identical), and "dynamic" (depending of the current flow).  Is it correct?  Also, can I assume that Eval(false) returns the currently playing subsong data in files with "chapters"?  (I don't have that kind of files here so I can't test right now.)

WSH Panel Mod

Reply #936
the script ExtremeHunter posted should work because it contains the on_playback_dynamic_info_track() callback??

(admittedly i haven't tested myself as i don't listen to any streams)

WSH Panel Mod

Reply #937
I add to use on_playback_dynamic_info_track() to refresh the (real) artist and title names in my script when a radio is playing.  It works as expected and is not called too often.  :-)

BTW, on the subject of callbacks, I have another question.  I want to select the next (or previous) playlist and play it.  It is easy to write a function that changes the playlist and issue fb.Play().  But I want to check if the new playlist contains something, and, in a loop, select the next one if it's not the case, and that's much more difficult.

As far as I know, there is no way to count the items in the current playlist.  So, I imagined that I could test fb.IsPlaying after the Play command.  If the result is false, I can assume that the playlist is empty, and select automatically the next playlist.  But the problem is that bf.IsPlaying is ALWAYS true when it is just after Play().  I have noticed that it becomes false after a short time (less than 250 ms).  So, I have to add a delay between Play() and the IsPlaying test.  In other words, I need a Sleep() function.

I've checked the available functions on the M$ site, and Sleep exists, but it is tied to the Windows Scripting Host engine, and apparently not available under WSH for F2K.  Since I'm a total newbie in jscript, I may not have called it the right way.  Someone can explain how to call that function in a F2K panel?  Is it possible?

Anyway, without that function, I've implemented what I need with WSH timers.  That works fine, but it's not elegant at all, I need global variables, and the script is uselessly complicated.  So, if the normal Sleep() function cannot be used, I would like to write that function myself.  It's perhaps possible using the on_timer callback, but honestly I don't know how.  I've tried many methods, but currently without success.  Only an infinite loop waiting for a global variable change seems to work, but I hate that method!  Someone has an idea?

Here is the script I have currently:
Code: [Select]
var g_stop_after_playlist_direction = 0;
var g_timer;

function play_adjacent_playlist(direction) {
    pl = fb.PlayingPlaylist + direction;
    if (pl < 0) pl = fb.PlaylistCount-1;
    if (pl >= fb.PlaylistCount) pl = 0;
    fb.PlayingPlaylist = pl;
    fb.Play();
    g_stop_after_playlist_direction = direction;
    g_timer = window.CreateTimerTimeout(250);
}

function on_timer(id) {
    if (g_timer && id == g_timer.ID && g_stop_after_playlist_direction) {
        if (! fb.IsPlaying) {
            play_adjacent_playlist(g_stop_after_playlist_direction);
        } else {
            g_stop_after_playlist_direction = 0;
            fb.ActivePlaylist = fb.PlayingPlaylist;
        }
        g_timer.Dispose();
    }
}

WSH Panel Mod

Reply #938
A new question (or suggestion):

Is it possible to check if a WSH panel is currently visible?  I have several WSH panels in tabs, and some of them are doing useless things, such as downloading/refreshing artist art or biography from last.fm, when nobody can see them.  I would like to check if the panel is visible, and do nothing when it's not the case.  If it's not possible, I suggest to add a callback, similar to on_focus(), when a panel is made visible or hidden.

WSH Panel Mod

Reply #939
from this old post about Flipping images :

@TomBarlow:
The Rotate() method in IGdiBitmap interface is TOTALLY BROKEN. I'll remove it later.
The "Rotate" should be add to DrawImage() as a prameter.

RotateFlip() apply current image only, that means, you should clone the image, and apply RotateFlip() to the new image, sample code
Code: [Select]
function get_album_art(metadb) {
if (metadb)
// Get front cover
return utils.GetAlbumArt(metadb.RawPath, 0);
}

var g_img = null;
var g_rotate_img = null;
var ww;

on_playback_new_track(fb.GetNowPlaying());

function on_paint(gr) {
if (g_img) {
gr.SetInterpolationMode(7); // Highest quality and also slowest
gr.DrawImage(g_img, 0, 0, 200, 200, 0, 0, g_img.Width, g_img.Height);
g_rotate_img && gr.DrawImage(g_rotate_img, 0, 200, 200, 200, 0, 0, g_rotate_img.Width, g_rotate_img.Height);
}
}

function on_size() {
ww = window.Width;
}

function on_playback_new_track(metadb) {
if (!metadb) return;

g_img = get_album_art(metadb);
g_rotate_img = g_img.Clone(0, 0, g_img.Width, g_img.Height);
g_rotate_img.RotateFlip(2); // 180
window.Repaint();
}


Hi TP, RotateFlip is to keep, it's the only way to draw a mirror image (i've found), so when you said "The Rotate() method in IGdiBitmap interface is TOTALLY BROKEN. I'll remove it later.", i hope if you do it a day, it's because there is another way to flip (not rotate!) an image ? could you point me in the right direction please ?


thanx by advance

WSH Panel Mod

Reply #940
You can flip an image by giving it a negative width, like this:

Code: [Select]
//Normal 
gr.DrawImage(g_img, img_x, img_y, img_w, img_h, 0, 0, g_img.Width, g_img.Height);
//Flipped+Rotated
gr.DrawImage(g_img, img_x+img_w, img_y+img_h-1, -img_w, img_h/2, 0, 0, g_img.Width, g_img.Height,180,220);
//Mirror mask
gr.FillGradRect(img_x-1, img_y+img_h-2, img_w+2, img_h/2+2,91,RGBA(25,25,25,128),RGBA(25,25,25,255));


Does that help?



WSH Panel Mod

Reply #943
Does anyone know how to get the height of a column header? It doesn't seem to be on the list of things GetSystemMetrics can get, unless it is called something odd?

WSH Panel Mod

Reply #944
EDIT:
Searched Deeper,  found the answer

WSH Panel Mod

Reply #945
Sorry if this questions sounds dumb to advanced WSH users, but where can I find all the functions of foobar2000? By this I mean things like fb.Play(), fb.GetNowPlaying() etc. In short, all those "fb." things. Of course I looked into the text files that come with the .zip, but I didn't find anything like that. Thanks for helping me.

WSH Panel Mod

Reply #946
Quote
Of course I looked into the text files that come with the .zip, but I didn't find anything like that.


are you sure about that? have a look in interfaces.txt.

WSH Panel Mod

Reply #947
i have a very stupid question. is there some sort of introduction/tutorial/... available to get started with all this? i know how to code js/vbscript but i just have no clue how to even invoke the editor to edit something =)

WSH Panel Mod

Reply #948
Sorry if this questions sounds dumb to advanced WSH users, but where can I find all the functions of foobar2000? By this I mean things like fb.Play(), fb.GetNowPlaying() etc. In short, all those "fb." things. Of course I looked into the text files that come with the .zip, but I didn't find anything like that. Thanks for helping me.



They are in interface.api file, included in the archive, located in components folder, you can open it with notepad etc.

WSH Panel Mod

Reply #949
i have a very stupid question. is there some sort of introduction/tutorial/... available to get started with all this? i know how to code js/vbscript but i just have no clue how to even invoke the editor to edit something =)


When  you have read this topic and this link thru, then you know almost all about how to code in wsh, you have already big benefit, like you said you know how to code in js. I had to learn all of this from scratch.  But now i laugh how stupid i was six months ago