logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

giabalanai.c (12534B)


  1. /* Copyright 2020 3araht
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "giabalanai.h"
  17. // the velocity difference from the velocity of the root note.
  18. #define UNISON_VELOCITY_OFFSET 30
  19. #ifdef RGBLIGHT_ENABLE
  20. # define NO_LED 255
  21. /* Conversion map from keylocation (MATRIX_ROWS x2(split) x MATRIX_COLS) to led IDs.
  22. led IDs are the number starts "0" from upper left corner of left side,
  23. enumerated from left to right, from top to bottom.
  24. Then emumeration follows to the right side, starting from "60".
  25. Note that the conversion from physical LED serial alighment to
  26. the led IDs is done with RGBLIGHT_LED_MAP beforehand. */
  27. # ifdef GIABARINAIX2
  28. const uint8_t PROGMEM convert_key_to_led[] =
  29. {
  30. 0, 12, 24, 36, 48, 11, 23, 35, 47, 59,
  31. 1, 13, 25, 37, 49, 10, 22, 34, 46, 58,
  32. 2, 14, 26, 38, 50, 9, 21, 33, 45, 57,
  33. 3, 15, 27, 39, 51, 8, 20, 32, 44, 56,
  34. 4, 16, 28, 40, 52, 7, 19, 31, 43, 55,
  35. 5, 17, 29, 41, 53, 6, 18, 30, 42, 54,
  36. 119, 107, 95, 83, 71, 108, 96, 84, 72, 60,
  37. 118, 106, 94, 82, 70, 109, 97, 85, 73, 61,
  38. 117, 105, 93, 81, 69, 110, 98, 86, 74, 62,
  39. 116, 104, 92, 80, 68, 111, 99, 87, 75, 63,
  40. 115, 103, 91, 79, 67, 112, 100, 88, 76, 64,
  41. 114, 102, 90, 78, 66, 113, 101, 89, 77, 65
  42. };
  43. # else
  44. const uint8_t PROGMEM convert_key_to_led[] =
  45. {
  46. 0, 12, 24, 36, 48, 11, 23, 35, 47, 59,
  47. 1, 13, 25, 37, 49, 10, 22, 34, 46, 58,
  48. 2, 14, 26, 38, 50, 9, 21, 33, 45, 57,
  49. 3, 15, 27, 39, 51, 8, 20, 32, 44, 56,
  50. 4, 16, 28, 40, 52, 7, 19, 31, 43, 55,
  51. 5, 17, 29, 41, 53, 6, 18, 30, 42, 54,
  52. 85, 86, 87, 88, 89, 90, 91, NO_LED, NO_LED, NO_LED,
  53. 98, 99, 100, 101, 102, 103, 104, NO_LED, NO_LED, NO_LED,
  54. NO_LED, 111, 112, 113, 114, 115, 116, NO_LED, NO_LED, NO_LED,
  55. NO_LED, 97, 96, 95, 94, 93, 92, NO_LED, NO_LED, NO_LED,
  56. NO_LED, 110, 109, 108, 107, 106, 105, NO_LED, NO_LED, NO_LED,
  57. NO_LED, 122, 121, 120, 119, 118, 117, NO_LED, NO_LED, NO_LED
  58. };
  59. /* Top 2 rows on the right side (LED:60-84) are
  60. duplicates of the bottom 2 rows (LED:85-122).
  61. LED:97 = Encoder,
  62. LED:110 don't have a duplicate on the top row,
  63. LED:72 is used when r20 is pressed (not a duplicate) */
  64. const uint8_t PROGMEM convert_key_to_led2[] =
  65. {
  66. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  67. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  68. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  69. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  70. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  71. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  72. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  73. 60, 61, 62, 63, 64, 65, 66, NO_LED, NO_LED, NO_LED,
  74. 72, 73, 74, 75, 76, 77, 78, NO_LED, NO_LED, NO_LED,
  75. NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED,
  76. NO_LED, NO_LED, 71, 70, 69, 68, 67, NO_LED, NO_LED, NO_LED,
  77. NO_LED, 84, 83, 82, 81, 80, 79, NO_LED, NO_LED, NO_LED
  78. };
  79. # endif
  80. #endif // RGBLIGHT_ENABLE
  81. #ifdef RGB_MATRIX_ENABLE
  82. led_config_t g_led_config = {
  83. {
  84. { 74, 75, 98, 99, 122, 63, 86, 87, 110, 111 },
  85. { 73, 76, 97, 100, 121, 64, 85, 88, 109, 112 },
  86. { 72, 77, 96, 101, 120, 65, 84, 89, 108, 113 },
  87. { 71, 78, 95, 102, 119, 66, 83, 90, 107, 114 },
  88. { 70, 79, 94, 103, 118, 67, 82, 91, 106, 115 },
  89. { 69, 80, 93, 104, 117, 68, 81, 92, 105, 116 },
  90. { 26, 27, 28, 29, 30, 31, 32, NO_LED, NO_LED, NO_LED },
  91. { 50, 49, 48, 47, 46, 45, 44, NO_LED, NO_LED, NO_LED },
  92. { 25, 51, 52, 53, 54, 55, 56, NO_LED, NO_LED, NO_LED },
  93. { NO_LED, 12, 37, 36, 35, 34, 33, NO_LED, NO_LED, NO_LED },
  94. { NO_LED, 38, 39, 40, 41, 42, 43, NO_LED, NO_LED, NO_LED },
  95. { NO_LED, 62, 61, 60, 59, 58, 57, NO_LED, NO_LED, NO_LED }
  96. }, {
  97. { 120, 0 }, { 128, 0 }, { 136, 0 }, { 144, 0 }, { 152, 0 }, { 160, 0 }, { 168, 0 }, { 176, 0 }, { 184, 0 }, { 192, 0 }, { 200, 0 }, { 208, 0 },
  98. { 224, 32 },
  99. { 212, 16 }, { 204, 16 }, { 196, 16 }, { 188, 16 }, { 180, 16 }, { 172, 16 }, { 164, 16 }, { 156, 16 }, { 148, 16 }, { 140, 16 }, { 132, 16 }, { 124, 16 }, { 116, 16 },
  100. { 120, 32 }, { 128, 32 }, { 136, 32 }, { 144, 32 }, { 152, 32 }, { 160, 32 }, { 168, 32 }, { 176, 32 }, { 184, 32 }, { 192, 32 }, { 200, 32 }, { 208, 32 },
  101. { 212, 48 }, { 204, 48 }, { 196, 48 }, { 188, 48 }, { 180, 48 }, { 172, 48 }, { 164, 48 }, { 156, 48 }, { 148, 48 }, { 140, 48 }, { 132, 48 }, { 124, 48 }, { 116, 48 },
  102. { 120, 64 }, { 128, 64 }, { 136, 64 }, { 144, 64 }, { 152, 64 }, { 160, 64 }, { 168, 64 }, { 176, 64 }, { 184, 64 }, { 192, 64 }, { 200, 64 }, { 208, 64 },
  103. { 88, 0 }, { 80, 0 }, { 72, 0 }, { 64, 0 }, { 56, 0 }, { 48, 0 }, { 40, 0 }, { 32, 0 }, { 24, 0 }, { 16, 0 }, { 8, 0 }, { 0, 0 },
  104. { 4, 16 }, { 12, 16 }, { 20, 16 }, { 28, 16 }, { 36, 16 }, { 44, 16 }, { 52, 16 }, { 60, 16 }, { 68, 16 }, { 76, 16 }, { 84, 16 }, { 92, 16 },
  105. { 96, 32 }, { 88, 32 }, { 80, 32 }, { 72, 32 }, { 64, 32 }, { 56, 32 }, { 48, 32 }, { 40, 32 }, { 32, 32 }, { 24, 32 }, { 16, 32 }, { 8, 32 },
  106. { 12, 48 }, { 20, 48 }, { 28, 48 }, { 36, 48 }, { 44, 48 }, { 52, 48 }, { 60, 48 }, { 68, 48 }, { 76, 48 }, { 84, 48 }, { 92, 48 }, { 100, 48 },
  107. { 104, 64 }, { 96, 64 }, { 88, 64 }, { 80, 64 }, { 72, 64 }, { 64, 64 }, { 56, 64 }, { 48, 64 }, { 40, 64 }, { 32, 64 }, { 24, 64 }, { 16, 64 }
  108. }, {
  109. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  110. 4,
  111. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  112. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  113. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  114. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  115. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  116. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  117. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  118. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  119. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  120. }
  121. };
  122. // const uint8_t PROGMEM convert_led_location2number[] = {
  123. // 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63,
  124. // 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
  125. // 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87,
  126. // 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
  127. // 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111,
  128. //
  129. // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  130. // 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,
  131. // 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 12,
  132. // 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38,
  133. // 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62
  134. // };
  135. #endif
  136. void my_process_midi4Bass(uint8_t channel, keyrecord_t *record,
  137. uint8_t *chord_status, uint8_t chord, uint16_t root_note, bool is_single_bass) {
  138. uint8_t velocity = midi_config.velocity;
  139. if (record->event.pressed) {
  140. if (chord_status[chord] == MIDI_INVALID_NOTE) {
  141. uint8_t note = midi_compute_note(root_note);
  142. if (is_single_bass) {
  143. midi_send_noteon(&midi_device, channel, note, velocity);
  144. } else {
  145. midi_send_noteon(&midi_device, channel, note, velocity);
  146. midi_send_noteon(&midi_device, channel, note + 12, velocity); // +1 Octave
  147. }
  148. dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
  149. chord_status[chord] = note; // store root_note status.
  150. }
  151. } else {
  152. uint8_t note = chord_status[chord];
  153. if (note != MIDI_INVALID_NOTE) {
  154. if (is_single_bass) {
  155. midi_send_noteoff(&midi_device, channel, note, velocity);
  156. } else {
  157. midi_send_noteoff(&midi_device, channel, note, velocity);
  158. midi_send_noteoff(&midi_device, channel, note + 12, velocity); // +1 Octave
  159. }
  160. dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
  161. }
  162. chord_status[chord] = MIDI_INVALID_NOTE;
  163. }
  164. }
  165. void my_process_midi4TriadChords(uint8_t channel, keyrecord_t *record,
  166. uint8_t *chord_status, uint8_t chord, uint16_t root_note,
  167. int8_t offset1, int8_t offset2, int8_t offset3) {
  168. uint8_t velocity = midi_config.velocity;
  169. if (record->event.pressed) {
  170. if (chord_status[chord] == MIDI_INVALID_NOTE) {
  171. uint8_t note = midi_compute_note(root_note);
  172. midi_send_noteon(&midi_device, channel, note + offset1, velocity);
  173. midi_send_noteon(&midi_device, channel, note + offset2, velocity);
  174. midi_send_noteon(&midi_device, channel, note + offset3, velocity);
  175. dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
  176. chord_status[chord] = note; // store root_note status.
  177. }
  178. } else {
  179. uint8_t note = chord_status[chord];
  180. if (note != MIDI_INVALID_NOTE) {
  181. midi_send_noteoff(&midi_device, channel, note + offset1, velocity);
  182. midi_send_noteoff(&midi_device, channel, note + offset2, velocity);
  183. midi_send_noteoff(&midi_device, channel, note + offset3, velocity);
  184. dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
  185. }
  186. chord_status[chord] = MIDI_INVALID_NOTE;
  187. }
  188. }
  189. void my_process_midi(uint8_t channel, uint16_t keycode, keyrecord_t *record, uint8_t *my_tone_status, int8_t offset, bool melody_unison_suppress) {
  190. uint8_t tone = keycode - MIDI_TONE_MIN;
  191. uint8_t melody_unison_velocity;
  192. if (melody_unison_suppress) {
  193. if (midi_config.velocity > UNISON_VELOCITY_OFFSET){
  194. melody_unison_velocity = midi_config.velocity - UNISON_VELOCITY_OFFSET;
  195. } else {
  196. melody_unison_velocity = 0;
  197. }
  198. } else {
  199. melody_unison_velocity = midi_config.velocity;
  200. }
  201. if (record->event.pressed) {
  202. if (my_tone_status[tone] == MIDI_INVALID_NOTE) {
  203. uint8_t note = midi_compute_note(keycode);
  204. midi_send_noteon(&midi_device, channel, note + offset, melody_unison_velocity);
  205. dprintf("midi noteon channel:%d note:%d tone:%d velocity:%d\n", channel, note, tone, melody_unison_velocity);
  206. my_tone_status[tone] = note; // store root_note status.
  207. }
  208. } else {
  209. uint8_t note = my_tone_status[tone];
  210. if (note != MIDI_INVALID_NOTE) {
  211. midi_send_noteoff(&midi_device, channel, note + offset, melody_unison_velocity);
  212. dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, melody_unison_velocity);
  213. }
  214. my_tone_status[tone] = MIDI_INVALID_NOTE;
  215. }
  216. }
  217. #ifdef RGBLIGHT_ENABLE
  218. void keylight_manager(keyrecord_t *record, uint8_t hue, uint8_t sat, uint8_t val, uint8_t keylocation) {
  219. if (keylocation == NO_LED) {
  220. return; // do nothing.
  221. # ifdef CONSOLE_ENABLE
  222. uprintf("keylight_manager, NO_LED\n");
  223. # endif
  224. }
  225. if (record->event.pressed) {
  226. rgblight_sethsv_at(hue, sat, val, keylocation);
  227. } else {
  228. rgblight_sethsv_at(HSV_BLACK, keylocation);
  229. }
  230. }
  231. #endif // RGBLIGHT_ENABLE