Recently Written · git

sad

sad (2f30.org simple audio daemon) with a Cygwin/OSS port on branch cygwin

git clone https://github.com/equwal/sad

Log | Files | Refs


commit 52844b6c2e07d2900336a63fb816e011a2b91450
dcat <dcat@iotek.org>
2015-01-14 19:44:30 +0000

Implement initial status command

 cmd.c      | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 playlist.c |  5 +++++
 sad.h      |  5 +++--
 3 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/cmd.c b/cmd.c
index 47a7926..bdefde7 100644
--- 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
index 38cb4aa..48daf4d 100644
--- 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
index f365413..8798c4c 100644
--- a/sad.h
+++ b/sad.h
@@ -18,8 +18,9 @@ enum {
 };
 
 enum {
-	REPEAT,
-	RANDOM
+	REPEAT = 1 << 0,
+	RANDOM = 1 << 1,
+	SINGLE = 1 << 2
 };
 
 enum {