sad

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

commit 6191ba9fb545bdeacc2a2720a53268625677ed1f
parent 5f931616f8e73c9122997ae57356c5cc2cdf7e46
Author: sin <sin@2f30.org>
Date:   Sun, 28 Dec 2014 11:18:33 +0000

Add empty command

Diffstat:
MPROTOCOL | 6++++--
Mcmd.c | 15+++++++++++++++
Mlibrary.c | 8+++++++-
Msad.h | 2+-
4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/PROTOCOL b/PROTOCOL @@ -37,8 +37,10 @@ Add the given song ID from the library to the playlist. If not ID is provided, all songs in the library are added. clear -Clear playlist and stop playback. The next file added will have a song ID -equal to 0. +Clear playlist and stop playback. + +empty +Empty the library, clear playlist and stop playback. remove [ID] Delete the song with the given ID or the currently selected song from diff --git a/cmd.c b/cmd.c @@ -195,6 +195,20 @@ cmdclear(int fd, char *arg) } static void +cmdempty(int fd, char *arg) +{ + if (arg[0]) { + dprintf(fd, "ERR unexpected argument\n"); + return; + } + + stopsong(getcursong()); + clearplaylist(); + emptylibrary(); + dprintf(fd, "OK\n"); +} + +static void cmddelete(int fd, char *arg) { } @@ -292,6 +306,7 @@ static Cmd cmds[] = { { "stop", cmdstop }, { "add", cmdadd }, { "clear", cmdclear }, + { "empty", cmdempty }, { "delete", cmddelete }, { "playlist", cmdplaylist }, { "library", cmdlibrary }, diff --git a/library.c b/library.c @@ -103,8 +103,14 @@ searchlibrary(int fd, const char *search) } void -clearlibrary(void) +emptylibrary(void) { + int i; + + for (i = 0; i < library.nsongs; i++) { + free(library.songs[i]); + library.songs[i] = NULL; + } library.nsongs = 0; rollingid = 0; } diff --git a/sad.h b/sad.h @@ -78,7 +78,7 @@ Song *addlibrary(const char *); Song *findsongid(int); void dumplibrary(int); int searchlibrary(int, const char *); -void clearlibrary(void); +void emptylibrary(void); /* wav.c */ extern Decoder wavdecoder;