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 282984 times) previous topic - next topic
0 Members and 5 Guests are viewing this topic.

Re: JScript Panel script discussion/help

Reply #650
2. where to change the font type?

The panel object uses the DUI or CUI font settings.


3. I want to display a text file with the name "discography.txt" in the root artist folder, the problem is that sometimes the depth of nesting, for example "artist \ album \" ... "artist \ album \ CD1"

It depends on your folder naming standards. For example, if all your multiple discs were in folders named CD%discnumber% this could be your custom path:
Code: [Select]
$if($strcmp($directory(%path%),CD%discnumber%),$replace($directory_path(%path%),$directory(%path%),),$directory_path(%path%))

2. I use when changing columns UI the font of a custom, only the headings change but not the actual display of the text file in the panel

3. CD%discnumber% - use of this code requires the insertion of tags% discnumber% ??? How to be if there are no tags (in CUE), and the folders are called CD1, CD2? And how to complete the code to take only the file with the name "discography.txt"?

Re: JScript Panel script discussion/help

Reply #651
2. I use when changing columns UI the font of a custom, only the headings change but not the actual display of the text file in the panel
You are right, in text_reader mode the panel always uses the lucida console character for the text. This is not my script, so I'm just groping around, but you can try editing the script and replace on line 11 the word "text_reader" with the word "allmusic", that should apply the CUI font.


3. CD%discnumber% - use of this code requires the insertion of tags% discnumber% ??? How to be if there are no tags (in CUE), and the folders are called CD1, CD2? And how to complete the code to take only the file with the name "discography.txt"?
Something like this?
Code: [Select]
$ifequal($strstr($directory(%path%),CD),1,$replace($directory_path(%path%),\$directory(%path%),),$directory_path(%path%))\discography.txt
I'm late

Re: JScript Panel script discussion/help

Reply #652
2. I use when changing columns UI the font of a custom, only the headings change but not the actual display of the text file in the panel
You are right, in text_reader mode the panel always uses the lucida console character for the text. This is not my script, so I'm just groping around, but you can try editing the script and replace on line 11 the word "text_reader" with the word "allmusic", that should apply the CUI font.


3. CD%discnumber% - use of this code requires the insertion of tags% discnumber% ??? How to be if there are no tags (in CUE), and the folders are called CD1, CD2? And how to complete the code to take only the file with the name "discography.txt"?
Something like this?
Code: [Select]
$ifequal($strstr($directory(%path%),CD),1,$replace($directory_path(%path%),\$directory(%path%),),$directory_path(%path%))\discography.txt


1. with allmusic stopped working as text reader((

2. the code does not see the file in the artist folder, you need to make the code for universal viewing from any sub-folder with any recursion up to the folder artist

var 1: artist\album\CD1\playable file

var 2: artist\album\playable file

in both variants "discography.txt" is located in "artist" folder

Re: JScript Panel script discussion/help

Reply #653
Hello. I use
// @name "Text Reader"
// @author "marc2003"

1. I want to use it for viewing сue located of course in the playing folder, how to set the path? Default $directory_path(%path%) ... $directory_path(%path%)\*.CUE ... dont work

2. where to change the font type?

3. I want to display a text file with the name "discography.txt" in the root artist folder, the problem is that sometimes the depth of nesting, for example "artist \ album \" ... "artist \ album \ CD1"

1. The text reader looks for *.txt *.log in  default custom path $directory_path(%path%) or a specific file when defined  $directory_path(%path%)\thecuefilename.cue

1a. Either specify the same name to all your cue files eg. tracklist.cue  and define the custom path $directory_path(%path%)\tracklist.cue

OR

1b. Modify text.js  in user-components\foo_jscript_panel\samples\complete\js to include *.cue by changing line #370
this.exts = 'txt|log';

TO
 
this.exts = 'cue|txt|log';

Remember that any future update to the component will overwrite text.js

2. The text panel follows the defined common (list items)  CUI font in the preferences page.
Uncheck "Fixed  width font" from the text panel submenu for it not to use fixed font Lucida Console.

3. This should work
Code: [Select]
$left(%path%,$strstr(%path%,\%artist%))%artist%)\discography.txt


Re: JScript Panel script discussion/help

Reply #654
EDIT: actually just follow zeremy's instructions
I'm late

Re: JScript Panel script discussion/help

Reply #655
zeremy, Thank you so much! "Fixed  width font" was in the most prominent place))))))))

I added this.exts = 'cue|txt|log'; ... but still does not read the only cue in the folder, only when assigning a relative path, how to make it work on any cue ... $directory_path(%path%)\*.cue  ???

Re: JScript Panel script discussion/help

Reply #656
zeremy, Thank you so much! "Fixed  width font" was in the most prominent place))))))))

I added this.exts = 'cue|txt|log'; ... but still does not read the only cue in the folder, only when assigning a relative path, how to make it work on any cue ... $directory_path(%path%)\*.cue  ???


Don't use $directory_path(%path%)\*.cue  in the custom path
Use  $directory_path(%path%)

The script will load the first file found out of the three extensions cue,txt,log ( you cant define a single one ) in the directory,

Re: JScript Panel script discussion/help

Reply #657
zeremy, Thank you, we created Cue Viewer!


Re: JScript Panel script discussion/help

Reply #659
Code: [Select]
var items = plman.GetPlaylistItems(plman.ActivePlaylist);
for (var i = 0; i < items.Count; i++) {
items.Item(i).SetRating(5);
}
items.RefreshStats();
items.Dispose();
What to do with this script? Thanks.

Re: JScript Panel script discussion/help

Reply #660
I've been doing a LOT of work with color handling in my script as I'm using image.GetColorScheme() to pull the colors to generate a dynamic theme. It works great, and I can't wait to show it to everyone, but I figured I ought to share some of the helper code I wrote as I'm sure it'd be useful to more than just me.

This code makes extensive use out of the getRed, getGreen, getBlue, rgb, rgba helper functions and I won't bother repeating them unless somebody can't find them in helpers.txt. Also, I renamed RGB and RGBA to lowercase versions.

prettyPrint a color. Useful for logging:
Code: [Select]
function colToRgb(c, showPrefix) {
if (typeof showPrefix === 'undefined') showPrefix = true;
var alpha = getAlpha(c);
var prefix = '';
if (alpha < 255) {
if (showPrefix) prefix = 'rgba'
return prefix + '('+ getRed(c) + ', ' + getGreen(c) + ', ' + getBlue(c) + ', ' + alpha + ')';
} else {
if (showPrefix) prefix = 'rgb'
return prefix + '(' + getRed(c) + ', ' + getGreen(c) + ', ' + getBlue(c) + ')';
}
}

Calculate Brightness of a color:
Code: [Select]
function calcBrightness(c) {
var r = getRed(c);
var g = getGreen(c);
var b = getBlue(c);
return Math.round(Math.sqrt( 0.299*r*r + 0.587*g*g + 0.114*b*b ));
}

Create Shades (darker) or Tints (lighter) of a color. These two functions take a percent number, i.e. pass 20 instead of .2. Passing 100 to shade will result in solid black, 100 to tint is solid white.
Code: [Select]
color = rgb(81, 89, 72); // gray-ish green
darker = shadeColor(color, 30);    // darker = rgb(57, 62, 50)
lighter = tintColor(color, 20);    // lighter = rgb(116, 122, 109)

function shadeColor(color, percent) {
var red = getRed(color);
var green = getGreen(color);
var blue = getBlue(color);

return rgba(darkenColorVal(red, percent), darkenColorVal(green, percent), darkenColorVal(blue, percent), getAlpha(color));
}

function tintColor(color, percent) {
var red = getRed(color);
var green = getGreen(color);
var blue = getBlue(color);

return rgba(lightenColorVal(red, percent), lightenColorVal(green, percent), lightenColorVal(blue, percent), getAlpha(color));
}

// helpers, don't call directly
function darkenColorVal(color, percent) {
var shift = Math.max(color * percent / 100, percent / 2);
val = Math.round(color - shift);
return Math.max(val, 0);
}

function lightenColorVal(color, percent) {
val = Math.round(color + ((255-color) * (percent / 100)));
return Math.min(val, 255);
}

Re: JScript Panel script discussion/help

Reply #661
HI,
Does somebody know what is the fromhook parameter in this callback function ?
Code: [Select]
function on_metadb_changed(handle_list, fromhook) {}
It seems to be  boolean, and it seems to be true when the callback is from a change by foobar, and false otherwise. Is that true ? Is there a documentation somewhere ? There is nothing in the "official" documentation

Thanks!

Re: JScript Panel script discussion/help

Reply #662
HI,
Does somebody know what is the fromhook parameter in this callback function ?
Code: [Select]
function on_metadb_changed(handle_list, fromhook) {}
It seems to be  boolean, and it seems to be true when the callback is from a change by foobar, and false otherwise. Is that true ? Is there a documentation somewhere ? There is nothing in the "official" documentation

Thanks!
From fb2k SDK documentation:
//! @param p_fromhook Set to true when actual file contents haven't changed but one of metadb_display_field_provider implementations requested an update so output of metadb_handle::format_title() etc has changed.

E.g. it will be true when %play_count% field provided by foo_playcount component has changed.

Re: JScript Panel script discussion/help

Reply #663
Okey, thanks, clear enough

 

Re: JScript Panel script discussion/help

Reply #664
To anyone using IntelliJ WebStorm or IDEA to create/edit scripts:
I've updated JSDoc'd version of JScript's interface.txt, which can be used as a plugin/library in IDEA/WebStorm.
This will remove most of 'undefined symbol' warnings and will also provide some type checks when using JScript interface.

Instructions:
  • Download all the files from >>git<< and put them in some folder.
  • File > Settings > Languages > JavaScript > Libraries > Add... > + > Attach Directories... > Choose folder from the previous step

Re: JScript Panel script discussion/help

Reply #665
Is there a way distinguish two different playlists with the same name, without knowing their index?
When I need to perform some action on a specific playlist, I usually retrieve the playlist index by looping through all playlists until I find the one with the matching name, but since nothing in foobar2000 prevents me from accidentally duplicating a playlist name and the index changes when moving the playlist, how can I make sure I identify the right playlist?
I'm late

Re: JScript Panel script discussion/help

Reply #666
Is there a way distinguish two different playlists with the same name, without knowing their index?
When I need to perform some action on a specific playlist, I usually retrieve the playlist index by looping through all playlists until I find the one with the matching name, but since nothing in foobar2000 prevents me from accidentally duplicating a playlist name and the index changes when moving the playlist, how can I make sure I identify the right playlist?
Well, if two playlists have the same name and content, then the only way to differentiate them is by their index. If you are working on the currently active playlist you can retrieve it's index via plman.ActivePlaylist. May be you could elaborate your scenario a bit more?

PS: reply #666 > : )

Re: JScript Panel script discussion/help

Reply #667
Well, if two playlists have the same name and content, then the only way to differentiate them is by their index.

No, I mean two different playlists by all means, different content, but accidentally named alike.

I have some sort of "service" playlists. For example a "Recently Added" autoplaylist with all tracks added in the past 6 weeks. I use a script to create said playlist if it is not present (in case I accidentally delete it, for example). Now, let's say I run the menu command Library-> Playback Statistics -> Show recently added. This will create a second "Recently Added" autoplaylist, but with a different format and content. If I accidentally delete my "Recently Added" playlist, the script will fail to recreate it, because it will find another playlist with the same name and mistake it for the deleted one.


PS: reply #666 > : )
8)
I'm late

Re: JScript Panel script discussion/help

Reply #668
I'm pretty sure there must be some sort of playlist identifier, other than the name and the index, because components such as playlist attributes can keep trace of a single playlist settings even if its name is not univocal and even after it is moved around, hence changing its index, but I don't know if and how this identifier is accessible with jscript.
I'm late

Re: JScript Panel script discussion/help

Reply #669
I'm pretty sure there must be some sort of playlist identifier, other than the name and the index, because components such as playlist attributes can keep trace of a single playlist settings even if its name is not univocal and even after it is moved around, hence changing its index, but I don't know if and how this identifier is accessible with jscript.
foo_playlist_attributes probably uses this API (https://github.com/marc2k3/foo_jscript_panel/blob/master/foobar2000/SDK/playlist.h#L386), which is not exposed in JScript. Nevertheless, this API only allows to set some property to playlists (i.e. playlists are differentiated by index in fb2k itself), so foo_playlist_attributes most likely sets unique properties to each playlist on startup, which allows it to track all the changes on those playlists.

Re: JScript Panel script discussion/help

Reply #670
To anyone using IntelliJ WebStorm or IDEA to create/edit scripts:
I've updated JSDoc'd version of JScript's interface.txt, which can be used as a plugin/library in IDEA/WebStorm.
This will remove most of 'undefined symbol' warnings and will also provide some type checks when using JScript interface.
Damnit, I could really use this for VSCode :)


Re: JScript Panel script discussion/help

Reply #672
Touché!

Alright, so I added your Interfaces.js to my VS Code, and it works perfectly, almost. fb, gdi, utils, etc. all work out of the box.... except for gr which is the one I most care about :D

Dig a little digging and your code generator was missing the new on the gr constructor. Change 2110 to:
var gr = new IGdiGraphics();

And everything works beautifully. Also, I think I owe you a beer now.

Re: JScript Panel script discussion/help

Reply #673
I just updated to 2.0.x this week and today I just realized I can't add items to the playbackQueue. Here's my call:

plman.AddPlaylistItemToPlaybackQueue(activeList, focusItemIndex);

where activeList is the index of the playlist and focusItemIndex is the index into that playlist of the song. Both those numbers are correct. Nothing appears to happen though. Am I missing something? There was some stuff in the breaking changes about this playlist stuff, but it doesn't look like AddPlaylistItemToPlaybackQueue was affected.

Re: JScript Panel script discussion/help

Reply #674
Touché!

Alright, so I added your Interfaces.js to my VS Code, and it works perfectly, almost. fb, gdi, utils, etc. all work out of the box.... except for gr which is the one I most care about :D

Dig a little digging and your code generator was missing the new on the gr constructor. Change 2110 to:
var gr = new IGdiGraphics();

And everything works beautifully. Also, I think I owe you a beer now.

Heh, will be fixed soon =)
And you are welcome! Glad that it was useful for someone other than me :P

I just updated to 2.0.x this week and today I just realized I can't add items to the playbackQueue. Here's my call:

plman.AddPlaylistItemToPlaybackQueue(activeList, focusItemIndex);

where activeList is the index of the playlist and focusItemIndex is the index into that playlist of the song. Both those numbers are correct. Nothing appears to happen though. Am I missing something? There was some stuff in the breaking changes about this playlist stuff, but it doesn't look like AddPlaylistItemToPlaybackQueue was affected.

Not sure about this - AddPlaylistItemToPlaybackQueue works fine for me... Queue is updated and the added item is played next as well :\
The function usage seems the same as well:
https://github.com/TheQwertiest/CaTRoX_QWR/blob/master/theme/Scripts/Panel_Playlist.js#L4013

What do you mean by "Nothing appears to happen"? Is it that the added track is ignored, or on_queue_changed callbacks are not called?

PS: Didn't have a chance to visit Austin (or Texas for that matter) yet, but now I'll have one more excuse to rectify that =)