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

Re: JScript Panel script discussion/help

Reply #2125
I'm trying to add some functionality to the original seekbar from the samples.

I added PlayOrPause to rightclick so you can start playing, pause or resume playing. Works.
I added some changes in the display of the TIME/seekbar stuff when width is limited. Also works.

I added hover on TIME/seekbar so the alpha goes up when being over the seekbar with the mouse. Works well too when playing. But not when paused or stopped.
While playing it uses the callback on_mouse_move to set the alpha, but this callback does not seem to be triggered when paused/stopped.
Checked all the docs, tried a lot but cannot activate the hover when paused/stopped.

Is there another callback I should use? Or does it require changes in seekbar.js?

Re: JScript Panel script discussion/help

Reply #2126
Hi
I can't seem to find this script. Theres only an outdated version on github.

Re: JScript Panel script discussion/help

Reply #2127
Hi
I can't seem to find this script. Theres only an outdated version on github.
Seems to be completely scrubbed now, even the 3.8.5 version that was left up for a while.  "Why?"  Nothing on the Wayback Machine link either besides documentation--clicking the 3.8.5 download link once it is finally found results in "url not archived."

The developer mentioned about putting some scripts on the Uploads forum, nothing there yet.  I've attached it here, hopefully not breaking any rules.

Re: JScript Panel script discussion/help

Reply #2128
Thank you very much. I will take a look at this because it seems most panels dont do what I want them to. Though I know this will be a pain.

Re: JScript Panel script discussion/help

Reply #2129
I'm using JScript Panel 3 to get some Artists Info statistics and Similar Artists from lastfm.
The default path that this component is writing the json files is profile\js_data\artists\<artist Name>
I would like to change that to <artist folder>\lastfm
This way in case I delete the artist I would like this data to be removed otherwise it just keep growing.

Any ideas?
Enjoy life now, this is not a rehearsal.

Re: JScript Panel script discussion/help

Reply #2130
I'm trying to add some functionality to the original seekbar from the samples.

I added PlayOrPause to rightclick so you can start playing, pause or resume playing. Works.
I added some changes in the display of the TIME/seekbar stuff when width is limited. Also works.

I added hover on TIME/seekbar so the alpha goes up when being over the seekbar with the mouse. Works well too when playing. But not when paused or stopped.
While playing it uses the callback on_mouse_move to set the alpha, but this callback does not seem to be triggered when paused/stopped.
Checked all the docs, tried a lot but cannot activate the hover when paused/stopped.

Is there another callback I should use? Or does it require changes in seekbar.js?
Nevermind. I figured it out. It was the latter and a bit of the first.

Re: JScript Panel script discussion/help

Reply #2131
Hello there, I know this might be abandoned but I'll try.

Is it possible to replace the spectogram view into waveform instead?

I tried to replace the ffmpeg command showspectrumpic in seekbar.js file into showwavespic but doesn't seems to work.

Re: JScript Panel script discussion/help

Reply #2132
You'll need to remove the existing this.properties.params.value from the command line as well because they won't apply here.

And looking at the docs, you'll need to add various other params as well.

But honestly, I'd just stick to this:

https://www.foobar2000.org/components/view/foo_wave_minibar_mod

edit: if you want to persist with the scripting, after the line that begins with var cmd =

Code: [Select]
console.log(ffmpeg_exe, cmd);

and then copy/paste the output from the fb2k console to a command prompt and run it. That will give clues as to it succeeding/failing.

Re: JScript Panel script discussion/help

Reply #2133
Thank you Marc, it works.
Yeah, I also use the wave_minibar_mod components and it has been solid for years.
I'm just looking for ways to emulate this design, it's the Amberol music player for Gnome.
I think the waveform would fit well in the Text Display sample.
The black background is the issue now.

Re: JScript Panel script discussion/help

Reply #2134
Edit on_paint in the main panel to remove the black background

Code: [Select]
function on_paint(gr) {
gr.Clear(RGB(0, 0, 0));
seekbar.paint(gr);
}

In my scripts, it's there for when images can't be generated. You can remove it/change the colour.

Re: JScript Panel script discussion/help

Reply #2135
I was trying the waveform on track + specto sample, I missed the gr.FillRectangle line haha.
Thanks again Marc!

Re: JScript Panel script discussion/help

Reply #2136
Hello there, I know this might be abandoned but I'll try.

Is it possible to replace the spectogram view into waveform instead?

I tried to replace the ffmpeg command showspectrumpic in seekbar.js file into showwavespic but doesn't seems to work.
Note that command creates an actual waveform image (bg included), which will differ a lot from what you showed at that pic. There will also be no way to change colors unless you also edit the CMD or paint using masks, which will greatly increase complexity. And forget about increasing/decreasing resolution, proper resizing, etc. Also everytime you change a setting, files would need to be reanalyzed.

You have an actual usage of ffmpeg at my waveform script which avoids those drawbacks by painting the waveform using the audio data, not an image, which looks exactly like that pic (if you disable animation). It's obviously not for JSP3, but you can either use other JS host or reuse the design.

Re: JScript Panel script discussion/help

Reply #2137
Thanks for the reply Regor.
The waveform images generated are actually has transparent layer, so the background can be adjusted from the script.
It's also generated really quickly without any performance impact, plus the cache files are smaller ~5kb per file, much smaller compared to spectogram.
It can also be resized and recoloured quite easily via the context menu command, I think it's simple enough for my use case.

Thanks for sharing your waveform script. I tried it, but honestly found it quite slow and not as fluid as I had hoped, even at the highest refresh rate. I appreciate your work on it, but I think I will explore other options for visualisation, thank you!


Re: JScript Panel script discussion/help

Reply #2138
The waveform images generated are actually has transparent layer, so the background can be adjusted from the script.

Great, then color could also be changed easily with masks without needing to touch the command line.

Quote
It's also generated really quickly without any performance impact, plus the cache files are smaller ~5kb per file, much smaller compared to spectogram.

It can also be resized and recoloured quite easily via the context menu command, I think it's simple enough for my use case.
Well one thing is adjusting the command line to your specific system and theme, and another making it work in general. Your gif is just resizing the 1024x128 image to your panel size, which may work for you, but for sure will not work if the program is meant to be adjusted to different DPIs or sizes (that's what happens in Georgia Reborn) or when you have more than 2 channels. The image is just distorted in such case. There is also no interpolation for data when you resize to lower/higher sizes, thus as I said, being totally different to the pic you showed. And then you also have the problem of track length, where tracks with higher length will show more "precission" than those with lower length. (which is fine if you like it that way)

That's also why it's faster.

Quote
Thanks for sharing your waveform script. I tried it, but honestly found it quite slow and not as fluid as I had hoped, even at the highest refresh rate. I appreciate your work on it, but I think I will explore other options for visualisation, thank you!

The script is only slower at the analyzing step, since contrary to the image approach, it will actually scan and store the waveform data which can then be interpolated to any size. But that's done once, and data can be reused, applying UI settings on top.

Unless you talk about the "animation" but that's up to you to find your right settings, if you disable it, it's on par with your approach. My system is pretty slow and It doesn't take more than 1 second to analyze (in the example it says 500ms), and then data is reused. it's also within Georgia Reborn and considering the entire theme is JS based, there were zero complains about not being fluid, so not sure where your experiences comes from.

Btw data size is less than 1 / 2 kbs per file in my case, since I use LZ16 compression. Which is much lower than the spectogram, ffmpeg images or anything out there.

Spoiler (click to show/hide)

Then there are also a myriad of settings to tweak how things look (cover background, dynamic colors, waveform styles, etc.), like the C++ component marc recommended you (which also allows to set different colors to the already played and remaining parts). Just giving the info and some insights about the problems of using ffmpeg to draw images because you specifically asked to emulate the design of your pic (which can't be done with ffmpeg alone), but use whatever suits you for sure :)

Edit: an image example, setting it to emulate your pic: (no current position, no alternate background, no animation, gray colors, width normalized to 2) with/out cover background
X X

 

Re: JScript Panel script discussion/help

Reply #2139
Hello, I would like to find the easiest way how to call a system command on track changes. I want to catch sample rate changes. I tried the very old foo_uie_biography which contains the possibility to run external command. It is outdated, it does not work for its original purpose (it supports only http, no https) and it attempts to contact allmusic server despite of I unconfigured everything what I could, but running an external command on track changes still works.

I would like to perform this task with some plugin or maybe API which is maintained and more current, preferably working in 64bit foobar2000 version. Could you suggest me one? Maybe the one of this thread, or any other which would be easy to setup for the given purpose?

Re: JScript Panel script discussion/help

Reply #2140
Well I will not bother looking for the missing deleted docs for this component, but on SMP (x32) / JSplitter (x64) you have a callback which is called when playing a new track, which sounds to me a solution.

https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/module-callbacks.html#~on_playback_new_track

"on_playback_new_track"

I suppose the JSP equivalent is even named the same. In any case, both work for x64. You can run CMD commands there, adding this line to the callback:

Code: [Select]
new ActiveXObject('WScript.Shell').Run(command, 0, bWait);

For ex: (copy old.txt to new.txt, hide the CMD window and wait to finish)

Code: [Select]
new ActiveXObject('WScript.Shell').Run('CMD /C COPY "old.txt" "new.txt"', 0, true);

All together: (I don't think I added anything incompatible with JSP)

Code: [Select]
const WshShell = new ActiveXObject('WScript.Shell');
const command = 'CMD /C COPY "old.txt" "new.txt"';

function on_playback_new_track(handle) {
    if (handle) {WshShell.Run(command, 0, false);}
}

Re: JScript Panel script discussion/help

Reply #2141
@regor  Thank you very much! Your code worked so I could adapt it. Much better for my needs than my yesterday attempt with foo_uie_biography.

Re: JScript Panel script discussion/help

Reply #2142
Glad you got it working.

I think I may create a script for this case, since "foo_uie_biography" is dead, for my toolbar buttons. Something which would easily allow to set a callback (on track played) and a CMD action, just using simple menus. No need to know anything about JS for that, so anyone could easily set their own actions.

Re: JScript Panel script discussion/help

Reply #2143
@regor   If it would allow to choose a callback, it would be really easily usable by anybody. Best if one could use title format strings about content played for example %album% or %samplerate%, so they could be set as command line parameters of the called external command.

My use case: I am using virtual audio cable to send foobar2000 output to other application. To avoid unnecessary resampling, I need to set sample rate in the other program to be the same as of the content played in foobar2000. From this reason I need to catch sample rate changes. It takes some time for the receiving program to process the sample rate switch, therefore I need to delay playback for few seconds. Since I need to perform more foobar2000 related operations at once, it is advantage for me to use SMP with javascript.

Other thing is that I generally understand programming, but I'm used to do simple procedural programming (bash, perl and python) with no things like async actions and event handlers. I didn't do any javascript programming before, but with some help from web I ended with this working code:

let last_sample_rate = null;
const WshShell = new ActiveXObject('WScript.Shell');

function on_playback_new_track(handle) {
    if (handle) {
        let current_sample_rate = fb.TitleFormat("%samplerate%").Eval();
        let command = `CMD /C D:\\tools\\sr-switcher\\sr-switcher.bat ${current_sample_rate}`;
        if (last_sample_rate != null && current_sample_rate != last_sample_rate) {
            fb.Stop();
            WshShell.Run(command, 0, false)
            setTimeout(() => fb.Play(), 2000);
        }
        last_sample_rate = current_sample_rate;
    }
}

Maybe some things are not optimal, but it works. Thanks for your previous help!

Re: JScript Panel script discussion/help

Reply #2144
Question about applying an effect (luminance) on a given image before saving.

I have a blurred image, I can save it and use it elsewhere outside of JS3.
Problem is that when the original image is too bright also the blurred image will be too bright.

I played a bit around with GetColourSchemeCount(count) and Luminance(colour), but I cannot find any documentation about the first function.

When count = 1 does it return the average colour for the whole image?
Or do I need for instance count 5 to get more predominant colours and if so is there also a weight available per returned array element (colour)?

In the end I want to calculate the overall luminance for a given image, then alter the luminance of the original image based on this calculated value, and then save.

I noticed there are some effects you can apply to an image (grayscale, invert, sepia), but those effects do not include increase/decrease luminance.
When the calculated luminance is too high, I could invert the image before saving, but that means I lose the original colours.

The JS3 draw functions themselves do accept an alpha setting upon displaying, but those are only available within JS3.

Does anyone have an idea, how to change the luminance of an image before saving?

Re: JScript Panel script discussion/help

Reply #2145
Obviously there is no builtin way for that. Neither you need it (although going that route, I would say JSP is simply not the right tool and you should execute a third party binary via CMD).

Just paint a black layer over the image with low alpha until you get your desired effect. You may also do a similar thing with a grayscale layer, and also have in mind you can use inverted and B&W images as alpha masks too (so you can selectively brighten/darken some parts).

For luminance, contrast and complex color manipulations I use chroma.js , I think the original repo is also being updated too. Don't expect further guidance by me about that part thought.

Re: JScript Panel script discussion/help

Reply #2146
Just paint a black layer over the image with low alpha until you get your desired effect. You may also do a similar thing with a grayscale layer, and also have in mind you can use inverted and B&W images as alpha masks too (so you can selectively brighten/darken some parts).
Does not work, because dark blurs will be darkened even more (and I actually want those dark blurs appear brighter).
I also want to keep the original album cover colors as the theme colors and not a inverted, sepia, b&w variant.

For luminance, contrast and complex color manipulations I use chroma.js , I think the original repo is also being updated too. Don't expect further guidance by me about that part thought.
I had a look in chroma.js and did not find anything to manipulate an image, and since I won't get any guidance for using this I consider it a dead end.

But I solved my issue, I now calculate the luminance of the dominant color and put that in the name of the blur image I save.
In PSS and ELP I modify the user requested base alpha based on this luminance value of the blur, either increasing (blurs with low luminance) or decreasing (blurs with high luminance).
Works remarkably well.

Re: JScript Panel script discussion/help

Reply #2147
Quote
Does not work, because dark blurs will be darkened even more (and I actually want those dark blurs appear brighter).

I also want to keep the original album cover colors as the theme colors and not a inverted, sepia, b&w variant.
Either I didn't explain it enough or you are not doing it right. If you have an image with shadows and lights, and you use the same image as a mask, then light areas will be filled while dark areas will be omitted. Thus, if you invert the image, to use it as a mask, and you apply a white tint, it necessarily brightens the dark areas.

That has nothing to do with changing colors. But obviously you can use inverted, sepia or b&w variants as masks to selectively  darken or brighten certain areas.

Additionally you can paint the image over a dark or white background with alpha applied, which is just the inverse operation.

In particular, you may apply such trick to paint the image over a background filled with an specific color (the most dominant for ex), with alpha. So everything will be nuked, except colors which have greatest contrast against it. You can use such image as a mask again, converting it to B&W.

Quote
In PSS and ELP I modify the user requested base alpha based on this luminance value of the blur, either increasing (blurs with low luminance) or decreasing (blurs with high luminance).

Works remarkably well.
To be honest I don't get how that's a solution to the problem. Or better said, why it was a problem in the first place.

If you already know the image is too bright (in JSP) and you just decrease the alpha on that case (in ELP), you are not changing the luminance of the source image at all, just doing a workaround xd which was my point, JSP or SMP are not image editors. You can apply tricks, that's all. (since changing transparency will just nuke darken areas, to try to save brighter areas)

But then, if you just apply a lower alpha (in ELP), you could also just save the image as png with a base transparency already applied (in JSP). There is no need to apply it in a third party panel (?) Unless I'm missing something, I don't see the difference between saving an image at 30% transpareceny as png or loading it in ELP and applying a 30% transparency there + the user value, since you are already clipping the max transparency in any case to that 30%. (leaving performance or other things out of the equation)

Anyway glad you found a way!


Re: JScript Panel script discussion/help

Reply #2149
Hey folks, question: is there a way to check whether a main menu command is enabled or not when a script first initializes?

I made a button to show status of Skip Tracks (foo_skip) command ("Playback/Skip tracks & use bookmarks") and to toggle it on/off, using panel properties to remember the setting. That all works fine. The problem now is I made different layouts with another instance of the button that does not remember the current setting.

I guess it'll be something to do with fb.EnumerateMainMenuCommands() and I see the example there prints all checked commands to console, but I'll need an example how to return a true/false on just the above command since I'm not savvy with the JS.

Thanks for any help. :)