stew

a monorepo of some sort
Log | Files | Refs

commit 132132406204d8b1521ae4d65a5b9175724e7e6e
parent 8310755c2cddb3be7ab0ef747d573e795632bc0c
Author: rpa <rpa@laika>
Date:   Sun,  5 Feb 2023 09:07:59 +0000

wave/track: expanded patternedit

Diffstat:
Msrc/wave/track.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 50 insertions(+), 28 deletions(-)

diff --git a/src/wave/track.c b/src/wave/track.c @@ -98,8 +98,7 @@ trackedit(void) print("%s", ps); while (read(0, cbuf, BufSize) > 0) { n = tokenize(cbuf, args, 64); - if (n == 0) continue; - switch (args[0][0]) { + if (n != 0) switch (args[0][0]) { case 'p': if (n != 2) goto err; patternedit(args[1]); @@ -158,8 +157,7 @@ patternedit(char *arg) print("%s", ps); while (read(0, cbuf, BufSize) > 0) { n = tokenize(cbuf, args, 64); - if (n == 0) continue; - switch(args[0][0]) { + if (n != 0) switch(args[0][0]) { case 'p': printpattern(ptrn); break; @@ -169,6 +167,7 @@ patternedit(char *arg) case 'q': return; case 'P': + sctl.PC = 0; sctl.play = 1; break; case 'S': @@ -192,8 +191,10 @@ printpattern(Step *ptrn) { int i; for (i = 0; i < PatternLength; i++) { - print("%02uhhx: %s %02uhhX - %04uhX %04uhX %04uhX\n", - i + 1, note2str(ptrn[i].note), ptrn[i].volume, + print("%02uhhx: %s ", i, note2str(ptrn[i].note)); + if (ptrn[i].volume == 0) print(".. - "); + else print("%02uhhX - ", ptrn[i].volume -1); + print("%04uhX %04uhX %04uhX\n", ptrn[i].cmd[0], ptrn[i].cmd[1], ptrn[i].cmd[2]); } } @@ -216,43 +217,61 @@ void patternset(Step *ptrn, int n, char **args) { long l; - int i, note; + int i, a, note; char *p; - if (n > 2) { - print("?\n"); - return; - } + + /* Address */ l = strtol(args[0], &p, 16); - if (p == args[0]) { - print("?\n"); - return; + if (p == args[0]) goto err; + if ((l < 0) || (l >= PatternLength)) goto err; + a = l; + + /* Note */ + args++, n--; + if (n <= 0) goto err; + if (strcmp(args[0], "-") != 0) { + note = str2note(args[0]); + if (note == NoteErr) goto err; + ptrn[a].note = note; } - if ((l < 1) || (l >= PatternLength)) { - print("?\n"); - return; + + /* Volume */ + args++, n--; + if (n <= 0) return; + if (strcmp(args[0], "-") != 0) { + if (strcmp(args[0], "..") == 0) l = 0; + else { + l = strtol(args[0], &p, 16) + 1; + if (p == args[0]) goto err; + } + if ((l < 0) || (l > 0x80)) goto err; + ptrn[a].volume = l; } - i = l; - note = str2note(args[1]); - if (note == NoteErr) { - print("?\n"); - return; + for (i = 0; i < 3; i++) { + args++, n--; + if (n <= 0) return; + if (strcmp(args[0], "-") == 0) continue; + l = strtol(args[0], &p, 16); + if (p == args[0]) goto err; + ptrn[a].cmd[i] = l; } - ptrn[i-1].note = note; + return; + err: + print("?\n"); } int str2note(char *str) { int i, note; - if (strncmp(str, "OFF", 3) == 0) return NoteOff; - if (strncmp(str, "off", 3) == 0) return NoteOff; - if (strncmp(str, "---", 3) == 0) return NoteNop; + if (strncmp(str, "OFF", 4) == 0) return NoteOff; + if (strncmp(str, "off", 4) == 0) return NoteOff; + if (strncmp(str, "...", 4) == 0) return NoteNop; str[0] = toupper(str[0]); for (i = 0; i < Octave; i++) { if (strncmp(str, notestr[i], 2) == 0) { if (isdigit(str[2])) { note = i + 12 * (str[2] - '0'); - print("note %d, freq %d\n", note, note2freq(note)); return note; } else return NoteErr; @@ -295,7 +314,10 @@ threadsynth(void *v) break; default: sctl->synth.mod.freq = note2freq(s.note); - sctl->synth.mod.vol = 0x7f; + sctl->synth.mod.vol = 0x7f00; + } + if ((s.volume > 0) && (s.volume <= 0x80)) { + sctl->synth.mod.vol = (s.volume - 1) * 0x100; } k = 0; sctl->PC++;