ref: ac088f11139fcbafed579dbd487a39a2ffd0a116
parent: b7eeb823e45f4465f5b19297ac1faed22b81ac13
author: cancel <cancel@cancel.fm>
date: Sun Jan 19 16:09:04 EST 2020
Change to extend range of allowed MIDI note glyphs Fixes #37
--- a/sim.c
+++ b/sim.c
@@ -99,34 +99,13 @@
// Returns UINT8_MAX if not a valid note.
static U8 midi_note_number_of(Glyph g) {
- switch (g) {
- case 'C':
- return 0;
- case 'c':
- return 1;
- case 'D':
- return 2;
- case 'd':
- return 3;
- case 'E':
- return 4;
- case 'F':
- return 5;
- case 'f':
- return 6;
- case 'G':
- return 7;
- case 'g':
- return 8;
- case 'A':
- return 9;
- case 'a':
- return 10;
- case 'B':
- return 11;
- default:
+ int deg, sharp = (g & 1 << 5) >> 5; // sharp=1 if lowercase
+ g &= ~(1 << 5); // make uppercase
+ if (g < 'A' || g > 'Z') // A through Z only
return UINT8_MAX;
- }
+ // We want C=0, D=1, E=2, etc. A and B are equivalent to H and I.
+ deg = g <= 'B' ? 'G' - 'B' + g - 'A' : g - 'C';
+ return (U8)(deg / 7 * 12 + (I8[]){0, 2, 4, 5, 7, 9, 11}[deg % 7] + sharp);
}
typedef struct {
--- a/tui_main.c
+++ b/tui_main.c
@@ -1046,6 +1046,8 @@
case Oevent_type_midi: {
Oevent_midi const *em = &e->midi;
Usz note_number = (Usz)(12u * em->octave + em->note);
+ if (note_number > 127)
+ note_number = 127;
Usz channel = em->channel;
Usz bar_div = em->bar_divisor;
midi_note_ons[midi_note_count] =