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

Re: JScript Panel script discussion/help

Reply #750
I don't think it's anything you have to worry about typically.

When fromhook is true, it means that information in a metadb changed, but not the tags in the file itself. For example, if you're using foo_playcount and you rate a song 5 *s, on_metadb_changed will be called with fromhook = true. If you open up the properties dialog and change a song title and then OK out of the dialog, on_metadb_changed will be called with fromhook = false. I can't think of a single good reason you'd want to ignore one or the other type of metadb change, so it's possible it's mainly for informational purposes.

Re: JScript Panel script discussion/help

Reply #751
Thanks a lot for the explanation, Mordred.
I'm late

Re: JScript Panel script discussion/help

Reply #752
I just upgraded from v1.3.2.2 to v2.1.4. I updated every script according to marc2003 instructions and everything works fine, but one panel, which crashes, warning me that "Object doesn't support this property or method". The referenced line, which as far as I can see shouldn't be affected by the breaking changes, is the following:
Code: [Select]
var filtered_list = _.uniq(autocomplete, true).filter(filterAutocomplete);


If it helps, the filter function is the following:
Code: [Select]
function filterAutocomplete(value){
    return value.indexOf(text) == 0;
}

It's a search-box script, where text is what is typed in the search-box and autocomplete is an array of previous entries.
I'm late

Re: JScript Panel script discussion/help

Reply #753
I just upgraded from v1.3.2.2 to v2.1.4. I updated every script according to marc2003 instructions and everything works fine, but one panel, which crashes, warning me that "Object doesn't support this property or method". The referenced line, which as far as I can see shouldn't be affected by the breaking changes, is the following:
Code: [Select]
var filtered_list = _.uniq(autocomplete, true).filter(filterAutocomplete);

One more clue: the problem seems to be gone after switching fom jscript to chakra engine.
I'm late

Re: JScript Panel script discussion/help

Reply #754
One more clue: the problem seems to be gone after switching fom jscript to chakra engine.
The problem is caused by using different JS engines:
Chakra engine provides ECMA-5 support, while JScript provides ECMA-3 (with some extensions).
`Array.indexOf` is a ECMA-262 5th edition feature, so it is not available under JScript engine, which is used by default when migrating from v1.3.2.2 to v2.* (v1.3.2.2 used Chakra if it was available though).

Re: JScript Panel script discussion/help

Reply #755
The problem is caused by using different JS engines:
Chakra engine provides ECMA-5 support, while JScript provides ECMA-3 (with some extensions).
`Array.indexOf` is a ECMA-262 5th edition feature, so it is not available under JScript engine, which is used by default when migrating from v1.3.2.2 to v2.* (v1.3.2.2 used Chakra if it was available though).

Thanks, I was not aware of using the Chakra engine, with the previous version. I was actually not even aware that different jscript engines exist.
I'm late

 

Re: JScript Panel script discussion/help

Reply #756
The plug-in uses system provided jscript engines, or else it would probably be significant in size, if it were, say, providing a complete copy of V8, like nodejs does.

Re: JScript Panel script discussion/help

Reply #757
@marc2003
I paid attention to the unexpected value of the variable time:undefined in the function on_playback_time(time) at the beginning of playback.
So it should be, or can it be fixed?

In script:
function on_playback_time(time) {
    fb.trace(' --------- on_playback_time --- time: ' +time+ ' ---- fb.PlaybackTime: ' +fb.PlaybackTime);

In console:
Opening track for playback: .....
 --------- on_playback_time --- time: undefined ---- fb.PlaybackTime: 0.14017006802721077
 --------- on_playback_time --- time: 1 ---- fb.PlaybackTime: 1.1074625850340127
 ...

Re: JScript Panel script discussion/help

Reply #758
... or else it would probably be significant in size, if it were, say, providing a complete copy of V8, like nodejs does.
Dunno about V8, but SpiderMonkey (Firefox JS engine) takes only ~18Mb, so it's not really that bad =)

Re: JScript Panel script discussion/help

Reply #759
... or else it would probably be significant in size, if it were, say, providing a complete copy of V8, like nodejs does.
Dunno about V8, but SpiderMonkey (Firefox JS engine) takes only ~18Mb, so it's not really that bad =)
I'm hearing you say you're going to do a fork with spidermonkey and full ES6 support.... ;)

Re: JScript Panel script discussion/help

Reply #760
I'm hearing you say you're going to do a fork with spidermonkey and full ES6 support.... ;)
Yeah, but it is a pretty big undertaking, so it won't be ready any time soon... It will probably take months to reimplement all the features.

Re: JScript Panel script discussion/help

Reply #761
I am using GetColourSchemeJSON to create themed colors layouts based on album art.
I would appreciate any help on how to determine the best text color ( with JScript )  for the background color, as to achieve comfortable  contrast.


Re: JScript Panel script discussion/help

Reply #763
That algorithm uses different numbers than I've seen. My theme currently uses the w3c brightness recommendation for calculating these values (I have a color helper class which makes these things much easier https://github.com/kbuffington/Georgia/blob/master/js/color.js):

Code: [Select]
// brightness from 0-255 divide by 2.55 if you want 0-100%
Math.round(Math.sqrt( 0.299*this.r*this.r + 0.587*this.g*this.g + 0.114*this.b*this.b ));

I can share my color picking code if you're interested. I've spent months on it and finally pretty happy with it.



Re: JScript Panel script discussion/help

Reply #764
Thank you for your feedback and link.
I will use the algorithm you recommended.
I will have to study more to understand how to use the helper class, but you provided me a start point.

If you don't mind please share your colour picking code, you seem to have spent a long time implementing it.

As for JScript Panel, I wish interfaces also had
window.SetColourDUI / window.SetColourCUI
Then it would be possible to also change the colours of native panels via JScript script.

Re: JScript Panel script discussion/help

Reply #765
You use the Color class by just instantiating it with new and passing a color value. Like var col = new Color(rgb(255,0,0)); Then you can just do col.r or col.brightness or col.isCloseToGreyscale. col.val will spit the foobar color back out (pull the latest version of color.js from github because I just changed this 5 minutes ago).

Here's my color picker code which shows this in action:
Code: [Select]
function getThemeColor(image, maxColorsToPull, maxColors) {
var selectedColor;
var minFrequency = 0.015;
var colorsWeighted = [];

try {
colorsWeighted = JSON.parse(image.GetColourSchemeJson(maxColorsToPull));
colorsWeighted.forEach(function (c, i) {
colorsWeighted[i].col = new Color(c.col);
});

console.log('idx      color        bright  freq   weight');
maxWeight = 0;
selectedColor = colorsWeighted[0].col;  // choose first color in case no color selected below
colorsWeighted.forEach(function (c, i) {
var col = c.col;
var midBrightness = 127 - Math.abs(127 - col.brightness);   // favors colors with a brightness around 127
c.weight = c.freq * midBrightness * 10; // multiply by 10 so numbers are easier to compare
if (c.freq >= minFrequency && !col.isCloseToGreyscale && col.brightness < 212) {
console.log(leftPad(i, 2), col.getRGB(true,true), leftPad(col.brightness, 4), ' ', leftPad(parseFloat(c.freq*100).toFixed(2),5) + '%', leftPad(parseFloat(c.weight).toFixed(2), 7));
if (c.weight > maxWeight) {
maxWeight = c.weight;
selectedColor = col;
}
} else if (col.isCloseToGreyscale) {
console.log(' -', col.getRGB(true,true), leftPad(col.brightness, 4), ' ', leftPad(parseFloat(c.freq*100).toFixed(2),5) + '%', '   grey');
} else {
console.log(' -', col.getRGB(true,true), leftPad(col.brightness, 4), ' ', leftPad(parseFloat(c.freq*100).toFixed(2),5) + '%', leftPad(parseFloat(c.weight).toFixed(2), 7));
}
});

if (selectedColor.brightness < 39) {
console.log(selectedColor.getRGB(true), 'brightness:', selectedColor.brightness, 'too dark -- searching for highlight color');
brightest = selectedColor;
maxWeight = 0;
colorsWeighted.forEach(function (c, i) {
if (c.col.brightness > selectedColor.brightness &&
c.col.brightness < 200 &&
!c.col.isCloseToGreyscale &&
c.weight > maxWeight &&
c.freq > .01) {
maxWeight = c.weight;
brightest = c.col;
}
});
selectedColor = brightest;
}
console.log('Selected Color:', selectedColor.getRGB(true));
return selectedColor.val;
} catch (e) {
return undefined;
}
}
Here's the explanation. My theme requires that the theme color (which I use for some backgrounds) has white text and white logos on it. So I want to choose a color that looks good but isn't too bright. I also try and avoid colors that are greyscale or close to it (GetColourSchemeJson will often return colors like rgb(100,101,97) which are essentially greyscale) because those are pretty boring. On my first pass I only want to choose a color that appears at least 1.5% of the time. I also weight colors more with a brightness around 127 (this portion of the weighting is linear but I'd like it to be more of a gaussian weight but it works well enough).

If after the first pass I didn't find a suitable color, I do a second pass looking for basically the brightest non-greyscale color which appears at least 1% of the time. If that still doesn't find anything suitable I just return the very first color because the image is obviously completely greyscale or very close to it.

When running this I have a lot of logging to the console to see what's going on. Change your font to Consolas if you want it to be readable :)

Re: JScript Panel script discussion/help

Reply #766

Have a BIG request (question):
How to achieve the normal operation of timers after exit Sleep or Hibernate.
All timers of various JScript Panel scripts try to "catch up" with the system time.
Help, how to solve this?

Re: JScript Panel script discussion/help

Reply #767
@MordredKLB
Thanks for sharing, your reply was very useful :)

Re: JScript Panel script discussion/help

Reply #768
foo_jscript_panel\samples\jsplaylist-mod\
Previously, JS common.js is enough for the playlist (JS Smooth Playlist) to work.
Why now import everything else ?? :
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHcommon.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHinputbox.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHtopbar.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHscrollbar.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHheaderbar.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHplaylist.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHplaylistmanager.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\WSHsettings.js"
// @import "%fb2k_component_path%samples\jsplaylist-mod\js\main.js
 :(

Re: JScript Panel script discussion/help

Reply #769
..

Re: JScript Panel script discussion/help

Reply #770
I have one question. It seems that framestyle (none, gray , sunken) doesn't work for some old plugins in foobar v 1.4 , and also doesn't work for Jscript. 'Edge Style' is grayed out in Jscript and cant be selected. Would that be fixed? Thanks.

Re: JScript Panel script discussion/help

Reply #771
Can someone help me. How to get toolbar panel color?  Which color is that?

I tried:

var CLR = 20;
g_syscolor = utils.GetSysColour(CLR);


This works. But i dont know which color is for toolbar?

Re: JScript Panel script discussion/help

Reply #772
I have been using the following definitions:

Code: [Select]
COLOR_SCROLLBAR           0
COLOR_BACKGROUND          1
COLOR_ACTIVECAPTION       2
COLOR_INACTIVECAPTION     3
COLOR_MENU                4
COLOR_WINDOW              5
COLOR_WINDOWFRAME         6
COLOR_MENUTEXT            7
COLOR_WINDOWTEXT          8
COLOR_CAPTIONTEXT         9
COLOR_ACTIVEBORDER        10
COLOR_INACTIVEBORDER      11
COLOR_APPWORKSPACE        12
COLOR_HIGHLIGHT           13
CLOR_HIGHLIGHTTEXT        14
COLOR_BTNFACE             15
COLOR_BTNSHADOW           16
COLOR_GRAYTEXT            17
COLOR_BTNTEXT             18
COLOR_INACTIVECAPTIONTEXT 19
COLOR_BTNHIGHLIGHT        20

I believe the toolbars use the COLOR_BTNFACE value.

Re: JScript Panel script discussion/help

Reply #773
I have been using the following definitions:

Code: [Select]
COLOR_SCROLLBAR           0
COLOR_BACKGROUND          1
COLOR_ACTIVECAPTION       2
COLOR_INACTIVECAPTION     3
COLOR_MENU                4
COLOR_WINDOW              5
COLOR_WINDOWFRAME         6
COLOR_MENUTEXT            7
COLOR_WINDOWTEXT          8
COLOR_CAPTIONTEXT         9
COLOR_ACTIVEBORDER        10
COLOR_INACTIVEBORDER      11
COLOR_APPWORKSPACE        12
COLOR_HIGHLIGHT           13
CLOR_HIGHLIGHTTEXT        14
COLOR_BTNFACE             15
COLOR_BTNSHADOW           16
COLOR_GRAYTEXT            17
COLOR_BTNTEXT             18
COLOR_INACTIVECAPTIONTEXT 19
COLOR_BTNHIGHLIGHT        20

I believe the toolbars use the COLOR_BTNFACE value.


No, i tried all that colors and even more, i cant get color for toolbar background.

I need this background color (so it should match OS, if its win 7 then it's blue if win 10 white) :


Re: JScript Panel script discussion/help

Reply #774
It appears that you are using Aero themes. In that case GetSysColour is not going to help you, as it only returns a single colour value.
If you look closely, the menu background is not a solid colour but a gradient, or maybe even a combination of two gradients depending on the theme.

I'm not aware of any documented ways of getting that info from the system. One thing you could try is extracting a sample of that pattern graphically from a screen shot and stretching it to the desired width.

That may cover your personal setups (until you make any changes in Windows themes), but a generic solution would be much more difficult to build.


 
SimplePortal 1.0.0 RC1 © 2008-2018