MoveNext MoveBack getSelectedTracklist

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

Moderators: jiri, drakinite, Addon Administrators

MPG
Posts: 286
Joined: Tue May 13, 2008 11:22 pm

MoveNext MoveBack getSelectedTracklist

Post by MPG »

I'm working on a dialog box that will allow users to spellcheck the song title. I have used the function getSelectedTracklist to get the selected track objects. I need to have the ability to start on the first selected track, display the song title, allow the user to do the spellcheck, then allow the user to move forwards and backwards through the selected songs.

I've been looking at the Track Properties code trying to understand how it navigates through the selected songs and I cannot, for the life of me, figure it out.

Can someone show me how to do it? I'm thinking something along the lines of:

OpenDialog:
get list of tracks and pass to dialog form

init:
move first
set textbox to track title

Previous button:
move back
set textbox to track title

Next button:
move next
set textbox to track title
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 646
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: MoveNext MoveBack getSelectedTracklist

Post by drakinite »

Your analysis looks correct. But please note that the TrackProperties dialog only shows the previous & next buttons when there's one song selected. Its MoveNext and MoveBack functions actually modify the track list to change the focused item. (See fixFocusedIndex in dlgTrackProperties; the this.tracks object is a native Tracklist object.)

Judging by your description of how you want your addon to work, it sounds like you want the user to pre-select a list of songs they want to check, then open the dialog. This can be done without any of the focusedIndex stuff that TrackProperties does.
Once you have the selected tracklist, you can use getValue(idx) to get an individual track, and just store the appropriate index in a local variable. (Make sure you enter a read lock with locked() before using that function). getSelectedTracklist also returns a native Tracklist object, so check that API documentation link to see more info on those objects.

Here's a sample of one way you could implement it.

Code: Select all


function updateDialogContents(newTrack) {
    // Update your HTML / controls with this new track object
}

var currentlySelectedTrackIdx = 0;
// assuming you have two Button controls, with data-id btnNext and btnPrev
var UI = getAllUIElements(); 

UI.btnNext.controlClass.localListen(UI.btnNext, 'click', function () {
    selectedTrackList.locked(function () {
        var newTrack = selectedTrackList.getValue(currentlySelectedTrackIdx + 1);
        if (newTrack) {
            currentlySelectedTrackIdx += 1;
            updateDialogContents(newTrack);
        }
        else {
            // this'll occur if you've reached the end of your list
        }
    });
});
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
MPG
Posts: 286
Joined: Tue May 13, 2008 11:22 pm

Re: MoveNext MoveBack getSelectedTracklist

Post by MPG »

Thank you drakinite. I got the move forward, move back working. Yea me. :)

I now have two more issues that I can't seem to resolve....maybe you can give me some hints:

1) I take the value of the textbox and save it to the tracklist using:
trackLst.getValue(currentlySelectedTrackIdx).title = qid('edtSongTitle').controlClass.value;
I didn't expect the database field to be updated until I did a commitAsync. I don't want the value saved to the database until they click OK. In case they click cancel, in which case the updated values wouldn't be saved.

2) for the spellcheck, I need to include a javascript file. In my js file I have the following:
requirejs('Scripts/spellCheck/dialogs/include');
It doesn't seem to matter how I try to access the file, the call fails. Any suggestions?
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 646
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: MoveNext MoveBack getSelectedTracklist

Post by drakinite »

Great!
MPG wrote: Fri Nov 19, 2021 11:58 am 1) I take the value of the textbox and save it to the tracklist using:
trackLst.getValue(currentlySelectedTrackIdx).title = qid('edtSongTitle').controlClass.value;
I didn't expect the database field to be updated until I did a commitAsync. I don't want the value saved to the database until they click OK. In case they click cancel, in which case the updated values wouldn't be saved.
To my understanding, editing a field in a shared object WILL instantly update within the UI and the rest of the program, but will not be saved to the database until commitAsync() is called. (Could be wrong; I'll double check). Either way, I agree that you won't want to edit the track objects until the user clicks OK. One solution would be to store the edited fields inside an array or object, then loop through the array and update the corresponding tracks' fields when the click OK.
MPG wrote: Fri Nov 19, 2021 11:58 am 2) for the spellcheck, I need to include a javascript file. In my js file I have the following:
requirejs('Scripts/spellCheck/dialogs/include');
It doesn't seem to matter how I try to access the file, the call fails. Any suggestions?
If you have a helper script whose name does not yet exist in MediaMonkey (i.e., something other than actions.js, mminit.js, controls/listView.js, etc etc), use localRequirejs. That way, you can guarantee that your version of the script is loaded, in the case of multiple addons using the same script name. Also, when using requirejs/localRequirejs, don't include the "Scripts/<addon id>/" in the call. MediaMonkey handles that path magic automatically.

So for example, if your script is located in helpers/spellcheck.js, then do localRequirejs('helpers/spellcheck"), not requirejs('Scripts/spellCheck/helpers/spellcheck').
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
MPG
Posts: 286
Joined: Tue May 13, 2008 11:22 pm

Re: MoveNext MoveBack getSelectedTracklist

Post by MPG »

Thanks for the quick reply.

I look forward to hearing what you find out about the commitAsync. I could possibly use an array, but that inherently has its own issues.

in regards to the include.js file. it is located in:
MediaMonkey 5\Scripts\spellCheck\dialogs

I have tried the following localRequirejs calls:
localRequirejs('include');
error: file:///customnodes/include.js can't be loaded! (NOT FOUND)
Image

localRequirejs('dialogs/include');
error: file:///customnodes/include.js can't be loaded! (NOT FOUND)

localRequirejs('file:///dialogs/include'); error: file.splice is not a function
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 646
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: MoveNext MoveBack getSelectedTracklist

Post by drakinite »

localRequirejs('dialogs/include'); is the correct syntax, if "include.js" is located inside the dialogs folder. I've tested it and it works. Are you sure you spelled the file's name correctly? Have you tried putting include.js in your addon root and just doing localRequirejs('include')?

Re localRequirejs('file:///dialogs/include'); error: file.splice is not a function: Looks like that is a bug. Fixed as https://www.ventismedia.com/mantis/view.php?id=18564
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
drakinite
Posts: 646
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: MoveNext MoveBack getSelectedTracklist

Post by drakinite »

Yes; CommitAsync writes changes to the database and possibly to tags, depending on the situation. Without a commit, changes only exist in memory. However, it's possible for the changes to be committed from other pieces of code. So you'd either need to only edit after they click OK, or to return the original values after they click Cancel.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
drakinite
Posts: 646
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: MoveNext MoveBack getSelectedTracklist

Post by drakinite »

For anyone else who may be wondering: The issue came from calling requirejs before localRequirejs. Because other addons' _add scripts can be included in the code run by requirejs, the global variable __scriptName may change, leading to MediaMonkey attempting to load the incorrect local file.

There are some sample scripts which call requirejs('actions') before localRequirejs('local'), but this is moreso a special case. It would be better practice to put requirejs('actions') inside their 'local' script; I might change that in a future version.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
Post Reply