aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-03-25 11:52:32 +0000
committerQMK Bot <hello@qmk.fm>2021-03-25 11:52:32 +0000
commit6ad0b004fa19e3be0e3d1830407f9dfd02be8a67 (patch)
tree6c6ab5096508b5e0f414feaef3815b1c7a1c5340 /quantum/process_keycode
parentc3483458fe57624603d6af28110599b65aae9656 (diff)
parent8e820cde131c72d7966fb5dd528ba0ed2c1cd577 (diff)
downloadqmk_firmware-6ad0b004fa19e3be0e3d1830407f9dfd02be8a67.tar.gz
qmk_firmware-6ad0b004fa19e3be0e3d1830407f9dfd02be8a67.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_midi.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index 8e2fb955e..9632d2b75 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -34,7 +34,7 @@ void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0);
34 34
35# include "timer.h" 35# include "timer.h"
36 36
37static uint8_t tone_status[MIDI_TONE_COUNT]; 37static uint8_t tone_status[2][MIDI_TONE_COUNT];
38 38
39static uint8_t midi_modulation; 39static uint8_t midi_modulation;
40static int8_t midi_modulation_step; 40static int8_t midi_modulation_step;
@@ -51,7 +51,8 @@ void midi_init(void) {
51 midi_config.modulation_interval = 8; 51 midi_config.modulation_interval = 8;
52 52
53 for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { 53 for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) {
54 tone_status[i] = MIDI_INVALID_NOTE; 54 tone_status[0][i] = MIDI_INVALID_NOTE;
55 tone_status[1][i] = 0;
55 } 56 }
56 57
57 midi_modulation = 0; 58 midi_modulation = 0;
@@ -68,19 +69,21 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) {
68 uint8_t tone = keycode - MIDI_TONE_MIN; 69 uint8_t tone = keycode - MIDI_TONE_MIN;
69 uint8_t velocity = midi_config.velocity; 70 uint8_t velocity = midi_config.velocity;
70 if (record->event.pressed) { 71 if (record->event.pressed) {
71 if (tone_status[tone] == MIDI_INVALID_NOTE) { 72 uint8_t note = midi_compute_note(keycode);
72 uint8_t note = midi_compute_note(keycode); 73 midi_send_noteon(&midi_device, channel, note, velocity);
73 midi_send_noteon(&midi_device, channel, note, velocity); 74 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
74 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); 75 tone_status[1][tone] += 1;
75 tone_status[tone] = note; 76 if (tone_status[0][tone] == MIDI_INVALID_NOTE) {
77 tone_status[0][tone] = note;
76 } 78 }
77 } else { 79 } else {
78 uint8_t note = tone_status[tone]; 80 uint8_t note = tone_status[0][tone];
79 if (note != MIDI_INVALID_NOTE) { 81 tone_status[1][tone] -= 1;
82 if (tone_status[1][tone] == 0) {
80 midi_send_noteoff(&midi_device, channel, note, velocity); 83 midi_send_noteoff(&midi_device, channel, note, velocity);
81 dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); 84 dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
85 tone_status[0][tone] = MIDI_INVALID_NOTE;
82 } 86 }
83 tone_status[tone] = MIDI_INVALID_NOTE;
84 } 87 }
85 return false; 88 return false;
86 } 89 }