Commit Diff
Commit:
13b838834600a04758caef4fae2f1ab61cd357d2
Date:
Wed Feb 16 22:25:41 2022
UTC
Message:
drop songs from the playlist on error
--- amused.c
+++ amused.c
@@ -160,10 +160,12 @@ main_dispatch_player(int sig, short event, void *d)
switch (imsg.hdr.type) {
case IMSG_ERR:
- /* TODO: remove current track from the playlist */
+ playlist_dropcurrent();
+ /* fallthrough */
case IMSG_EOF:
main_playlist_advance();
break;
+
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
@@ -397,7 +399,7 @@ main_playlist_advance(void)
if (main_play_song(song))
break;
- /* TODO: remove the song from the playlist */
+ playlist_dropcurrent();
}
}
@@ -413,7 +415,7 @@ main_restart_track(void)
if (main_play_song(song))
return;
- /* TODO: remove the song from the playlist */
+ playlist_dropcurrent();
main_playlist_advance();
}
--- playlist.c
+++ playlist.c
@@ -98,3 +98,20 @@ playlist_truncate(void)
playlist.cap = 0;
play_off = -1;
}
+
+void
+playlist_dropcurrent(void)
+{
+ size_t i;
+
+ if (play_off == -1 || playlist.len == 0)
+ return;
+
+ free(playlist.songs[play_off]);
+
+ playlist.len--;
+ for (i = play_off; i < playlist.len; ++i)
+ playlist.songs[i] = playlist.songs[i+1];
+
+ playlist.songs[playlist.len] = NULL;
+}
--- playlist.h
+++ playlist.h
@@ -41,5 +41,6 @@ void playlist_truncate(void);
const char *playlist_advance(void);
void playlist_reset(void);
void playlist_truncate(void);
+void playlist_dropcurrent(void);
#endif
Omar Polo