commit 3361dbe483971b71157f1b70c51637a1d0c3d254
parent 8fd86fbed1eacfc1953696dababa9edc42ca1e37
Author: rpa <rpa@laika>
Date: Sun, 18 Dec 2022 15:43:10 +0000
mu/trk: add jump and return commands
Diffstat:
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/src/mu/trk.c b/src/mu/trk.c
@@ -1,6 +1,5 @@
/*
Primitive sequencer / music-tracker
-
reads lines from stdin and prints them at controllable rate
*/
@@ -15,7 +14,7 @@ struct List {
List *next;
};
-List *list;
+List *list, *rstack[64], **rp = rstack;
char *file;
vlong t, dt;
long bpm = 120, steps = 1;
@@ -38,8 +37,11 @@ struct Cmds {
void (*func)(List **, int, char **);
} cmds[] = {
{ "#", nil }, /* comment */
+ { ":", nil }, /* label */
{ ".bpm", cmdbpm }, /* update bpm to new value */
{ "----", cmdpause },
+ { ".jmp", cmdjump },
+ { ".ret", cmdret },
{ ".rld", cmdreload }, /* reload file and start from the beginning */
};
@@ -76,6 +78,35 @@ cmdpause(List **, int, char **)
}
void
+cmdjump(List **lp, int n, char **args)
+{
+ if (n != 2) {
+ fprint(2, "cmdjump: wrong argument count %d\n", n);
+ return;
+ }
+ List *jp = list;
+ while (strcmp(args[1], (char *)jp->v) != 0) {
+ jp = jp->next;
+ if (jp == nil) return;
+ }
+ *rp = (*lp);
+ rp ++;
+ if (rp > rstack + 64) exits("rstack overflow");
+ *lp = jp->next;
+}
+
+void
+cmdret(List **lp, int n, char **)
+{
+ if (n != 1) {
+ fprint(2, "cmdret: too much arguments\n");
+ };
+ rp --;
+ if (rp < rstack) exits("rstack underflow");
+ *lp = (*rp);
+}
+
+void
cmdreload(List **lp, int, char **)
{
clearlist(list);