ref: 47a3ffafda11941ff2f4a50604601d8cae123351
parent: 4e57b4305b80468e2e50ed71189d32e20b18886f
author: Sigrid Haflínudóttir <[email protected]>
date: Sat Mar 28 16:16:48 EDT 2020
display volume
--- a/zuke.c
+++ b/zuke.c
@@ -37,6 +37,7 @@
static int plnum;
static char *plraw;
static int plrawsize;
+static int volume;
struct Player
{
@@ -217,16 +218,17 @@
draw(screen, r, cover, nil, ZP);
}
- if(pcurplaying >= 0){
- snprint(tmp, sizeof(tmp), "%P/%P", (int)(byteswritten/Bps), pl[pcurplaying].duration/1000);
- r = screen->r;
- r.min.x = r.max.x - stringwidth(f, tmp) - 4;
- r.min.y = r.max.y - f->height - 4;
- draw(screen, r, display->black, nil, ZP);
- r.min.x += 2;
- r.min.y += 2;
- string(screen, r.min, cola, sp, f, tmp);
- }
+ if(pcurplaying >= 0)
+ snprint(tmp, sizeof(tmp), "%P/%P %d%%", (int)(byteswritten/Bps), pl[pcurplaying].duration/1000, volume);
+ else
+ snprint(tmp, sizeof(tmp), "%d%%", volume);
+ r = screen->r;
+ r.min.x = r.max.x - stringwidth(f, tmp) - 4;
+ r.min.y = r.max.y - f->height - 4;
+ draw(screen, r, display->black, nil, ZP);
+ r.min.x += 2;
+ r.min.y += 2;
+ string(screen, r.min, cola, sp, f, tmp);
flushimage(display, 1);
unlockdisplay(display);
@@ -688,7 +690,7 @@
}
static void
-volume(int d)
+chvolume(int d)
{
int f, l, r, ol, or;
Biobuf b;
@@ -698,25 +700,25 @@
return;
Binit(&b, f, OREAD);
+ l = r = 0;
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);
+ l += d;
+ r += d;
+ fprint(f, "master %d %d\n", l, 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]) == l && atoi(a[2]) == r)
+ goto end;
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;
+ break;
}
}
}
@@ -724,6 +726,12 @@
}
end:
+ volume = (l+r)/2;
+ if(volume > 100)
+ volume = 100;
+ else if(volume < 0)
+ volume = 0;
+
Bterm(&b);
close(f);
}
@@ -772,6 +780,7 @@
colb = display->black;
srand(time(0));
pcurplaying = -1;
+ chvolume(0);
fmtinstall('P', positionfmt);
threadsetname("zuke");
@@ -879,10 +888,12 @@
start(playercurr);
break;
case '-':
- volume(-1);
+ chvolume(-1);
+ redraw();
break;
case '+':
- volume(+1);
+ chvolume(+1);
+ redraw();
break;
case 's':
stop(playercurr);