aboutsummaryrefslogtreecommitdiffstats
path: root/quantum/process_keycode/process_midi.c
diff options
context:
space:
mode:
authorGravatar Chris Browne <cbbrowne@hpaq.int.linuxdatabases.info>2016-10-10 17:18:15 -0400
committerGravatar Chris Browne <cbbrowne@hpaq.int.linuxdatabases.info>2016-10-10 17:18:15 -0400
commit4b682ea63e2b3dd0bc1132917be7985ce0da57a6 (patch)
tree6d79874c5542148c27907511ecdb2e9e5e12b24b /quantum/process_keycode/process_midi.c
parent04759d63ef9b520fc41d76de64bb65198448fc1c (diff)
parenta9df99b81c787862dc3fa11bd854fe39e704da81 (diff)
downloadqmk_firmware-4b682ea63e2b3dd0bc1132917be7985ce0da57a6.tar.gz
Merge branch 'master' of github.com:cbbrowne/qmk_firmware
Diffstat (limited to 'quantum/process_keycode/process_midi.c')
-rw-r--r--quantum/process_keycode/process_midi.c68
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 @@
+#include "process_midi.h"
+
+bool midi_activated = false;
+uint8_t midi_starting_note = 0x0C;
+int midi_offset = 7;
+
+bool process_midi(uint16_t keycode, keyrecord_t *record) {
+ if (keycode == MI_ON && record->event.pressed) {
+ midi_activated = true;
+#ifdef AUDIO_ENABLE
+ music_scale_user();
+#endif
+ return false;
+ }
+
+ if (keycode == MI_OFF && record->event.pressed) {
+ midi_activated = false;
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ return false;
+ }
+
+ if (midi_activated) {
+ if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
+ if (record->event.pressed) {
+ midi_starting_note++; // Change key
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ }
+ return false;
+ }
+ if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
+ if (record->event.pressed) {
+ midi_starting_note--; // Change key
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ }
+ return false;
+ }
+ if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
+ midi_offset++; // Change scale
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ return false;
+ }
+ if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
+ midi_offset--; // Change scale
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ return false;
+ }
+ // basic
+ // uint8_t note = (midi_starting_note + SCALE[record->event.key.col + midi_offset])+12*(MATRIX_ROWS - record->event.key.row);
+ // advanced
+ // uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+12*(MATRIX_ROWS - record->event.key.row);
+ // guitar
+ uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+5*(MATRIX_ROWS - record->event.key.row);
+ // violin
+ // uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+7*(MATRIX_ROWS - record->event.key.row);
+
+ if (record->event.pressed) {
+ // midi_send_noteon(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127);
+ midi_send_noteon(&midi_device, 0, note, 127);
+ } else {
+ // midi_send_noteoff(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127);
+ midi_send_noteoff(&midi_device, 0, note, 127);
+ }
+
+ if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
+ return false;
+ }
+ return true;
+}