Editing tracks in a tracklist

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Editing tracks in a tracklist

Re: Editing tracks in a tracklist

by drakinite » Wed Aug 23, 2023 3:58 pm

Sorry for the late response. You're right, to get a read lock you need to use the locked method and put your code in a callback. Inside a read lock, you can use getValue and getFastObject. getFastObject is faster than getValue when you call it multiple times because it doesn't require extra memory allocation, but it reuses the same item in memory so you can't use it when storing track data for later use.

beginUpdate and endUpdate are unrelated to read/write locking and are instead used if you plan to modify the list, where a single change event is fired once after you're done, instead of firing a change event any time you make a modification. Haven't checked the source code but I think you should do beginUpdate and endUpdate inside of a modifyAsync callback. If you want to update *track data* like a song title you don't need to use modifyAsync, but if you want to add/remove songs from the list, modify the selected index, etc., use modifyAsync.

The new (WIP) documentation pages aren't super clear on those distinctions, and I can't find the SharedList blurb from the old documentation page (https://www.mediamonkey.com/docs/api/cl ... dList.html) so I'll try and make sure that's added.

Re: Editing tracks in a tracklist

by DaledeSilva » Thu Jul 20, 2023 8:47 am

I figured out the problem (Or how to get around).
I was treating the list of tracks returned from uitools.getSelectedTracklist as a Tracklist object and only looking at those docs.

The methods I found there are what I described above, which didn't work for me.
But in seeing that Tracklist extends SharedList, I had a look at those docs and found an example approach using it's methods.

So now my code is something like:

Code: Select all

let list = uitools.getSelectedTracklist();
await list.whenLoaded();
list.locked(() => {
   for(let i=0; i<list.count; i++) {
    console.log('track', track);
   }
});

Editing tracks in a tracklist

by DaledeSilva » Mon Jul 17, 2023 6:52 am

I've attempted to edit access tracks from the now playing list in two ways.
The first is what the documentation seemed to encourage as far as I could tell.
However, even though I'm using the commands to lock the list, I still get Uncaught (in promise) Error: Read lock not acquired!. (I also get it if I don't lock the list).

Code: Select all

let list = uitools.getSelectedTracklist();
await list.whenLoaded();
list.beginUpdate();
for(let i=0; i<list.count; i++) {
    console.log('track', track);
}
list.endUpdate();
However, with the second method, found on the forums, it works fine (Even when I edit the extended meta tags).

Code: Select all

let list = uitools.getSelectedTracklist();
await list.whenLoaded();
list.forEach(track => {
    console.log('track', track);
});

This confuses me. What's different about the two approaches? Aren't I still getting a track object either way?
Also, when does one need to lock the list if not in this case?

Thanks,
Dale.

Top