ref: a0e420b2e38e80b1aa36131332d1f3e8516782c9
parent: 3a3863dbbe54b0615927b2f30681d12085fb813b
author: qwx <[email protected]>
date: Wed Jul 26 01:31:22 EDT 2023
cmd: add commands: j (jump) L (left bound) R (right bound) also add a function for pixel to absolute offset; use offsets only in draw.c setters instead of a mix of both; force aligned offsets always
--- a/cmd.c
+++ b/cmd.c
@@ -10,7 +10,38 @@
static int epfd[2];
+// FIXME: cursor moves too fast
static int
+setright(char *s)
+{
+ vlong off, m;
+
+ off = atoll(s) * Sampsz;
+ if(current->cur > off){
+ m = Rate * Sampsz;
+ setjump(off - m >= 0 ? off - m : 0);
+ }
+ return setloop(off);
+}
+
+static int
+setleft(char *s)
+{
+ vlong off;
+
+ off = atoll(s) * Sampsz;
+ if(current->cur < off)
+ setjump(off + Sampsz);
+ return setloop(off);
+}
+
+static int
+jumpto(char *s)
+{
+ return setjump(atoll(s) * Sampsz);
+}
+
+static int
paste(char *)
{
return cpaste(current) == 0 ? 1 : -1;
@@ -224,8 +255,12 @@
case '<': x = pipefrom(s); break;
case '^': x = pipethrough(s); break;
case '|': x = pipeto(s); break;
+ case 'L': x = setleft(s); break;
+ case 'R': x = setright(s); break;
case 'c': x = copy(s); break;
case 'd': x = cut(s); break;
+ case 'j': x = jumpto(s); break;
+ //case 'm': x = mark(s); break;
case 'p': x = paste(s); break;
case 'q': threadexitsall(nil);
case 'r': x = readfrom(s); break;
--- a/draw.c
+++ b/draw.c
@@ -302,8 +302,8 @@
void
setrange(usize from, usize to)
{
- assert((from & 3) == 0);
- assert((to & 3) == 0);
+ from &= ~3;
+ to &= ~3;
if(current->from > views)
drawpos(current->from, view);
if(current->to < viewe)
@@ -318,41 +318,40 @@
static int
setcur(usize off)
{
+ off &= ~3;
if(off < current->from || off > current->to - Outsz){
- werrstr("cannot jump outside of loop bounds\n");
+ werrstr("cannot jump outside of loop bounds");
return -1;
}
current->off = current->cur = off;
- if(paused)
- update(0, 0);
return 0;
}
-void
+int
setloop(vlong off)
{
- off *= T;
- off += views;
- if(off < 0 || off > current->totalsz)
- return;
+ off &= ~3;
+ if(off < 0 || off > current->totalsz){
+ werrstr("invalid range");
+ return -1;
+ }
if(off < current->cur)
setrange(off, current->to);
else
setrange(current->from, off);
- if(paused)
- update(0, 0);
+ return 0;
}
-void
-setjump(usize off)
+int
+setjump(vlong off)
{
- setcur(off);
+ return setcur(off) & ~3;
}
-void
-setofs(usize ofs)
+vlong
+p2off(int x)
{
- setcur(views + ofs * T);
+ return views + x * T & ~3;
}
static void
--- a/fns.h
+++ b/fns.h
@@ -14,11 +14,11 @@
void setzoom(int, int);
int zoominto(vlong, vlong);
void setrange(usize, usize);
-void setloop(vlong);
-void setofs(usize);
+int setloop(vlong);
void setpan(int);
void setpage(int);
-void setjump(usize);
+int setjump(vlong);
+vlong p2off(int);
void redraw(int);
void initdrw(int);
int advance(Dot*, usize);
--- a/pplay.c
+++ b/pplay.c
@@ -137,8 +137,8 @@
if(eqpt(mo.xy, ZP))
mo = mc->Mouse;
switch(mc->buttons){
- case 1: setofs(mc->xy.x - screen->r.min.x); break;
- case 2: setloop(mc->xy.x - screen->r.min.x); break;
+ case 1: setjump(p2off(mc->xy.x - screen->r.min.x)); if(paused) update(0, 0); break;
+ case 2: setloop(p2off(mc->xy.x - screen->r.min.x)); if(paused) update(0, 0); break;
case 4: setpan(mo.xy.x - mc->xy.x); break;
case 8: setzoom(1, 1); break;
case 16: setzoom(-1, 1); break;