* Remove a song from a custom playlist. * @param song_index Index in the custom playlist to remove. */
| 362 | * @param song_index Index in the custom playlist to remove. |
| 363 | */ |
| 364 | void 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. |
no test coverage detected