upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keymap_midi.c 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright 2015 Jack Humbert <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "keymap_common.h"
  15. #include "keymap_midi.h"
  16. uint8_t starting_note = 0x0C;
  17. int offset = 7;
  18. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  19. {
  20. if (id != 0) {
  21. if (record->event.pressed) {
  22. midi_send_noteon(&midi_device, opt, (id & 0xFF), 127);
  23. } else {
  24. midi_send_noteoff(&midi_device, opt, (id & 0xFF), 127);
  25. }
  26. }
  27. if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
  28. if (record->event.pressed) {
  29. starting_note++;
  30. play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
  31. midi_send_cc(&midi_device, 0, 0x7B, 0);
  32. midi_send_cc(&midi_device, 1, 0x7B, 0);
  33. midi_send_cc(&midi_device, 2, 0x7B, 0);
  34. midi_send_cc(&midi_device, 3, 0x7B, 0);
  35. midi_send_cc(&midi_device, 4, 0x7B, 0);
  36. return;
  37. } else {
  38. stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)));
  39. stop_all_notes();
  40. return;
  41. }
  42. }
  43. if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
  44. if (record->event.pressed) {
  45. starting_note--;
  46. play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
  47. midi_send_cc(&midi_device, 0, 0x7B, 0);
  48. midi_send_cc(&midi_device, 1, 0x7B, 0);
  49. midi_send_cc(&midi_device, 2, 0x7B, 0);
  50. midi_send_cc(&midi_device, 3, 0x7B, 0);
  51. midi_send_cc(&midi_device, 4, 0x7B, 0);
  52. return;
  53. } else {
  54. stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)));
  55. stop_all_notes();
  56. return;
  57. }
  58. }
  59. if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
  60. offset++;
  61. midi_send_cc(&midi_device, 0, 0x7B, 0);
  62. midi_send_cc(&midi_device, 1, 0x7B, 0);
  63. midi_send_cc(&midi_device, 2, 0x7B, 0);
  64. midi_send_cc(&midi_device, 3, 0x7B, 0);
  65. midi_send_cc(&midi_device, 4, 0x7B, 0);
  66. stop_all_notes();
  67. for (int i = 0; i <= 7; i++) {
  68. play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
  69. _delay_us(80000);
  70. stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)));
  71. _delay_us(8000);
  72. }
  73. return;
  74. }
  75. if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
  76. offset--;
  77. midi_send_cc(&midi_device, 0, 0x7B, 0);
  78. midi_send_cc(&midi_device, 1, 0x7B, 0);
  79. midi_send_cc(&midi_device, 2, 0x7B, 0);
  80. midi_send_cc(&midi_device, 3, 0x7B, 0);
  81. midi_send_cc(&midi_device, 4, 0x7B, 0);
  82. stop_all_notes();
  83. for (int i = 0; i <= 7; i++) {
  84. play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
  85. _delay_us(80000);
  86. stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)));
  87. _delay_us(8000);
  88. }
  89. return;
  90. }
  91. if (record->event.pressed) {
  92. // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
  93. // midi_send_noteon(&midi_device, 0, (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row), 127);
  94. play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
  95. } else {
  96. // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
  97. // midi_send_noteoff(&midi_device, 0, (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row), 127);
  98. stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
  99. }
  100. }