commit e1e23b060a8b2933eddb1a77d192a4467a06d324
parent de2c1409887cf7f1563c0d2bc4c89d6f0f968785
Author: Renev Pavel <an2qzavok@gmail.com>
Date: Fri, 13 Jan 2023 12:02:28 +0000
wave: wfedit
Diffstat:
2 files changed, 111 insertions(+), 1 deletion(-)
diff --git a/src/wave/mkfile b/src/wave/mkfile
@@ -1,6 +1,6 @@
</$objtype/mkfile
-TARG=draw loop fade piano sampler harm smoke inst
+TARG=draw loop fade piano sampler harm smoke inst wfedit
BIN=/$objtype/bin
HFILES=util.h wavetable.h prog.h
OFILES=wavetable.$O prog.$O util.$O
diff --git a/src/wave/wfedit.c b/src/wave/wfedit.c
@@ -0,0 +1,110 @@
+/*
+ * Waveform Editor
+ */
+
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <draw.h>
+#include <mouse.h>
+#include <cursor.h>
+#include <keyboard.h>
+
+#include "wavetable.h"
+
+enum {
+ BufMax = 8,
+ BufSize = sizeof(s16int) * WFSize,
+ CmdBufSize = 256,
+};
+
+typedef struct CmdCtl CmdCtl;
+typedef struct Command Command;
+
+struct CmdCtl {
+ Channel *c;
+};
+
+struct Command {
+ int in;
+ int out;
+ void (*op)(void *);
+ char **args;
+};
+
+void usage(void);
+void threadcmd(void *);
+int getinput(char *);
+int getoutput(char *);
+void* getop(char *);
+void bufcpy(int, int);
+
+s16int *buf[BufMax];
+
+void
+threadmain(int argc, char **argv)
+{
+ int i;
+ for (i = 0; i < BufMax; i++) buf[i] = sbrk(BufSize);
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+}
+
+void
+usage(void)
+{
+ fprint(2, "usage: %s [file]\n", argv0);
+ threadexitsall("usage");
+}
+
+void
+threadcmd(void *v)
+{
+ int n;
+ Command cmd;
+ char cmdbuf[CmdBufSize], *args[64];
+ CmdCtl *rctl = v;
+ while (recv(v,cmdbuf) > 0) {
+ n = tokenize(cmdbuf, args, 64);
+ cmd = (Command) {
+ getinput(args[0]),
+ getoutput(args[n-1]),
+ getop(args[1]),
+ args + 2,
+ };
+ args[n - 1] = nil;
+ if ((cmd.in >= 0) && (cmd.out >= 0) && (cmd.op != nil)) {
+ bufcpy(cmd.in, 0);
+ cmd.op(args);
+ bufcpy(0, cmd.out);
+ } else {
+ // TODO: output error message here?
+ }
+ }
+}
+
+int
+getinput(char *)
+{
+ return 0;
+}
+
+int
+getoutput(char *)
+{
+ return 0;
+}
+
+void *
+getop(char *)
+{
+ return nil;
+}
+
+void
+bufcpy(int, int)
+{
+}