Commit Diff


commit - 805c96fb4b4e3b14dcf623e029fef265a5601836
commit + 13b838834600a04758caef4fae2f1ab61cd357d2
blob - ecebe462e172d3998394f107fc495bf4dd088ae6
blob + 1eebcee3c871c31f5bbda5c71f86ce45c82ac7b5
--- 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();
 }
 
blob - c94f708c54094dff1a108faba7a287ecd3b187ab
blob + c8931b7db81980b7e55d276290bc9d1093b72de6
--- 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;
+}
blob - 3b2e2ed26d78dceb8e3fa7c637cb95218fedc322
blob + 3f4ea37cca318baf7e9b932e6232fa814d018c4f
--- playlist.h
+++ playlist.h
@@ -41,5 +41,6 @@ const char		*playlist_current(void);
 const char		*playlist_advance(void);
 void			 playlist_reset(void);
 void			 playlist_truncate(void);
+void			 playlist_dropcurrent(void);
 
 #endif