ref: b82f25085001fe3d7c68ccb450d5d6306f2a2e3f
parent: 8ebcb9b38e8fc8a5a9b6d73adb0048870194730c
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Feb 15 19:49:21 EST 2020
plan9: add basic commands, enter with C-b
--- a/plan9.c
+++ b/plan9.c
@@ -66,7 +66,7 @@
static vlong tick;
static int gridw = 8, gridh = 8;
static int rulerstyle = Sfancy, dotstyle = Sfancy;
-static int bpm = 120, pause, forward;
+static int bpm = 120, apm = 120, pause, forward;
static int curx, cury;
static int selw = 1, selh = 1;
static int charw, charh;
@@ -299,6 +299,11 @@
framedev = (processnew - processold - 15000000000LL/bpm)/1000000LL;
tick++;
+
+ if (apm < bpm)
+ bpm--;
+ else if (apm > bpm)
+ bpm++;
}
}
@@ -651,6 +656,39 @@
}
}
+static void
+command(char *s)
+{
+ char *a;
+ int x;
+
+ if ((a = strchr(s, ':')) != nil)
+ *a++ = 0;
+
+ if (strcmp(s, "play") == 0)
+ pause = 0;
+ else if (strcmp(s, "stop") == 0)
+ pause = 1;
+ else if (strcmp(s, "run") == 0)
+ forward = 1;
+ else if (a != nil) {
+ x = atoi(a);
+
+ if (strcmp(s, "bpm") == 0)
+ apm = bpm = MAX(1, x);
+ else if (strcmp(s, "apm") == 0)
+ apm = MAX(1, x);
+ else if (strcmp(s, "frame") == 0)
+ tick = MAX(0, x);
+ else if (strcmp(s, "skip") == 0)
+ tick = MAX(0, tick+x);
+ else if (strcmp(s, "rewind") == 0)
+ tick = MAX(0, tick-x);
+
+ /* FIXME color, find, select, inject, write, time */
+ }
+}
+
void
threadmain(int argc, char **argv)
{
@@ -915,14 +953,19 @@
h = snaphigh(h, gridh);
break;
case '>':
- bpm++;
+ apm = ++bpm;
break;
case '<':
- bpm = MAX(1, bpm-1);
+ apm = bpm = MAX(1, bpm-1);
break;
case 0x09: /* C-i */
case Kins:
mode = mode != Mappend ? Mappend : Minsert;
+ break;
+ case Kstx:
+ tmp[0] = 0;
+ if (enter("command:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0)
+ command(tmp);
break;
case Kesc:
if (mode == Mslide || mode != Minsert)