shithub: qk1

Download patch

ref: 07d119a17d5ebc9245470fb3d16c40f31e6745e5
parent: d204ae749ad120af2e41b864d147a66380830891
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Sun Sep 6 19:50:04 EDT 2015

cd: read uNNN tracks too, fix minor bugs

the track count includes the data track on unix, so requesting the
playback of track 2 corresponds to playing [au]001.

--- a/README
+++ b/README
@@ -19,7 +19,7 @@
 
 % quake
 
-qk1 reads /mnt/cd/aNNN files as in cdfs(1) to play music. the directory needn't
+qk1 reads /mnt/cd/[au]NNN files as in cdfs(1) to play music. the directory needn't
 be populated by cdfs(1), so long as the files are in the format described by
 audio(3). this currently requires the use of mixfs(1).
 
--- a/cd.c
+++ b/cd.c
@@ -11,6 +11,7 @@
 static int chtrk;
 static int ntrk;
 static int trk;
+static char trtype;
 static int ctid = -1;
 static Reprog *pat;
 
@@ -29,8 +30,11 @@
 		goto err;
 	close(fd);
 	for(i = 0; i < n; i++)
-		if(regexec(pat, d[i].name, nil, 0))
+		if(regexec(pat, d[i].name, nil, 0)){
+			if(!trtype)
+				trtype = d[i].name[0];
 			ntrk++;
+		}
 	free(d);
 	if(ntrk < 1)
 		return -1;
@@ -57,7 +61,7 @@
 		if(chtrk > 0){
 			close(fd);
 			trk = chtrk;
-			snprint(s, sizeof s, "/mnt/cd/a%03ud", trk);
+			snprint(s, sizeof s, "/mnt/cd/%c%03ud", trtype, trk);
 			if((fd = open(s, OREAD)) < 0)
 				fprint(2, "cproc: %r");
 			chtrk = 0;
@@ -93,6 +97,7 @@
 {
 	if(ctid < 0)
 		return;
+	nt -= 1;	/* d001 was assumed part of the track list */
 	if(nt < 1 || nt > ntrk){
 		Con_Printf("cd: invalid track number %ud\n", nt);
 		return;
@@ -147,7 +152,7 @@
 		CDAudio_Resume();
 		return;
 	}else if(cistrcmp(cmd, "info") == 0){
-		Con_Printf("track %ud/%ud; loop %d; vol %f\n", trk, ntrk, cdloop, cdvol);
+		Con_Printf("track %ud/%ud; loop %d; vol %d\n", trk, ntrk, cdloop, cdvol);
 		return;
 	}
 }
@@ -170,7 +175,7 @@
 {
 	if(cls.state == ca_dedicated)
 		return -1;
-	pat = regcomp("a[0-9][0-9][0-9]");
+	pat = regcomp("[au][0-9][0-9][0-9]");
 	if(cdinfo() < 0)
 		return -1;
 	if((ctid = proccreate(cproc, nil, 16384)) < 0)