playlist: call clearPlayerQueue() only if song is queued
Simplify and merge several if clauses before the clearPlayerQueue() invocation. Call clearPlayerQueue() only if a song is actually queued; add an assertion for that in clearPlayerQueue().
This commit is contained in:
parent
9d51bd392b
commit
35a16b9923
@ -526,6 +526,8 @@ static void syncPlaylistWithQueue(void)
|
|||||||
|
|
||||||
static void clearPlayerQueue(void)
|
static void clearPlayerQueue(void)
|
||||||
{
|
{
|
||||||
|
assert(playlist.queued >= 0);
|
||||||
|
|
||||||
if (getPlayerQueueState() == PLAYER_QUEUE_PLAY ||
|
if (getPlayerQueueState() == PLAYER_QUEUE_PLAY ||
|
||||||
getPlayerQueueState() == PLAYER_QUEUE_FULL) {
|
getPlayerQueueState() == PLAYER_QUEUE_FULL) {
|
||||||
playerQueueLock();
|
playerQueueLock();
|
||||||
@ -599,11 +601,9 @@ addSongToPlaylist(struct song *song, int *added_id)
|
|||||||
if (playlist.length == playlist_max_length)
|
if (playlist.length == playlist_max_length)
|
||||||
return PLAYLIST_RESULT_TOO_LARGE;
|
return PLAYLIST_RESULT_TOO_LARGE;
|
||||||
|
|
||||||
if (playlist_state == PLAYLIST_STATE_PLAY) {
|
if (playlist_state == PLAYLIST_STATE_PLAY && playlist.queued >= 0 &&
|
||||||
if (playlist.queued >= 0
|
playlist.current == playlist.length - 1)
|
||||||
&& playlist.current == playlist.length - 1)
|
clearPlayerQueue();
|
||||||
clearPlayerQueue();
|
|
||||||
}
|
|
||||||
|
|
||||||
id = getNextId();
|
id = getNextId();
|
||||||
|
|
||||||
@ -640,18 +640,13 @@ addSongToPlaylist(struct song *song, int *added_id)
|
|||||||
|
|
||||||
enum playlist_result swapSongsInPlaylist(int song1, int song2)
|
enum playlist_result swapSongsInPlaylist(int song1, int song2)
|
||||||
{
|
{
|
||||||
int queuedSong = -1;
|
|
||||||
int currentSong;
|
|
||||||
|
|
||||||
if (song1 < 0 || song1 >= playlist.length ||
|
if (song1 < 0 || song1 >= playlist.length ||
|
||||||
song2 < 0 || song2 >= playlist.length)
|
song2 < 0 || song2 >= playlist.length)
|
||||||
return PLAYLIST_RESULT_BAD_RANGE;
|
return PLAYLIST_RESULT_BAD_RANGE;
|
||||||
|
|
||||||
if (playlist_state == PLAYLIST_STATE_PLAY) {
|
if (playlist_state == PLAYLIST_STATE_PLAY && playlist.queued >= 0) {
|
||||||
if (playlist.queued >= 0) {
|
int queuedSong = playlist.order[playlist.queued];
|
||||||
queuedSong = playlist.order[playlist.queued];
|
int currentSong = playlist.order[playlist.current];
|
||||||
}
|
|
||||||
currentSong = playlist.order[playlist.current];
|
|
||||||
|
|
||||||
if (queuedSong == song1 || queuedSong == song2
|
if (queuedSong == song1 || queuedSong == song2
|
||||||
|| currentSong == song1 || currentSong == song2)
|
|| currentSong == song1 || currentSong == song2)
|
||||||
@ -710,12 +705,10 @@ enum playlist_result deleteFromPlaylist(int song)
|
|||||||
if (song < 0 || song >= playlist.length)
|
if (song < 0 || song >= playlist.length)
|
||||||
return PLAYLIST_RESULT_BAD_RANGE;
|
return PLAYLIST_RESULT_BAD_RANGE;
|
||||||
|
|
||||||
if (playlist_state == PLAYLIST_STATE_PLAY) {
|
if (playlist_state == PLAYLIST_STATE_PLAY && playlist.queued >= 0
|
||||||
if (playlist.queued >= 0
|
&& (playlist.order[playlist.queued] == song
|
||||||
&& (playlist.order[playlist.queued] == song
|
|| playlist.order[playlist.current] == song))
|
||||||
|| playlist.order[playlist.current] == song))
|
clearPlayerQueue();
|
||||||
clearPlayerQueue();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!song_is_file(playlist.songs[song])) {
|
if (!song_is_file(playlist.songs[song])) {
|
||||||
song_free(playlist.songs[song]);
|
song_free(playlist.songs[song]);
|
||||||
@ -992,10 +985,9 @@ bool getPlaylistRandomStatus(void)
|
|||||||
|
|
||||||
void setPlaylistRepeatStatus(bool status)
|
void setPlaylistRepeatStatus(bool status)
|
||||||
{
|
{
|
||||||
if (playlist_state == PLAYLIST_STATE_PLAY) {
|
if (playlist_state == PLAYLIST_STATE_PLAY &&
|
||||||
if (playlist.repeat && !status && playlist.queued == 0)
|
playlist.repeat && !status && playlist.queued == 0)
|
||||||
clearPlayerQueue();
|
clearPlayerQueue();
|
||||||
}
|
|
||||||
|
|
||||||
playlist.repeat = status;
|
playlist.repeat = status;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user