aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_midi.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_midi.c')
-rw-r--r--quantum/process_keycode/process_midi.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index 4d60aefb1..9190fa047 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -1,22 +1,6 @@
1#include "process_midi.h" 1#include "process_midi.h"
2#include "timer.h" 2#include "timer.h"
3 3
4typedef union {
5 uint32_t raw;
6 struct {
7 uint8_t octave :4;
8 int8_t transpose :4;
9 uint8_t velocity :4;
10 uint8_t channel :4;
11 uint8_t modulation_interval :4;
12 };
13} midi_config_t;
14
15midi_config_t midi_config;
16
17#define MIDI_INVALID_NOTE 0xFF
18
19#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
20static uint8_t tone_status[MIDI_TONE_COUNT]; 4static uint8_t tone_status[MIDI_TONE_COUNT];
21 5
22static uint8_t midi_modulation; 6static uint8_t midi_modulation;
@@ -70,6 +54,11 @@ void midi_task(void)
70 } 54 }
71} 55}
72 56
57uint8_t midi_compute_note(uint16_t keycode)
58{
59 return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose;
60}
61
73bool process_midi(uint16_t keycode, keyrecord_t *record) 62bool process_midi(uint16_t keycode, keyrecord_t *record)
74{ 63{
75 switch (keycode) { 64 switch (keycode) {
@@ -79,7 +68,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
79 uint8_t tone = keycode - MIDI_TONE_MIN; 68 uint8_t tone = keycode - MIDI_TONE_MIN;
80 uint8_t velocity = compute_velocity(midi_config.velocity); 69 uint8_t velocity = compute_velocity(midi_config.velocity);
81 if (record->event.pressed) { 70 if (record->event.pressed) {
82 uint8_t note = 12 * midi_config.octave + tone + midi_config.transpose; 71 uint8_t note = midi_compute_note(keycode);
83 midi_send_noteon(&midi_device, channel, note, velocity); 72 midi_send_noteon(&midi_device, channel, note, velocity);
84 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); 73 dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
85 tone_status[tone] = note; 74 tone_status[tone] = note;