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 32ed3b063534d51ca2c4c7a83ca6eeff9e599a05
Spenser Truex <truex@equwal.com>
2021-01-20 05:24:12 -0800

No to "pause [0|1]" toggles pause

old: pause 0|1
new: pause [0|1]

It is simpler to have a toggle for these so they can be implemented as a
single button (as is very often done). On my keyboard, Fn+f5 is that
button.

pause <no argument>

This change is therefore backward compatible.

Doing this outside of sad required some kind of locking mechanism to
keep track, and is prone to timing-related errors or failing to remove
the lock.

 PROTOCOL |  4 ++--
 cmd.c    | 63 ++++++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/PROTOCOL b/PROTOCOL
index e36d97a..c702799 100644
--- a/PROTOCOL
+++ b/PROTOCOL
@@ -17,8 +17,8 @@ Set the output volume.  This is applied equally to all outputs.
 next
 Play next song.
 
-pause 0|1
-Pause currently playing song.
+pause [0|1]
+Pause currently playing song. Toggle pause if no argument.
 
 play [ID]
 Play the song with the given ID or the current song if no ID is provided.
diff --git a/cmd.c b/cmd.c
index fbac201..a8528df 100644
--- a/cmd.c
+++ b/cmd.c
@@ -147,36 +147,40 @@ cmdpause(int fd, char *arg)
 	const char *errstr;
 
 	if (!arg[0]) {
-		dprintf(fd, "ERR argument should be 0 or 1\n");
-		return;
-	}
-
-	pause = strtonum(arg, 0, 1, &errstr);
-	if (errstr) {
-		dprintf(fd, "ERR argument should be 0 or 1\n");
-		return;
-	}
-
-	s = getcursong();
-	if (!s) {
-		dprintf(fd, "ERR playlist is empty\n");
-		return;
-	}
+        s = getcursong();
+        if (s->state == PAUSED)
+            s->state = PLAYING;
+        else
+            s->state = PAUSED;
+	} else {
 
-	switch (s->state) {
-	case PLAYING:
-		if (pause == 1)
-			s->state = PAUSED;
-		break;
-	case PAUSED:
-		if (pause == 0)
-			s->state = PLAYING;
-		break;
-	case NONE:
-		dprintf(fd, "ERR no song is active\n");
-		return;
-	}
-	dprintf(fd, "OK\n");
+        pause = strtonum(arg, 0, 1, &errstr);
+        if (errstr) {
+            dprintf(fd, "ERR argument should be 0 or 1, or no argument\n");
+            return;
+        }
+
+        s = getcursong();
+        if (!s) {
+            dprintf(fd, "ERR playlist is empty\n");
+            return;
+        }
+
+        switch (s->state) {
+        case PLAYING:
+            if (pause == 1)
+                s->state = PAUSED;
+            break;
+        case PAUSED:
+            if (pause == 0)
+                s->state = PLAYING;
+            break;
+        case NONE:
+            dprintf(fd, "ERR no song is active\n");
+            return;
+        }
+    }
+    dprintf(fd, "OK\n");
 }
 
 static void
@@ -498,3 +502,4 @@ docmd(int clifd)
 	}
 	return 0;
 }
+