sad

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

commit 52844b6c2e07d2900336a63fb816e011a2b91450
parent 8074ce6e181a3b3dfd4073c60c2e522709b81782
Author: dcat <dcat@iotek.org>
Date:   Wed, 14 Jan 2015 19:44:30 +0000

Implement initial status command

Diffstat:
Mcmd.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mplaylist.c | 5+++++
Msad.h | 5+++--
3 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/cmd.c b/cmd.c @@ -15,6 +15,68 @@ static void cmdstatus(int fd, char *arg) { + Song *s; + int ok = 0; + + if (!arg[0]) { + dprintf(fd, "ERR expected argument\n"); + return; + } + + if (!strncmp(arg, "random", 7)) { + ok = 1; + dprintf(fd, "%d\n", getplaylistmode() & RANDOM == 1); + } + + if (!strncmp(arg, "repeat", 7)) { + ok = 1; + dprintf(fd, "%d\n", getplaylistmode() & REPEAT == 1); + } + + if (!strncmp(arg, "single", 7)) { + ok = 1; + dprintf(fd, "%d\n", getplaylistmode() & SINGLE == 1); + } + + if (!strncmp(arg, "songid", 7)) { + ok = 1; + s = getcursong(); + + if (!s) { + dprintf(fd, "ERR no song is active\n"); + return; + } + + dprintf(fd, "%d\n", s->id); + } + + if (!strncmp(arg, "playback", 9)) { + ok = 1; + s = getcursong(); + + + if (s) + switch (s->state) { + case PLAYING: + dprintf(fd, "play\n"); + break; + case PAUSED: + dprintf(fd, "pause\n"); + break; + case NONE: + dprintf(fd, "stop\n"); + break; + } + else + dprintf(fd, "stop\n"); + } + + if (ok) { + dprintf(fd, "OK\n"); + return; + } + + dprintf(fd, "ERR unknown command\n"); } static void diff --git a/playlist.c b/playlist.c @@ -222,3 +222,8 @@ playlistmode(int mode) { playlist.mode = mode; } + +int getplaylistmode(void) +{ + return playlist.mode; +} diff --git a/sad.h b/sad.h @@ -18,8 +18,9 @@ enum { }; enum { - REPEAT, - RANDOM + REPEAT = 1 << 0, + RANDOM = 1 << 1, + SINGLE = 1 << 2 }; enum {