keymap.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. Copyright 2021 v3ritas <v3ritas@tempoturtle.com>
  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 QMK_KEYBOARD_H
  15. extern MidiDevice midi_device;
  16. enum layers {
  17. _NATURAL,
  18. _SHARP,
  19. _FLAT,
  20. };
  21. /*
  22. MIDI CC codes for generic ON/OFF swiches
  23. 80,81,82,83
  24. values off = 0-63
  25. */
  26. #define OFF 0
  27. /*values on = 64-127*/
  28. #define ON 127
  29. /*implementation inspo taken from here: https://github.com/luantty2/pheromone_keyboard/blob/master/keyboards/pheromone/keymaps/default/keymap.c */
  30. enum custom_keycodes { MIDI_CC80 = SAFE_RANGE, MIDI_CC81, MIDI_CC82, MIDI_CC83 };
  31. static bool toggled_MIDI_CC80 = 0, toggled_MIDI_CC81 = 0, toggled_MIDI_CC82 = 0, toggled_MIDI_CC83 = 0;
  32. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  33. switch (keycode) {
  34. case MIDI_CC80:
  35. if (!IS_LAYER_ON(_NATURAL)) {
  36. toggled_MIDI_CC80 = false;
  37. if (record->event.pressed) {
  38. midi_send_cc(&midi_device, midi_config.channel, 80, ON);
  39. } else {
  40. midi_send_cc(&midi_device, midi_config.channel, 80, OFF);
  41. }
  42. return true;
  43. } else {
  44. if (record->event.pressed) {
  45. if (!toggled_MIDI_CC80) {
  46. midi_send_cc(&midi_device, midi_config.channel, 80, ON);
  47. } else {
  48. midi_send_cc(&midi_device, midi_config.channel, 80, OFF);
  49. }
  50. toggled_MIDI_CC80 = !toggled_MIDI_CC80;
  51. }
  52. return false;
  53. }
  54. case MIDI_CC81:
  55. if (!IS_LAYER_ON(_NATURAL)) {
  56. toggled_MIDI_CC81 = false;
  57. if (record->event.pressed) {
  58. midi_send_cc(&midi_device, midi_config.channel, 81, ON);
  59. } else {
  60. midi_send_cc(&midi_device, midi_config.channel, 81, OFF);
  61. }
  62. return true;
  63. } else {
  64. if (record->event.pressed) {
  65. if (!toggled_MIDI_CC81) {
  66. midi_send_cc(&midi_device, midi_config.channel, 81, ON);
  67. } else {
  68. midi_send_cc(&midi_device, midi_config.channel, 81, OFF);
  69. }
  70. toggled_MIDI_CC81 = !toggled_MIDI_CC81;
  71. }
  72. return false;
  73. }
  74. case MIDI_CC82:
  75. if (!IS_LAYER_ON(_NATURAL)) {
  76. toggled_MIDI_CC82 = false;
  77. if (record->event.pressed) {
  78. midi_send_cc(&midi_device, midi_config.channel, 82, ON);
  79. } else {
  80. midi_send_cc(&midi_device, midi_config.channel, 82, OFF);
  81. }
  82. return true;
  83. } else {
  84. if (record->event.pressed) {
  85. if (!toggled_MIDI_CC82) {
  86. midi_send_cc(&midi_device, midi_config.channel, 82, ON);
  87. } else {
  88. midi_send_cc(&midi_device, midi_config.channel, 82, OFF);
  89. }
  90. toggled_MIDI_CC82 = !toggled_MIDI_CC82;
  91. }
  92. return false;
  93. }
  94. case MIDI_CC83:
  95. if (!IS_LAYER_ON(_NATURAL)) {
  96. toggled_MIDI_CC83 = false;
  97. if (record->event.pressed) {
  98. midi_send_cc(&midi_device, midi_config.channel, 83, ON);
  99. } else {
  100. midi_send_cc(&midi_device, midi_config.channel, 83, OFF);
  101. }
  102. return true;
  103. } else {
  104. if (record->event.pressed) {
  105. if (!toggled_MIDI_CC83) {
  106. midi_send_cc(&midi_device, midi_config.channel, 83, ON);
  107. } else {
  108. midi_send_cc(&midi_device, midi_config.channel, 83, OFF);
  109. }
  110. toggled_MIDI_CC83 = !toggled_MIDI_CC83;
  111. }
  112. return false;
  113. }
  114. }
  115. return true;
  116. }
  117. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  118. [_NATURAL] = LAYOUT(
  119. MI_C, MI_BENDD, MI_BENDU, MI_G,
  120. MI_D, MIDI_CC80, MIDI_CC81, MI_A,
  121. MI_E, MIDI_CC82, MIDI_CC83, MI_B,
  122. MI_F, MI_OCTD, MI_OCTU, MI_C,
  123. MO(_SHARP), MO(_FLAT)),
  124. [_SHARP] = LAYOUT(
  125. MI_Cs, KC_TRNS, KC_TRNS, MI_Gs,
  126. MI_Ds, KC_TRNS, KC_TRNS, MI_As,
  127. MI_F , KC_TRNS, KC_TRNS, MI_C ,
  128. MI_Fs, MI_TRNSD, MI_TRNSU, MI_Cs,
  129. KC_TRNS, KC_TRNS),
  130. [_FLAT] = LAYOUT(
  131. MI_B , KC_TRNS, KC_TRNS, MI_Gb,
  132. MI_Db, KC_TRNS, KC_TRNS, MI_Ab,
  133. MI_Eb, KC_TRNS, KC_TRNS, MI_Bb,
  134. MI_E , MI_TRNSD, MI_TRNSU, MI_B,
  135. KC_TRNS, KC_TRNS),
  136. };