ref: 9e1e20f6b9552189fef5111638f84d944fd6451b
parent: cb5c7c76921d6e656102eac49178874fb3d60e3c
author: qwx <qwx@sciops.net>
date: Fri Aug 9 04:25:46 EDT 2024
remove all mooltitrack code, improve line marker visibility
--- a/cmd.c
+++ b/cmd.c
@@ -4,9 +4,8 @@
#include "dat.h"
#include "fns.h"
-usize ntracks;
+Dot dot;
Dot *current;
-Track *tracks;
static int epfd[2];
@@ -300,10 +299,7 @@
void
advance(usize n)
{
- Track *t;
-
- for(t=tracks; t<tracks+ntracks; t++)
- advanceone(t, n);
+ advanceone(&dot, n);
}
static void
@@ -318,15 +314,11 @@
addtrack(char *path)
{
int fd;
- Track *t;
if((fd = path != nil ? open(path, OREAD) : 0) < 0)
sysfatal("open: %r");
- tracks = erealloc(tracks, (ntracks+1) * sizeof *tracks, ntracks * sizeof *tracks);
- t = tracks + ntracks;
- t->trk = ntracks++;
- if(loadfile(fd, t) == nil)
+ if(loadfile(fd, &dot) == nil)
sysfatal("initcmd: %r");
close(fd);
- current = &t->Dot;
+ current = ˙
}
--- a/dat.h
+++ b/dat.h
@@ -1,21 +1,9 @@
typedef struct Chunk Chunk;
typedef struct Dot Dot;
typedef struct Buf Buf;
-typedef struct Track Track;
-typedef struct Punkt Punkt;
-typedef struct Rekt Rekt;
typedef intptr ssize;
-struct Punkt{
- int x;
- int y;
-};
-struct Rekt{
- Punkt min;
- Punkt max;
-};
-
enum{
Rate = 44100,
WriteRate = 25,
@@ -32,7 +20,6 @@
Chunk *left;
Chunk *right;
};
-// FIXME: some stuff goes in track
struct Dot{
ssize trk;
usize from;
@@ -42,17 +29,8 @@
usize totalsz;
Chunk *norris;
};
-struct Track{
- Dot;
- Rekt;
- int working;
- // FIXME: both for samples:
- vlong len;
- s16int *graph[2];
-};
+extern Dot dot;
extern Dot *current;
-extern usize ntracks;
-extern Track *tracks;
extern QLock lsync;
--- a/draw.c
+++ b/draw.c
@@ -5,12 +5,8 @@
#include "dat.h"
#include "fns.h"
-/* urgh */
-typedef Point Punkt;
-typedef Rectangle Rekt;
-
QLock lsync;
-int debugdraw;
+int debugdraw = 1;
enum{
Cbg,
@@ -28,12 +24,20 @@
static usize views, viewe, viewmax, linepos;
static int bgscalyl, bgscalyr;
static double bgscalf;
-static Channel *upyours, *drawc;
+static Channel *drawc;
static usize T;
static int sampwidth = 1; /* pixels per sample */
static double zoom = 1.0;
-static int stalerender, working;
+static int stalerender, tworking;
+// FIXME
+static int nbuf = 1;
+static Channel *trkc[1];
+static Rectangle tr;
+static int working;
+static vlong slen;
+static s16int *graph[2];
+
static Image *
eallocimage(Rectangle r, int repl, ulong col)
{
@@ -128,28 +132,38 @@
}
static void
-rendersamples(Track *t, Rectangle rr)
+rendersamples(void)
{
s16int *l, *e, *r;
- Rectangle rx;
+ Rectangle rx, rr;
+ if(slen == 0)
+ return;
+ rr = tr;
draw(view, rr, col[Cbg], nil, ZP);
- if(Dx(rr) > t->len / 2)
- rr.max.x = rr.min.x + t->len / 2;
+ if(Dx(rr) > slen / 2)
+ rr.max.x = rr.min.x + slen / 2;
rx = rr;
- for(l=t->graph[0]+2*rx.min.x, e=l+2*Dx(rr); l<e; l+=2, rx.min.x++){
- rx.min.y = bgscalyl - l[1] / bgscalf;
+ for(l=graph[0]+2*rx.min.x, e=l+2*Dx(rr); l<e; l+=2, rx.min.x++){
+ rx.min.y = rr.min.y + bgscalyl - l[1] / bgscalf;
rx.max.x = rx.min.x + sampwidth;
- rx.max.y = bgscalyl - l[0] / bgscalf;
+ rx.max.y = rr.min.y + bgscalyl - l[0] / bgscalf;
draw(view, rx, col[Csamp], nil, ZP);
}
if(!stereo)
return;
- rx = rr;
- for(r=t->graph[1]+2*rx.min.x, e=r+2*Dx(rr); r<e; r+=2, rx.min.x++){
- rx.min.y = bgscalyr - r[1] / bgscalf;
+
+/*
+FIXME: wrong midpoint.
+rendersamples 0x410450 [0 0] [1365 187] view [0 0] [1365 375]→ [187 0] [1552 187]
+*/
+
+ rx = rectaddpt(rr, Pt(Dy(view->r)/2,0));
+ //fprint(2, "→ %R\n", rx);
+ for(r=graph[1]+2*rx.min.x, e=r+2*Dx(rr); r<e; r+=2, rx.min.x++){
+ rx.min.y = rr.min.y + bgscalyr - r[1] / bgscalf;
rx.max.x = rx.min.x + sampwidth;
- rx.max.y = bgscalyr - r[0] / bgscalf;
+ rx.max.y = rr.min.y + bgscalyr - r[0] / bgscalf;
draw(view, rx, col[Csamp], nil, ZP);
}
}
@@ -157,10 +171,7 @@
static void
render(void)
{
- Track *t;
-
- for(t=tracks; t<tracks+ntracks; t++)
- rendersamples(t, view->r);
+ rendersamples();
rendermarks();
}
@@ -204,7 +215,10 @@
threadsetname("drawer");
for(;;){
+ what = Drawrender;
+ // FIXME
if(recv(drawc, &what) < 0){
+// if(nbrecv(drawc, &what) < 0){
fprint(2, "drawproc: %r\n");
break;
}
@@ -221,6 +235,7 @@
drawstat();
flushimage(display, 1);
unlockdisplay(display);
+ sleep(100);
}
}
@@ -231,30 +246,38 @@
}
static void
-sample(Dot d)
+sampler(void *cp)
{
int n, lmin, lmax, rmin, rmax;
usize k;
uchar *p, *e;
s16int s, *l, *r, *le;
- Track *t;
vlong N;
+ Dot d;
+ Channel *c;
- t = tracks + d.trk; // FIXME: just pass track?
+ c = cp;
+again:
+ if(recv(c, &d) < 0)
+ threadexits("recv: %r");
+ tworking = ++working;
+ stalerender++;
N = (d.to - d.from) / (T * sampwidth);
- if(t->len < 2*N){ /* min, max */
- t->graph[0] = erealloc(t->graph[0],
- 2*N * sizeof *t->graph[0],
- t->len * sizeof *t->graph[0]);
- t->graph[1] = erealloc(t->graph[1],
- 2*N * sizeof *t->graph[1],
- t->len * sizeof *t->graph[1]);
+ if(slen < 2*N){ /* min, max */
+ graph[0] = erealloc(graph[0],
+ 2*N * sizeof *graph[0],
+ slen * sizeof *graph[0]);
+ graph[1] = erealloc(graph[1],
+ 2*N * sizeof *graph[1],
+ slen * sizeof *graph[1]);
}
- t->len = 2*N;
- l = t->graph[0];
- r = t->graph[1];
- le = l + t->len;
+ slen = 2*N;
+ l = graph[0];
+ r = graph[1];
+ le = l + slen;
while(l < le){
+ if(c->n > 0)
+ break;
n = T * sampwidth;
lmin = lmax = rmin = rmax = 0;
while(n > 0){
@@ -287,66 +310,27 @@
*r++ = rmin;
*r++ = rmax;
}
- if(upyours->n > 0)
- return;
}
+ working--;
+ refresh(Drawrender);
+ goto again;
}
-static void
-sampleproc(void*)
-{
- Dot d;
-
- threadsetname("sampler");
- for(;;){
- if(recv(upyours, &d) < 0){
- fprint(2, "sampproc: %r\n");
- break;
- }
- working = 1;
- stalerender = 1;
- sample(d);
- refresh(Drawall);
- working = 0;
- }
-}
-
void
setcurrent(Point o)
{
int dy;
- Track *t;
Rectangle r;
- dy = screen->r.max.y / ntracks;
+ dy = screen->r.max.y / 1;
r = Rpt(screen->r.min, Pt(screen->r.max.x, dy));
- for(t=tracks; t<tracks+ntracks; t++){
- if(ptinrect(o, r)){
- current = &t->Dot;
- return;
- }
- r.min.y += dy;
- r.max.y += dy;
+ if(ptinrect(o, r)){
+ current = ˙
+ return;
}
sysfatal("setcurrent: phase error");
}
-void
-resizetracks(void)
-{
- int dy;
- Track *t;
- Rectangle r;
-
- dy = screen->r.max.y / ntracks;
- r = Rpt(screen->r.min, Pt(screen->r.max.x, dy));
- for(t=tracks; t<tracks+ntracks; t++){
- t->Rectangle = r;
- r.min.y += dy;
- r.max.y += dy;
- }
-}
-
static void
resetdraw(void)
{
@@ -361,10 +345,16 @@
statr.min.y = screen->r.max.y - font->height;
freeimage(view);
view = eallocimage(viewr, 0, DNofill);
- bgscalyl = (viewr.max.y - font->height) / (stereo ? 4 : 2);
+ bgscalyl = (viewr.max.y - font->height) / (1 * (stereo ? 4 : 2));
bgscalyr = viewr.max.y - bgscalyl;
bgscalf = 32767. / bgscalyl;
- resizetracks();
+ if(trkc[0] == nil){
+ if((trkc[0] = chancreate(sizeof(Dot), 2)) == nil)
+ sysfatal("chancreate: %r");
+ if(proccreate(sampler, trkc[0], mainstacksize) < 0)
+ sysfatal("00reate: %r");
+ }
+ tr = Rpt(view->r.min, Pt(view->r.max.x, Dy(view->r)));
}
void
@@ -371,7 +361,6 @@
redraw(int all)
{
usize span;
- Track *t;
Dot d;
lockdisplay(display);
@@ -388,13 +377,10 @@
unlockdisplay(display);
if(paused)
refresh(Drawall);
- // FIXME: one worker per file?
- for(t=tracks; t<tracks+ntracks; t++){
- d = t->Dot;
- d.from = d.cur = views;
- d.to = viewe;
- nbsend(upyours, &d);
- }
+ d = dot;
+ d.from = d.cur = views;
+ d.to = viewe;
+ nbsend(trkc[0], &d);
}
void
@@ -514,10 +500,10 @@
col[Cbg] = eallocimage(Rect(0,0,1,1), 1, 0xFFFFC0FF);
col[Csamp] = eallocimage(Rect(0,0,1,1), 1, 0x3F3F20FF);
col[Ctext] = display->black;
- col[Cline] = eallocimage(Rect(0,0,1,1), 1, 0xFF2222FF);
- col[Cins] = eallocimage(Rect(0,0,1,1), 1, DBlue);
- col[Cloop] = eallocimage(Rect(0,0,1,1), 1, 0xDD00DDFF);
- col[Cchunk] = eallocimage(Rect(0,0,1,1), 1, DPaleyellow);
+ col[Cline] = eallocimage(Rect(0,0,1,1), 1, DBlue);
+ col[Cins] = eallocimage(Rect(0,0,1,1), 1, DPaleblue);
+ col[Cloop] = eallocimage(Rect(0,0,1,1), 1, DBluegreen);
+ col[Cchunk] = eallocimage(Rect(0,0,1,1), 1, DRed);
}else{
col[Cbg] = display->black;
col[Csamp] = eallocimage(Rect(0,0,1,1), 1, 0x2A2A2AFF);
@@ -527,12 +513,9 @@
col[Cloop] = eallocimage(Rect(0,0,1,1), 1, 0x8888CCFF);
col[Cchunk] = eallocimage(Rect(0,0,1,1), 1, 0xEE0000FF);
}
- if((drawc = chancreate(sizeof(int), 1)) == nil
- // FIXME: fudge until better perceptual fix
- || (upyours = chancreate(sizeof(Dot), 32)) == nil)
+ if((drawc = chancreate(sizeof(int), 1)) == nil)
sysfatal("chancreate: %r");
redraw(1);
- if(proccreate(drawproc, nil, mainstacksize) < 0
- || proccreate(sampleproc, nil, mainstacksize) < 0)
+ if(proccreate(drawproc, nil, mainstacksize) < 0)
sysfatal("proccreate: %r");
}
--- a/fns.h
+++ b/fns.h
@@ -8,10 +8,8 @@
void ccut(Dot*);
void ccrop(Dot*);
Chunk* loadfile(int, Dot*);
-void quit(void);
int cmd(char*);
void addtrack(char*);
-void resizetracks(void);
void refresh(int);
void setzoom(int, int);
int zoominto(vlong, vlong);