sad

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

commit 05275952416a7f9531eecf102969f9b6e839dcac
parent bb14221f3534759ee0090fec583e0f0096cf6ea7
Author: sin <sin@2f30.org>
Date:   Sat, 27 Dec 2014 00:55:11 +0000

Add play() and stop()

Diffstat:
Mcmd.c | 29+++++------------------------
Mplaylist.c | 29+++++++++++++++++++----------
Msad.h | 2++
3 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/cmd.c b/cmd.c @@ -55,7 +55,7 @@ cmdnext(int fd, char *arg) return; } - playnext(); + play(getnextsong()); dprintf(fd, "OK\n"); } @@ -112,11 +112,6 @@ cmdplay(int fd, char *arg) return; } - if (cur->state != NONE) { - cur->decoder->close(); - cur->state = NONE; - } - if (arg[0]) { id = atoi(arg); s = findsongid(id); @@ -128,8 +123,7 @@ cmdplay(int fd, char *arg) s = cur; } - s->state = PREPARE; - putcursong(s); + play(s); printf("Playing song %s with %d\n", s->path, s->id); } @@ -150,12 +144,7 @@ cmdprev(int fd, char *arg) return; } - if (s->state != NONE) { - s->decoder->close(); - s->state = NONE; - } - - playprev(); + play(getprevsong()); dprintf(fd, "OK\n"); } @@ -175,11 +164,7 @@ cmdstop(int fd, char *arg) return; } - if (s->state != NONE) { - s->decoder->close(); - s->state = NONE; - } - + stop(s); dprintf(fd, "OK\n"); } @@ -216,11 +201,7 @@ cmdclear(int fd, char *arg) return; } - s = getcursong(); - if (s && s->state != NONE) { - s->decoder->close(); - s->state = NONE; - } + stop(getcursong()); clearplaylist(); dprintf(fd, "OK\n"); } diff --git a/playlist.c b/playlist.c @@ -185,11 +185,7 @@ playnext(void) { Song *s; - s = playlist.cursong; - if (s && s->state != NONE) { - s->decoder->close(); - s->state = NONE; - } + stop(playlist.cursong); /* default to a repeat/cycle through mode */ s = getnextsong(); s->state = PREPARE; @@ -201,13 +197,26 @@ playprev(void) { Song *s; - s = playlist.cursong; - if (s && s->state != NONE) { - s->decoder->close(); - s->state = NONE; - } + stop(playlist.cursong); /* default to a repeat/cycle through mode */ s = getprevsong(); s->state = PREPARE; playlist.cursong = s; } + +void +play(Song *new) +{ + stop(playlist.cursong); + new->state = PREPARE; + playlist.cursong = new; +} + +void +stop(Song *s) +{ + if (s && s->state != NONE) { + s->decoder->close(); + s->state = NONE; + } +} diff --git a/sad.h b/sad.h @@ -68,6 +68,8 @@ void clearplaylist(void); int searchplaylist(int, const char *); Song *playnext(void); Song *playprev(void); +void play(Song *); +void stop(Song *); /* wav.c */ extern Decoder wavdecoder;