commit a9f1b9e8a483e8b8858f6e119a3870b94ad569b9
parent 5b17b7ea8ef7ba98d9a452e12dc461c5fa1b0b11
Author: glenda <glenda@device>
Date: Thu, 27 Oct 2022 20:15:10 +0000
fresh mu
Diffstat:
M | src/mu/track2 | | | 54 | ++++++++++++++++++++++-------------------------------- |
M | src/mu/trk.c | | | 73 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- |
2 files changed, 78 insertions(+), 49 deletions(-)
diff --git a/src/mu/track2 b/src/mu/track2
@@ -1,35 +1,25 @@
-#C-2 C-5 k
-#C#5 k
-#E-5 N4f n02
-#F-5 k
-#G-5 k
-#
-#N4f
-#
-# END
-k
+.bpm 120 4
-k
+d0.1
-k
+. k C-3 C-5
+.
+. C-6
+. C-5
+. k F-5
+. C-6
+. F-6
+. F-5
+. k C-3 G-5
+. F-6
+. G-6
+. G-5
+. k D#5
+. G-6
+. D#6
+. D#5
-k
-
-b0.999999 C-4 d0.01 k N3f n0f
-C-5 d0.01 N3f
-D#5 d0.01 N3f
-F-5 d0.01 N3f
-G-5 d0.01 N7f n08
-N3f n0f
-A#5 k N3f
-N3f
-G-5 N3f
-N3f
-F-5 N3f
-N3f
-G-5 N7f n08
-N2f n0f
-k N1f
-N1f
-
-# END
+. k
+. D#6
+.
+.
diff --git a/src/mu/trk.c b/src/mu/trk.c
@@ -4,30 +4,69 @@
#include <libc.h>
#include <bio.h>
-void
-cmd(char *)
+typedef struct List List;
+struct List {
+ void *v;
+ List *next;
+};
+
+List start;
+long bpm = 120, steps = 1;
+
+vlong dt;
+
+int
+cmd(char *s)
{
+ if (s[0] == '.') {
+ int argc; char *argv[32];
+ argc = tokenize(s, argv, 32);
+ if (strcmp(argv[0], ".") == 0) {
+ int i;
+ for (i = 0; i < argc; i++) print("%s ", argv[i]);
+ print("\n");
+ return 1;
+ }
+ if (strcmp(argv[0], ".bpm") == 0) {
+ long x = 0;
+ if (argc > 1) x = strtol(argv[1], nil, 10);
+ if (x != 0) bpm = x;
+ if (argc > 2) x = strtol(argv[2], nil, 10);
+ if (x != 0) steps = x;
+ dt = 60000000000 / (bpm * steps);
+ return 0;
+ }
+ if (strcmp(argv[0], ".end") == 0) {
+
+ }
+ } else if (s[0] == ':') return 0;
+ print("%s\n", s);
+ return 0;
}
void
main(void)
{
- vlong t;
- Biobuf *in;
- in = Bfdopen(0, OREAD);
- t = nsec();
- for (;;) {
- char *s = Brdstr(in, '\n', 1);
- if (s == nil) break;
- else if (s[0] == ':'); // labels
- else if (s[0] == '.') cmd(s); // commands
- else if (s[0] != '#'){
- t += 1000000000 / 4;
- // fprint(2, "%lld ", t - nsec());
- print("%s\n", s);
-
+ Biobuf *in = Bfdopen(0, OREAD);
+ vlong t = nsec();
+ List *lp = &start;
+ char *s;
+ dt = 60000000000 / (bpm * steps);
+ while ((s = Brdstr(in, '\n', 1)) != nil) {
+ while((s[0] == ' ') || (s[0] == '\t')) s++;
+ if ((s[0] == '\0') || (s[0] == '#')) {
+ free(s);
+ } else {
+ lp->v = s;
+ lp->next = sbrk(sizeof(List));
+ lp = lp->next;
+ lp->next = nil, lp->v = nil;
+ }
+ }
+ for (lp = &start, s = lp->v; s!= nil; lp = lp->next, s = lp->v) {
+ if (cmd(s) != 0) {
+ t += dt;
sleep((t - nsec()) / 1000000);
}
- free(s);
}
}