Editing tracks in a tracklist

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

DaledeSilva
Posts: 906
Joined: Sun May 28, 2006 4:22 am
Location: Australia
Contact:

Editing tracks in a tracklist

Post by DaledeSilva »

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.
Product Designer & Indie Developer.
Building at the intersection of motion, art, and code.
Find me on twitter and all the other ones here.
DaledeSilva
Posts: 906
Joined: Sun May 28, 2006 4:22 am
Location: Australia
Contact:

Re: Editing tracks in a tracklist

Post by DaledeSilva »

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);
   }
});
Product Designer & Indie Developer.
Building at the intersection of motion, art, and code.
Find me on twitter and all the other ones here.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Editing tracks in a tracklist

Post by drakinite »

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.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Post Reply