sad

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

commit 35a8df987d7c66437cbfd47c74d69a83460a629f
parent f65599189398f234231e84617c41804bb790936a
Author: sin <sin@2f30.org>
Date:   Thu Dec 25 17:40:36 +0000

Implement next command

Diffstat:
cmd.c | 24++++++++++++++++++++++++
playlist.c | 21+++++++++++++++++++++
sad.h | 1+
3 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/cmd.c b/cmd.c @@ -35,6 +35,30 @@ cmdvolume(int fd, int argc, char **argv) static void cmdnext(int fd, int argc, char **argv) { + Song *s, *next; + + if (argc != 1) { + dprintf(fd, "ERR \"usage: next\"\n"); + return; + } + + s = getcursong(); + if (!s) { + dprintf(fd, "ERR \"no song active\"\n"); + return; + } + + next = getnextsong(s); + if (!next) { + dprintf(fd, "ERR \"invalid song id\"\n"); + return; + } + + decoder->close(); + s->state = NONE; + next->state = PREPARE; + putcursong(next); + dprintf(fd, "OK\n"); } static void diff --git a/playlist.c b/playlist.c @@ -57,6 +57,27 @@ findsongid(int id) } Song * +getnextsong(Song *cur) +{ + Song *s; + int i; + + for (i = 0; i < playlist.nsongs; i++) { + s = &playlist.songs[i]; + if (s->id == cur->id) { + break; + } + } + if (i == playlist.nsongs) + return NULL; + if (i == playlist.nsongs - 1) + s = &playlist.songs[0]; + else + s = &playlist.songs[i + 1]; + return s; +} + +Song * getcursong(void) { return playlist.cursong; diff --git a/sad.h b/sad.h @@ -57,6 +57,7 @@ int initplaylist(void); Song *addplaylist(const char *); Song *findsong(const char *); Song *findsongid(int); +Song *getnextsong(Song *); Song *getcursong(void); void putcursong(Song *); void dumpplaylist(int);