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 289345 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel script discussion/help

Reply #450
Yes, it looks like if you call window.Repaint in rapid succession, it doesn't process. This timer is using 2ms whereas I suspect those callbacks were happening much closer together.

Code: [Select]
var x = 0;

var timer = window.SetInterval(function () {
x++;
if (x > 100)
window.ClearInterval(timer);
fb.trace("timer " + x);
window.Repaint();
}, 2);

function on_paint(gr) {
fb.trace("on_paint " + x);
}

Result:
Code: [Select]
on_paint 0
timer 1
timer 2
on_paint 2
timer 3
timer 4
timer 5
on_paint 5
timer 6
timer 7
on_paint 7
timer 8
timer 9
timer 10
on_paint 10
timer 11
on_paint 11
timer 12
on_paint 12

Re: JScript Panel script discussion/help

Reply #451
Yes, it looks like if you call window.Repaint in rapid succession, it doesn't process. This timer is using 2ms whereas I suspect those callbacks were happening much closer together.
Darn, guess I'll have to take it into account when making scripts... Thanks for figuring it out.

[EDIT]: it might be linked to monitor refresh rate: 60HZ == 1 refresh every 16,(6) ms. Will test it out on 120HZ monitor later.

[EDIT2]: Nah, I was wrong, it seems it depends purely on CPU, i.e. how fast it can process Repaint calls. Because I have logs like this
Code: [Select]
timer 60
on_paint 60
timer 61
on_paint 61
timer 62
on_paint 62
timer 63
on_paint 63
timer 64
on_paint 64
timer 65
on_paint 65
timer 66
on_paint 66
timer 67
on_paint 67
timer 68
timer 69
on_paint 69

Re: JScript Panel script discussion/help

Reply #452
[EDIT]: Do you know the difference between on_playlist_items_selection_change and on_selection_changed? What I gathered from docs is that on_selection_changed might not always work, but then why use it at all instead of always using on_playlist_items_selection_change?

on_selection_changed gets called when selecting tracks in Library viewers like Album List, not just playlists.

Re: JScript Panel script discussion/help

Reply #453
window.Repaint(force) maps to HostComm::Repaint on the C++ side. With force set to false it just marks the window as as dirty, i.e. it sets a flag which tells the window manager that this window needs to be redrawn. With force set to true it causes the window to be redrawn immediately. The idea is to use the delayed redraw (with force set to false) whenever possible because redrawing a window is usually an expensive operation (compared to setting a flag, adding two numbers or formatting a string). You should generally use a delayed redraw inside a callback from foobar2000, i.e. for playback events or playlist changes.

Re: JScript Panel script discussion/help

Reply #454
Sorry for disturbing back again...
If GdiDrawText is called in gdi.CreateImage(), is it impossible to avoid the black edge, even if having filled a solid background behind that?

The highlighted "Oh Nana" was drawn in an image created, with the pink background just behind it in the same image, while the "(2016)" was drawn directly in on_paint() callback.

I know that drawstring() could solve this problem, but I just do not like its look, and wonder if there is a way to perfectly use GDI.
Thanks for any help or hints...

Use g.DrawString instead of gdiDrawText, and g.SetTextRenderingHint(4) before that.
A rose will bloom, it then will fade.

Re: JScript Panel script discussion/help

Reply #455
window.Repaint(force) maps to HostComm::Repaint on the C++ side. With force set to false it just marks the window as as dirty, i.e. it sets a flag which tells the window manager that this window needs to be redrawn. With force set to true it causes the window to be redrawn immediately. The idea is to use the delayed redraw (with force set to false) whenever possible because redrawing a window is usually an expensive operation (compared to setting a flag, adding two numbers or formatting a string). You should generally use a delayed redraw inside a callback from foobar2000, i.e. for playback events or playlist changes.

Completely forgot about the "force". I've never had to use it myself and I don't think I've seen it anyone else's scripts either. I don't think real world usage needs it. Like you say, the whole point is to reduce redrawing if you can.

Re: JScript Panel script discussion/help

Reply #456
Sorry for disturbing back again...
If GdiDrawText is called in gdi.CreateImage(), is it impossible to avoid the black edge, even if having filled a solid background behind that?

The highlighted "Oh Nana" was drawn in an image created, with the pink background just behind it in the same image, while the "(2016)" was drawn directly in on_paint() callback.

I know that drawstring() could solve this problem, but I just do not like its look, and wonder if there is a way to perfectly use GDI.
Thanks for any help or hints...

Use g.DrawString instead of gdiDrawText, and g.SetTextRenderingHint(4) before that.

I know. As you see, I mentioned it in the original post.

I'm just not in favor of what it looks like... And the fact that gdidrawstring() resulting weirdly, even if with a solid background, seems strange to me. I hope it can be fixed somehow... Or I have to use those dirty, dirty hacks...

Re: JScript Panel script discussion/help

Reply #457
Even this snippet which saves as .png has the same problem. I doubt I'll find out how to fix this.

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// ==/PREPROCESSOR==
var font = _.gdiFont("Segoe UI", 72, 1);
var white = _.RGB(255, 255, 255);
var img = gdi.CreateImage(400, font.Height);
var gb = img.GetGraphics();
gb.gdiDrawText("JScript", font, white, 0, 0, 400, font.Height, CENTRE | DT_VCENTER)
img.ReleaseGraphics(gb);
img.SaveAs("z:\\test.png"); //png is default, no need to specify type

Re: JScript Panel script discussion/help

Reply #458
Even this snippet which saves as .png has the same problem. I doubt I'll find out how to fix this.

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// ==/PREPROCESSOR==
var font = _.gdiFont("Segoe UI", 72, 1);
var white = _.RGB(255, 255, 255);
var img = gdi.CreateImage(400, font.Height);
var gb = img.GetGraphics();
gb.gdiDrawText("JScript", font, white, 0, 0, 400, font.Height, CENTRE | DT_VCENTER)
img.ReleaseGraphics(gb);
img.SaveAs("z:\\test.png"); //png is default, no need to specify type
As I know, gdidrawtext() needs a background to run, and if it is running on a transparent background, as in the snippet above, it will use black (0-0-0) as a background by default.
So, technically, there is no bug in that snippet. And my real problem is, in a temp graphic part, even if a (colorful) background is defined before, the gdidrawtext() still runs as the background is black; while the problem don't appear with normal gr. in on_paint() callbacks.
Hope I successfully delivered what I thought...

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// ==/PREPROCESSOR==
var font = _.gdiFont("Segoe UI", 72, 1);
var white = _.RGB(255, 255, 255);
var img = gdi.CreateImage(400, font.Height);
var gb = img.GetGraphics();
//Pre-define a background
gb.FillSolidRect(0, 0, 400, font.Height, 0xffabcdef);
gb.gdiDrawText("JScript", font, white, 0, 0, 400, font.Height, CENTRE | DT_VCENTER);
img.ReleaseGraphics(gb);
img.SaveAs("z:\\test.png"); //png is default, no need to specify type
Hope this may somehow result a smooth image...

Re: JScript Panel script discussion/help

Reply #459
The component creates image objects which use premultiplied alpha (see https://github.com/19379/foo-jscript-panel/blob/master/foo_jscript_panel/script_interface_impl.cpp#L1122).

PNG on the other hand uses non-premultiplied alpha (see https://www.w3.org/TR/PNG-Rationale.html#R.Non-premultiplied-alpha).

One would hope that GDI+ did the right thing when drawing an image. On the other hand your experiments indicate that it uses the blend formula for non-premultiplied alpha. As a quick search reveals other people have noticed this behaviour as well (see http://stackoverflow.com/questions/19809506/drawing-pixelformat32bpppargb-images-with-gdi-uses-conventional-formula-instead).

Changing the pixel format would solve this problem. Some part of the code may require changes as well if they expect premultiplied alpha.

Re: JScript Panel script discussion/help

Reply #460
Forgive me if I'm being dense but I'm not sure any of that is relevant given DrawString works fine?? You'll have to ask Scrummble why it's not good enough.


Re: JScript Panel script discussion/help

Reply #461
You have a point there. I should have paid closer attention. I might have noticed that GdiDrawText does not use GDI+ but plain old GDI.

Re: JScript Panel script discussion/help

Reply #462
It's possible to trick it, ala what I did in foo_osd for GDI text drawing: Render an alpha mask separately, by rendering the text again using solid white on solid black, and capture the green channel of the result as the alpha level, and treat the correctly colored text on black background as the color channels pre-multiplied.

 

Re: JScript Panel script discussion/help

Reply #463
My assumption is that changing PixelFormat32bppPARGB to PixelFormat32bppARGB may works in this issue. Had anyone given it a try? I'm afraid I do not have any knowledge of C++, so please teach me if there's anything wrong.

It's possible to trick it, ala what I did in foo_osd for GDI text drawing: Render an alpha mask separately, by rendering the text again using solid white on solid black, and capture the green channel of the result as the alpha level, and treat the correctly colored text on black background as the color channels pre-multiplied.

Thanks for the alternative method, but it will dispose of the LCD specified rendering. I haven't give it a try, but I guess it may look just like SetTextRenderingHint(4). I think I should stick on the "all on_paint and concealing with fake background" hack anyway...

Re: JScript Panel script discussion/help

Reply #464
Thanks for the alternative method, but it will dispose of the LCD specified rendering. I haven't give it a try, but I guess it may look just like SetTextRenderingHint(4). I think I should stick on the "all on_paint and concealing with fake background" hack anyway...
Actually, it only tosses out the LCD rendering for the alpha mask, where it would be impossible to calculate an alpha mask anyway. The red/blue hinting would still exist on the RGB colored text that is rendered separately as the pre-scaled RGB channels. Assuming your GDI rendering code doesn't force grayscale hinting.

And even if that doesn't work, you can always render your own LCD hinted text, simply by scaling the text up to 3x size, then using an RGB matrix to downscale the horizontal part to 1/3 size with just the right R/G/B crosstalk. Search for the old "Clearize" demo for Allegro for an example reduction matrix.

E: Disregard "Clearize" tip, said site and software no longer exists. But there's still this.

Re: JScript Panel script discussion/help

Reply #465
I've fixed up all 3 of Falstaff/Br3tt's JS Smooth scripts so they work in the latest version of JScript Panel. It was some badly formatted if/else statements that prevented it working with the Chakra engine.

https://github.com/19379/JS-Smooth-Scripts-By-Br3tt

@Falstaff, if you read this sometime, the new component didn't like you coding like this...

Code: [Select]
if (something) {

};
else {

}

It had to be replaced with

Code: [Select]
} else {

edit: Just realised I missed the catch statements so an updated version has been uploaded.

Re: JScript Panel script discussion/help

Reply #466
Hi everyone,

How i can get rid of the white border around the cover in the Js Smooth Playlist ?
Can't spot the function. :(

Re: JScript Panel script discussion/help

Reply #467
Do you mean jsplaylist-mod? I can't see any border in the Smooth version.

edit: Seems to be line 770 in user-components\foo_jscript_panel\samples\jsplaylist-mod\js\WSHPlaylist.js. Either change the colour or comment the entire line out. Remember that any future component update would overwrite changes so make sure you save a copy elsewhere.

Re: JScript Panel script discussion/help

Reply #468
I have been using JScript Panel along with marc's last.fm bio.txt and thumbs.txt.  Both worked admirably up until some time this week.  At some point after updating JScript to v1.2.0, both now are displaying blank windows for new artists but still showing bio/pics for existing artists (cached I assume).   Is anyone else having this issue?  I tried rolling back the JScript to v 1.1.3--no luck

Any help would be much appreciated.

fb2k v1.3.14
Windows 10

Re: JScript Panel script discussion/help

Reply #469
I have been using JScript Panel along with marc's last.fm bio.txt and thumbs.txt.  Both worked admirably up until some time this week.  At some point after updating JScript to v1.2.0, both now are displaying blank windows for new artists but still showing bio/pics for existing artists (cached I assume).   Is anyone else having this issue?  I tried rolling back the JScript to v 1.1.3--no luck

Any help would be much appreciated.

fb2k v1.3.14
Windows 10

Yeah, I think Last.fm may have done something to break the bio panel on their end. This is what I get when I try to download artist art with the Bio Script:

"np_basic: HTTP error: 0"

Re: JScript Panel script discussion/help

Reply #470
I have been using JScript Panel along with marc's last.fm bio.txt and thumbs.txt.  Both worked admirably up until some time this week.  At some point after updating JScript to v1.2.0, both now are displaying blank windows for new artists but still showing bio/pics for existing artists (cached I assume).   Is anyone else having this issue?  I tried rolling back the JScript to v 1.1.3--no luck

Any help would be much appreciated.

fb2k v1.3.14
Windows 10

Yep, here too. Had foreseen this was to happen considering last.fm's track record. Lucky I cached as much as I could before it stopped working.

Re: JScript Panel script discussion/help

Reply #471
Last.fm have updated their website to use https therefore the scripts need to be updated. Edit your text.js/thumbs.js files and replace http with https.

text.js
Code: [Select]
var url = "https://" + this.bio_lastfm_sites[this.bio_lastfm_site] + "/music/" + encodeURIComponent(this.artist) + "/+wiki";

thumbs.js
Code: [Select]
this.xmlhttp.open("GET", "https://www.last.fm/music/" + encodeURIComponent(this.artist) + "/+images", true);

Re: JScript Panel script discussion/help

Reply #472
Cross-posting here since it slipped my mind there was a separate discussion/help thread when replying in the other thread and I can't now delete it.

JSplaylist is now bundled with the component itself.

https://github.com/19379/foo-jscript-panel/tree/master/component/samples

Ah, good to know.

With regard to force sorting in the panel, any ideas? I find I have to right-click the columns header>Groups>Apply group sorting to override the filename sorting and apply track number order, but the option doesn't seem to be able to be permanently set.

Re: JScript Panel script discussion/help

Reply #473
Last.fm have updated their website to use https therefore the scripts need to be updated. Edit your text.js/thumbs.js files and replace http with https.

text.js
Code: [Select]
var url = "https://" + this.bio_lastfm_sites[this.bio_lastfm_site] + "/music/" + encodeURIComponent(this.artist) + "/+wiki";

thumbs.js
Code: [Select]
this.xmlhttp.open("GET", "https://www.last.fm/music/" + encodeURIComponent(this.artist) + "/+images", true);
 

Thanks!

Re: JScript Panel script discussion/help

Reply #474
Is it possible with jscript to hide or show a columns ui panel? In other words to trigger the panelshow command of panel stack splitter?

I finally learned a workaorund for this: you can create and delete an empty text file with the CreateTextFile and DeleteFile methods which than PSS can check out with the $findfile function to trigger any command you like.

I have to credit the russian forum for this.
I'm late