process_midi.c 2.7 KB

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