sad

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

commit bb14221f3534759ee0090fec583e0f0096cf6ea7
parent d509bfdd852686ad5abece6b622b0213506feff8
Author: sin <sin@2f30.org>
Date:   Sat, 27 Dec 2014 00:41:23 +0000

Add playnext() and playprev()

Diffstat:
Mcmd.c | 21++++-----------------
Mplaylist.c | 32++++++++++++++++++++++++++++++++
Msad.c | 7+------
Msad.h | 2++
4 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/cmd.c b/cmd.c @@ -42,7 +42,7 @@ cmdvolume(int fd, char *arg) static void cmdnext(int fd, char *arg) { - Song *s, *next; + Song *s; if (arg[0]) { dprintf(fd, "ERR unexpected argument\n"); @@ -55,16 +55,7 @@ cmdnext(int fd, char *arg) return; } - if (s->state != NONE) { - s->decoder->close(); - s->state = NONE; - } - - next = getnextsong(); - next->state = PREPARE; - putcursong(next); - printf("Playing song %s with %d\n", - s->path, s->id); + playnext(); dprintf(fd, "OK\n"); } @@ -146,7 +137,7 @@ cmdplay(int fd, char *arg) static void cmdprev(int fd, char *arg) { - Song *s, *prev; + Song *s; if (arg[0]) { dprintf(fd, "ERR unexpected argument\n"); @@ -164,11 +155,7 @@ cmdprev(int fd, char *arg) s->state = NONE; } - prev = getprevsong(); - prev->state = PREPARE; - putcursong(prev); - printf("Playing song %s with %d\n", - s->path, s->id); + playprev(); dprintf(fd, "OK\n"); } diff --git a/playlist.c b/playlist.c @@ -179,3 +179,35 @@ clearplaylist(void) rollingid = 0; playlist.cursong = NULL; } + +Song * +playnext(void) +{ + Song *s; + + s = playlist.cursong; + if (s && s->state != NONE) { + s->decoder->close(); + s->state = NONE; + } + /* default to a repeat/cycle through mode */ + s = getnextsong(); + s->state = PREPARE; + playlist.cursong = s; +} + +Song * +playprev(void) +{ + Song *s; + + s = playlist.cursong; + if (s && s->state != NONE) { + s->decoder->close(); + s->state = NONE; + } + /* default to a repeat/cycle through mode */ + s = getprevsong(); + s->state = PREPARE; + playlist.cursong = s; +} diff --git a/sad.c b/sad.c @@ -82,12 +82,7 @@ playaudio(void) break; case PLAYING: if ((nbytes = s->decoder->decode(buf, sizeof(buf))) <= 0) { - s->decoder->close(); - s->state = NONE; - /* default to a repeat/cycle through mode */ - s = getnextsong(); - s->state = PREPARE; - putcursong(s); + playnext(); } else { output->play(buf, nbytes); } diff --git a/sad.h b/sad.h @@ -66,6 +66,8 @@ void putcursong(Song *); void dumpplaylist(int); void clearplaylist(void); int searchplaylist(int, const char *); +Song *playnext(void); +Song *playprev(void); /* wav.c */ extern Decoder wavdecoder;