shithub: pplay

Download patch

ref: 3615c3b7feb6c1144ebb939d4d107ab87961e6a9
parent: de50e1384e1691a5779f2e1be53aeee4a207a8ab
author: qwx <qwx@sciops.net>
date: Mon Nov 28 20:24:20 EST 2022

fix panning bounding bugs

--- a/cmd.c
+++ b/cmd.c
@@ -114,6 +114,7 @@
 {
 	Chunk *c;
 
+	assert(p < totalsz);
 	c = norris.right;
 	while(p > c->bufsz){
 		p -= c->bufsz;
@@ -261,6 +262,10 @@
 	usize Δbuf, Δloop, m, off, Δ;
 	Chunk *c;
 
+	if(d.pos >= totalsz){
+		*boff = 0;
+		return nil;
+	}
 	c = p2c(d.pos, &off);
 	p = c->buf + off;
 	m = n;
--- a/draw.c
+++ b/draw.c
@@ -95,7 +95,8 @@
 			p = getbuf(d, n, sbuf, &n);
 			qunlock(&lsync);
 			if(p == nil){
-				fprint(2, "getbuf: %r\n");
+				if(n > 0)
+					fprint(2, "getbuf: %r\n");
 				goto end;
 			}
 			d.pos += n;
@@ -127,7 +128,7 @@
 			if(stereo)
 				draw(viewbg, r, col[Csamp], nil, ZP);
 			unlockdisplay(display);
-			x++;
+			x = (d.pos - views) / T;
 		}
 	}
 }
@@ -207,8 +208,6 @@
 	lockdisplay(display);
 	drawview();
 	x = screen->r.min.x + (p - views) / T;
-	//if(liner.min.x == x || p < views && x > liner.min.x)
-	//	return;
 	draw(screen, screen->r, view, nil, ZP);
 	liner.min.x = x;
 	liner.max.x = x + 1;
@@ -239,10 +238,20 @@
 void
 setpan(int Δx)
 {
+	usize new;
+
 	Δx *= T;
-	if(zoom == 1 || views == 0 && Δx < 0 || views >= viewmax && Δx > 0)
+	if(zoom == 1)
 		return;
-	views += Δx;
+	if(Δx < 0 && -Δx > views)
+		new = 0;
+	else if(views + Δx >= viewmax)
+		new = viewmax;
+	else
+		new = views + Δx;
+	if(new == views)
+		return;
+	views = new;
 	redraw(0);
 }