diff options
| author | 3araht <69518343+3araht@users.noreply.github.com> | 2024-01-09 20:05:30 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-09 22:05:30 +1100 |
| commit | 8b48f0dea36c192a1a98a2ead3b72412e23d08d6 (patch) | |
| tree | a5c42674cd78add9b5ea37bc4a6239208220c1a9 /quantum/process_keycode | |
| parent | 8b671b99693698f87a4a27c9964f41addb38f2c7 (diff) | |
MIDI sustain effect fix on qmk 0.22.2 (#22114)
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_midi.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 377fcb69e2..5ecd897d16 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c | |||
| @@ -38,7 +38,7 @@ void process_midi_all_notes_off(void) { | |||
| 38 | #endif // MIDI_BASIC | 38 | #endif // MIDI_BASIC |
| 39 | 39 | ||
| 40 | #ifdef MIDI_ADVANCED | 40 | #ifdef MIDI_ADVANCED |
| 41 | static uint8_t tone_status[2][MIDI_TONE_COUNT]; | 41 | static uint8_t tone_status[MIDI_TONE_COUNT]; |
| 42 | 42 | ||
| 43 | static uint8_t midi_modulation; | 43 | static uint8_t midi_modulation; |
| 44 | static int8_t midi_modulation_step; | 44 | static int8_t midi_modulation_step; |
| @@ -57,8 +57,7 @@ void midi_init(void) { | |||
| 57 | midi_config.modulation_interval = 8; | 57 | midi_config.modulation_interval = 8; |
| 58 | 58 | ||
| 59 | for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { | 59 | for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { |
| 60 | tone_status[0][i] = MIDI_INVALID_NOTE; | 60 | tone_status[i] = MIDI_INVALID_NOTE; |
| 61 | tone_status[1][i] = 0; | ||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | midi_modulation = 0; | 63 | midi_modulation = 0; |
| @@ -77,21 +76,19 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { | |||
| 77 | uint8_t tone = keycode - MIDI_TONE_MIN; | 76 | uint8_t tone = keycode - MIDI_TONE_MIN; |
| 78 | uint8_t velocity = midi_config.velocity; | 77 | uint8_t velocity = midi_config.velocity; |
| 79 | if (record->event.pressed) { | 78 | if (record->event.pressed) { |
| 80 | uint8_t note = midi_compute_note(keycode); | 79 | if (tone_status[tone] == MIDI_INVALID_NOTE) { |
| 81 | midi_send_noteon(&midi_device, channel, note, velocity); | 80 | uint8_t note = midi_compute_note(keycode); |
| 82 | dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); | 81 | midi_send_noteon(&midi_device, channel, note, velocity); |
| 83 | tone_status[1][tone] += 1; | 82 | dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); |
| 84 | if (tone_status[0][tone] == MIDI_INVALID_NOTE) { | 83 | tone_status[tone] = note; |
| 85 | tone_status[0][tone] = note; | ||
| 86 | } | 84 | } |
| 87 | } else { | 85 | } else { |
| 88 | uint8_t note = tone_status[0][tone]; | 86 | uint8_t note = tone_status[tone]; |
| 89 | tone_status[1][tone] -= 1; | 87 | if (note != MIDI_INVALID_NOTE) { |
| 90 | if (tone_status[1][tone] == 0) { | ||
| 91 | midi_send_noteoff(&midi_device, channel, note, velocity); | 88 | midi_send_noteoff(&midi_device, channel, note, velocity); |
| 92 | dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); | 89 | dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); |
| 93 | tone_status[0][tone] = MIDI_INVALID_NOTE; | ||
| 94 | } | 90 | } |
| 91 | tone_status[tone] = MIDI_INVALID_NOTE; | ||
| 95 | } | 92 | } |
| 96 | return false; | 93 | return false; |
| 97 | } | 94 | } |
