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

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #501
Hi snotlicker
Thanks for the quick response. You are correct and I'm guilty of such a stupid js school-boy error. Too embarrassed to tell what I'd done wrong. All working now. Thanks.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #502
BTW, I stupidly had clicked the "don't show me this again" checkbox. Is deleting the foo_spider_monkey.dll.cfg good enough to reset that? It didn't reset the panel configuration so some data is being stored elsewhere at least.

"don't show me this again" options is fb2k-instance-local. Meaning that it only affects the current process of fb2k and it does not persist across different fb2k launches.

@ your "hanging" problem: I'm trying to make "Slow script" dialog async, so that it would not halt the script execution. But I don't think I can do anything other than that.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #503
Does that mean you could also hide the dialog again, once things become responsive again, or no? Even if not it'd be a big improvement since users would be able to see the theme load behind the dialog.


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #505
I'm trying  to process selected files from a playlist. Firstly I want to convert them and I'm using:
fb.RunContextCommandWithMetadb("Convert/mp3 tablet",handle_list);
then I want to embed the album cover. My problem is the the RunContextCommand doesn't block so I need an event that is raised when all the files have been converted. Any ideas?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #506
@Black_Over_Bills_Mothers , that's just the way fb2k API works. Hence can't do much if the invoked command is non-blocking :\

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #507
I'm trying  to process selected files from a playlist. Firstly I want to convert them and I'm using:
fb.RunContextCommandWithMetadb("Convert/mp3 tablet",handle_list);
then I want to embed the album cover. My problem is the the RunContextCommand doesn't block so I need an event that is raised when all the files have been converted. Any ideas?
In general you could use something like the code below. You need to replace <get handleList> and <do the processing for metaDb> with valid code and you might need to play a little bit with the timings.
Code: [Select]
const handleList= <get handleList>;                                         

fb.RunContextCommandWithMetadb("Convert/mp3 tablet",handleList);
 
const processItem=() => {
  if(!handleList.Count) return false;
     
  const metaDb=handleList[0];

  <do the processing for metaDb>

  handleList.RemoveById(0);

  return Boolean(handleList.Count);
};

() => {
   if(!processItem()) return;
   
   setTimeout(arguments.callee,20);
}();

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #508
That seems dangerous to me. You're essentially just guessing that each file will be written in 20ms. If HDDs need to spin back up, or a file is huge, this will fail just like B_O_B_M's original case.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #509
That seems dangerous to me. You're essentially just guessing that each file will be written in 20ms. If HDDs need to spin back up, or a file is huge, this will fail just like B_O_B_M's original case.
No, it's not dangerous. You just need to make additional tests during the processing and return false return true, if the file, which needs to be processed is not ready. Additionally a guard should be implemented to avoid endless processing.

Edit: Corrected and extended the answer.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #510
@All. Thanks for your replies. My best effort was to create an autoplaylist targeted at the destination for the converted files. I made a note of the file total and tested the playlist index of the autoplaylist and file count in the 'on_playlist_items_added(playlistIndex)' event. When I had all the files in the destination folder, I continued and embedded the album image in them all. Seems to work so far.

Thanks for your valuable time spent in helping me on this.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #511
@MordredKLB , I've tinkered around a bit . Regretfully, it seems that it's impossible to make `slow script` dialog asynchronyous (without writing/using a new GUI stack): the problem is that GUI handling/processing is performed on the main thread, so if the main thread is stuck (e.g. in the infinite loop in JS), then no GUI messages can be processed making it impossible to interact with any dialogs (including `slow script` dialog).

While I understand your problem, I just don't know what can be done without removing the `slow script` check. I will try to extend the time limit a bit for the script on fb2k startup (in case there's some async stuff that hogging up the CPU), but it's still won't be a universal solution and it might not help much in your case.

[EDIT] Welp, no idea how to check that fb2k has loaded everything. Hence decided to make `slow script` time limit configurable (Advanced > SMP > Performance > Execution time limit).

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #512
@MordredKLB , I've tinkered around a bit . Regretfully, it seems that it's impossible to make `slow script` dialog asynchronyous (without writing/using a new GUI stack): the problem is that GUI handling/processing is performed on the main thread, so if the main thread is stuck (e.g. in the infinite loop in JS), then no GUI messages can be processed making it impossible to interact with any dialogs (including `slow script` dialog).

While I understand your problem, I just don't know what can be done without removing the `slow script` check. I will try to extend the time limit a bit for the script on fb2k startup (in case there's some async stuff that hogging up the CPU), but it's still won't be a universal solution and it might not help much in your case.

[EDIT] Welp, no idea how to check that fb2k has loaded everything. Hence decided to make `slow script` time limit configurable (Advanced > SMP > Performance > Execution time limit).
Thanks for investigating and I was afraid that might be the issue.

In further thinking, I might play around with async loading, just to see if maybe that can help. It all depends on what's actually happening behind the scenes with FB freezes trying to read from the HDD. i.e. do the other threads completely get locked out while that's happening, or are they just processing very slowly. If it's the first (which seems likely) then there's nothing to be done, but if it's the second, it might make this issue harder to encounter. It's weird though that SMP can still display the dialog.

Honestly this seems like a FB issue, and I'm wondering if we should report to @Peter .

 

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #513
It's weird though that SMP can still display the dialog.
SMP can display a modal `slow script` dialog during JS execution, because this dialog is invoked during JS interruption callback (i.e. it actually stops JS execution, thus it no longer stalls the main thread). The dialog could not have been displayed if the main thread was stalled by smth not JS related (this `not JS related` stuff might slow-down JS execution enough to trigger the `slow script` though).

If you have a debugger (e.g. visual studio), you may try to diagnose the issue by attaching to fb2k and breaking during the freeze. It will at least show the `.dll` on which fb2k is stuck.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #514
Well this is my confusion. Are you saying SMP executes the JS in the main thread then? In that case I would have thought that the interruption handler wouldn't have been able to work since it's also on the main thread, unless I'm misunderstanding how that even works.

I might try the debugger trick, or maybe just wait and see if I'm the only one actually running into the issue. It's a pain in the ass to get conditions right to even occur naturally (although I haven't messed with HDD spin-down times yet...)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #515
Are you saying SMP executes the JS in the main thread then?
Yep. Most of the JS stuff is executed on the main thread. A lot (most?) of GC is performed on worker threads though (memory deallocation is not cheap, so it gives a good performance boost).

In that case I would have thought that the interruption handler wouldn't have been able to work since it's also on the main thread, unless I'm misunderstanding how that even works.
I didn't look in the Spider Monkey internals too much, but it probably looks smth like this:

Code: [Select]
// SM internals
// Everything here is executed on the main thread

void JSMachineRunner()
{
  while (hasStuffToDo)
  {
    auto currentPart = GetNewPart();
    ExecuteJSMaybe(currentPart);
  }
}

void ExecuteJSMaybe(JSPart part)
{
  if (interruptRequested)
  {
    InvokeInterruptCallback();
  }
  ExecuteJS(part);
}

I.e. in JS engine itself the JS code is not monolithic, but split in parts that are fed in a JS runner (even an infinite loop like `while(true){}`). Thus making the interruption (and `slow script` dialog) possible.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #516
Got it. Well, i'll give the async script loading a shot. Wrap every file in a await promise with setTimeout(() => {}, 1) and see if that improves the situation.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #517
problem 1: Artist Images (thumbs.js)

help to configure the paths for displaying the covers in the "covers" folder, the problem is that sometimes I place this folder in the album, it is one level higher (in the case of a two-disc edition) - I just can't configure the second option. I want the code to look for the "covers" folder first in the lower directory, then, not finding it there, went up one level, and so on

problem 2: last.fm similar artists + user charts + recent tracks

similar unicode characters are not displayed correctly (bands in German, French)

problem 3: last.fm

I can not configure the folder for uploading photos from last.fm to the same directory as the artist

problem 4: musicbrainz

the discography is sorted by year in reverse order and I want to increase

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #518
I might try some tests with async/await wrapping includes.
Wanted to follow up that loading scripts async made the issue go away. I haven't seen the slow-script warning popup in the last 2 months.

My code for anyone who has this same problem (probably nobody else):

Code: [Select]
function loadAsyncFile(filePath) {
    return new Promise(resolve => {
        setTimeout(() => {
            include(filePath);
            resolve();
        }, 1);
    })
}

const basePath = fb.ProfilePath + 'georgia\\';

async function includeFiles(fileList) {
    for (let i = 0; i < fileList.length; i++) {
        await loadAsyncFile(basePath + fileList[i]);
    }
}

includeFiles([
    'js\\CaTRoX_QWR\\lodash.min.js',
    . . . // all other files
]);

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #519
@Mrakobes , regretfully my free time is very limited currently (even more than before, because of the new job I've landed). Because of that I won't be focusing on script development, but rather on component itself (I will steal some script fixes\improvements from @marc though :P)

@MordredKLB , glad to hear that it's working out for you =)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #520
Hi :) This is obviously not the best moment judging from your last post. I just wanted to remind you this one from about 6 months ago, so you can keep it in mind when the moment comes. Many thanks in advance !

@wcs13 , it might be possible to implement such logic in the script (ignoring low-res images that is), but I'm currently prioritizing component development over script improvement. In other words it won't be fixed anytime soon, sorry.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #521
Quick hack, complete\js\thumbs.js, line 492, replace the existing function with this..
Code: [Select]
	this.update = () => {
this.image = 0;
this.files = [];
this.images = [];

let tmp = _getFiles(this.folder, this.exts, this.properties.sort.value == 1);
tmp.forEach((item) => {
let img = gdi.Image(item);
if (img && img.Width >= 500 && img.Height >= 500) {
this.files.push(item);
this.images.push(img);
}
});

this.size(true);
window.Repaint();
}

Change the dimensions as required.


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #523
fb.GetNowPlaying() method returns the actually playing (or paused) track, and returns a null value when the player is stopped, but it seems that foobar2000 stores a reference to the track even once it is stopped, because it is resumed when pressing the "play" button subsequently. Panel Stack Splitter also seems to access that reference when titleformat mode on start up is set to "Now playing".
So, given my assumption is not wrong, is there a SMP method that returns that same reference?
I'm late