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.

696 lines
27 KiB

  1. /* Copyright 2021 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 QMK_KEYBOARD_H
  17. #include "version.h"
  18. // define which MIDI ch to use.
  19. // Note that (actual MIDI ch# - 1) -> 0 .. 15 is used for coding.
  20. // ch1
  21. #define DEFAULT_MAIN_CH_NUMBER 0
  22. // ch3
  23. #define DEFAULT_SUB_CH_NUMBER 2
  24. // ch2
  25. #define ALT_MAIN_CH_NUMBER 1
  26. // ch4
  27. #define ALT_SUB_CH_NUMBER 3
  28. static uint8_t midi_left_ch = DEFAULT_SUB_CH_NUMBER; // By default, DEFAULT_SUB_CH_NUMBER is used for left side when separated.
  29. // By default( when use_alt_ch_gr == false), DEFAULT ch group (DEFAULT_MAIN_CH_NUMBER for entirely, or right side when separated, DEFAULT_SUB_CH_NUMBER for left side) is used.
  30. // When false, ALT ch group (ALT_MAIN_CH_NUMBER for entirely, or right side when separated, ALT_SUB_CH_NUMBER for left side) is used.
  31. static bool use_alt_ch_gr = false;
  32. // Defines names for use in layer keycodes and the keymap
  33. enum layer_names {
  34. _BASE, // Base layer, shift mode, single channel.
  35. _SEPALEFTOCT, // 1st oct channel separated version. Shift mode.
  36. _SEPAHALF, // Half channel separated version. Shift mode.
  37. _SEPARIGHTOCT, // 2nd oct channel separated version. Shift mode.
  38. _TRANS, // Transpose feature is enabled instead of shift mode, single channel.
  39. _FLIPBASE, // Horizontal flipped version entirely. single channel.
  40. _FLIPTRANS, // Horizontal flipped version entirely. Transpose is used. single channel.
  41. _FN // FuNction layer. This must be at the end of the enumurate to use the range from _LS_FN ... _LS_FN_MAX for FN layer LED settings.
  42. };
  43. // Layer State
  44. #define _LS_BASE (1UL << _BASE)
  45. #define _LS_SEPALEFTOCT (1UL << _SEPALEFTOCT)
  46. #define _LS_SEPAHALF (1UL << _SEPAHALF)
  47. #define _LS_SEPARIGHTOCT (1UL << _SEPARIGHTOCT)
  48. #define _LS_FLIPBASE (1UL << _FLIPBASE)
  49. #define _LS_TRANS (1UL << _BASE | 1UL << _TRANS)
  50. #define _LS_SEPALEFTOCT_T (1UL << _SEPALEFTOCT | 1UL << _TRANS)
  51. #define _LS_SEPAHALF_T (1UL << _SEPAHALF | 1UL << _TRANS)
  52. #define _LS_SEPARIGHTOCT_T (1UL << _SEPARIGHTOCT | 1UL << _TRANS)
  53. #define _LS_FLIPTRANS (1UL << _FLIPBASE | 1UL << _FLIPTRANS)
  54. #define _LS_FN (1UL << _FN)
  55. #define _LS_MAX (_LS_FN << 1)
  56. // Don't change the DEFAULT_SCALE_COL value below. It must be 0.
  57. #define DEFAULT_SCALE_COL 0
  58. static uint8_t scale_indicator_col = DEFAULT_SCALE_COL;
  59. static bool trans_mode_indicator_loc_sel = true; // when it is true, the location is _KEY01, _KEY13, ...
  60. // use led indicator or not.
  61. static bool led_indicator_enable = true;
  62. // Defines the keycodes used by our macros in process_record_user
  63. enum custom_keycodes {
  64. SHIFT_L = SAFE_RANGE,
  65. SHIFT_R,
  66. TGLINDI, // ToGgLe INDIcator
  67. TGLINTR, // ToGgLe INdicator location {(_KEY01, _KEY13, _KEY25, _KEY37) or (_KEY02, _KEY14, _KEY26) / (_KEY12, _KEY24, _KEY36)}in TRans mode
  68. TGLTRNS, // ToGgLe TRaNS and shift
  69. TGLCHGR, // ToGgLe CH GRoup
  70. VERSION,
  71. B_BASE, // border set to the left end.
  72. B_LEFT, // border set to the 1st left octave.
  73. B_CENTER, // border set to the center.
  74. B_RIGHT, // border set to the 1st right octave.
  75. B_FLIP, // border set to the right end.
  76. // MY tone for _FLIPHALF and _FLIPLEFTOCT layers to distinguish the notes to avoid sustain effect, etc.
  77. // Since they are flipped, their subscripts are not MY_ but YM_, to make them easier to tell.
  78. YM_TONE_MIN,
  79. YM_C = YM_TONE_MIN,
  80. YM_Cs,
  81. YM_Db = YM_Cs,
  82. YM_D,
  83. YM_Ds,
  84. YM_Eb = YM_Ds,
  85. YM_E,
  86. YM_F,
  87. YM_Fs,
  88. YM_Gb = YM_Fs,
  89. YM_G,
  90. YM_Gs,
  91. YM_Ab = YM_Gs,
  92. YM_A,
  93. YM_As,
  94. YM_Bb = YM_As,
  95. YM_B,
  96. YM_C_1,
  97. YM_Cs_1,
  98. YM_Db_1 = YM_Cs_1,
  99. YM_D_1,
  100. YM_Ds_1,
  101. YM_Eb_1 = YM_Ds_1,
  102. YM_E_1,
  103. YM_F_1,
  104. YM_Fs_1,
  105. YM_Gb_1 = YM_Fs_1,
  106. YM_G_1,
  107. YM_Gs_1,
  108. YM_Ab_1 = YM_Gs_1,
  109. YM_A_1,
  110. YM_As_1,
  111. YM_Bb_1 = YM_As_1,
  112. YM_B_1,
  113. YM_C_2,
  114. YM_Cs_2,
  115. YM_Db_2 = YM_Cs_2,
  116. YM_D_2,
  117. YM_Ds_2,
  118. YM_Eb_2 = YM_Ds_2,
  119. YM_E_2,
  120. YM_F_2,
  121. YM_Fs_2,
  122. YM_Gb_2 = YM_Fs_2,
  123. YM_G_2,
  124. YM_Gs_2,
  125. YM_Ab_2 = YM_Gs_2,
  126. YM_A_2,
  127. YM_As_2,
  128. YM_Bb_2 = YM_As_2,
  129. YM_B_2,
  130. YM_C_3,
  131. YM_Cs_3,
  132. YM_Db_3 = YM_Cs_3,
  133. YM_D_3,
  134. YM_Ds_3,
  135. YM_Eb_3 = YM_Ds_3,
  136. YM_E_3,
  137. YM_F_3,
  138. YM_Fs_3,
  139. YM_Gb_3 = YM_Fs_3,
  140. YM_G_3,
  141. YM_Gs_3,
  142. YM_Ab_3 = YM_Gs_3,
  143. YM_A_3,
  144. YM_As_3,
  145. YM_Bb_3 = YM_As_3,
  146. YM_B_3,
  147. YM_C_4,
  148. YM_Cs_4,
  149. YM_Db_4 = YM_Cs_4,
  150. YM_D_4,
  151. YM_Ds_4,
  152. YM_Eb_4 = YM_Ds_4,
  153. YM_E_4,
  154. YM_F_4,
  155. YM_Fs_4,
  156. YM_Gb_4 = YM_Fs_4,
  157. YM_G_4,
  158. YM_Gs_4,
  159. YM_Ab_4 = YM_Gs_4,
  160. YM_A_4,
  161. YM_As_4,
  162. YM_Bb_4 = YM_As_4,
  163. YM_B_4,
  164. YM_C_5,
  165. YM_Cs_5,
  166. YM_Db_5 = YM_Cs_5,
  167. YM_D_5,
  168. YM_Ds_5,
  169. YM_Eb_5 = YM_Ds_5,
  170. YM_E_5,
  171. YM_F_5,
  172. YM_Fs_5,
  173. YM_Gb_5 = YM_Fs_5,
  174. YM_G_5,
  175. YM_Gs_5,
  176. YM_Ab_5 = YM_Gs_5,
  177. YM_A_5,
  178. YM_As_5,
  179. YM_Bb_5 = YM_As_5,
  180. YM_B_5,
  181. YM_C_6,
  182. YM_TONE_MAX = YM_C_6
  183. };
  184. #define MY_TONE_COUNT (YM_TONE_MAX - YM_TONE_MIN + 1)
  185. static uint8_t my_tone_status[MY_TONE_COUNT];
  186. // Long press: go to _FN layer, tap: MUTE
  187. #define FN_MUTE LT(_FN, KC_MUTE)
  188. // Used to set octave to MI_OCT_0
  189. extern midi_config_t midi_config;
  190. static bool is_trans_mode = false; // By default, shift mode is chosen.
  191. static uint8_t key_separator_col = _KEY01; // (_KEY01 .. _KEY37). By default, _KEY01 (= _BASE layer) is chosen. _KEY13 = *LEFT, _KEY19 = *HALF, _KEY25 = *RIGHT, _KEY37 = _FLIPBASE and _FLIPTRANS.
  192. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  193. /* Base */
  194. [_BASE] = LAYOUT(
  195. FN_MUTE, MI_SUS,
  196. MI_BENDU,
  197. SHIFT_L, SHIFT_R, MI_C_2, MI_D_2, MI_E_2, MI_Fs_2, MI_Ab_2, MI_Bb_2, MI_C_3, MI_D_3, MI_E_3, MI_Fs_3, MI_Ab_3, MI_Bb_3, MI_C_4, MI_D_4, MI_E_4, MI_Fs_4, MI_Ab_4, MI_Bb_4, MI_C_5,
  198. MI_BENDD, MI_Db_2, MI_Eb_2, MI_F_2, MI_G_2, MI_A_2, MI_B_2, MI_Db_3, MI_Eb_3, MI_F_3, MI_G_3, MI_A_3, MI_B_3, MI_Db_4, MI_Eb_4, MI_F_4, MI_G_4, MI_A_4, MI_B_4
  199. ),
  200. /* 1 octave on the left side is ch2, others are ch1 (normal) */
  201. [_SEPALEFTOCT] = LAYOUT(
  202. _______, _______,
  203. _______,
  204. SHIFT_L, SHIFT_R, YM_C_2, YM_D_2, YM_E_2, YM_Fs_2, YM_Ab_2, YM_Bb_2, MI_C_3, MI_D_3, MI_E_3, MI_Fs_3, MI_Ab_3, MI_Bb_3, MI_C_4, MI_D_4, MI_E_4, MI_Fs_4, MI_Ab_4, MI_Bb_4, MI_C_5,
  205. _______, YM_Db_2, YM_Eb_2, YM_F_2, YM_G_2, YM_A_2, YM_B_2, MI_Db_3, MI_Eb_3, MI_F_3, MI_G_3, MI_A_3, MI_B_3, MI_Db_4, MI_Eb_4, MI_F_4, MI_G_4, MI_A_4, MI_B_4
  206. ),
  207. /* Half ch2, half ch1 (normal) */
  208. [_SEPAHALF] = LAYOUT(
  209. _______, _______,
  210. _______,
  211. SHIFT_L, SHIFT_R, YM_C_2, YM_D_2, YM_E_2, YM_Fs_2, YM_Ab_2, YM_Bb_2, YM_C_3, YM_D_3, YM_E_3, MI_Fs_3, MI_Ab_3, MI_Bb_3, MI_C_4, MI_D_4, MI_E_4, MI_Fs_4, MI_Ab_4, MI_Bb_4, MI_C_5,
  212. _______, YM_Db_2, YM_Eb_2, YM_F_2, YM_G_2, YM_A_2, YM_B_2, YM_Db_3, YM_Eb_3, YM_F_3, MI_G_3, MI_A_3, MI_B_3, MI_Db_4, MI_Eb_4, MI_F_4, MI_G_4, MI_A_4, MI_B_4
  213. ),
  214. /* 2 octave on the left side is ch2, others are ch1 (normal) */
  215. [_SEPARIGHTOCT] = LAYOUT(
  216. _______, _______,
  217. _______,
  218. SHIFT_L, SHIFT_R, YM_C_2, YM_D_2, YM_E_2, YM_Fs_2, YM_Ab_2, YM_Bb_2, YM_C_3, YM_D_3, YM_E_3, YM_Fs_3, YM_Ab_3, YM_Bb_3, MI_C_4, MI_D_4, MI_E_4, MI_Fs_4, MI_Ab_4, MI_Bb_4, MI_C_5,
  219. _______, YM_Db_2, YM_Eb_2, YM_F_2, YM_G_2, YM_A_2, YM_B_2, YM_Db_3, YM_Eb_3, YM_F_3, YM_G_3, YM_A_3, YM_B_3, MI_Db_4, MI_Eb_4, MI_F_4, MI_G_4, MI_A_4, MI_B_4
  220. ),
  221. /* TRANS This layer must locate 1 layer below _FN layer. */
  222. [_TRANS] = LAYOUT(
  223. _______, _______,
  224. _______,
  225. MI_TRNSD, MI_TRNSU, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  226. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  227. ),
  228. /* Flip Base SFIFTUP and SHIFT_L are swapped. */
  229. [_FLIPBASE] = LAYOUT(
  230. FN_MUTE, MI_SUS,
  231. MI_BENDU,
  232. SHIFT_L, SHIFT_R, MI_C_5, MI_Bb_4, MI_Ab_4, MI_Fs_4, MI_E_4, MI_D_4, MI_C_4, MI_Bb_3, MI_Ab_3, MI_Fs_3, MI_E_3, MI_D_3, MI_C_3, MI_Bb_2, MI_Ab_2, MI_Fs_2, MI_E_2, MI_D_2, MI_C_2,
  233. MI_BENDD, MI_B_4, MI_A_4, MI_G_4, MI_F_4, MI_Eb_4, MI_Db_4, MI_B_3, MI_A_3, MI_G_3, MI_F_3, MI_Eb_3, MI_Db_3, MI_B_2, MI_A_2, MI_G_2, MI_F_2, MI_Eb_2, MI_Db_2
  234. ),
  235. /* Flip Trans This layer must locate 1 layer above _FLIPBASE layer. MI_TRNSU and MI_TRNSD are swapped. */
  236. [_FLIPTRANS] = LAYOUT(
  237. _______, _______,
  238. _______,
  239. MI_TRNSU, MI_TRNSD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  240. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  241. ),
  242. [_FN] = LAYOUT(
  243. _______, XXXXXXX,
  244. MI_VELU,
  245. MI_OCTD, MI_OCTU, B_BASE, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, B_LEFT, XXXXXXX, XXXXXXX, B_CENTER, XXXXXXX, XXXXXXX, B_RIGHT, XXXXXXX, XXXXXXX, XXXXXXX, VERSION, XXXXXXX, B_FLIP,
  246. MI_VELD, TGLINTR, TGLTRNS, TGLCHGR, XXXXXXX, XXXXXXX, RGB_SAD, RGB_SAI, RGB_HUD, RGB_HUI, RGB_SPD, RGB_SPI, RGB_VAD, RGB_VAI, RGB_RMOD, RGB_MOD, EEP_RST, TGLINDI, RGB_TOG
  247. )
  248. };
  249. #if defined(ENCODER_MAP_ENABLE)
  250. const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
  251. [_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
  252. [_SEPALEFTOCT] = { ENCODER_CCW_CW(_______, _______) },
  253. [_SEPAHALF] = { ENCODER_CCW_CW(_______, _______) },
  254. [_SEPARIGHTOCT] = { ENCODER_CCW_CW(_______, _______) },
  255. [_TRANS] = { ENCODER_CCW_CW(_______, _______) },
  256. [_FLIPBASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
  257. [_FLIPTRANS] = { ENCODER_CCW_CW(_______, _______) },
  258. [_FN] = { ENCODER_CCW_CW(RGB_RMOD, RGB_MOD) },
  259. };
  260. #endif
  261. // commom codes called from eeconfig_init_user() and keyboard_post_init_user().
  262. void my_init(void){
  263. // Set octave to MI_OCT_1
  264. midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN;
  265. // avoid using 127 since it is used as a special number in some sound sources.
  266. midi_config.velocity = MIDI_INITIAL_VELOCITY;
  267. default_layer_set(_LS_BASE);
  268. layer_state_set(_LS_BASE);
  269. #ifdef RGB_MATRIX_ENABLE
  270. rgb_matrix_sethsv(HSV_BLUE);
  271. rgb_matrix_mode(RGB_MATRIX_CUSTOM_my_solid_reactive_col);
  272. #endif // RGB_MATRIX_ENABLE
  273. }
  274. void eeconfig_init_user(void) { // EEPROM is getting reset!
  275. midi_init();
  276. #ifdef RGB_MATRIX_ENABLE
  277. rgb_matrix_enable();
  278. rgb_matrix_set_speed(RGB_MATRIX_STARTUP_SPD);
  279. #endif // RGB_MATRIX_ENABLE
  280. my_init(); // commom codes called from eeconfig_init_user() and keyboard_post_init_user().
  281. }
  282. void keyboard_post_init_user(void) {
  283. for (uint8_t i = 0; i < MY_TONE_COUNT; i++) {
  284. my_tone_status[i] = MIDI_INVALID_NOTE;
  285. }
  286. my_init(); // commom codes called from eeconfig_init_user() and keyboard_post_init_user().
  287. }
  288. void reset_scale_indicator(void) {
  289. // reset transpose value and scale_indicator_col to default.
  290. midi_config.transpose = 0;
  291. scale_indicator_col = DEFAULT_SCALE_COL;
  292. trans_mode_indicator_loc_sel = true;
  293. }
  294. void reset_all(void) {
  295. reset_scale_indicator();
  296. is_trans_mode = false; // trans mode is disabled by default.
  297. }
  298. void my_process_midi4single_note(uint8_t channel, uint16_t keycode, keyrecord_t *record, uint8_t *my_tone_status) {
  299. uint8_t mytone = keycode - YM_TONE_MIN;
  300. uint16_t mykeycode = mytone + MIDI_TONE_MIN;
  301. // uint16_t mykeycode = keycode - YM_TONE_MIN;
  302. // uint8_t mytone = mykeycode - MIDI_TONE_MIN;
  303. uint8_t velocity = midi_config.velocity;
  304. // uprintf("keycode=%u,mykeycode=%u,mytone =%u,velo = %u\n", keycode, mykeycode, mytone, velocity);
  305. if (record->event.pressed) {
  306. if (my_tone_status[mytone] == MIDI_INVALID_NOTE) {
  307. uint8_t note = midi_compute_note(mykeycode);
  308. midi_send_noteon(&midi_device, channel, note, velocity);
  309. dprintf("midi noteon channel:%d note:%d mytone:%d velocity:%d\n", channel, note, mytone, velocity);
  310. // uprintf("midi noteon channel:%d note:%d mytone:%d velocity:%d\n", channel, note, mytone, velocity);
  311. my_tone_status[mytone] = note; // store root_note status.
  312. }
  313. } else {
  314. uint8_t note = my_tone_status[mytone];
  315. if (note != MIDI_INVALID_NOTE) {
  316. midi_send_noteoff(&midi_device, channel, note, velocity);
  317. dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
  318. // uprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
  319. }
  320. my_tone_status[mytone] = MIDI_INVALID_NOTE;
  321. }
  322. }
  323. void select_layer_state_set(void) {
  324. switch (key_separator_col) {
  325. case _KEY01:
  326. if (is_trans_mode) {
  327. layer_state_set(_LS_TRANS);
  328. } else {
  329. layer_state_set(_LS_BASE);
  330. }
  331. break;
  332. case _KEY13:
  333. if (is_trans_mode) {
  334. layer_state_set(_LS_SEPALEFTOCT_T);
  335. } else {
  336. layer_state_set(_LS_SEPALEFTOCT);
  337. }
  338. break;
  339. case _KEY19:
  340. if (is_trans_mode) {
  341. layer_state_set(_LS_SEPAHALF_T);
  342. } else {
  343. layer_state_set(_LS_SEPAHALF);
  344. }
  345. break;
  346. case _KEY25:
  347. if (is_trans_mode) {
  348. layer_state_set(_LS_SEPARIGHTOCT_T);
  349. } else {
  350. layer_state_set(_LS_SEPARIGHTOCT);
  351. }
  352. break;
  353. case _KEY37:
  354. if (is_trans_mode) {
  355. layer_state_set(_LS_FLIPTRANS);
  356. } else {
  357. layer_state_set(_LS_FLIPBASE);
  358. }
  359. break;
  360. }
  361. }
  362. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  363. // uprintf("keycode=%u, YM_C_3=%u, YM_Db_2 =%u, YM_MIN = %u, YM_MAX = %u\n", keycode, YM_C_3, YM_Db_2, YM_TONE_MIN, YM_TONE_MAX);
  364. switch (keycode) {
  365. case VERSION: // Output firmware info.
  366. if (record->event.pressed) {
  367. SEND_STRING(QMK_KEYBOARD ":" QMK_KEYMAP " @ " QMK_VERSION " | " QMK_BUILDDATE);
  368. }
  369. break;
  370. // Layer-related settings.
  371. // reset_scale_indicator() first, followed by each modification, and then change the default layer.
  372. // 1, separator column modification
  373. case B_BASE:
  374. if (record->event.pressed) {
  375. reset_all();
  376. key_separator_col = _KEY01;
  377. select_layer_state_set();
  378. }
  379. break;
  380. case B_LEFT:
  381. if (record->event.pressed) {
  382. reset_all();
  383. key_separator_col = _KEY13;
  384. select_layer_state_set();
  385. }
  386. break;
  387. case B_CENTER:
  388. if (record->event.pressed) {
  389. reset_all();
  390. key_separator_col = _KEY19;
  391. select_layer_state_set();
  392. }
  393. break;
  394. case B_RIGHT:
  395. if (record->event.pressed) {
  396. reset_all();
  397. key_separator_col = _KEY25;
  398. select_layer_state_set();
  399. }
  400. break;
  401. case B_FLIP:
  402. if (record->event.pressed) {
  403. reset_all();
  404. key_separator_col = _KEY37;
  405. select_layer_state_set();
  406. }
  407. break;
  408. // 2, Toggle scale shift mode and transpose mode
  409. case TGLTRNS:
  410. if (record->event.pressed) {
  411. reset_scale_indicator();
  412. is_trans_mode = !is_trans_mode;
  413. select_layer_state_set();
  414. }
  415. break;
  416. // SHIFT_L and SHIFT_R can be pressed only when layer is either _BASE, _FLIPBASE.
  417. case SHIFT_L:
  418. if (record->event.pressed) {
  419. switch (layer_state) {
  420. case _LS_BASE:
  421. case _LS_SEPALEFTOCT:
  422. case _LS_SEPAHALF:
  423. case _LS_SEPARIGHTOCT:
  424. case _LS_FLIPBASE:
  425. scale_indicator_col = shift_led_indicator_left(scale_indicator_col);
  426. break;
  427. }
  428. }
  429. break;
  430. case SHIFT_R:
  431. if (record->event.pressed) {
  432. switch (layer_state) {
  433. case _LS_BASE:
  434. case _LS_SEPALEFTOCT:
  435. case _LS_SEPAHALF:
  436. case _LS_SEPARIGHTOCT:
  437. case _LS_FLIPBASE:
  438. scale_indicator_col = shift_led_indicator_right(scale_indicator_col);
  439. break;
  440. }
  441. }
  442. break;
  443. case TGLINDI:
  444. if (record->event.pressed) {
  445. led_indicator_enable = !led_indicator_enable;
  446. }
  447. break;
  448. case TGLINTR:
  449. if (record->event.pressed) {
  450. switch (layer_state) {
  451. // main function of the TGLINTR part 1. alternate the status of trans_mode_indicator_loc_sel.
  452. case _LS_TRANS | (1UL << _FN):
  453. case _LS_SEPALEFTOCT_T | (1UL << _FN):
  454. case _LS_SEPAHALF_T | (1UL << _FN):
  455. case _LS_SEPARIGHTOCT_T | (1UL << _FN):
  456. trans_mode_indicator_loc_sel = !trans_mode_indicator_loc_sel;
  457. // when trans_mode_indicator_loc_sel == false, change the scale indicator and transpose.
  458. scale_indicator_col = trans_mode_indicator_loc_sel ? 0:1;
  459. // when TGLINTR is pressed, it also change the initial transpose setting to follow the scale indicator.
  460. if (scale_indicator_col == 1) {
  461. midi_config.transpose = -1;
  462. } else {
  463. midi_config.transpose = 0;
  464. }
  465. break;
  466. // main function of the TGLINTR part 2. alternate the status of trans_mode_indicator_loc_sel.
  467. case _LS_FLIPTRANS | (1UL << _FN):
  468. trans_mode_indicator_loc_sel = !trans_mode_indicator_loc_sel;
  469. // when trans_mode_indicator_loc_sel == false, change the scale indicator and transpose.
  470. scale_indicator_col = trans_mode_indicator_loc_sel ? 0:11;
  471. // when TGLINTR is pressed, it also change the initial transpose setting to follow the scale indicator.
  472. if (scale_indicator_col == 11) {
  473. midi_config.transpose = -1;
  474. } else {
  475. midi_config.transpose = 0;
  476. }
  477. break;
  478. // special treatment when TGLINTR is pressed in _LS_FLIPBASE layer.
  479. case _LS_FLIPBASE | (1UL << _FN): // when in FLIPBASE layer && non-Trans mode, change it to Trans mode.
  480. trans_mode_indicator_loc_sel = false;
  481. scale_indicator_col = 11;
  482. midi_config.transpose = -1;
  483. is_trans_mode = true;
  484. select_layer_state_set();
  485. break;
  486. // special treatment when TGLINTR is pressed in other non-Trans layer.
  487. default : // when other layers = non-Trans mode, change it to Trans mode.
  488. trans_mode_indicator_loc_sel = false;
  489. scale_indicator_col = 1;
  490. midi_config.transpose = -1;
  491. is_trans_mode = true;
  492. select_layer_state_set();
  493. }
  494. }
  495. break;
  496. case TGLCHGR:
  497. if (record->event.pressed) {
  498. use_alt_ch_gr = !use_alt_ch_gr;
  499. if (use_alt_ch_gr) {
  500. midi_config.channel = ALT_MAIN_CH_NUMBER;
  501. midi_left_ch = ALT_SUB_CH_NUMBER;
  502. } else { // default
  503. midi_config.channel = DEFAULT_MAIN_CH_NUMBER;
  504. midi_left_ch = DEFAULT_SUB_CH_NUMBER;
  505. }
  506. }
  507. break;
  508. case YM_TONE_MIN ... YM_TONE_MAX: // MY tone
  509. // uprintf("keycode=%u, YM_C_3=%u, YM_Db_2 =%u, YM_MIN = %u, YM_MAX = %u\n", keycode, YM_C_3, YM_Db_2, YM_TONE_MIN, YM_TONE_MAX);
  510. // DO NOT THROW BELOW into 'if (record->event.pressed) {}' STATEMENT SINCE IT IS USED IN THE FUNCTION BELOW.
  511. my_process_midi4single_note(midi_left_ch, keycode, record, my_tone_status);
  512. break;
  513. }
  514. return true;
  515. }
  516. #ifdef RGB_MATRIX_ENABLE
  517. void set_led_scale_indicator(uint8_t r, uint8_t g, uint8_t b) {
  518. uint8_t max_scale_indicator_led_loop;
  519. uint8_t i;
  520. if (led_indicator_enable) { // turn on indicators when enabled.
  521. max_scale_indicator_led_loop = ( scale_indicator_col == DEFAULT_SCALE_COL ) ? 12 : 9;
  522. for (i = 0; i < max_scale_indicator_led_loop; i++) {
  523. rgb_matrix_set_color(led_scale_indicator[scale_indicator_col][i], r, g, b);
  524. }
  525. }
  526. }
  527. bool rgb_matrix_indicators_user(void) {
  528. // uint32_t mode = rgblight_get_mode();
  529. if (rgb_matrix_is_enabled()) { // turn the lights on when it is enabled.
  530. // uint8_t max_scale_indicator_led_loop;
  531. uint8_t i;
  532. switch (layer_state) {
  533. case _LS_BASE:
  534. set_led_scale_indicator(BASE_LAYER_COLOR);
  535. break;
  536. case _LS_FLIPBASE:
  537. set_led_scale_indicator(FLIPB_LAYER_COLOR);
  538. for (i = 0; i < 3; i++) {
  539. rgb_matrix_set_color(led_single_col_indicator[_KEY37][i], FLIP_BORDER_COLOR); // right end
  540. }
  541. break;
  542. case _LS_TRANS:
  543. set_led_scale_indicator(TRANS_LAYER_COLOR);
  544. break;
  545. case _LS_SEPALEFTOCT_T:
  546. set_led_scale_indicator(SEPALEFT_T_LAYER_COLOR);
  547. for (i = 0; i < 3; i++) {
  548. rgb_matrix_set_color(led_single_col_indicator[_KEY13][i], FLIP_BORDER_COLOR); // Left
  549. }
  550. break;
  551. case _LS_SEPAHALF_T:
  552. set_led_scale_indicator(SEPAHALF_T_LAYER_COLOR);
  553. for (i = 0; i < 3; i++) {
  554. rgb_matrix_set_color(led_single_col_indicator[_KEY19][i], FLIP_BORDER_COLOR); // Center
  555. }
  556. break;
  557. case _LS_SEPARIGHTOCT_T:
  558. set_led_scale_indicator(SEPARIGHT_T_LAYER_COLOR);
  559. for (i = 0; i < 3; i++) {
  560. rgb_matrix_set_color(led_single_col_indicator[_KEY25][i], FLIP_BORDER_COLOR); // Right
  561. }
  562. break;
  563. case _LS_FLIPTRANS:
  564. set_led_scale_indicator(FLIPT_LAYER_COLOR);
  565. for (i = 0; i < 3; i++) {
  566. rgb_matrix_set_color(led_single_col_indicator[_KEY37][i], FLIP_BORDER_COLOR); // right end
  567. }
  568. break;
  569. case _LS_SEPALEFTOCT:
  570. set_led_scale_indicator(SEPALEFT_LAYER_COLOR);
  571. for (i = 0; i < 3; i++) {
  572. rgb_matrix_set_color(led_single_col_indicator[_KEY13][i], FLIP_BORDER_COLOR); // Left
  573. }
  574. break;
  575. case _LS_SEPAHALF:
  576. set_led_scale_indicator(SEPAHALF_LAYER_COLOR);
  577. for (i = 0; i < 3; i++) {
  578. rgb_matrix_set_color(led_single_col_indicator[_KEY19][i], FLIP_BORDER_COLOR); // Center
  579. }
  580. break;
  581. case _LS_SEPARIGHTOCT:
  582. set_led_scale_indicator(SEPARIGHT_LAYER_COLOR);
  583. for (i = 0; i < 3; i++) {
  584. rgb_matrix_set_color(led_single_col_indicator[_KEY25][i], FLIP_BORDER_COLOR); // Right
  585. }
  586. break;
  587. case _LS_FN ... _LS_MAX: // When Mute Button is long-pressed, the previous layers are still active.
  588. for (i = 1; i < 5; i++) {
  589. rgb_matrix_set_color(i, RGB_DARKSPRINGGREEN); // up(1) down(4) left(3) right(2) keys
  590. }
  591. rgb_matrix_set_color(led_single_col_indicator[_KEY02][0], RGB_DARKSPRINGGREEN); // TGLTRNS
  592. rgb_matrix_set_color(led_single_col_indicator[_KEY04][0], RGB_DARKSPRINGGREEN); // TGLINTR
  593. rgb_matrix_set_color(led_single_col_indicator[_KEY06][0], RGB_DARKSPRINGGREEN); // TGLCHGR
  594. for (i = 0; i < 3; i++) {
  595. rgb_matrix_set_color(led_single_col_indicator[_KEY01][i], BASE_LAYER_COLOR); // B_BASE
  596. rgb_matrix_set_color(led_single_col_indicator[_KEY13][i], SEPALEFT_LAYER_COLOR); // B_LEFT
  597. rgb_matrix_set_color(led_single_col_indicator[_KEY19][i], SEPAHALF_LAYER_COLOR); // B_CENTER
  598. rgb_matrix_set_color(led_single_col_indicator[_KEY25][i], SEPARIGHT_LAYER_COLOR); // B_RIGHT
  599. rgb_matrix_set_color(led_single_col_indicator[_KEY37][i], FLIPB_LAYER_COLOR); // B_FLIP
  600. }
  601. for (i = _KEY12; i < _KEY37; i+=2){ // even numbers from _KEY12 to _KEY36 are LED related settings.
  602. // turn on the bottom row only to keep the visibility of the RGB MATRIX effects.
  603. rgb_matrix_set_color(led_single_col_indicator[i][0], RGB_DARKSPRINGGREEN); // // LED related settings.
  604. }
  605. break;
  606. }
  607. }
  608. return false;
  609. }
  610. #endif // RGB_MATRIX_ENABLE