I have collectible items representing each of the tracks that you can listen to. The main event looks something like this (I stripped out a few bits related to other plugins):
Code:
◆Script:$gameSystem.requestedMusicTracks = $gameSystem.requestedMusicTracks || {}
◆Save BGM
◆Fadeout BGM:1 second
◆Text:People4(2), Window, Bottom
: :Yes, did you want something?
◆Show Choices:Change Track, No (Window, Right, #2, #2)
:When Change Track
◆Control Variables:#0012 Random = PubTrack
◆Text:Actor1(0), Window, Bottom
: :I wondered if you could play a different
: :song.
◆Text:People4(2), Window, Bottom
: :Sure, what would you like?
◆Select Item:PubTrack, Hidden Item B
◆If:PubTrack > 0
◆Control Switches:#0171 PubTrack = OFF
◆Script:var track = $gameVariables.value(76); // PubTrack
: :$gameSystem.requestedMusicTracks[track] = true;
◆
:Else
◆Control Variables:#0076 PubTrack = Random
◆Replay BGM
◆
:End
◆
:When No
◆Text:Actor1(0), Window, Bottom
: :Not really, just listening to the music.
◆Replay BGM
◆
:End
The script calls aren't strictly necessary – they just keep track of whether or not you've ever requested each track before. I used this to make an achievement for listening to all of them at least once, but I cut out the code to actually implement that for this example. This event is just set to Action Trigger. It just lets you select a track – it doesn't actually switch to it.
To make the track switching actually function, there's a second event set to Autorun that looks like this:
Code:
◆If:PubTrack = 0
◆Control Variables:#0076 PubTrack = 108
◆
:End
◆Script:var bgmItem = $gameVariables.value(76); // PubTrack
: :var bgmTrack = $dataItems[bgmItem].meta.bgm;
: :var bgm = {
: : "name": bgmTrack,
: : "pan": 0,
: : "pitch": 100,
: : "volume": 90
: :};
: :AudioManager.playBgm(bgm);
◆Control Switches:#0171 PubTrack = ON
Then it also has a second page that's activated if the PubTrack switch is on, which just does nothing. So, in other words, that event is triggered when the first event turns off the PubTrack switch.
The last step to make that work is to create items of type Hidden Item B and put a <bgm:Castle1> note tag in each one that specifies which track it represents. Also, if you want to use Exclude Unused files, you may want to add a plugin with the following:
JavaScript:
/*:
@noteParam bgm
@noteRequire 1
@noteDir audio/bgm/
@noteType file
@noteData items
*/
That just makes the Exclude Unused Files feature read the <bgm> note tag and make sure to include any files you reference from there. However, it's not needed if all those tracks are also used in other places.
Though I used this approach in MV, I'm pretty sure it'll work in MZ too. If needed, you could probably modify it to draw the list of tracks from something other than items.