stew

a monorepo of some sort
Log | Files | Refs

commit e81b652a91646b3f46ad03664106a80295571b12
parent 11bb1bb1fcc688b91f19405b272c130028e9db92
Author: rpa <rpa@laika>
Date:   Sun, 29 Jan 2023 17:50:52 +0000

wave/inst: add prog input

Diffstat:
Msrc/wave/inst.c | 67++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 52 insertions(+), 15 deletions(-)

diff --git a/src/wave/inst.c b/src/wave/inst.c @@ -28,6 +28,7 @@ #include <u.h> #include <libc.h> +#include <ctype.h> #include <thread.h> #include <draw.h> #include <mouse.h> @@ -89,6 +90,7 @@ int loadfile(char *, void *, long); void rcalc(UI *); Widget * findhot(UI *); void drawwidgets(UI *); +void drawprogmask(void); void wxfiledraw(UI *, void *); void wxfileactivate(UI *, void *); void wxprogdraw(UI *, void *); @@ -126,13 +128,14 @@ threadmain(int argc, char **argv) fprint(2, "loading %s\n", argv[1]); snprint(prog.path, NameBufSize, "%s", argv[1]); } else prog.path[0] = '\0'; + ped.p = prog.p; if (initdraw(nil, nil, "inst") == 0) sysfatal("%r"); if ((ui.mctl = initmouse(nil, screen)) == nil) sysfatal("%r"); if ((ui.kctl = initkeyboard(nil)) == nil) sysfatal("%r"); synthc = chancreate(sizeof(Rune), 8); proccreate(threadsynth, nil, 64 * 1024); - proccreate(threadkbd, nil, 64 * 1024); + // proccreate(threadkbd, nil, 64 * 1024); palette[0] = allocimage(display, ZR, XRGB32, 1, 0x7f0000ff); palette[1] = allocimage(display, ZR, XRGB32, 1, 0xffff00ff); @@ -146,19 +149,7 @@ threadmain(int argc, char **argv) progmask = allocimage(display, Rect(0, 0, strlen(barsample) * cw, 256 * ch), GREY1, 0, DBlack); - int i; - for (i = 0; i < 128; i++) { - Point pt = Pt(0, i * ch); - char buf[256]; - char *prp = prog.p + i * 16; - snprint(buf, 256, - "%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX\0", - i, - prp[0], prp[1], prp[2], prp[3], prp[4], prp[5], prp[6], prp[7], - prp[8], prp[9], prp[10], prp[11], prp[12], prp[13], prp[14], prp[15]); - - string(progmask, pt, display->white, ZP, font, buf); - } + drawprogmask(); wxf_wt = (Widget) { ZR, palette, &wavetable, wxfiledraw, wxfileactivate, @@ -290,7 +281,12 @@ threadkbd(void *) memset(kbuf, 0, KbdBufSize); while ((read(kbd, kbuf, KbdBufSize)) > 0) { + + n = runesnprint(rbuf, KbdBufSize, "%s", kbuf + 1); + + if (rbuf[n-1] == Kdel) break; + switch (kbuf[0]) { case 'K': case 'k': @@ -300,7 +296,7 @@ threadkbd(void *) break; case 'c': /* hacks! */ - nbsend(ui.kctl->c, &rbuf[0]); + // nbsend(ui.kctl->c, &rbuf[0]); break; } memset(kbuf, 0, KbdBufSize); @@ -330,7 +326,11 @@ handlemouse(UI *ui) void handlekeyboard(UI *ui) { + char buf[256]; switch (ui->kv) { + case ' ': + proccreate(threadkbd, nil, 64 * 1024); + break; case Kup: ped.curl--; if (ped.curl < 0) ped.curl = 127; @@ -347,6 +347,24 @@ handlekeyboard(UI *ui) ped.curc++; if (ped.curc >= 32) ped.curc = 0; break; + default: + if (isxdigit(ui->kv)) { + sprint(buf, "%C\0", ui->kv); + int n, i; + i = ped.curl * 32 + ped.curc; + n = strtol(buf, nil, 16); + if ((i & 1) != 0) { + ped.p[i>>1] = ped.p[i>>1] & 0xf0 | n; + } else { + ped.p[i>>1] = ped.p[i>>1] & 0x0f | (n << 4); + } + drawprogmask(); + if ((ped.curc & 1) == 0) ped.curc++; + else { + ped.curc--; + ped.curl = (ped.curl + 1) % ProgMax; + } + } } drawwidgets(ui); flushimage(display, 1); @@ -409,6 +427,24 @@ drawwidgets(UI *ui) }; } +void +drawprogmask(void) +{ + int i; + draw(progmask, progmask->r, display->black, nil, ZP); + for (i = 0; i < 128; i++) { + Point pt = Pt(0, i * ch); + char buf[256]; + char *prp = prog.p + i * 16; + snprint(buf, 256, + "%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX %02uhhX:%02uhhX\0", + i, + prp[0], prp[1], prp[2], prp[3], prp[4], prp[5], prp[6], prp[7], + prp[8], prp[9], prp[10], prp[11], prp[12], prp[13], prp[14], prp[15]); + + string(progmask, pt, display->white, ZP, font, buf); + } +} void wxfiledraw(UI *, void *arg) @@ -429,6 +465,7 @@ wxfileactivate(UI *ui, void *arg) if (enter("path:", fb->path, NameBufSize, ui->mctl, ui->kctl, nil) != 0) { loadfile(fb->path, fb->p, fb->n); } + drawprogmask(); } void