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

Re: JScript Panel script discussion/help

Reply #800
The JScript "Coverflow View" by Br3tt doesn't work with JScript Panel 2.2.1 anymore.
Problem is line 1535:
Code: [Select]
window.DlgCode = DLGC_WANTALLKEYS;
I tried
Code: [Select]
// window.DlgCode = DLGC_WANTALLKEYS;
but the error still remains.

Re: JScript Panel script discussion/help

Reply #801
marc2003

I found bug!
When Foobar started a window POPs up with a message:
Quote
JScript Panel v2.2.1 (JS Smooth Playlist Manager v2018-mod by Br3tt aka Falstaff)
JavaScript execution failed:
Overflow
File: G:\Foobar2000\user-components\foo_jscript_panel\samples\js-smooth\js\jsspm.js
Line: 432, Col: 3
Then I go to the window with this script and click on the right mouse button to restart the script. Now it works1

Re: JScript Panel script discussion/help

Reply #802
FYI marc2003 hasn't been active on the forum since 2017.

Re: JScript Panel script discussion/help

Reply #803
If you have a bug report for JScript Panel, please contact marc2k3 at Github (https://github.com/marc2k3/foo_jscript_panel) and open an issue.

Re: JScript Panel script discussion/help

Reply #804
Hi, marc.
I am currently using SMP, and looking for a method to implement box-shadow effect like in CSS.
Is there any way to do it in albumart.js without using an external shadow image?

Re: JScript Panel script discussion/help

Reply #805
(I'll reply there, but maybe you should consider moving to SMP, which is faster and offer more possibilites.)
You need to create an image with this shadow, and then you draw the shadow image below/before the final image. Here is a function which create such image:
Code: [Select]
function createShadow(width, height, color){
var shadow = gdi.CreateImage(width, height);
    var gb = shadow.GetGraphics();
    gb.FillSolidRect(10, 10, width-20, height-20, color);
shadow.ReleaseGraphics(gb);

shadow = shadow.Resize(width*1/10, height*1/10,2);
shadow = shadow.Resize(width, height, 2);
return shadow;
};

And then using this function, it's quite easy:
Code: [Select]
cover_shadow = createShadow(image_width, image_height, RGB(0,0,0));
gr.DrawImage(cover_shadow, 0, 0, image_width+20, image_height+20, 0, 0, cover_shadow.Width, cover_shadow.Height);

To achieve the desired effect (shadow blur radius/position), you need to play mostly with the values in DrawImage

Re: JScript Panel script discussion/help

Reply #806
(I'll reply there, but maybe you should consider moving to SMP, which is faster and offer more possibilites.)
You need to create an image with this shadow, and then you draw the shadow image below/before the final image. Here is a function which create such image:
Code: [Select]
function createShadow(width, height, color){
var shadow = gdi.CreateImage(width, height);
    var gb = shadow.GetGraphics();
    gb.FillSolidRect(10, 10, width-20, height-20, color);
shadow.ReleaseGraphics(gb);

shadow = shadow.Resize(width*1/10, height*1/10,2);
shadow = shadow.Resize(width, height, 2);
return shadow;
};

And then using this function, it's quite easy:
Code: [Select]
cover_shadow = createShadow(image_width, image_height, RGB(0,0,0));
gr.DrawImage(cover_shadow, 0, 0, image_width+20, image_height+20, 0, 0, cover_shadow.Width, cover_shadow.Height);

To achieve the desired effect (shadow blur radius/position), you need to play mostly with the values in DrawImage

Code: [Select]
function createShadow(width, height, color){
let shadow = gdi.CreateImage(width, height);
let gb = shadow.GetGraphics();
gb.FillSolidRect(0, 0, width, height, color);
shadow.ReleaseGraphics(gb);

shadow = shadow.Resize(width / 128, height / 128, 2);
shadow = shadow.Resize(width, height, 2);
return shadow;
}
Code: [Select]
if (this.img) {
let cover_shadow = createShadow(this.img.Width, this.img.Height, _RGBA(0, 0, 0, 128));
_drawImage(gr, cover_shadow, this.x, this.y, this.w, this.h, this.properties.aspect.value);
_drawImage(gr, this.img, this.x + 10, this.y + 10, this.w - 20, this.h - 20, this.properties.aspect.value);
}
Thanks for the tip.
So, what the script is doing is that resize the image to a smaller size and then resize it back to original dimension so that it can be generated with blurred border? If so, what I don't get is the resized shadow image has blurred edge only on right and bottom, but no blurred effect on left and top. Is this a rendering bug from resize()?

Re: JScript Panel script discussion/help

Reply #807
Yes, you understood correctly. I didn't try myself your code, but i guess the issue is with the rectangle drawn inside the createShadow function. In my function, I intentionly left 10px of padding, in order to leave space for the blur effect:
Code: [Select]
gb.FillSolidRect(10, 10, width-20, height-20, color);
You removed this padding:
Code: [Select]
gb.FillSolidRect(0, 0, width, height, color);

Otherwise, you can probably use the function StackBlur instead of this resize trick which create a blur effect, look into SMP doc.

Re: JScript Panel script discussion/help

Reply #808
Yes, you understood correctly. I didn't try myself your code, but i guess the issue is with the rectangle drawn inside the createShadow function. In my function, I intentionly left 10px of padding, in order to leave space for the blur effect:
Code: [Select]
gb.FillSolidRect(10, 10, width-20, height-20, color);
You removed this padding:
Code: [Select]
gb.FillSolidRect(0, 0, width, height, color);

Otherwise, you can probably use the function StackBlur instead of this resize trick which create a blur effect, look into SMP doc.

I found a ref in one of Br3tt's skins https://www.deviantart.com/br3tt/art/DUiTunes-beta3-412700925

I tried different ways to achieve it in SMP, the only function missing for this is BoxBlur() which has been removed since Jscript(?).
Eventually, I am using a png shadow file instead, overall it works fine. Thanks anyway.

https://imgur.com/94NqVBy

Re: JScript Panel script discussion/help

Reply #809
i gave you the name of the function, StackBlur.
For example:
Code: [Select]
function createCoverShadowStack(cover_width, cover_height, color, radius){
var shadow = gdi.CreateImage(cover_width, cover_height);
    var gb = shadow.GetGraphics();
var radius = Math.floor(Math.min(cover_width/2,cover_height/2,radius));
    gb.FillSolidRect(radius, radius, cover_width-radius*2, cover_height-radius*2, color);
shadow.ReleaseGraphics(gb);
shadow.StackBlur(radius);
return shadow;
};

Re: JScript Panel script discussion/help

Reply #810
i gave you the name of the function, StackBlur.
For example:
Code: [Select]
function createCoverShadowStack(cover_width, cover_height, color, radius){
var shadow = gdi.CreateImage(cover_width, cover_height);
    var gb = shadow.GetGraphics();
var radius = Math.floor(Math.min(cover_width/2,cover_height/2,radius));
    gb.FillSolidRect(radius, radius, cover_width-radius*2, cover_height-radius*2, color);
shadow.ReleaseGraphics(gb);
shadow.StackBlur(radius);
return shadow;
};


Many THNAKS! It works perfectly.

Re: JScript Panel script discussion/help

Reply #811
(Strange that there's no activity in this thread for the last 120 days... are you all moved over to SMP?  ::) )

Hi at all,

i try to calculate the days between %first_played% and today and used this code (example):
Code: [Select]
var a = fb.TitleFormat("$date(%first_played%)").Eval()
var b = new Date();
var c = new Date(a);
var d = Math.floor((b.getTime() - c.getTime()) / 86400000);
I have no idea if i use it correctly because i have no clue about this Date() stuff...

The code snippet works with Chakra engine but not with Jscript engine.
So my question is: do i use it wrong?

Or is there any other (maybe inbuilt?) method for calculate date differences?

Re: JScript Panel script discussion/help

Reply #812
The code snippet works with Chakra engine but not with Jscript engine.
So my question is: do i use it wrong?

Or is there any other (maybe inbuilt?) method for calculate date differences?
I wonder if Date(a) is failing in Jscript. You should be using Chakra only though. Jscript is outdated.

I don't think there are any built in date difference functions. Yours works pretty well if you just want a good number of days difference. I wanted d/m/y diffs which used normal human differences (i.e. April 5th - Feb 5th = 2 months and not 1 month 28 days), so I wrote my own:

Code: [Select]
function dateDiff(startingDate, endingDate) {
    var hasStartDay = (startingDate.length > 7) ? true : false;
    if (!hasStartDay) {
        startingDate = startingDate + '-02';    // avoid timezone issues
    }
    var startDate = new Date(new Date(startingDate).toISOString().substr(0, 10));
    if (!endingDate) {
        endingDate = new Date().toISOString().substr(0, 10);    // need date in YYYY-MM-DD format
    }
    var endDate = new Date(endingDate);
    if (startDate > endDate) {
        var swap = startDate;
        startDate = endDate;
        endDate = swap;
    }
    var startYear = startDate.getFullYear();
    var february = (startYear % 4 === 0 && startYear % 100 !== 0) || startYear % 400 === 0 ? 29 : 28;
    var daysInMonth = [31, february, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var yearDiff = endDate.getFullYear() - startYear;
    var monthDiff = endDate.getMonth() - startDate.getMonth();
    if (monthDiff < 0) {
        yearDiff--;
        monthDiff += 12;
    }
    var dayDiff = 0;
    if (hasStartDay) {
        dayDiff = endDate.getDate() - startDate.getDate();
        if (dayDiff < 0) {
            if (monthDiff > 0) {
                monthDiff--;
            } else {
                yearDiff--;
                monthDiff = 11;
            }
            dayDiff += daysInMonth[startDate.getMonth()];
        }
    }

    return (yearDiff ? yearDiff + 'y ' : '') + (monthDiff > 0 ? monthDiff + 'm ': '') + (dayDiff ? dayDiff + 'd': '');
}

It handles regular foobar dates and also dates without a day value: "2018-08". It's pretty fault tolerant.

Re: JScript Panel script discussion/help

Reply #813
@MordredKLB
Thanks for this function, maybe its useful for me ;-)

But for now i only need the day difference for calculating and displaying "autorating" depending on the times a song has been played since "first play" and "today".

Re: JScript Panel script discussion/help

Reply #814
Now i've encountered another problem with the latest v2.2.2.4 (that wasn't present in the old v1.2.3 that i used before... yes, i used a quite old version...  :-* )

I coded a button script that has the option to enable additional buttons.
The commands and button names can be typed in a vb InputBox.

But all the time a button is enabled or disabled the default context menu of the jscript panel pops up... and i can't find the reason...

Can somebody (with enough time) please take a look at the code, and tell me what's wrong with it?

https://pastebin.com/tGJgTvta

P.S.: Attention!
Because you don't have the images for the upper two buttons:
If you want to try this script in a config be aware of that the upper left button exits foobar2000!
The upper right one is the menu button, all other buttons are obvious.

Re: JScript Panel script discussion/help

Reply #815
Problem solved.
I just forgot to add "return true" after "window.Reload"  to suppress the context menu :-*

Re: JScript Panel script discussion/help

Reply #816
And again my optional button panel...

With the linked script i can add optional buttons via context menu and ask for the command and the button name with Input boxes.
With a function (line 335 in the script) i test on first click on the new button if the given command (like: View/Playlist Manager, Playback statisctics/Rating/5 or fb.Play()) is a main menu, context menu or a JScript command and "assign" it, so there's no need to test the command every hit on the button again.
And this works good.

But how can i test (and execute) a predefined function (like getMainMenu, when i created a function getMainMenu() in the Script, like i did at line 470)?

Any ideas are welcome ;)

Optional Button Panel

Btw.: If there is someone who has a better idea or a more elegant way to test commands: i'm open for any improvements/enhancements ;)

Re: JScript Panel script discussion/help

Reply #817
I'm new to javascript and not entirely sure this is the right place to ask, but it seems better than the others I've found. I've got the various js smooth components loaded into spider monkey panels and love them, but the playlist doesn't seem to support drag and drop. I can drag files onto a playlist in the playlist manager, but I'd like to move them within the playlist itself. Is it a matter of marrying the code in DragnDrop.js in the samples with that in jssp.js? Has anyone done this, and are there any common pitfalls for the unwary? I've successfully made play/pause and mute buttons toggle their images, but that's about my level of sophistication.

Re: JScript Panel script discussion/help

Reply #818
Btw. i replaced:
Code: [Select]
eval(tmp_string);
both times with:
Code: [Select]
var tmp_func = new Function('"use strict";' + tmp_string);
tmp_func();
in the script i linked HERE in the meantime.
(I'm open for any better solution).

But my question is still relevant: how can i call and execute predefined functions with arguments (i forgot to mention it above, because without arguments my code works well) with my code?
The problem is that sometimes the functions don't have arguments so it should work in both cases.

Re: JScript Panel script discussion/help

Reply #819
 JScript Panel v 2.2.2.
fb.GetFocusItem() does not work

For for example:
Code: [Select]
    var tfo = fb.TitleFormat("%artist%");
    var items = tfo.EvalWithMetadb(fb.GetFocusItem());
"JavaScript runtime error:
Type mismatch"
UR5EQF. Ukraine

Re: JScript Panel script discussion/help

Reply #820
Read the docs. fb.GetFocusItem can return null if nothing is selected so you must always check it first...

Code: [Select]
var metadb = fb.GetFocusItem();
if (metadb) {
    //do something with metadb
}

Re: JScript Panel script discussion/help

Reply #821
@marc2003/snotlicker: still using your latest version of Coverflow View (originally from Br3tt) version 1.5.1 as posted by Grimes here on JScript panel 2.4.0. It works well except with rightklick - error in line 3604
Code: [Select]
    Context.BuildMenu(_menu, 1, -1);
or when typing a letter to jump to the respective artists - error in line 3510
Code: [Select]
    if(list.total==0 || !fb.GetFocusItem(false)) return true;
Any chance to take a look into that?

I think it would even be great if Coverflow View could be included in the SMP Script Showcases from TheQweriest.

Re: JScript Panel script discussion/help

Reply #822
@marc2003/snotlicker: still using your latest version of Coverflow View (originally from Br3tt) version 1.5.1 as posted by Grimes here on JScript panel 2.4.0. It works well except with rightklick - error in line 3604
Code: [Select]
    Context.BuildMenu(_menu, 1, -1);
or when typing a letter to jump to the respective artists - error in line 3510
Code: [Select]
    if(list.total==0 || !fb.GetFocusItem(false)) return true;
Any chance to take a look into that?

I think it would even be great if Coverflow View could be included in the SMP Script Showcases from TheQweriest.

BuildMenu only takes two parameters now. Just do:
Code: [Select]
Context.BuildMenu(_menu, 1);

fb.GetFocusItem does not take any parameters any longer:
Code: [Select]
if(list.total==0 || !fb.GetFocusItem()) return true;

Re: JScript Panel script discussion/help

Reply #823
@MordredKLB: Wow, that was quick + it works!! Thanks very much!!! :)
Enclosed is the updated script.

What do you think about adding it to the SMP showcases?

Re: JScript Panel script discussion/help

Reply #824
That'd be a question for TheQwertiest and possibly Marc. I'm not sure if there was a reason it was excluded to begin with.