sad

simple audio daemon
git clone git://git.2f30.org/sad.git
Log | Files | Refs | LICENSE

commit c68f913e25b52cb755d84702c0ae8f047f30d34a
parent ec6157f5d4e6924d949e312cd82f2a56cd0fefce
Author: sin <sin@2f30.org>
Date:   Fri Jan  2 15:48:21 +0000

Add support to remove playlist entries

Diffstat:
cmd.c | 24++++++++++++++++++++++++
playlist.c | 19+++++++++++++++++++
sad.h | 1+
3 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/cmd.c b/cmd.c @@ -252,6 +252,30 @@ cmdempty(int fd, char *arg) static void cmdremove(int fd, char *arg) { + Song *s; + const char *errstr; + int id; + + if (!arg[0]) { + s = getcursong(); + stopsong(s); + } else { + id = strtonum(arg, 0, INT_MAX, &errstr); + if (errstr) { + dprintf(fd, "ERR invalid song id\n"); + return; + } + s = findsongid(id); + if (!s) { + dprintf(fd, "ERR cannot find song with given id\n"); + return; + } + } + if (rmplaylist(s->id) < 0) { + dprintf(fd, "ERR failed to remove song\n"); + return; + } + dprintf(fd, "OK\n"); } static void diff --git a/playlist.c b/playlist.c @@ -36,6 +36,25 @@ addplaylist(int id) return s; } +int +rmplaylist(int id) +{ + Song *s; + int i; + + for (i = 0; i < playlist.nsongs; i++) + if (playlist.songs[i]->id == id) + break; + if (i == playlist.nsongs) + return -1; + s = getnextsong(); + memmove(&playlist.songs[i], &playlist.songs[i+1], + (playlist.nsongs - i - 1) * sizeof(*playlist.songs[i])); + putcursong(s); + playlist.nsongs--; + return 0; +} + Song * getnextsong(void) { diff --git a/sad.h b/sad.h @@ -84,6 +84,7 @@ int docmd(int); /* playlist.c */ Song *addplaylist(int); +int rmplaylist(int); Song *getnextsong(void); Song *getprevsong(void); Song *getcursong(void);