~ruther/qmk_firmware

8b48f0dea36c192a1a98a2ead3b72412e23d08d6 — 3araht 1 year, 4 months ago 8b671b9
MIDI sustain effect fix on qmk 0.22.2 (#22114)

1 files changed, 10 insertions(+), 13 deletions(-)

M quantum/process_keycode/process_midi.c
M quantum/process_keycode/process_midi.c => quantum/process_keycode/process_midi.c +10 -13
@@ 38,7 38,7 @@ void process_midi_all_notes_off(void) {
#endif // MIDI_BASIC

#ifdef MIDI_ADVANCED
static uint8_t tone_status[2][MIDI_TONE_COUNT];
static uint8_t tone_status[MIDI_TONE_COUNT];

static uint8_t  midi_modulation;
static int8_t   midi_modulation_step;


@@ 57,8 57,7 @@ void midi_init(void) {
    midi_config.modulation_interval = 8;

    for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) {
        tone_status[0][i] = MIDI_INVALID_NOTE;
        tone_status[1][i] = 0;
        tone_status[i] = MIDI_INVALID_NOTE;
    }

    midi_modulation       = 0;


@@ 77,21 76,19 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) {
            uint8_t tone     = keycode - MIDI_TONE_MIN;
            uint8_t velocity = midi_config.velocity;
            if (record->event.pressed) {
                uint8_t note = midi_compute_note(keycode);
                midi_send_noteon(&midi_device, channel, note, velocity);
                dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
                tone_status[1][tone] += 1;
                if (tone_status[0][tone] == MIDI_INVALID_NOTE) {
                    tone_status[0][tone] = note;
                if (tone_status[tone] == MIDI_INVALID_NOTE) {
                    uint8_t note = midi_compute_note(keycode);
                    midi_send_noteon(&midi_device, channel, note, velocity);
                    dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
                    tone_status[tone] = note;
                }
            } else {
                uint8_t note = tone_status[0][tone];
                tone_status[1][tone] -= 1;
                if (tone_status[1][tone] == 0) {
                uint8_t note = tone_status[tone];
                if (note != MIDI_INVALID_NOTE) {
                    midi_send_noteoff(&midi_device, channel, note, velocity);
                    dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
                    tone_status[0][tone] = MIDI_INVALID_NOTE;
                }
                tone_status[tone] = MIDI_INVALID_NOTE;
            }
            return false;
        }

Do not follow this link