shithub: pplay

Download patch

ref: bb8274cffd9f0754e871812118df2e94bedc1ce3
parent: 280f1defcfb292bc604825da676b889360f63649
author: qwx <[email protected]>
date: Wed Nov 16 19:40:24 EST 2022

add debug mode: draw chunk splits

--- a/cmd.c
+++ b/cmd.c
@@ -64,7 +64,7 @@
 }
 
 /* stupidest possible approach for now: minimal bookkeeping */
-static Chunk *
+Chunk *
 p2c(usize p, usize *off)
 {
 	Chunk *c;
--- a/dat.h
+++ b/dat.h
@@ -30,6 +30,7 @@
 
 extern int stereo;
 extern int zoom;
+extern int debug;
 
 #define MIN(x,y)	((x) < (y) ? (x) : (y))
 #define MAX(x,y)	((x) > (y) ? (x) : (y))
--- a/draw.c
+++ b/draw.c
@@ -9,6 +9,7 @@
 	Csamp,
 	Cline,
 	Cloop,
+	Cchunk,
 	Ncol,
 };
 static Image *col[Ncol];
@@ -33,6 +34,31 @@
 }
 
 static void
+drawchunks(void)
+{
+	int x;
+	usize p, off;
+	Chunk *c;
+	Rectangle r;
+
+	c = p2c(views, &off);
+	r = view->r;
+	for(p=views-off; p<viewe; p+=c->bufsz, c=c->right){
+		if(p == 0)
+			continue;
+		x = (p - views) / T;
+		if(x > Dx(view->r))
+			break;
+		r = view->r;
+		r.min.x += x;
+		r.max.x = r.min.x + 1;
+		draw(view, r, col[Cchunk], nil, ZP);
+		if(c->bufsz == 0)
+			break;
+	}
+}
+
+static void
 drawsamps(void*)
 {
 	int x, lmin, lmax, rmin, rmax;
@@ -159,6 +185,7 @@
 		r.max.x = r.min.x + 1;
 		draw(view, r, col[Cloop], nil, ZP);
 	}
+	drawchunks();
 }
 
 void
@@ -308,6 +335,7 @@
 	col[Csamp] = eallocimage(Rect(0,0,1,1), 1, 0x440000FF);
 	col[Cline] = eallocimage(Rect(0,0,1,1), 1, 0x884400FF);
 	col[Cloop] = eallocimage(Rect(0,0,1,1), 1, 0x777777FF);
+	col[Cchunk] = eallocimage(Rect(0,0,1,1), 1, 0x777700FF);
 	if((drawc = chancreate(sizeof(ulong), 4)) == nil)
 		sysfatal("chancreate: %r");
 	if(proccreate(drawsamps, nil, mainstacksize) < 0)
--- a/fns.h
+++ b/fns.h
@@ -11,6 +11,7 @@
 void	initdrw(void);
 void	advance(Dot*, usize);
 void	jump(usize);
+Chunk*	p2c(usize, usize*);
 void	setrange(usize, usize);
 int	setpos(usize);
 uchar*	getbuf(Dot, usize, uchar*, usize*);
--- a/pplay.c
+++ b/pplay.c
@@ -8,6 +8,7 @@
 #include "fns.h"
 
 int stereo, zoom = 1;
+int debug;
 
 static Keyboardctl *kc;
 static Mousectl *mc;
@@ -76,7 +77,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-cs] [pcm]\n", argv0);
+	fprint(2, "usage: %s [-Dcs] [pcm]\n", argv0);
 	threadexits("usage");
 }
 
@@ -89,6 +90,7 @@
 	Rune r;
 
 	ARGBEGIN{
+	case 'D': debug = 1; break;
 	case 'c': cat = 1; break;
 	case 's': stereo = 1; break;
 	default: usage();