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: Spider Monkey Panel (foo_spider_monkey_panel) (Read 349856 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #575
To give you some idea on the workload: just a small overview of all the currently planned features for next releases: https://github.com/TheQwertiest/foo_spider_monkey_panel/projects/1#column-3416309

Delighted to see these ❤

Keep it up, this component makes foobar2000 so much fun!
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #576
Not sure, I need to check if there's any built-in sorting function that allows to do that, since I don't want to drag a big chunk of code in component just for that.

For now you can just append three zeroes, I mean I doubt that there'll be more than 1k buttons :D
Yep, did that and works great. Most things have <30 options, and as you said I don't plan to have more than 10 buttons on the same bar.

Quote
- additional display mode for Properties dialog: properties are displayed as a tree view, where `.` character is used as a separator.
- support for arrays (yet to figure how it will work though).
- ability to set property type explicitly (in dialog and via JS).
- support for enum values (the feature that you are requesting).
- ability to manipulate properties as a json (where objects are generated the same way as the tree view).
That would be great!
I support arrays and objects separating keys/values by commas and then converting it to arrays/objects with my own helper hahahaha not pretty but works. I needed it to allow setting arbitrary tags on filters (remapping X tags to be treated as 'genre'). Or pairs {tag: value}. Obviously the downside is that you have to manually follow the convention needed for that property and warn about it on the description (one "solution" is use the value for that: PUT HERE AN OBJECT {...}).
For simplicity I just use x,value,y,value... but I see no reason to allow "{}" or "[]" notation.

Btw, I manipulate properties as objects. I simply create one with default properties (the main function), then I add new properties on buttons if required. Use [...old, ...new] and have my own set of functions to set, get all values at once. Since I use prefixes and unique IDs, I can pass the object to functions and load the associated properties by merging the default keys with the ID. That works good enough for me, and I even use properties to set tooltips dynamically for every button. Prefixes can be set to name different categories within the properties. Also using  [...old, ...new], you can simply create 4 different properties objects on the js file (if that makes easier the readability or you need conditional settings) and then merging them. Not a tree like view but works.

About that, the only thing I could not make to work are paths. Property values seem to be converted to strings when using the "get..."), so paths with "/" get broken. I was expecting to be able to use raw on output and then change "/" to "//" before converting the path to a string, but no way. Also that string implicit conversion gave me some headaches, since numbers were sometimes treated as strings until I found I had to explicitly add Number() when getting properties (and tags too! -like date-)

Quote
The `panels` you are talking about are virtual panels, but there is no such concept in SMP right now and I don't think I want to introduce it and there several reasons for that:
- This is quite a big feature. The proper concept introduction will require quite a lot of new API (and component code to support it).
- It's use-case is quite niche. In 99,999% cases buttons don't need any additional properties and usually work just as a dumb callback-invoker.
Well that's exactly the use-case for all the things I have developed for playlist creation hahaha But it's working using my framework, so it's not a needed thing at all. Got it right with the padding and creating unique IDs. I also managed to show the IDs within the tooltips, so it's pretty easy to know which button is associated to which ID. That's good enough for me and once I share it on github, could be used by anyone as a workaround.

Oh, and other thing I noticed these days. Just a question. Why the getMeta... way is slower than ussing TF? Let's say you have 30k tracks and I need to get all the values of genre, mood, style, etc. and then loop through them to check some things. I have noticed it's faster to use evalwithmetadbs(), setting a TF expression like "tagX | tagY ..." and then splitting things on multidimensional arrays using "|" per tag, and ", " per value than looping through files and getting tags... that was weird. I mean... the method to get tags is slower than the method expected to be the slowest one. What's the use of the getMeta... then? Am I missing something?

And could you confirm this?
Quote
Thanks! Well the html rendering part is done outside foobar with a browser, so it's just using standard js code. I'm not sure if it could be integrated in any way within foobar as a html popup though (?) On github, you told me IE is used for html rendering, so I could try that path once I install it. I don't use fancy things, just standard js, SVG rendering and jquery as a library. It would be awesome: I could do things like showing tracks from the library matching the node selected, playlists by node and "radius", etc.

I still have to check the iso subsong bug, I will update the issue on github as soon as I can. Thanks for this great component and all your work!

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #577
@Qwertiest
Not wishing to add to your workload too much... any chance of changing the file name sent to an external editor. At the moment it is smpxxxx.tmp. To help get the most out of MS Code for example, it would be good if the file name used was smpxxxx.js.
Sure =)

About that, the only thing I could not make to work are paths. Property values seem to be converted to strings when using the "get..."), so paths with "/" get broken. I was expecting to be able to use raw on output and then change "/" to "//" before converting the path to a string, but no way. Also that string implicit conversion gave me some headaches, since numbers were sometimes treated as strings until I found I had to explicitly add Number() when getting properties (and tags too! -like date-)
Not sure I understand your problem with paths, could you elaborate, plz?
Regarding strings and types - this is the only way I can find out the property type, i.e. I can't convert string to int myself, since it might've been intended to be a string by user, but just happened to contain numbers inside.

Oh, and other thing I noticed these days. Just a question. Why the getMeta... way is slower than ussing TF? Let's say you have 30k tracks and I need to get all the values of genre, mood, style, etc. and then loop through them to check some things. I have noticed it's faster to use evalwithmetadbs(), setting a TF expression like "tagX | tagY ..." and then splitting things on multidimensional arrays using "|" per tag, and ", " per value than looping through files and getting tags... that was weird. I mean... the method to get tags is slower than the method expected to be the slowest one. What's the use of the getMeta... then? Am I missing something?
What do you mean by getmeta?

And could you confirm this?
https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/utils.html#.ShowHtmlDialog


@davideleo , no ETA though :P (as usual)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #578
What's the use of the getMeta... then? Am I missing something?

The point of using GetFileInfo() is that you can access all tags within a file without knowing what they are. Using title formatting, you have to know in advance what tags you want to access. Load up the samples\properties sample. It doesn't know or care about your tags but displays them all regardless. If that script was based on title formatting, you'd have to tell it about each and every tag your files might contain.

edit: some sections of that properties sample are based on title formatting but the main meta and tech info sections use GetFileInfo and loop through the available fields without knowing the names.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #579
Quote
Not sure I understand your problem with paths, could you elaborate, plz?
Regarding strings and types - this is the only way I can find out the property type, i.e. I can't convert string to int myself, since it might've been intended to be a string by user, but just happened to contain numbers inside.
Let's say I create a property.
window.GetProperty(blabla, 'C:\path\gbqaws');
For sure, that path it's wrong if you use it as is within js. You know it, I know it. Ok. But what about users?
window.GetProperty(blabla, 'PUT HERE YOUR PATH');
Then the user just copy/paste paths from explorer and...
99.99% programs within windows give you paths with single "\" when copying them.

Maybe that's easily solved with other method (I'm totally novice on js) but as far as I know the only way to manage that usage is using String.raw'whatever' . But that workaround does nothing in this case since the getProperty value has been already converted to string where escapes have been processed. So...
window.GetProperty(blabla, 'PUT HERE YOUR PATH').replace('\','\\'); for sure doesn't work.
neither
String.raw'${window.GetProperty(blabla, 'PUT HERE YOUR PATH')}'.replace('\','\\');
nor
String.raw'${window.GetProperty(blabla, String.raw'C:\path\gbqaws')}'.replace('\','\\');
As far as I tested, you are forced to put double \ on the panel (?) because the returned value has been already converted to string. Similar behavior can be found with other escapes.

Quote
What do you mean by getmeta?

This
Code: [Select]
function getTagsValues(handle, tagsArray, bMerged = false) {
if (!isArrayStrings (tagsArray)) {return null;}
if (!handle) {return null;}

const sel_info = sel.GetFileInfo();
const tagArray_length = tagsArray.length;
let outputArray = [];
let i = 0;

while (i < tagArray_length) {
let tagValues = [];
const tagIdx = sel_info.MetaFind(tagsArray[i]);
        const tagNumber = (tagIdx != -1) ? sel_info.MetaValueCount(tagIdx) : 0;
if (tagNumber != 0) {
let j = 0;
while (j < tagNumber) {
tagValues[j] = sel_info.MetaValue(tagIdx,j);
j++;
}
}
outputArray.push(tagValues);
i++;
}

if (bMerged) {outputArray = outputArray.flat();}
return outputArray;
};

Is slower than this;
Code: [Select]
]function getTagsValuesV3(handle, tagsArray, bMerged = false) {
if (!isArrayStrings (tagsArray)) {return null;}
if (!handle) {return null;}

const tagArray_length = tagsArray.length;
let outputArray = [];
let i = 0;
let tagString = "";
const outputArray_length = handle.Count;
while (i < tagArray_length) {
if (bMerged) {tagString += i == 0 ? "[%" + tagsArray[i] + "%]" : "[, " + "%" + tagsArray[i] + "%]";} // We have all values separated by comma
else {tagString += i == 0 ? "[%" + tagsArray[i] + "%]" : "| " + "[%" + tagsArray[i] + "%]";} // We have tag values separated by comma and different tags by |
i++;
}
let tfo = fb.TitleFormat(tagString);
outputArray = tfo.EvalWithMetadbs(handle);
if (bMerged) { // Just an array of values per track: n x 1
for (let i = 0; i < outputArray_length; i++) {
outputArray[i] = outputArray[i].split(', ')
}
} else { // Array of values tag and per track; n x tagNumber
let tfo = fb.TitleFormat(tagString);
outputArray = tfo.EvalWithMetadbs(handle);
for (let i = 0; i < outputArray_length; i++) {
outputArray[i] = outputArray[i].split('| ');
for (let j = 0; j < tagArray_length; j++) {
outputArray[i][j] = outputArray[i][j].split(', ');
}
}
}
return outputArray;
}

Try it iterating on 30k tracks. I didn't understand how a TF approach is faster than using the methods to get tags. I mean... take a look at how many things I have to do to get usable output with TF...

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #580
What's the use of the getMeta... then? Am I missing something?

The point of using GetFileInfo() is that you can access all tags within a file without knowing what they are. Using title formatting, you have to know in advance what tags you want to access. Load up the samples\properties sample. It doesn't know or care about your tags but displays them all regardless. If that script was based on title formatting, you'd have to tell it about each and every tag your files might contain.

edit: some sections of that properties sample are based on title formatting but the main meta and tech info sections use GetFileInfo and loop through the available fields without knowing the names.
Ok that makes sense now... all my use-cases use already known tags names to compare things. So then those methods are only useful when iterating all tags. At least performance wise. I was slowing my scripts using the first approach without needing.

Quote
https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/utils.html#.ShowHtmlDialog
Well If I understand the w3s web... looks bad,

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #581
For sure, that path it's wrong if you use it as is within js. You know it, I know it. Ok. But what about users?

This is how the language works and there is nothing you can do about it. You have to do the same thing in C++ too.

https://github.com/marc2k3/foo_jscript_panel/blob/c2cf47859536c1bfffc956cf3996ae5e9df7d70d/src/Helpers/Component.h#L10

If you're intending to share your scripts then you should be building menus/buttons that use utils.InputBox or the Properties dialog for entering strings.

Editing scripts directly is obviously very error prone and is highly discouraged.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #582
For sure, that path it's wrong if you use it as is within js. You know it, I know it. Ok. But what about users?

This is how the language works and there is nothing you can do about it. You have to do the same thing in C++ too.

https://github.com/marc2k3/foo_jscript_panel/blob/c2cf47859536c1bfffc956cf3996ae5e9df7d70d/src/Helpers/Component.h#L10

If you're intending to share your scripts then you should be building menus/buttons that use utils.InputBox or the Properties dialog for entering strings.

Editing scripts directly is obviously very error prone and is highly discouraged.

That's what I already do. That's the point, I don't expect users to know \ should be doubled. It's also pretty inconvenient.
I mean, the UI panel is exposed to the user... so I expect usage according to the user mentality (copy/paste). Using panels solves nothing if they put paths with single \ there, I was not talking about editing scripts directly. That's why string.raw exists, for arbitrary user input.

But if nothing can be done about it, then I will just warn about it.

EDIT:
window.GetProperty(description, defaultval, function)

wouldn't that solve the problem with types?
Instead of Number(window.GetProperty(description, defaultval))
just window.GetProperty(description, defaultval, function(value) {return Number(value); })
Instead of strings processed
just window.GetProperty(description, defaultval, function(value) {return string.raw'${value}'.replace('/','//'; })
function should be applied as first step when loading the user value, not later.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #583
You don't have to double the \ when using the Properties window. It really is that simple.

As an example, load up samples\thumbs. Do not use the Custom folder menu option that I've nicely added. Instead, hold down Shift+Winkey and right click to open the Properties (I always hide easy access).

Now edit the value for 2K3.THUMBS.CUSTOM.FOLDER.TF to any folder that contains images using single slashes and click OK. Do the images display? I should hope so...

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #584
You don't have to double the \ when using the Properties window. It really is that simple.
I'm lost... and how do you convert that string to something usable within your code then?
let path = window.GetProperty(blabla);

becomes an unusable string (?) and replace('\','\\'); wiill not work.



Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #586
Quote
Now edit the value for 2K3.THUMBS.CUSTOM.FOLDER.TF to any folder that contains images using single slashes and click OK. Do the images display? I should hope so...
Quote
Now edit the value for 2K3.THUMBS.CUSTOM.FOLDER.TF to any folder that contains images using single slashes and click OK. Do the images display? I should hope so...
Nope. Strings with single \ definitely don't work on the panel for me, that's why I reported it... because I have tested it. With your samples, I got this on console...

c:\Users\xxx\AppData\Roaming\foobar2000\scripts\SMP\samples\js-smooth\images\default.png (panel)
->
c:UsersxxxAppDataRoamingfoobar2000scriptsSMPsamplesjs-smoothimagesdefault.png (console)

If you assure the properties should work that way, I will check on a new foobar profile since there is definitely something wrong here.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #587
I should have made it clear that the script expects a path to a folder - not a filename.

Check the attachment to see my previous post illustrated.




Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #588
If you assure the properties should work that way, I will check on a new foobar profile since there is definitely something wrong here.
Yeah, I'm not sure what you're doing. As marc showed, it works just fine. I also tested this out just to make sure. If you're doing SetProperty in a script you have to escape the slashes, but you certainly don't when editing in the properties panel, because again, those are already strings.

A simple console.log(window.GetProperty('FOLDER_PATH')) will demonstrate that it's correct (once you've defined a property called FOLDER_PATH). Are you doing anything to those strings after calling GetProperty to retrieve them?

 

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #589
I feel that you are talking past each other =)
So, I'll try to sum up all the things that @snotlicker said.

@regor , as it was mentioned above, in quite a few programming languages (and even in RegExp and windows command line) `\` character is used as an escape character or to form a control character. For example, `\n` is a control character for a new line, `\"` - escape the quote character.
Values that can be seen in property dialog have all the escape chars and control chars parsed.

So, in JS (and SMP) it will work like this:
Code: [Select]
window.SetProperty("escape_1", "\"");
console.log(window.GetProperty("escape_1"));  // Logged and displayed in Property dialog as `"`

window.SetProperty("escape_2", "\\");
console.log(window.GetProperty("escape_2"));  // Logged and displayed as `\`

window.SetProperty("path_1", "path\\to\\file.ext");
console.log(window.GetProperty("path_1")); // Logged and displayed as `path\to\file.ext`

window.SetProperty("path_2", "path/to/file.ext");
console.log(window.GetProperty("path_2")); // Logged and displayed as `path/to/file.ext`

window.SetProperty("control_1", "line_1\nline_2");
console.log(window.GetProperty("control_1"));
// Logged as:
// `line_1
// line_2`
// displayed as:
// `line_1line_2`

Thus, path strings in JS code should be either like this `path/to/file.ext` or like this `path\\to\\file.ext` .

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #590
Hi
I'm trying to get an indication if the single track selected is an individual flac file or part of a multi-track flac file. Any ideas?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #591
Hi
I'm trying to get an indication if the single track selected is an individual flac file or part of a multi-track flac file. Any ideas?


Check if the path ends with .cue or use title formatting for embedded cuesheets %__cue_embedded% equals yes

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #592
Check if the path ends with .cue or use title formatting for embedded cuesheets %__cue_embedded% equals yes
If cue is external (i.e. not embedded), you may also try checking FbMetadbHandle.SubSong, it seems to be above zero only when it's a multi-track file.


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #594
I always thought SubSong begain with zero for the first track which is why I didn't mention it. My mistake!
So did I =)
Just happened to have a cue file in my library to actually verify it >_<

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #595
Well done and thanks.
Most of my examples are a single flac file without a .cue companion. And low-and-behold the .SubSong method yields 1 upwards for each track. It is always 0 for non multi-track flacs.

Great.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #596
Just found out that if you use the internal editor to export a script and the name has spaces in it then the external editor (MS Code in my case) doesn't like it. Eg export as "prep new music" then use the external editior, MS Code opens two text files (prep and new) and one js file (music.js). Not sure if it's worth a code change but it's worth noting.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #597
Just found out that if you use the internal editor to export a script and the name has spaces in it then the external editor (MS Code in my case) doesn't like it. Eg export as "prep new music" then use the external editior, MS Code opens two text files (prep and new) and one js file (music.js). Not sure if it's worth a code change but it's worth noting.
That's a bug =)
Will be fixed.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #598
I've tried looking through the documentation but I'm not getting any wiser so I thought I'd ask here.

I want to make a button that switches between shuffle track and default playback that works like how the play/pause button in the sample "playback buttons", anyone have any suggestions on how to make it work?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #599
I've tried looking through the documentation but I'm not getting any wiser so I thought I'd ask here.

I want to make a button that switches between shuffle track and default playback that works like how the play/pause button in the sample "playback buttons", anyone have any suggestions on how to make it work?

Code: [Select]
			if (plman.PlaybackOrder === 4){
fb.RunMainMenuCommand("Playback/Order/Default");
} else {
fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)");
}
I'm late