keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* Copyright 2015-2017 Jack Humbert
  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 "muse.h"
  18. enum preonic_layers {
  19. _QWERTY,
  20. _FN,
  21. _NUMPAD,
  22. _LOWER,
  23. _RAISE,
  24. _ADJUST
  25. };
  26. enum preonic_keycodes {
  27. LOWER = SAFE_RANGE,
  28. RAISE,
  29. SHRUG, // ¯\_(ツ)_/¯
  30. TFLIP, // (╯°□°)╯︵ ┻━┻
  31. POOP, // 💩
  32. DPOINT, // (ಠ_ಠ)
  33. STRUT // ᕕ( ᐛ )ᕗ
  34. };
  35. #define TG_NUMP TG(_NUMPAD)
  36. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  37. /* Qwerty
  38. * ,-----------------------------------------------------------------------------------.
  39. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  40. * |------+------+------+------+------+------+------+------+------+------+------+------|
  41. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Del |
  42. * |------+------+------+------+------+-------------+------+------+------+------+------|
  43. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  44. * |------+------+------+------+------+------|------+------+------+------+------+------|
  45. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  46. * |------+------+------+------+------+------+------+------+------+------+------+------|
  47. * | FN | Ctrl | GUI | ALT |Lower | Space |Raise | Left | Down | Up |Right |
  48. * `-----------------------------------------------------------------------------------'
  49. */
  50. [_QWERTY] = LAYOUT_preonic_grid(
  51. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  52. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL,
  53. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  54. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT,
  55. MO(_FN), KC_LCTL, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  56. ),
  57. /* FN
  58. * ,-----------------------------------------------------------------------------------.
  59. * |RGBTgl|Brigt-|Brigt+| | | | | | | | | POOP |
  60. * |------+------+------+------+------+------+------+------+------+------+------+------|
  61. * | RGB+ | Hue- | Hue+ | | | | | | | |PrtScr|UC_Nxt|
  62. * |------+------+------+------+------+-------------+------+------+------+------+------|
  63. * | RGB- | Sat- | Sat+ | | | | | | | | |UC_Wnc|
  64. * |------+------+------+------+------+------|------+------+------+------+------+------|
  65. * | |Effct-|Effct+| | | | | | | | |UC_Lin|
  66. * |------+------+------+------+------+------+------+------+------+------+------+------|
  67. * | |SHRUG |TFLIP |DPOINT|STRUT | | | | |TgNmpd| |UC_Mac|
  68. * `-----------------------------------------------------------------------------------'
  69. */
  70. [_FN] = LAYOUT_preonic_grid(
  71. RGB_TOG, RGB_VAD, RGB_VAI, _______, _______, _______, _______, _______, _______, _______, _______, POOP,
  72. RGB_MOD, RGB_HUD, RGB_HUI, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, UC_NEXT,
  73. RGB_RMOD, RGB_SAD, RGB_SAI, _______, _______, _______, _______, _______, _______, _______, _______, UC_WINC,
  74. _______, RGB_SPD, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, UC_LINX,
  75. _______, SHRUG, TFLIP, DPOINT, STRUT, _______, _______, _______, _______, TG_NUMP, _______, UC_MAC
  76. ),
  77. /* Numpad
  78. * ,-----------------------------------------------------------------------------------.
  79. * | | | | | | |NumLk | 7 | 8 | 9 | / | Bksp |
  80. * |------+------+------+------+------+------+------+------+------+------+------+------|
  81. * | Tab | | | | | | | 4 | 5 | 6 | * | Del |
  82. * |------+------+------+------+------+-------------+------+------+------+------+------|
  83. * | Esc | | | | | | | 1 | 2 | 3 | - | / |
  84. * |------+------+------+------+------+------|------+------+------+------+------+------|
  85. * | | | | | | | | 0 | . | = | + |Enter |
  86. * |------+------+------+------+------+------+------+------+------+------+------+------|
  87. * | | | | | | | | | | | | |
  88. * `-----------------------------------------------------------------------------------'
  89. */
  90. [_NUMPAD] = LAYOUT_preonic_grid(
  91. _______, _______, _______, _______, _______, _______, KC_NUM, KC_P7, KC_P8, KC_P9, KC_PSLS, KC_BSPC,
  92. KC_ESC, _______, _______, _______, _______, _______, _______, KC_P4, KC_P5, KC_P6, KC_PAST, KC_DEL,
  93. KC_TAB, _______, _______, _______, _______, _______, _______, KC_P1, KC_P2, KC_P3, KC_PMNS, _______,
  94. _______, _______, _______, _______, _______, _______, _______, KC_P0, KC_PDOT, KC_PEQL, KC_PPLS, _______,
  95. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  96. ),
  97. /* Lower
  98. * ,-----------------------------------------------------------------------------------.
  99. * | | | | | | | | | | | | Bksp |
  100. * |------+------+------+------+------+-------------+------+------+------+------+------|
  101. * | | | | | | | | | | | | Del |
  102. * |------+------+------+------+------+-------------+------+------+------+------+------|
  103. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  104. * |------+------+------+------+------+------|------+------+------+------+------+------|
  105. * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | | |
  106. * |------+------+------+------+------+------+------+------+------+------+------+------|
  107. * | | | | | | | |Raise | Home | PgDn | PgUp | End |
  108. * `-----------------------------------------------------------------------------------'
  109. */
  110. [_LOWER] = LAYOUT_preonic_grid(
  111. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BSPC,
  112. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
  113. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  114. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______,
  115. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END
  116. ),
  117. /* Raise
  118. * ,-----------------------------------------------------------------------------------.
  119. * | | | | | | | | | | | | Bksp |
  120. * |------+------+------+------+------+-------------+------+------+------+------+------|
  121. * | | | | | | | | | | | | Del |
  122. * |------+------+------+------+------+-------------+------+------+------+------+------|
  123. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  124. * |------+------+------+------+------+------|------+------+------+------+------+------|
  125. * | | F7 | F8 | F9 | F10 | F11 | F12 | | Prev | | | |
  126. * |------+------+------+------+------+------+------+------+------+------+------+------|
  127. * | | | | |Lower | | | | Next | Vol- | Vol+ | Play |
  128. * `-----------------------------------------------------------------------------------'
  129. */
  130. [_RAISE] = LAYOUT_preonic_grid(
  131. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BSPC,
  132. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
  133. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  134. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_MPRV, _______, _______, _______,
  135. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  136. ),
  137. /* Adjust (Lower + Raise)
  138. * ,-----------------------------------------------------------------------------------.
  139. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  140. * |------+------+------+------+------+------+------+------+------+------+------+------|
  141. * | | Reset| | | | | | | | | | Del |
  142. * |------+------+------+------+------+-------------+------+------+------+------+------|
  143. * | | | |Aud on|AudOff|AGnorm|AGswap| | | | | |
  144. * |------+------+------+------+------+------|------+------+------+------+------+------|
  145. * | |Voice-|Voice+|Mus on|MusOff|MidiOn|MidOff| | | | | |
  146. * |------+------+------+------+------+------+------+------+------+------+------+------|
  147. * | | | | | | | | | | | |
  148. * `-----------------------------------------------------------------------------------'
  149. */
  150. [_ADJUST] = LAYOUT_preonic_grid(
  151. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  152. _______, QK_BOOT, DB_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
  153. _______, _______, MU_NEXT, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______,
  154. _______, AU_PREV, AU_NEXT, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______,
  155. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  156. )
  157. };
  158. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  159. switch (keycode) {
  160. case LOWER:
  161. if (record->event.pressed) {
  162. layer_on(_LOWER);
  163. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  164. } else {
  165. layer_off(_LOWER);
  166. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  167. }
  168. return false;
  169. break;
  170. case RAISE:
  171. if (record->event.pressed) {
  172. layer_on(_RAISE);
  173. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  174. } else {
  175. layer_off(_RAISE);
  176. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  177. }
  178. return false;
  179. break;
  180. case SHRUG:
  181. if (record->event.pressed) {
  182. send_unicode_string("¯\\_(ツ)_/¯");
  183. }
  184. return false;
  185. break;
  186. case TFLIP:
  187. if (record->event.pressed) {
  188. send_unicode_string("(╯°□°)╯︵ ┻━┻");
  189. }
  190. return false;
  191. break;
  192. case POOP:
  193. if (record->event.pressed) {
  194. send_unicode_string("💩");
  195. }
  196. return false;
  197. break;
  198. case DPOINT:
  199. if (record->event.pressed) {
  200. send_unicode_string("(ಠ_ಠ)");
  201. }
  202. return false;
  203. break;
  204. case STRUT:
  205. if (record->event.pressed) {
  206. send_unicode_string("ᕕ( ᐛ )ᕗ");
  207. }
  208. return false;
  209. break;
  210. }
  211. return true;
  212. };
  213. bool muse_mode = false;
  214. uint8_t last_muse_note = 0;
  215. uint16_t muse_counter = 0;
  216. uint8_t muse_offset = 70;
  217. uint16_t muse_tempo = 50;
  218. bool encoder_update_user(uint8_t index, bool clockwise) {
  219. if (muse_mode) {
  220. if (IS_LAYER_ON(_RAISE)) {
  221. if (clockwise) {
  222. muse_offset++;
  223. } else {
  224. muse_offset--;
  225. }
  226. } else {
  227. if (clockwise) {
  228. muse_tempo+=1;
  229. } else {
  230. muse_tempo-=1;
  231. }
  232. }
  233. } else {
  234. if (clockwise) {
  235. tap_code(KC_PGDN);
  236. } else {
  237. tap_code(KC_PGUP);
  238. }
  239. }
  240. return true;
  241. }
  242. bool dip_switch_update_user(uint8_t index, bool active) {
  243. switch (index) {
  244. case 0:
  245. if (active) {
  246. layer_on(_ADJUST);
  247. } else {
  248. layer_off(_ADJUST);
  249. }
  250. break;
  251. case 1:
  252. if (active) {
  253. muse_mode = true;
  254. } else {
  255. muse_mode = false;
  256. }
  257. }
  258. return true;
  259. }
  260. void matrix_scan_user(void) {
  261. #ifdef AUDIO_ENABLE
  262. if (muse_mode) {
  263. if (muse_counter == 0) {
  264. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  265. if (muse_note != last_muse_note) {
  266. stop_note(compute_freq_for_midi_note(last_muse_note));
  267. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  268. last_muse_note = muse_note;
  269. }
  270. }
  271. muse_counter = (muse_counter + 1) % muse_tempo;
  272. } else {
  273. if (muse_counter) {
  274. stop_all_notes();
  275. muse_counter = 0;
  276. }
  277. }
  278. #endif
  279. }
  280. bool music_mask_user(uint16_t keycode) {
  281. switch (keycode) {
  282. case RAISE:
  283. case LOWER:
  284. return false;
  285. default:
  286. return true;
  287. }
  288. }