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.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
new file mode 100644
index 000000000..d6ab9c626
--- /dev/null
+++ b/quantum/process_keycode/process_midi.c
@@ -0,0 +1,66 @@
1#include "process_midi.h"
2
3bool midi_activated = false;
4uint8_t starting_note = 0x0C;
5int offset = 7;
6
7bool process_midi(uint16_t keycode, keyrecord_t *record) {
8 if (keycode == MI_ON && record->event.pressed) {
9 midi_activated = true;
10 music_scale_user();
11 return false;
12 }
13
14 if (keycode == MI_OFF && record->event.pressed) {
15 midi_activated = false;
16 midi_send_cc(&midi_device, 0, 0x7B, 0);
17 return false;
18 }
19
20 if (midi_activated) {
21 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
22 if (record->event.pressed) {
23 starting_note++; // Change key
24 midi_send_cc(&midi_device, 0, 0x7B, 0);
25 }
26 return false;
27 }
28 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
29 if (record->event.pressed) {
30 starting_note--; // Change key
31 midi_send_cc(&midi_device, 0, 0x7B, 0);
32 }
33 return false;
34 }
35 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
36 offset++; // Change scale
37 midi_send_cc(&midi_device, 0, 0x7B, 0);
38 return false;
39 }
40 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
41 offset--; // Change scale
42 midi_send_cc(&midi_device, 0, 0x7B, 0);
43 return false;
44 }
45 // basic
46 // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
47 // advanced
48 // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
49 // guitar
50 uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
51 // violin
52 // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
53
54 if (record->event.pressed) {
55 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
56 midi_send_noteon(&midi_device, 0, note, 127);
57 } else {
58 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
59 midi_send_noteoff(&midi_device, 0, note, 127);
60 }
61
62 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
63 return false;
64 }
65 return true;
66} \ No newline at end of file