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 script discussion/help (Read 1389014 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

WSH Panel Mod script discussion/help

Reply #4150
This does not work.

Use ...


I didn't even start yet, don't have internet, so i can't try anything
My modem is dead..
Thanks.

WSH Panel Mod script discussion/help

Reply #4151
Hi folks,
It looks like I am extremely late to the party, and as such am going to get a few rolled eyes directed at me.
I'll confess I (like many here) have no experience programming javascript and as such everything is a point of learning.

I am currently just trying to make Marc2003's buttons panel have toggle button for stop after current.  One I understand that, and how it works, I can implement other toggle buttons for various things.
The thing is, I had gotten the button to change graphic depending on the status of the stop after current function, however, I have to open the WSH script and hit apply to make the button graphic change.  It's not updating by its self, and this must be because I am not invoking redrawing the panel for this.

Post #3 (yep, 5 years ago) in this thread is where I've started.  dui_buttons.js and marc2003.js
http://www.hydrogenaud.io/forums/index.php...st&p=680459

After making some simple and easy personal additions (a couple of variables), I added a condition for the button graphic, based on the status of StopAfterCurrent - however, it doesn't refresh by itself.  This is obviously not the way to do it.

Code: [Select]
but7: new Button(((bw + w_spacer)*6) + left_margin,top_margin,bw,bh, {
        normal: fb.StopAfterCurrent ? image_path + "SAC_on_36.png" : image_path + "SAC_off_36.png", hover: image_path + "SAC_h_36.png", down: fb.StopAfterCurrent ? image_path + "SAC_off_36.png" : image_path + "SAC_on_36.png"
        }, function(){fb.RunMainMenuCommand('Playback/Stop after current');}, "Stop After Current")


I've editing Delphi's "Stop after current" panel down to just being an indicator.
http://www.hydrogenaud.io/forums/index.php...st&p=739640

Icedtea is requesting help on the same kind of thing, but with a play/pause toggle. 
http://www.hydrogenaud.io/forums/index.php...st&p=684728

It would seem that I require tooltip_buttons.js or even a modified version of this.  However Marc2003's samples.zip link doesn't work for me at all.
http://cid-649d3bfeaf541fbb.skydrive.live....ide/samples.zip

Without me having to tread through 130+ pages (I've got to about page 30), am I missing something, have these resources moved?
I really do appreciate all the effort the relevant parties have put in, it's a great tool and the results can be awesome.

I'll refrain from asking for direct help in actually writing the script, as well, I'm sure you folks have better things to do than go back over something trivial from a few years ago.  If I can get the tools I need, then I can learn in my own time how this all falls together.  (I have started commenting dui_buttons.js just to understand how each bit works).

Thanks muchly for any help.

WSH Panel Mod script discussion/help

Reply #4152
you just need to add the following callback to your code...

Code: [Select]
function on_playlist_stop_after_current_changed() {
    //call the function that updates your buttons here
}

WSH Panel Mod script discussion/help

Reply #4153
you just need to add the following callback to your code...

Code: [Select]
function on_playlist_stop_after_current_changed() {
    //call the function that updates your buttons here
}


Thanks for replying so quickly Marc

That makes sense - even more sense, now because of what I just did.
I just put your WSH panel "Buttons = ( ... )" part, inside an "on_paint(gr){ <button stuff here> }" and it refreshed all of the buttons.

However, I can appreciate that it's inefficient, I guess it's redrawing the buttons constantly, even though there maybe no changes.

in dui_buttons.js the "on_paint(gr)" part includes the color for the window background, a solid fill of chosen color, "buttonsDraw(gr)"*, and the rectangle to give the window some 3D shape.

* function buttonsDraw(gr) is linked to "i" which I'm guessing is determined by the x/y mouse positions and therefore what button the mouse is over.

Hmm, now where would the button redrawing be called up, somewhere in dui_buttons.js ....
I'll try redirecting the result on status change to different places in dui_buttons.js, so far I haven't had any luck, but I'm sure I just haven't foun the right spot yet.

Thanks again for your help.

WSH Panel Mod script discussion/help

Reply #4154
Sorry for not getting it, but I've tried to send the "function on_playlist_stop_after_current_change() { . . . }" to multiple places in dui_buttons.js and can't get it to refresh.  I've also tried "function on_playlist_stop_after_current_change(state) { . . . }", but it's not that this bit is wrong, it's just where I am trying to send it.

Plugging in Delphi's code, into Marc2003's dui_buttons.js, gets me a graphic that changes based on the status of [stop after current], which is right next to the button that controls it, but, the button behaves just as the others.  In that it's a simple momentary switch, and doesn't change graphic itself to the 'down' state when [stop after current] is engaged.

Code: [Select]
function on_init(bool) {
    imgname =bool  ?   "sac_on_36.png" : "SAC_off_36.png";
    SAC = gdi.image(fb.FoobarPath + "scripts\\buttons\\" + imgname);
    window.Repaint();
};

on_init(fb.StopAfterCurrent);

function on_paint(gr){
    switch(window.GetProperty("mode", 1)) {
        case 1:
            col = window.GetColorDUI(1);
            break;
        case 2:
            col = utils.GetSysColor(4);
            break;
        case 3:
            col = custom;
            break;
    }
    gr.FillSolidRect(0, 0, ww, wh, col);
    buttonsDraw(gr);
    gr.DrawImage(SAC, 258, 6, 36, 36, 0, 0, 36, 36);
    gr.DrawRect(0,0, ww, wh, 1.0, -6250336);
}

function on_playlist_stop_after_current_changed(state) {on_init(fb.StopAfterCurrent);}


I see that buttonsDraw(gr) is something that calls for the buttons to be redrawn by on_paint(gr), but this seems selective, based on mouse over or mouse click, and I can't work out how to inject the necessary bits to make it work for the SAC button.

I've looked into using a variable with two states for the button normal graphic, however, this still doesn't work because the buttons are not being refreshed.  It's the same point that I need to find.

I have a feeling that I am overly complicating the situation.

I guess that it's not all that hard to make two images, make the button larger, and just use two halves for the status.  Whilst not all that pretty it does work.

WSH Panel Mod script discussion/help

Reply #4155
It has been so long I'm not here.

Can I know how to make the default "Simple Text Reader" by marc2003 to be responsive with foobar2000 state?

For example, I want the text being read to disappear when playback has not started or stopped, and instead it should display "No tracks played".

I did noticed this in his script
Code: [Select]
    if (!p.metadb) p.centre_text(gr, "[no selection]", p.normal_font, p.textcolour, 0, 0, t.w, t.h);
    else t.draw(gr);
but I never get that [no selection] text.

I'm using Windows Scripting Host Panel Modded v1.5.10 Modded by T.P. Wang
(or I installed the wrong version? It IS written as WSH Panel Mod in Installed Components list)



This is his full code
Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_profile_path%marc2003\common7.js"
// @name "Simple Text Reader"
// @author "marc2003"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==
var p = new panel("Simple Text Reader", ["metadb", "simple_text"]);
var t = new text(7, 10, p.w - 12, p.h - 15);

on_item_focus_change();

function on_size() {
    p.size();
    t.w = p.w - 12;
    t.h = p.h - 15;
    t.size();
}

function on_paint(gr) {
    p.draw_background(gr);
    p.left_text(gr, p.eval(t.title), p.title_font, p.textcolour_hl, 6, 6, p.w - 12, 14);
    gr.DrawLine(6, 19, p.w - 6, 19, 1, p.textcolour_hl);
    if (!p.metadb) p.centre_text(gr, "[no selection]", p.normal_font, p.textcolour, 0, 0, t.w, t.h);
    else t.draw(gr);
}

function on_metadb_changed() {
    t.metadb_changed();
}

function on_mouse_wheel(step) {
    t.wheel(step);
}

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

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

WSH Panel Mod script discussion/help

Reply #4156
Code: [Select]
if (fb.IsPlaying)
    t.draw(gr)
else
    p.centre_text(gr, "No tracks played.", p.normal_font, p.textcolour, 0, 0, t.w, t.h);


also, you need to add this extra bit of code not inside any other functions.

Code: [Select]
function on_playback_starting() {
    window.Repaint();
}

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

WSH Panel Mod script discussion/help

Reply #4157
I want calculate length of a string
so i used
Code: [Select]
// Used with GDI functions, such as GdiDrawText().
    uint CalcTextWidth(str, IGdiFont);

Like this
Code: [Select]
 fb.trace(CalcTextWidth("abcdef", gdi.Font("PCDE", 55, 3)));

And got this error :
WSH Panel Mod (Thumbs): Microsoft JScript runtime error:
Object expected
What am i doing wrong??

WSH Panel Mod script discussion/help

Reply #4158
@marc2003
The code works like a charm, thank you very much! 

By using logic, I also used the code you gave as a sample to change the title too.
The title will default to some text when not playing and change into track title when playing.

So, it will be like this when not playing anything


And this when it plays something
(eg. Rally Go Round)


I will dig further into these scripts stuffs and make more edits,
I feel kinda happy when I can display what I want...

If anyone wondered why I use this external text method to display lyrics, it's because I only save the romanized lyrics in FLAC, so I use external text to display original lyrics together with trilingual translations, they were saved in different files.

WSH Panel Mod script discussion/help

Reply #4159
Object expected
What am i doing wrong??


you either have to do it inside on_paint with gr like this...

Code: [Select]
//i think it's best practice to create the font once
var my_font = gdi.Font("PCDE", 55, 3);

function on_paint(gr) {
    fb.trace(gr.CalcTextWidth("abc", my_font));
}


if you want to do it in other functions, you have to do something a bit more messy like this...

Code: [Select]
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
fb.trace(temp_gr.CalcTextWidth("abc", my_font));
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;

WSH Panel Mod script discussion/help

Reply #4160
Code: [Select]
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
fb.trace(temp_gr.CalcTextWidth("abc", my_font));
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;


That worked  thanks a lot marc!!

WSH Panel Mod script discussion/help

Reply #4161
Hi Marc,
I'm really sorry to say this, but I cannot get a redraw of the button graphic.
I've worked out that in dui_buttons.js, it calls on the "Buttons" part in the WSH panel to get the info on what graphics to use, and where the positions are etc.  However, once this data has been acquired (on panel launch/manual refresh) the graphic is permanent.

I just can't figure out a way to get the "function Button" in dui_buttons.js to refresh the graphic data when a status, like Stop After Current, is changed.  Everything I have tried hasn't worked, or has made a crash.  I've double checked my brackets etc, it's not a silly error like that causing a crash. 

Do you have tooltip_buttons.js knocking around somewhere by chance?  This link:
http://cid-649d3bfeaf541fbb.skydrive.live....ide/samples.zip
doesn't work for me at all, I've registered but the file isn't there it tells me.
I have a feeling there maybe something in the code in this script that will make it all click for me...

I'd like tooltips to change as well, which ties in with the current layout of things.  If I can get "Buttons" in the WSH panel to be recalled, then it'll change the tooltip also (all birds with one stone),  else I may just leave the tooltip as is, knowing that putting inside the on_paint function will surely cause it to flicker, as you've documented somewhere.


Reading some other topics related to WSH, I can see that folks have given you a hard time, intentionally or not, and done that whole "I'm sure it'll take only a few minutes of your time" thing.  I can understand completely if you don't have time to, or just don't wish to assist further on this particular topic that I'm having a particular challenge with.  You've done a great deal already, as have a few other contributors.

I was looking around for it, and it's not there in js, the "CALL" function as in MS-DOS.  I thought about just simply making the script jump back to the top when the state of something is changed.  However, no "call" exists, and the way to implement it breaks all the rest of the code, so no deal that way - which is the wrong way to do it, I know.

Thanks again

WSH Panel Mod script discussion/help

Reply #4162
all my download links in this thread don't exist anymore. i'll post my latest buttons script later on/tomorrow.

WSH Panel Mod script discussion/help

Reply #4163
Hello marc2003 & everyone,

Last.fm Playcount Sync script recently started crashing on me (regularly) and I haven't found any info on this particular error text - from foobar console:
Code: [Select]
Error: WSH Panel Mod (Playcount Sync by marc2003): Microsoft JScript compilation error:
Syntax error
File: <main>
Ln: 178, Col: 2
<source text only available at compile time>

Not sure if this the correct thread in which I am supposed to post, apologies. Am I doing something stupid? Does anyone have any idea what's causing this error? Thank you. In case of usefulness, I'm posting my entire script code below:

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_profile_path%marc2003\common4.js"
// @import "%fb2k_profile_path%marc2003\tooltip_buttons.js"
// @name "Playcount Sync"
// @author "marc2003"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

var top_margin = 0;
var left_margin = 0;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var script_name = "Playcount Sync";
var selection_mode = 1;
var username_file = settings_path + "username";
var username = read(username_file);
var api_key_file = settings_path + "api_key";
var api_key = read(api_key_file);
var sql_file = data_folder + "test.sql";
var loved_working = null;
var playcount_working = null;
var page = 0;
var last_page = 0;
var auto_correct = window.GetProperty("auto_correct", true);
var auto_love = window.GetProperty("auto_love", false);
var auto_love_tf = window.GetProperty("auto_love_tf", "");
var bg = window.GetProperty("bg", 102);
var custom_background = window.GetProperty("custom_background", "");
var icon = window.GetProperty("icon", "tango");
var show_console = window.GetProperty("show_console", true);
var library = window.GetProperty("library", false);

var g_timer = window.SetInterval(function() {
var temp = page > 1 ? page - 1 : 1;
if (loved_working && page == last_page) {
xmlhttp.abort();
sync_library_loved(temp);
} else if (playcount_working && page == last_page) {
xmlhttp.abort();
sync_library_playcount(temp);
} else {
last_page = page;
}
}, 15000);

if (fb.IsPlaying) on_playback_new_track();
else if (g_metadb) on_item_focus_change();
else update_button();

function update_button() {
exclamation = icon == "tango" ? "exclamation.png" : "exclamation_small.png";
love = icon == "tango" ? "love.png" : "love_small.png";
love_h = icon == "tango" ? "love_h.png" : "love_h_small.png";
size = icon == "tango" ? 32 : 20;
switch(true) {
case !g_metadb:
n = exclamation;
h = exclamation;
tooltip = "No selection";
func = null;
break;
case !utils.CheckComponent("foo_customdb", true):
n = exclamation;
h = exclamation;
tooltip = "The foo_customdb component is not installed. Please refer to the readme.";
func = null;
break;
case username.length == 0:
case api_key.length != 32:
n = exclamation;
h = exclamation;
tooltip = "Please use the context menu to set your Last.fm username and API KEY.";
func = null;
break;
case !utils.CheckComponent("foo_softplaylists", true):
n = exclamation;
h = exclamation;
tooltip = "The foo_softplaylists component is required to love tracks.";
func = null;
break;
default:
n = old_userloved == 1 ? love_h : love;
h = old_userloved == 1 ? love : love_h;
tooltip = command;
func = function() { lfm_track(); }
break;
}
Buttons = { but: new Button(left_margin, top_margin, size, size, {normal: images_path + n, hover: images_path + h}, func, tooltip) };
window.Repaint();
}

function on_metadb_changed() {
if (!g_metadb) return;
artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
track = fb.TitleFormat("%title%").EvalWithMetadb(g_metadb);
old_userloved = fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(g_metadb) == 1 ? 1 : 0;
old_userplaycount = fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(g_metadb);
command = "Last.fm " + (old_userloved == 1 ? "Unlove" : "Love") + " Track '" + track + "' by '" + artist + "'";
crc32 = fb.TitleFormat("$crc32($lower(%artist%%title%))").EvalWithMetadb(g_metadb);
update_button();
}

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

function on_paint(gr) {
buttons_background(gr);
buttonsDraw(gr);
}

function on_notify_data(name, data) {
if (name == "lastfm_update" && data == 1) {
username = read(username_file);
api_key = read(api_key_file);
on_metadb_changed();
loved_working = null;
playcount_working = null;
}
}

function on_playback_new_track() {
time_elapsed = 0;
switch(true) {
case fb.PlaybackLength == 0:
target_time = 240;
break;
case fb.PlaybackLength >= 30:
target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240);
break;
default:
target_time = 5;
break;
}
on_item_focus_change();
}

function on_playback_time(time) {
time_elapsed++;
if (time_elapsed == 3 && auto_love && fb.TitleFormat(auto_love_tf).Eval() == 1 && old_userloved == 0) {
fb.trace(script_name + ": Automatically loving this track....");
lfm_track();
}
if (time_elapsed == target_time && (!library || fb.IsMetadbInMediaLibrary(g_metadb))) sync();
}

function lfm_track() {
fb.RunContextCommandWithMetadb(command, g_metadb, 8);
sync();
}

function sync() {
switch(true) {
case loved_working || playcount_working:
return;
case !utils.CheckComponent("foo_customdb", true):
fb.trace(script_name + ": Not contacting Last.fm. foo_customdb is missing.");
return;
default:
fb.trace(script_name + ": Contacting Last.fm....");
lastfm("&method=track.getinfo&artist=" + encodeURIComponent(artist) + "&track=" + encodeURIComponent(track) + "&autocorrect=" + (auto_correct ? 1 : 0), "foo_playcount_sync", function() { process(); });
}
}

function tf(value) {
value = value.replace(/'/g, "''");
value = value.replace(/,/g, "','");
value = value.replace(/\//g, "'/'");
value = value.replace(/\(/g, "'('");
value = value.replace(/\)/g, "')'");
value = value.replace(/\[/g, "'['");
return (value.replace(/\]/g, "']'"));
}

function process() {
parsed_data = JSON.parse(xmlhttp.responsetext);
if (parsed_data.error > 0) {
if (parsed_data.error == 6) fb.trace(script_name + ": artist / track not found.");
else fb.trace(script_name + ": " + xmlhttp.responsetext);
return;
}
fb.trace(script_name + ": Last.fm responded 'OK'");
userplaycount = parsed_data.track.userplaycount > 0 ? ++parsed_data.track.userplaycount : 1;
userloved = parsed_data.track.userloved == 1 ? 1 : 0;
if (fb.IsPlaying && time_elapsed >= target_time && fb.PlaybackLength > 29 && fb.PlaybackLength < 10800) {
switch(true) {
case userplaycount < old_userplaycount:
fb.trace(script_name + ": Playcount returned from Last.fm is lower than current value. Not updating.");
break;
case old_userplaycount == userplaycount:
fb.trace(script_name + ": No changes found. Not updating.");
break;
default:
fb.RunContextCommandWithMetadb("Customdb Delete Playcount", g_metadb, 8);
if (old_userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 0", g_metadb, 8);
var attempt = 0;
while(fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(g_metadb) != userplaycount && attempt <= 3) {
var query1 = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + userplaycount + '\\")\";';
WshShell.Run(fso.GetFile(script_path + "sqlite3.exe").ShortPath + " " + fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath + " " + query1, 0, true);
attempt++;
}
fb.RunContextCommandWithMetadb("Customdb Refresh", g_metadb, 8);
break;
}
}
if (old_userloved != userloved) fb.RunContextCommandWithMetadb("Customdb Love " + userloved, g_metadb, 8);
}

function sync_library_loved(p) {
if (loved_working == null) return(fb.trace(script_name + ": Import aborted."));
page = p;
lastfm("&method=user.getlovedtracks&limit=200&user=" + username + "&page=" + page, "foo_playcount_sync", function() { process_library_loved(); });
}

function process_library_loved() {
parsed_data = JSON.parse(xmlhttp.responsetext);
if (parsed_data.error > 0) {
loved_working = null;
fb.ShowPopupMessage("There is a problem with the Last.fm web services. Please try again later.\n\n" + xmlhttp.responsetext, script_name);
return;
}
if (page == 1) { try { pages = parsed_data.lovedtracks["@attr"].totalPages; } catch(e) {} }
if (pages > 0 && xmlhttp.responsetext.indexOf('{"lovedtracks":') == 0) {
for (i = 0; i < parsed_data.lovedtracks.track.length; i++) {
try {
var data = [];
data[0] = parsed_data.lovedtracks.track[i].artist.name;
data[1] = parsed_data.lovedtracks.track[i].name;
data[2] = 1;
if (data.length == 3) {
fb.trace(r + ": " + data[0] + " - " + data[1]);
url = fb.TitleFormat("$crc32($lower(" + tf(data[0]) + tf(data[1]) + "))").EvalWithMetadb(g_metadb);
sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","' + data[2] + '");' + "\n";
r++;
}
} catch(e) {
errors++;
}
}
fb.trace("Completed page " + page + " of " + pages + " (loved tracks)");
} else {
loved_page_errors++;
}
if (page < pages) {
page++;
sync_library_loved(page);
} else {
loved_working = null;
playcount_working = true;
pages = 0;
r = 1;
sync_library_playcount(1);
}
}

function sync_library_playcount(p) {
if (playcount_working == null) return(fb.trace(script_name + ": Import aborted."));
page = p;
lastfm("&method=library.gettracks&limit=100&user=" + username + "&page=" + page, "foo_playcount_sync", function() { process_library_playcount(); });
}

function process_library_playcount() {
parsed_data = JSON.parse(xmlhttp.responsetext);
if (parsed_data.error > 0) {
playcount_working = null;
fb.ShowPopupMessage("There is a problem with the Last.fm web services. Please try again later.\n\n" + xmlhttp.responsetext, script_name);
return;
}
if (page == 1) { try { pages = parsed_data.tracks["@attr"].totalPages; } catch(e) {} }
if (pages > 0 && xmlhttp.responsetext.indexOf('{"tracks":') == 0) {
for (i = 0; i < parsed_data.tracks.track.length; i++) {
try {
var data = [];
data[0] = parsed_data.tracks.track[i].artist.name;
data[1] = parsed_data.tracks.track[i].name;
data[2] = parsed_data.tracks.track[i].playcount;
if (data[2] == 0) {
page = pages;
break;
}
if (data.length == 3) {
fb.trace(r + ": " + data[0] + " - " + data[1] + " " + data[2]);
url = fb.TitleFormat("$crc32($lower(" + tf(data[0]) + tf(data[1]) + "))").EvalWithMetadb(g_metadb);
sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + data[2] + '");' + "\n";
r++;
}
} catch(e) {
errors++;
}
}
fb.trace("Completed page " + page + " of " + pages + " (playcount)");
} else {
playcount_page_errors++;
}
if (page < pages) {
page++;
sync_library_playcount(page);
} else {
try {
sql += "COMMIT;"
ts = fso.OpenTextFile(sql_file, 2, true, 0);
ts.WriteLine(sql);
ts.close();
import_sql();
} catch(e) {
}
playcount_working = null;
fb.trace("Loved track page errors: " + loved_page_errors + " (200 records are lost for every page that fails.)");
fb.trace("Playcount page errors: " + playcount_page_errors + " (100 records are lost for every page that fails.)");
fb.trace("Individual errors: " + errors);
}
}

function import_sql() {
try {
cmd_file = fso.GetFile(script_path + "lastfm_sql.cmd").ShortPath;
db_file = fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath;
WshShell.Run(cmd_file + " " + fso.GetFile(script_path + "sqlite3.exe").ShortPath + " " + db_file + " " + fso.GetFile(sql_file).ShortPath);
} catch(e) {
}
}

function on_mouse_move(x, y) {
buttonsMove(x, y);
}

function on_mouse_lbtn_up(x, y) {
buttonsUp(x, y);
}

function on_mouse_leave() {
buttonsLeave();
}

function on_mouse_rbtn_up(x, y) {
var _menu = window.CreatePopupMenu();
var _li = window.CreatePopupMenu();
var _au = window.CreatePopupMenu();
var _child = window.CreatePopupMenu();
var _auto = window.CreatePopupMenu();
var _icon = window.CreatePopupMenu();
var idx;
_li.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && !loved_working && !playcount_working && g_metadb && username.length > 0 && api_key.length == 32 ? MF_STRING : MF_GRAYED, 4, "Create and import SQL file");
_li.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && fso.FileExists(sql_file) ? MF_STRING : MF_GRAYED, 5, "Import SQL file");
_li.AppendMenuSeparator();
_li.AppendMenuItem(MF_STRING, 7, "Show console");
_li.CheckMenuItem(7, show_console);
_li.AppendTo(_menu, MF_STRING, "Library import");
_au.AppendMenuItem(MF_STRING, 6, "Use Last.fm auto-correct");
_au.AppendMenuItem(MF_STRING, 8, "Only update tracks in library");
_au.CheckMenuItem(6, auto_correct);
_au.CheckMenuItem(8, library);
_au.AppendTo(_menu, MF_STRING, "Auto-updates");
_menu.AppendMenuSeparator();
_auto.AppendMenuItem(MF_STRING, 200, "Off");
_auto.AppendMenuItem(MF_STRING, 201, "On");
_auto.CheckMenuRadioItem(200, 201, auto_love ? 201 : 200);
_auto.AppendMenuSeparator();
_auto.AppendMenuItem(auto_love ? MF_STRING : MF_GRAYED, 202, "Condition");
_auto.AppendTo(_menu, MF_STRING, "Automatically love tracks");
_menu.AppendMenuSeparator();
if (!dui) _child.AppendMenuItem(MF_STRING, 101, "None");
_child.AppendMenuItem(MF_STRING, 102, (dui ? "Default UI " : "Columns UI ") + "default");
_child.AppendMenuItem(MF_STRING, 103, "Splitter");
_child.AppendMenuItem(MF_STRING, 104, "Custom ");
_child.AppendMenuSeparator();
_child.AppendMenuItem(bg == 104 ? MF_STRING : MF_GRAYED, 105, "Set custom colour...");
_child.CheckMenuRadioItem(101, 104, bg);
_child.AppendTo(_menu, MF_STRING, "Background");
_menu.AppendMenuSeparator();
_icon.AppendMenuItem(MF_STRING, 20, "tango");
_icon.AppendMenuItem(MF_STRING, 21, "silk");
_icon.CheckMenuRadioItem(20, 21, icon == "tango" ? 20 : 21);
_icon.AppendTo(_menu, MF_STRING, "Icon");
_menu.AppendMenuSeparator();
_menu.AppendMenuItem(username.length > 0 ? MF_STRING : MF_GRAYED, 1, "Visit your Last.fm user profile page");
_menu.AppendMenuSeparator();
_menu.AppendMenuItem(!loved_working && !playcount_working ? MF_STRING : MF_GRAYED, 2, "Set your Last.fm username...");
_menu.AppendMenuItem(!loved_working && !playcount_working ? MF_STRING : MF_GRAYED, 3, "Set your API KEY...");
_menu.AppendMenuSeparator();
if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 9, "Properties");
_menu.AppendMenuItem(MF_STRING, 10, "Configure...");
idx = _menu.TrackPopupMenu(x, y);
switch(idx) {
case 1:
try {
WshShell.run("http://www.last.fm/user/" + encodeURIComponent(username));
} catch(e) {
MsgBox("Unable to launch your default browser.", 0, script_name);
}
break;
case 2:
set_username();
update_button();
break;
case 3:
set_api_key();
update_button();
break;
case 4:
if (show_console) fb.ShowConsole();
loved_page_errors = 0;
playcount_page_errors = 0;
errors = 0;
pages = 0;
r = 1;
sql = "BEGIN TRANSACTION;\n";
loved_working = true;
sync_library_loved(1);
break;
case 5:
import_sql();
break;
case 6:
auto_correct = !auto_correct;
window.SetProperty("auto_correct", auto_correct);
break;
case 7:
show_console = !show_console;
window.SetProperty("show_console", show_console);
break;
case 8:
library = !library;
window.SetProperty("library", library);
break;
case 20:
case 21:
icon = idx == 20 ? "tango" : "silk";
window.SetProperty("icon", icon);
update_button();
break;
case 101:
case 102:
case 103:
case 104:
bg = idx;
window.SetProperty("bg", bg);
window.Repaint();
break;
case 105:
set_custom_background();
break;
case 200:
case 201:
auto_love = idx == 200 ? false : true;
window.SetProperty("auto_love", auto_love);
break;
case 202:
var new_auto_love_tf = InputBox("The result of the title formatting set here must equal 1 for a track to be automatically loved.\n\nExample:\n\n$ifequal(%rating%,5,1,0)", script_name, auto_love_tf);
auto_love_tf = new_auto_love_tf;
window.SetProperty("auto_love_tf", auto_love_tf);
break;
case 9:
window.ShowProperties();
break;
case 10:
window.ShowConfigure();
break;
}
_menu.Dispose();
_icon.Dispose();
_auto.Dispose();
_li.Dispose();
_au.Dispose();
_child.Dispose();
return true;
}

WSH Panel Mod script discussion/help

Reply #4164
Hello marc2003 & everyone,

Last.fm Playcount Sync script recently started crashing on me (regularly) and I haven't found any info on this particular error text - from foobar console:
Code: [Select]
Error: WSH Panel Mod (Playcount Sync by marc2003): Microsoft JScript compilation error:
Syntax error
File: <main>
Ln: 178, Col: 2
<source text only available at compile time>


Not sure if this the correct thread in which I am supposed to post, apologies. Am I doing something stupid? Does anyone have any idea what's causing this error? Thank you. In case of usefulness, I'm posting my entire script code below:



This is the part at line 177:

Code: [Select]
177 function process() {
178    parsed_data = JSON.parse(xmlhttp.responsetext);
179    if (parsed_data.error > 0) {
180        if (parsed_data.error == 6) fb.trace(script_name + ": artist / track not found.");
181        else fb.trace(script_name + ": " + xmlhttp.responsetext);
182        return;
183    }


It looks to me like something has changed in the way JSON is handled, or even the response text.  I'll confess though, that I don't know this stuff well enough (as evident in my own postings) to really add any help.

WSH Panel Mod script discussion/help

Reply #4165
that's some ancient script right there... i had no clue. JSON.parse falls over when you feed it invalid JSON so you can add a function like this...

Code: [Select]
function json_parse(text) {
    try {
        return JSON.parse(text);
    } catch(e) {
        fb.trace("JSON.parse error: " + text);
        return false;
    }
}


now search the code for the 3 instances of this...

Code: [Select]
parsed_data = JSON.parse(xmlhttp.responsetext);


and replace it with

Code: [Select]
var parsed_data = json_parse(xmlhttp.responsetext);
if (!parsed_data)
    return; //no need to display any error because the json_parse function has already done that...


this won't make the script work again but it shouldn't crash on errors and least you might get a clue what the problem is by checking the console for the server response.

@Spanky Monkey, if you can provide the images for this button you want, i'll just make it. it'll be easier than explaining.

WSH Panel Mod script discussion/help

Reply #4166
from foo_quicksearch thread:

Works great. 2 questions, if you have time to help:
1. Is there a way to place this button not on tab, but near the menus anywhere? Like the Play, Pause... buttons.
2. How to modify the code, to allways reuse the created autoplaylist? Because, interesting, after every new search it creats a new one, with the same name ("Search").


1) using columns UI, WSH panel mod can be a toolbar. in DUI, it's just a standard panel. it can be style many ways but i'm not going into that.
2) it's not possible to re-use autoplaylists so as a workaround, you can loop through all playlists and delete any matching the same name before creating a new one...

Code: [Select]
var playlist_name = "Search...";

$buttons = {
    search: new SimpleButton(5, 5, 80, 26, "Search", function () {
        var sel = fb.GetFocusItem();
        if (!sel)
            return;
        var i = 0;
        while (i < fb.PlaylistCount) {
            if (fb.GetPlaylistName(i) == playlist_name)
                fb.RemovePlaylist(i);
            else
                i++;
        }
        fb.CreateAutoPlaylist(plman.PlaylistCount, playlist_name, "title HAS " + fb.TitleFormat("$left(%title%,15)").EvalWithMetadb(sel));
        plman.ActivePlaylist = plman.PlaylistCount - 1;
    })
}

WSH Panel Mod script discussion/help

Reply #4167
Thank you, Marc! It works well.
With the DUI I solved it, with splitting and resizing containers.

WSH Panel Mod script discussion/help

Reply #4168
Hi there,
I'm trying to install twnsnd's foo_ncmpcpp skin on foobar2000 1.3.8.
Everything seems to be set up right and I have all of the components but WSH panel mod is giving me a bit of trouble (hence my post here)
Sorry if this sort of issue has been posted before, this was the best result that I found from googling my error.
The error I have is:
Code: [Select]
Components loaded in: 0:00.016024
Configuration read in: 0:00.001925
User Interface initialized in: 0:00.043214
Startup time : 0:00.067918
WSH Panel Mod ({4C938474-B7D5-41AA-BD68-647EDA24A1BE}): initialized in 4 ms
WSH Panel Mod ({1634002F-44F5-4550-AFE5-09796FEAB447}): initialized in 2 ms
Custom bitmap D:\Apps\Program Files\foobar2000\skins\masood_\butns\search-bri_dark.bmp could not be loaded
Error: WSH Panel Mod (Playcount Sync by marc2003): Parsing file "C:\Users\Bjorn\Desktop\foobar2000\scripts\masood_\common.js": Failed to load
Error: WSH Panel Mod (Playcount Sync by marc2003): Parsing file "C:\Users\Bjorn\Desktop\foobar2000\scripts\masood_\tooltip_buttons.js": Failed to load
Error: WSH Panel Mod (Playcount Sync by marc2003): Microsoft JScript runtime error:
'settings_path' is undefined
File: <main>
Ln: 17, Col: 1
<source text only available at compile time>
Thanks for reading, any ideas for helping would be great
PS if it helps I used the portable install of foobar and the directory is right on my desktop

WSH Panel Mod script discussion/help

Reply #4169
@Spanky Monkey, if you can provide the images for this button you want, i'll just make it. it'll be easier than explaining.


Marc, I am very grateful for this offer but I really don't want to take up your time in making bespoke custom scripts.
However if you do find you have free time, and do wish to, here is the image set as a zip.
http://www.filedropper.com/buttonsgfx
A little readme is included with instructions on how the "stop after current" graphic should be used - but it's fairly obvious (I think) by the naming scheme.

Thanks again

WSH Panel Mod script discussion/help

Reply #4170
that file host sucks. it took minutes to load in firefox and even then i couldn't see any link - possibly because i use an adblocker.

@Saeolus, the required files required do not exist.

Quote
Error: WSH Panel Mod (Playcount Sync by marc2003): Parsing file "C:\Users\Bjorn\Desktop\foobar2000\scripts\masood_\common.js": Failed to load


check the paths/instructions again. even if you do sort that out, i'm not even sure it would work being so old.

WSH Panel Mod script discussion/help

Reply #4171
that file host sucks. it took minutes to load in firefox and even then i couldn't see any link - possibly because i use an adblocker.


using different internet now and i was able to get it immediately. odd as i don't usually have problems with the other internet i was using earlier.

i'll post a script later.

WSH Panel Mod script discussion/help

Reply #4172
Salut everybody!

I know about WSH, thanks to Marc, but newbie to its javascript, and forgot muuuch of usual javascript (last used it about 6 years ago). I'd like to do a simple (I think) task: to make a scrollable panel, showing the content of COMMENT tag. I started from sample script, and ended here:

Code: [Select]
// {{
// Used in window.GetColorDUI()
ColorTypeDUI = {
    text: 0,
    background: 1,
    highlight: 2,
    selection: 3
};

// Used in window.GetFontDUI()
FontTypeDUI = {
    defaults: 0,
    tabs: 1,
    lists: 2,
    playlists: 3,
    statusbar: 4,
    console: 5
};
//}}

var g_instancetype = window.InstanceType;
var g_font = null;
var g_text = "Create your script\nClick here to open the editor.";
var ww = 0, wh = 0;
var g_textcolor = 0, g_textcolor_hl = 0;
var g_backcolor = 0;
var g_hot = false;

function get_font() {
    if (g_instancetype == 0) { // CUI
        g_font = window.GetFontCUI(FontTypeCUI.items);
    } else if (g_instancetype == 1) { // DUI
        g_font = window.GetFontDUI(FontTypeDUI.defaults);
    } else {
        // None
    }
}
get_font();

function get_colors() {
    if (g_instancetype == 0) { // CUI
        g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
        g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
        g_backcolor = window.GetColorCUI(ColorTypeCUI.background);
    } else if (g_instancetype == 1) { // DUI
        g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
        g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
        g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
    } else {
        // None
    }
}
get_colors();







// 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:
// http://msdn.microsoft.com/en-us/library/ms534177(VS.85).aspx
StringAlignment = {
    Near: 0,
    Center: 0,
    Far: 2
};

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

// flags, can be combined of:
// http://msdn.microsoft.com/en-us/library/ms534181(VS.85).aspx
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_tfo = fb.TitleFormat("%comment%");
g_font = gdi.Font("Tahoma", 14, 0);
g_stringformat = StringFormat(StringAlignment.Justify, StringAlignment.Justify);

// 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.FillSolidRect(0, 0, window.Width, window.Height, g_backcolor);
        gr.SetSmoothingMode(4);
        gr.SetInterpolationMode(7);
        gr.DrawString(g_tfo.EvalWithMetadb(g_focus_metadb), g_font, RGB(0, 0, 0), 0, 0, window.Width, window.Height, g_stringformat);
    }
}
// APPLICATION - END


2 not resolved problems:
1. The panel is not scrollable.
2. After some event, script does an error, and I must restart it every time (configure > OK). Sorry, couldn't find a cause, console overwrote the error message since the last one, and now I can not reproduce it (as usual situation...) - despite, that it happens very often. I think, something like removing actual playlist, or song. But I think, for JS specialist it's easy to find out the error nature.

I would be grateful for any help.

off
By the way, why this forum engine has no closable boxes? I mean, on the click it scrolls up, to 1 line, on the next click it opens again to full length. It will be very usful for better viewing the page. Or, as variant, fixed heigth, scrollable box (overflow:auto).

WSH Panel Mod script discussion/help

Reply #4173
I catched the error message. Here is my translation from hungarian, so it's not exactly the same, as the english variant.

Code: [Select]
Error: WSH Panel Mod (SimpleFollowCursor by T.P Wang): Microsoft JScript runtime error:
'g_focus_metadb' value is NULL, or is not an object.
File: <main>
Ln: 157, Col: 5


This happend after erasing (but not removing) a simple playlist.

WSH Panel Mod script discussion/help

Reply #4174
@marc
I recently updated to windows 10 and in your now playing script (which i added rating and similar artists and couple of buttons)
i'm getting this error but it worked without any errors in windows 8.1

WSH Panel Mod (Thumbs): Microsoft JScript runtime error:
Out of stack space
File: F:\Desktop\foobar2000\marc2003\common8.js
Line: 1166, Col: 3
<source text only available at compile time>

any idea what caused this ??