+ fvwm_cmd("+", "Not in play queue", "Title") if @notqueued;
+ foreach my $entry (@notqueued) {
+ fvwm_cmd("+", menu_trackname($entry));
+ }
+} elsif ($mode eq "artist") {
+ # Create an artist menu.
+ my ($matches, @recs) = get_releases_by_artist_mbid(keys %artistids);
+
+ $menu //= "MenuMPDArtist";
+
+ my @mbids = sort { datesort($matches, $a, $b) } keys %$matches;
+ my @files = map { $matches->{$_}->{file} } @mbids;
+ my @thumbs = get_item_thumbnails({ small => 1 }, @files);
+
+ unless (@mbids) {
+ fvwm_cmd("AddToMenu", $menu, "No releases found", "Title")
+ }
+
+ foreach my $mbid (@mbids) {
+ my $entry = $matches->{$mbid};
+ my $thumb = shift @thumbs;
+
+ my @submenu = make_submenu("$topmenu-$mbid",
+ "--album-id=$mbid");
+ fvwm_cmd("AddToMenu", $menu,
+ $thumb . fvwm_label_escape($entry->{Album}),
+ @submenu);
+ }
+
+ my @artists = map { "--artist-id=$_" } keys %artistids;
+ my %nonalbums = map { $_->{Album} => $_ } @recs;
+ foreach my $name (sort keys %nonalbums) {
+ my $mbid = $nonalbums{$name}->{MUSICBRAINZ_TRACKID};
+ my @submenu = make_submenu("$topmenu-$mbid", @artists,
+ "--album-name=$name");
+ fvwm_cmd("AddToMenu", $menu, fvwm_label_escape($name), @submenu);
+ }
+} elsif ($mode eq "albumname") {
+ # Create a standalone recordings menu
+ my ($releases, @recs) = get_releases_by_artist_mbid(keys %artistids);
+
+ $menu //= "MenuMPDRecordings";
+ my @tracks = sort { $a->{Title} cmp $b->{Title} }
+ grep { $_->{Album} eq $albumname } @recs;
+
+ # Show thumbnails for standalone recordings
+ my @thumbs = get_item_thumbnails({ small => 1 },
+ map { $_->{file} } @tracks);
+ foreach my $entry (@tracks) {
+ $entry->{thumb} = shift @thumbs;
+ }
+
+ my @notqueued = update_entry_ids(@tracks);
+
+ fvwm_cmd("AddToMenu", $menu);
+ fvwm_cmd("+", "No tracks found", "Title") unless @tracks;
+
+ foreach my $entry (@tracks) {
+ next unless exists $entry->{Id};
+
+ fvwm_cmd("+", menu_trackname($entry), "Exec",
+ "exec", "$FindBin::Bin/mpdexec.pl",
+ "playid", $entry->{Id});
+ }
+
+ fvwm_cmd("+", "Not in play queue", "Title") if @notqueued;
+ foreach my $entry (@notqueued) {
+ fvwm_cmd("+", menu_trackname($entry));
+ }
+} elsif ($mode eq "track" || $mode eq "recording") {
+ my ($matches, $mbid);
+ my @notqueued;
+
+ if ($mode eq "track") {
+ $matches = get_tracks_by_track_mbid($trackid)
+ } else {
+ $matches = get_tracks_by_recording_mbid($recordingid)
+ }
+
+ $menu //= "MenuMPDTrack";
+ fvwm_cmd("DestroyMenu", $menu);
+
+ my @files = sort { datesort($matches, $a, $b) } keys %$matches;
+ my @thumbs = get_item_thumbnails({ small => 1 }, @files);
+
+ fvwm_cmd("AddToMenu", $menu);
+ fvwm_cmd("+", "No tracks found", "Title") unless @files;
+ foreach my $file (@files) {
+ my $entry = $matches->{$file};
+ $entry->{thumb} = shift @thumbs;
+
+ unless (exists $entry->{Id}) {
+ my ($id) = get_ids_by_filename($file);
+ if (defined $id) {
+ $entry->{Id} = $id;
+ } else {
+ push @notqueued, $entry;
+ next;
+ }
+ }
+
+ fvwm_cmd("+", menu_trackname($entry), "Exec",
+ "exec", "$FindBin::Bin/mpdexec.pl",
+ "playid", $entry->{Id});
+ }
+
+ fvwm_cmd("+", "Not in play queue", "Title") if @notqueued;
+ foreach my $entry (@notqueued) {
+ fvwm_cmd("+", menu_trackname($entry));