MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / PlaylistRemove

Method PlaylistRemove

src/music_gui.cpp:364–392  ·  view source on GitHub ↗

* Remove a song from a custom playlist. * @param song_index Index in the custom playlist to remove. */

Source from the content-addressed store, hash-verified

362 * @param song_index Index in the custom playlist to remove.
363 */
364void MusicSystem::PlaylistRemove(size_t song_index)
365{
366 if (!this->IsCustomPlaylist()) return;
367
368 if (song_index >= this->active_playlist.size()) return;
369
370 PlaylistEntry song = this->active_playlist[song_index];
371 this->active_playlist.erase(std::next(std::begin(this->active_playlist), song_index));
372
373 Playlist &playlist = this->standard_playlists[this->selected_playlist];
374 auto it = std::end(playlist);
375 if (this->IsShuffle()) {
376 /* Playlist is shuffled, so remove the first instance. */
377 it = std::ranges::find_if(playlist, [&song](const auto &s) { return s.filename == song.filename && s.cat_index == song.cat_index; });
378 } else if (song_index < playlist.size()) {
379 /* Not shuffled, we can remove the entry directly. */
380 it = std::next(std::begin(playlist), song_index);
381 }
382
383 if (it == std::end(playlist)) return;
384 it = playlist.erase(it);
385
386 /* If it's the current song restart playback. */
387 if (this->IsPlaying() && std::distance(std::begin(playlist), it) == this->playlist_position) this->Play();
388
389 this->SaveCustomPlaylist(this->selected_playlist);
390
391 InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
392}
393
394/**
395 * Remove all songs from the current custom playlist.

Callers 1

OnClickMethod · 0.80

Calls 10

IsCustomPlaylistMethod · 0.95
IsShuffleMethod · 0.95
IsPlayingMethod · 0.95
PlayMethod · 0.95
SaveCustomPlaylistMethod · 0.95
InvalidateWindowDataFunction · 0.70
beginFunction · 0.50
endFunction · 0.50
sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected