keymap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* Copyright 2019 Brandon Schlack
  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. #ifdef KEYBOARD_preonic_rev3
  18. #include "muse.h"
  19. #endif
  20. #include "brandonschlack.h"
  21. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  22. /* Qwerty */
  23. [_BASE] = LAYOUT_ortho_5x12( \
  24. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  25. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSLS, \
  26. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  27. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \
  28. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  29. HY_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  30. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  31. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SFT_ENT, \
  32. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  33. MCO_LYR, KC_LCTL, KC_LOPT, KC_LCMD, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  34. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  35. ),
  36. /* Lower */
  37. [_LOWER] = LAYOUT_ortho_5x12( \
  38. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  39. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  40. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  41. KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DELT, \
  42. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  43. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, _______, \
  44. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  45. SF_CAPS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, KC_PGDN, KC_PGUP, KC_END, _______, \
  46. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  47. _______, _______, _______, _______, _______, KC_MUTE, KC_MUTE, _______, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT \
  48. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  49. ),
  50. /* Raise */
  51. [_RAISE] = LAYOUT_ortho_5x12( \
  52. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  53. KC_GRV, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_PIPE, \
  54. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  55. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DELT, \
  56. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  57. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, _______, \
  58. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  59. SF_CAPS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, KC_PGDN, KC_PGUP, KC_END, _______, \
  60. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  61. _______, _______, _______, _______, _______, KC_MPLY, KC_MPLY, _______, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT \
  62. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  63. ),
  64. /* Function */
  65. [_MACRO] = LAYOUT_ortho_5x12( \
  66. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  67. _______, _______, _______, _______, _______, _______, _______, KC_BRMD, KC_BRMU, MC_MSSN, MC_LHPD, MC_SLPD, \
  68. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  69. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  70. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  71. _______, _______, _______, _______, _______, _______, _______, MC_BACK, MC_FWRD, PRV_TAB, NXT_TAB, NXT_WIN, \
  72. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  73. _______, _______, _______, _______, _______, _______, PX_AFLL, OP_AFLL, _______, _______, _______, _______, \
  74. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  75. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  76. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  77. ),
  78. /* Adjust (Lower + Raise) */
  79. [_ADJUST] = LAYOUT_ortho_5x12( \
  80. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  81. KC_ESC, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, MC_SLPD, \
  82. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  83. QM_MAKE, QK_BOOT, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, \
  84. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  85. QM_FLSH, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______, \
  86. // ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  87. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, RGB_RTHM,RGB_THM, _______, _______, _______, \
  88. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  89. EEP_RST, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  90. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  91. )
  92. };
  93. layer_state_t layer_state_set_keymap(layer_state_t state) {
  94. state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  95. return state;
  96. }
  97. #ifdef KEYBOARD_preonic_rev3
  98. #ifdef AUDIO_ENABLE
  99. float plover_song[][2] = SONG(PLOVER_SOUND);
  100. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  101. #endif
  102. bool muse_mode = false;
  103. uint8_t last_muse_note = 0;
  104. uint16_t muse_counter = 0;
  105. uint8_t muse_offset = 70;
  106. uint16_t muse_tempo = 50;
  107. bool encoder_update_keymap(uint8_t index, bool clockwise) {
  108. if (muse_mode) {
  109. if (IS_LAYER_ON(_RAISE)) {
  110. if (clockwise) {
  111. muse_offset++;
  112. } else {
  113. muse_offset--;
  114. }
  115. } else {
  116. if (clockwise) {
  117. muse_tempo+=1;
  118. } else {
  119. muse_tempo-=1;
  120. }
  121. }
  122. } else {
  123. if (clockwise) {
  124. #ifdef MOUSEKEY_ENABLE
  125. tap_code(MC_WH_U);
  126. #else
  127. tap_code(KC_VOLU);
  128. #endif
  129. } else {
  130. #ifdef MOUSEKEY_ENABLE
  131. tap_code(MC_WH_D);
  132. #else
  133. tap_code(KC_VOLD);
  134. #endif
  135. }
  136. }
  137. return true;
  138. }
  139. bool dip_switch_update_user(uint8_t index, bool active) {
  140. switch (index) {
  141. case 0: {
  142. #ifdef AUDIO_ENABLE
  143. static bool play_sound = false;
  144. #endif
  145. if (active) {
  146. #ifdef AUDIO_ENABLE
  147. if (play_sound) { PLAY_SONG(plover_song); }
  148. #endif
  149. layer_on(_ADJUST);
  150. } else {
  151. #ifdef AUDIO_ENABLE
  152. if (play_sound) { PLAY_SONG(plover_gb_song); }
  153. #endif
  154. layer_off(_ADJUST);
  155. }
  156. #ifdef AUDIO_ENABLE
  157. play_sound = true;
  158. #endif
  159. break;
  160. }
  161. case 1:
  162. if (active) {
  163. muse_mode = true;
  164. } else {
  165. muse_mode = false;
  166. }
  167. }
  168. return true;
  169. }
  170. void matrix_scan_keymap(void) {
  171. #ifdef AUDIO_ENABLE
  172. if (muse_mode) {
  173. if (muse_counter == 0) {
  174. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  175. if (muse_note != last_muse_note) {
  176. stop_note(compute_freq_for_midi_note(last_muse_note));
  177. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  178. last_muse_note = muse_note;
  179. }
  180. }
  181. muse_counter = (muse_counter + 1) % muse_tempo;
  182. } else {
  183. if (muse_counter) {
  184. stop_all_notes();
  185. muse_counter = 0;
  186. }
  187. }
  188. #endif
  189. }
  190. bool music_mask_user(uint16_t keycode) {
  191. switch (keycode) {
  192. case RAISE:
  193. case LOWER:
  194. case MCO_LYR:
  195. return false;
  196. default:
  197. return true;
  198. }
  199. }
  200. #endif