diff --git a/examples/APCmini.midizaprc b/examples/APCmini.midizaprc index 3c25a38..d4c77ad 100644 --- a/examples/APCmini.midizaprc +++ b/examples/APCmini.midizaprc @@ -182,14 +182,14 @@ G#7 D7 # meters, which actually have 8 different values, have to be squashed # into 5 LEDs per channel. -?CP[16] C2[0,1] G#2[0:3,1] E3[0:5,5] C4[0:7,5] G#4[0:8,3] +?CP[16] C2{0,1} G#2{0:3,1} E3{0:5,5} C4{0:7,5} G#4{0:8,3} # Here's an alternative decoding, which creates horizontal meters -# covering the full range, with the first channel on top. Note, -# however, that this ranges across the entire 8x8 grid and will thus -# clobber the rec/solo/mute controls! +# covering the full range, with the first channel on top. This is just +# for illustration purposes -- as it ranges across the entire 8x8 grid, +# it will clobber the rec/solo/mute controls. -#?CP[16][-8] G#4[0,1] A4[0,0,1] A#4[0:3,1] B4[0:4,1] C5[0:5,5] C#5[0:6,5] D5[0:7,5] D#5[0:8,3] +#?CP[16][-8] G#4{0,1} A4{0,0,1} A#4{0:3,1} B4{0:4,1} C5{0:5,5} C#5{0:6,5} D5{0:7,5} D#5{0:8,3} # This decodes the least significant digit in the time display (CC69) to # count off time on the 4 bottommost scene launch buttons. Note that @@ -197,7 +197,7 @@ G#7 D7 # zeros in the value lists below to skip over all the non-digit # characters at the beginning of the ASCII table. -?CC69[128] F7[0:49,1,0] E7[0:50,1,0] Eb7[0:51,1,0] D7[0:52,1,0] +?CC69[128] F7{0:49,1,0} E7{0:50,1,0} Eb7{0:51,1,0} D7{0:52,1,0} # no feedback for faders (faders aren't motorized) diff --git a/midizap.c b/midizap.c index 4534216..f607d47 100644 --- a/midizap.c +++ b/midizap.c @@ -543,12 +543,12 @@ static char *debug_key(translation *tr, char *name, sprintf(name, "%s%s%d[%d][%d]-%d%s", prefix, note_name(data), note_octave(data), mod, step, chan+1, suffix); else if (n_steps) { - sprintf(name, "%s%s%d[%d][", prefix, note_name(data), + sprintf(name, "%s%s%d[%d]{", prefix, note_name(data), note_octave(data), mod); int l = strlen(name); for (int i = 0; i < n_steps; i++, (l = strlen(name))) sprintf(name+l, "%s%d", i?",":"", steps[i]); - sprintf(name+l, "]-%d%s", chan+1, suffix); + sprintf(name+l, "}-%d%s", chan+1, suffix); } else sprintf(name, "%s%s%d[%d]-%d%s", prefix, note_name(data), note_octave(data), mod, chan+1, suffix); @@ -578,12 +578,12 @@ static char *debug_key(translation *tr, char *name, sprintf(name, "%sKP:%s%d[%d][%d]-%d%s", prefix, note_name(data), note_octave(data), mod, step, chan+1, suffix); else if (n_steps) { - sprintf(name, "%sKP:%s%d[%d][", prefix, note_name(data), + sprintf(name, "%sKP:%s%d[%d]{", prefix, note_name(data), note_octave(data), mod); int l = strlen(name); for (int i = 0; i < n_steps; i++, (l = strlen(name))) sprintf(name+l, "%s%d", i?",":"", steps[i]); - sprintf(name+l, "]-%d%s", chan+1, suffix); + sprintf(name+l, "}-%d%s", chan+1, suffix); } else sprintf(name, "%sKP:%s%d[%d]-%d%s", prefix, note_name(data), note_octave(data), mod, chan+1, suffix); @@ -613,11 +613,11 @@ static char *debug_key(translation *tr, char *name, if (step != 1) sprintf(name, "%sCC%d[%d][%d]-%d%s", prefix, data, mod, step, chan+1, suffix); else if (n_steps) { - sprintf(name, "%sCC%d[%d][", prefix, data, mod); + sprintf(name, "%sCC%d[%d]{", prefix, data, mod); int l = strlen(name); for (int i = 0; i < n_steps; i++, (l = strlen(name))) sprintf(name+l, "%s%d", i?",":"", steps[i]); - sprintf(name+l, "]-%d%s", chan+1, suffix); + sprintf(name+l, "}-%d%s", chan+1, suffix); } else sprintf(name, "%sCC%d[%d]-%d%s", prefix, data, mod, chan+1, suffix); else @@ -646,11 +646,11 @@ static char *debug_key(translation *tr, char *name, if (step != 1) sprintf(name, "%sCP[%d][%d]-%d", prefix, mod, step, chan+1); else if (n_steps) { - sprintf(name, "%sCP[%d][", prefix, mod); + sprintf(name, "%sCP[%d]{", prefix, mod); int l = strlen(name); for (int i = 0; i < n_steps; i++, (l = strlen(name))) sprintf(name+l, "%s%d", i?",":"", steps[i]); - sprintf(name+l, "]-%d", chan); + sprintf(name+l, "}-%d", chan); } else sprintf(name, "%sCP[%d]-%d", prefix, mod, chan+1); else diff --git a/readconfig.c b/readconfig.c index 1aa69a3..07d44a9 100644 --- a/readconfig.c +++ b/readconfig.c @@ -640,11 +640,11 @@ print_stroke(stroke *s, int mod, int step, int n_steps, int *steps, int val) printf("%s%d[%d]-%d%s ", note_name(d), note_octave(d), v, channel, suffix); } else if (s->steps) { - printf("%s%d[", note_name(s->data), + printf("%s%d{", note_name(s->data), note_octave(s->data)); for (int i = 0; i < s->n_steps; i++) printf("%s%d", i?",":"", s->steps[i]); - printf("]-%d%s ", channel, suffix); + printf("}-%d%s ", channel, suffix); } else if (s->step) printf("%s%d[%d]-%d%s ", note_name(s->data), note_octave(s->data), s->step, channel, suffix); @@ -660,11 +660,11 @@ print_stroke(stroke *s, int mod, int step, int n_steps, int *steps, int val) printf("KP:%s%d[%d]-%d%s ", note_name(d), note_octave(d), v, channel, suffix); } else if (s->steps) { - printf("KP:%s%d[", note_name(s->data), + printf("KP:%s%d{", note_name(s->data), note_octave(s->data)); for (int i = 0; i < s->n_steps; i++) printf("%s%d", i?",":"", s->steps[i]); - printf("]-%d%s ", channel, suffix); + printf("}-%d%s ", channel, suffix); } else if (s->step) printf("KP:%s%d[%d]-%d%s ", note_name(s->data), note_octave(s->data), s->step, channel, suffix); @@ -679,10 +679,10 @@ print_stroke(stroke *s, int mod, int step, int n_steps, int *steps, int val) int v = datavals(r, s->step, s->steps, s->n_steps); printf("CC%d[%d]-%d%s ", d, v, channel, suffix); } else if (s->steps) { - printf("CC%d[", s->data); + printf("CC%d{", s->data); for (int i = 0; i < s->n_steps; i++) printf("%s%d", i?",":"", s->steps[i]); - printf("]-%d%s ", channel, suffix); + printf("}-%d%s ", channel, suffix); } else if (s->step) printf("CC%d[%d]-%d%s ", s->data, s->step, channel, suffix); else @@ -700,10 +700,10 @@ print_stroke(stroke *s, int mod, int step, int n_steps, int *steps, int val) int v = datavals(s->swap?val/mod:val%mod, s->step, s->steps, s->n_steps); printf("CP[%d]-%d%s ", v, channel, suffix); } else if (s->steps) { - printf("CP["); + printf("CP{"); for (int i = 0; i < s->n_steps; i++) printf("%s%d", i?",":"", s->steps[i]); - printf("]-%d%s ", channel, suffix); + printf("}-%d%s ", channel, suffix); } else if (s->step) printf("CP[%d]-%d%s ", s->step, channel, suffix); else @@ -714,10 +714,10 @@ print_stroke(stroke *s, int mod, int step, int n_steps, int *steps, int val) int v = datavals(s->swap?val/mod:val%mod, s->step, s->steps, s->n_steps); printf("PB[%d]-%d%s ", v, channel, suffix); } else if (s->steps) { - printf("PB["); + printf("PB{"); for (int i = 0; i < s->n_steps; i++) printf("%s%d", i?",":"", s->steps[i]); - printf("]-%d%s ", channel, suffix); + printf("}-%d%s ", channel, suffix); } else if (s->step) printf("PB[%d]-%d%s ", s->step, channel, suffix); else @@ -955,15 +955,16 @@ static char *parse_steps(char *tok, char *p, int *step, int *n_steps, int **steps) { int l, n; - if (sscanf(++p, "%d%n", &l, &n) == 1) { + char c = *p++, d = c=='[' ? ']' : '}'; + if (sscanf(p, "%d%n", &l, &n) == 1) { p += n; - if (*p == ',' || *p == ':') { + if (c == '{') { int n_st = 1; static int st[MAXSTEPS]; st[0] = l; while (*p == ',' || *p == ':') { - char c = *p; - if (sscanf(++p, "%d%n", &l, &n) == 1) { + char c = *p++; + if (sscanf(p, "%d%n", &l, &n) == 1) { p += n; } else return 0; @@ -996,7 +997,10 @@ static char *parse_steps(char *tok, char *p, *steps = 0; *step = l; } - return p; + if (*p == d) + return ++p; + else + return 0; } else { return 0; } @@ -1051,7 +1055,7 @@ parse_midi(char *tok, char *s, int lhs, int mode, // step size / modulus *mod = 0; int step2 = 0, n_steps2 = 0, *steps2 = 0; - if (*p == '[') { + if (*p == '[' || *p == '{') { if ((p = parse_steps(tok, p, step, n_steps, steps))) { if (*n_steps) { // only permitted on the rhs in mod translations @@ -1059,9 +1063,7 @@ parse_midi(char *tok, char *s, int lhs, int mode, } else if (!*step || (lhs && *step<0)) // must be nonzero / positive on lhs return 0; - if (*p != ']') return 0; - p++; - if (*p == '[') { + if (*p == '[' || *p == '{') { // possible step size on lhs for mod translations (we just record it // here, will be resolved later) if ((p = parse_steps(tok, p, &step2, &n_steps2, &steps2))) { @@ -1069,8 +1071,6 @@ parse_midi(char *tok, char *s, int lhs, int mode, } else { return 0; } - if (*p != ']') return 0; - p++; } } else { return 0;