process_midi.c 2.5 KB

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