shithub: zuke

Download patch

ref: 4e57b4305b80468e2e50ed71189d32e20b18886f
parent: 149d383fd0d26eae1c2de4743eceebee94f75d1b
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Mar 28 15:22:21 EDT 2020

add volume control

--- a/README.md
+++ b/README.md
@@ -39,22 +39,25 @@
 ## Hot keys
 
 ```
-left/right                 - seek backwards/forward (10 seconds step)
-,/.                        - seek backwards/forward (one minute step)
-up/down/pgup/pgdn/home/end - move within the playlist
-o                          - move to the currently playing track
-enter                      - play the selected track
+-  volume down
++  volume up
 
->     - skip next
-<     - skip prev
-s     - stop
-p     - pause/resume
-q/del - quit
+left/right                  seek backwards/forward (10 seconds step)
+,/.                         seek backwards/forward (one minute step)
+up/down/pgup/pgdn/home/end  move within the playlist
+o                           move to the currently playing track
+enter                       play the selected track
 
-/ - search forward
-? - search backwards
-n - repeat search forward
-N - repeat search backwards
+>      skip next
+<      skip prev
+s      stop
+p      pause/resume
+q/del  quit
+
+/  search forward
+?  search backwards
+n  repeat search forward
+N  repeat search backwards
 ```
 
 ## Mouse
--- a/mkfile
+++ b/mkfile
@@ -14,4 +14,6 @@
 
 BIN=/$objtype/bin/audio
 
+default:V: all
+
 </sys/src/cmd/mkmany
--- a/zuke.c
+++ b/zuke.c
@@ -5,6 +5,7 @@
 #include <keyboard.h>
 #include <thread.h>
 #include <ctype.h>
+#include <bio.h>
 #include "plist.h"
 
 typedef struct Player Player;
@@ -686,6 +687,47 @@
 	}
 }
 
+static void
+volume(int d)
+{
+	int f, l, r, ol, or;
+	Biobuf b;
+	char *s, *a[4];
+
+	if((f = open("/dev/volume", ORDWR)) < 0)
+		return;
+	Binit(&b, f, OREAD);
+
+	for(; (s = Brdline(&b, '\n')) != nil;) {
+		if(strncmp(s, "master", 6) == 0 && tokenize(s, a, 3) == 3){
+			l = ol = atoi(a[1]);
+			r = or = atoi(a[2]);
+			l += d;
+			r += d;
+			for(;;){
+retry:
+				fprint(f, "master %d %d\n", (int)l, (int)r);
+				Bseek(&b, 0, 0);
+				for(; (s = Brdline(&b, '\n')) != nil;){
+					if(strncmp(s, "master", 6) == 0 && tokenize(s, a, 3) == 3){
+						if(atoi(a[1]) != ol && atoi(a[2]) != or)
+							goto end;
+						l += d;
+						r += d;
+						if (l < 0 || r < 0 || l > 100 || r > 100)
+							goto end;
+						goto retry;
+					}
+				}
+			}
+		}
+	}
+
+end:
+	Bterm(&b);
+	close(f);
+}
+
 void
 threadmain(int argc, char **argv)
 {
@@ -835,6 +877,12 @@
 				stop(playercurr);
 				playercurr = newplayer(pcur, 1);
 				start(playercurr);
+				break;
+			case '-':
+				volume(-1);
+				break;
+			case '+':
+				volume(+1);
 				break;
 			case 's':
 				stop(playercurr);