sad

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

commit 32ed3b063534d51ca2c4c7a83ca6eeff9e599a05
parent d580122112b03b26b2c13e8ec6d792a4be09d63a
Author: Spenser Truex <truex@equwal.com>
Date:   Wed, 20 Jan 2021 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.

Diffstat:
MPROTOCOL | 4++--
Mcmd.c | 63++++++++++++++++++++++++++++++++++-----------------------------
2 files changed, 36 insertions(+), 31 deletions(-)

diff --git 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 @@ -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; } +