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