keymap.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. /* _
  17. * ___ _ __ ___ __ __ | | __ _ _ _ __ ___ __ _
  18. * / __| | '_ \ / _ \ \ \ /\ / / | |/ / | | | | | '_ ` _ \ / _` |
  19. * \__ \ | | | | | (_) | \ V V / | < | |_| | | | | | | | | (_| |
  20. * |___/ |_| |_| \___/ \_/\_/ |_|\_\ \__,_| |_| |_| |_| \__,_|
  21. *
  22. * https://github.com/snowkuma
  23. *
  24. * version 0.1
  25. */
  26. #include QMK_KEYBOARD_H
  27. #include "muse.h"
  28. #include "custom_keycodes.h"
  29. #include "my_strings.h"
  30. extern keymap_config_t keymap_config;
  31. enum planck_layers {
  32. _COLEMAK = 0,
  33. _SYMBOL,
  34. _SFT_NAV,
  35. _REGEX,
  36. _NUMBER,
  37. _ARRANGE,
  38. _FUNCTION,
  39. _MOUSE,
  40. _THUMB
  41. };
  42. enum planck_keycodes {
  43. EMAIL = SAFE_RANGE,
  44. EMOJI,
  45. EXT_PLV,
  46. ITERM,
  47. LESSON,
  48. TYPE_FU,
  49. VS_CODE,
  50. VIM
  51. };
  52. // Tap Dance Declarations
  53. enum {
  54. TD_RESET = 0,
  55. TD_TILD
  56. };
  57. // Tap Dance Definitions
  58. void safe_reset(qk_tap_dance_state_t *state, void *user_data) {
  59. if (state->count >=3) {
  60. // Reset the keyboard if you tap the key more than three times
  61. reset_keyboard();
  62. reset_tap_dance(state);
  63. }
  64. }; void tilde_home(qk_tap_dance_state_t *state, void *user_data) {
  65. if (state->count > 2) {
  66. register_code(KC_LSFT);
  67. register_code(KC_GRV);
  68. }
  69. else {
  70. register_code(KC_LSFT);
  71. register_code(KC_GRV);
  72. if (state->count > 1) {
  73. // Outputs ~/ if tilde tapped twice
  74. unregister_code(KC_GRV);
  75. unregister_code(KC_LSFT);
  76. register_code(KC_SLSH);
  77. }
  78. }
  79. }
  80. void tilde_reset(qk_tap_dance_state_t *state, void *user_data)
  81. {
  82. if (state->count == 2) {
  83. unregister_code(KC_SLSH);
  84. } else {
  85. unregister_code(KC_GRV);
  86. unregister_code(KC_LSFT);
  87. }
  88. }
  89. qk_tap_dance_action_t tap_dance_actions[] = {
  90. [TD_RESET] = ACTION_TAP_DANCE_FN (safe_reset),
  91. [TD_TILD] = ACTION_TAP_DANCE_FN_ADVANCED (NULL, tilde_home, tilde_reset)
  92. };
  93. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  94. /* COLEMAK
  95. *
  96. * Base layer
  97. * ,-----------------------------------------------------------------------------------------------------------.
  98. * | q | w | f | p | g | | | j | l | u | y | ; |
  99. * | CTRL | ALT | GUI | | | | | | | GUI | ALT | CTRL |
  100. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  101. * | a | r | s | t | d | | | h | n | e | i | o |
  102. * | | | | Shift | | | | | Shift | | | |
  103. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  104. * | z | x | c | v | b | | | k | m | , | . | ' |
  105. * | | | | | | | | | | | | |
  106. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  107. * | | | | Esc | BkSp | - | Tab | Space | Enter | | |
  108. * | | | | Num | Regex | Arrange| Shift | Sym | Thumb | | | |
  109. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  110. */
  111. [_COLEMAK] = LAYOUT_planck_grid(
  112. Q_CTL, W_ALT, F_GUI, KC_P, KC_G, _______, _______, KC_J, KC_L, U_GUI, Y_ALT, SCL_CTL,
  113. KC_A, KC_R, KC_S, T_SFT, KC_D, _______, _______, KC_H, N_SFT, KC_E, KC_I, KC_O,
  114. KC_Z, KC_X, KC_C, KC_V, KC_B, _______, _______, KC_K, KC_M, KC_COMM, KC_DOT, KC_QUOT,
  115. _______, _______, _______, ESC_NUM, BSP_REG, MIN_ARR, TAB_SFT, SPC_SYM, ENT_THU, _______, _______, _______
  116. ),
  117. /* Symbol & Cursor Nav layer
  118. * ,-----------------------------------------------------------------------------------------------------------.
  119. * | ! | @ | € | & | | | | | | Home | Up | End | PgUp |
  120. * | | | | | | | | | | | | |
  121. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  122. * | ~ | < | % | > | + | | | | Left | Down | Right | PgDn |
  123. * | 2x ~/ | | | | | | | | | | | |
  124. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  125. * | ` | | £ | = | - | | | | | | | |
  126. * | | | | | | | | | | | | |
  127. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  128. * | | | | _ | Del | - | | f() | | | | |
  129. * | | | | | Mouse | | | Sym |Function| | | |
  130. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  131. */
  132. [_SYMBOL] = LAYOUT_planck_grid(
  133. KC_EXLM, KC_AT, EURO, KC_AMPR, KC_PIPE, _______, _______, _______, KC_HOME, KC_UP, KC_END, KC_PGUP,
  134. TD(TD_TILD), KC_LT, KC_PERC, KC_GT, KC_PLUS, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, KC_PGDN,
  135. KC_GRV, _______, GBP, KC_EQL, KC_MINS, _______, _______, _______, _______, _______, _______, _______,
  136. _______, _______, _______, KC_UNDS, DEL_REG, KC_MINS, _______, _______, _______, _______, _______, _______
  137. ),
  138. /* Regex layer
  139. * ,-----------------------------------------------------------------------------------------------------------.
  140. * | | | | | | | | * | [ | ^ | ] | : |
  141. * | | | | | | | | | | | | |
  142. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  143. * | | | | | | | | ? | ( | $ | ) | / |
  144. * | | | | | | | | | | | | |
  145. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  146. * | | | | | | | | | | { | # | } | \ |
  147. * | | | | | | | | | | | | |
  148. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  149. * | | | | | f() | | | Space | | | |
  150. * | | | | | Regex | | | Mouse | Enter | | | |
  151. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  152. */
  153. [_REGEX] = LAYOUT_planck_grid(
  154. _______, _______, _______, _______, _______, _______, _______, KC_ASTR, KC_LBRC, KC_CIRC, KC_RBRC, KC_COLN,
  155. _______, _______, _______, _______, _______, _______, _______, KC_QUES, KC_LPRN, KC_DLR, KC_RPRN, KC_SLSH,
  156. _______, _______, _______, _______, _______, _______, _______, KC_PIPE, KC_LCBR, KC_HASH, KC_RCBR, KC_BSLS,
  157. _______, _______, _______, _______, _______, _______, _______, _______, KC_ENT, _______, _______, _______
  158. ),
  159. /* Number Layer
  160. * ,-----------------------------------------------------------------------------------------------------------.
  161. * | : | F | E | D | G | | | * | 7 | 8 | 9 | 0 |
  162. * | | | | | | | | | | | | |
  163. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  164. * | # | C | B | A | + | | | . | 4 | 5 | 6 | / |
  165. * | | | | | | | | | | | | |
  166. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  167. * | € | x | £ | = | - | | | , | 1 | 2 | 3 | \ |
  168. * | | | | | | | | | | | | |
  169. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  170. * | | | | f() | | | | | | | | |
  171. * | | | | Number | | | | Space | Enter | | | |
  172. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  173. *
  174. */
  175. [_NUMBER] = LAYOUT_planck_grid(
  176. KC_COLN, S(KC_F), S(KC_E), S(KC_D), S(KC_G), _______, _______, KC_ASTR, KC_7, KC_8, KC_9, KC_0,
  177. KC_HASH, S(KC_C), S(KC_B), S(KC_A), KC_PLUS, _______, _______, KC_DOT, KC_4, KC_5, KC_6, KC_SLSH,
  178. EURO, KC_X, GBP, KC_EQL, KC_MINS, _______, _______, KC_COMM, KC_1, KC_2, KC_3, KC_BSLS,
  179. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  180. ),
  181. /* Mouse Layer
  182. * ,-----------------------------------------------------------------------------------------------------------.
  183. * | Ctrl | Alt | GUI | | | | | | | Up | | wUp |
  184. * | | | | | | | | | | | | |
  185. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  186. * | Btn3 | Btn2 | Btn1 | Shift | | | | | Left | Down | Right | wDn |
  187. * | | | | | | | | | | | | |
  188. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  189. * | | | | | | | | | | | | |
  190. * | | | | | | | | | | | | |
  191. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  192. * | | | | | f() | | | f() | | | |
  193. * | | | | | Mouse | | | Mouse | | | | |
  194. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  195. */
  196. [_MOUSE] = LAYOUT_planck_grid(
  197. KC_LCTL, KC_LALT, KC_LGUI, _______, _______, _______, _______, _______, _______, KC_MS_U, _______, KC_WH_U,
  198. KC_BTN3, KC_BTN2, KC_BTN1, KC_LSFT, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R, KC_WH_D,
  199. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  200. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  201. ),
  202. /* Thumb Layer
  203. * ,-----------------------------------------------------------------------------------------------------------.
  204. * | Reset | | SC_CAPF| SC_CAPP| | | | |Input L | | | |
  205. * | (3x) | | | | | | | | | | | |
  206. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  207. * | | | | TypeFu | CMD + | | | | Caps | emoji | iterm | |
  208. * | | | | | | | | | Lock | | | |
  209. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  210. * | | | VS_Code| Vim | CMD - | | | | | | | |
  211. * | | | | | | | | | | | | |
  212. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  213. * | | | | | | | | | f() | | | |
  214. * | | | | | | | | | Thumb | | | |
  215. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  216. */
  217. [_THUMB] = LAYOUT_planck_grid(
  218. TD(TD_RESET), _______, SC_CAPF, SC_CAPP, _______, _______, _______, _______, INPUT_L, _______, _______, _______,
  219. _______, _______, _______, TYPE_FU, TXT_PLS, _______, _______, _______, KC_CAPS, EMOJI, ITERM, _______,
  220. _______, _______, VS_CODE, VIM, TXT_MIN, _______, _______, _______, _______, _______, _______, _______,
  221. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  222. ),
  223. /* Arrange Layer
  224. * ,-----------------------------------------------------------------------------------------------------------.
  225. * | | | Full | | | | | | Top L | Top | Top R | |
  226. * | | | Screen | | | | | | | | |
  227. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  228. * | L 1/3 | L 2/3 | C 1/3 | R 2/3 | R 1/3 | | | Prev | Left | Bottom | Right | Next |
  229. * | | | | | | | | | | | |
  230. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  231. * | Restore| | Center | | | | | | Bottom | | Bottom | |
  232. * | | | | | | | | | Left | | Right |
  233. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  234. * | | | | | | f() | | | | | |
  235. * | | | | | | Arrange| | | | | | |
  236. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  237. */
  238. [_ARRANGE] = LAYOUT_planck_grid(
  239. _______, _______, M_MAX, _______, _______, _______, _______, _______, M_TOPL, M_TOP, M_TOPR, _______,
  240. M_L13, M_L23, M_C13, M_R23, M_R13, _______, _______, M_PREV, M_LEFT, M_BOTT, M_RGHT, M_NEXT,
  241. M_REST, _______, M_CEN, _______, _______, _______, _______, _______, M_BOTL, _______, M_BOTR, _______,
  242. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  243. ),
  244. /* Function Layer
  245. * ,-----------------------------------------------------------------------------------------------------------.
  246. * | Ctrl | Alt | GUI | | | | | | F7 | F8 | F9 | F10 |
  247. * | | | | | | | | | | | |
  248. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  249. * | | | | Shift | | | | | F4 | F5 | F6 | F11 |
  250. * | | | | | | | | | | | |
  251. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  252. * | | | | | | | | | F1 | F2 | F3 | F12 |
  253. * | | | | | | | | | | | |
  254. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  255. * | | | | | | | | f() | f() | | | |
  256. * | | | | | | | |Function|Function| | | |
  257. * `--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------'
  258. */
  259. [_FUNCTION] = LAYOUT_planck_grid(
  260. KC_LCTL, KC_LALT, KC_LGUI, _______, _______, _______, _______, KC_F13, KC_F7, KC_F8, KC_F9, KC_F10,
  261. _______, _______, _______, KC_LSFT, _______, _______, _______, KC_F14, KC_F4, KC_F5, KC_F6, KC_F11,
  262. _______, _______, _______, _______, _______, _______, _______, KC_F15, KC_F1, KC_F2, KC_F3, KC_F12,
  263. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  264. )
  265. };
  266. #ifdef AUDIO_ENABLE
  267. float plover_song[][2] = SONG(PLOVER_SOUND);
  268. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  269. #endif
  270. uint32_t layer_state_set_user(uint32_t state) {
  271. state = update_tri_layer_state(state, _SYMBOL, _THUMB, _FUNCTION);
  272. state = update_tri_layer_state(state, _SYMBOL, _REGEX, _MOUSE);
  273. return state;
  274. }
  275. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  276. switch (keycode) {
  277. case EMAIL:
  278. if (record->event.pressed) {
  279. SEND_STRING(MY_EMAIL);
  280. }
  281. return false;
  282. break;
  283. case ITERM:
  284. if (record->event.pressed) {
  285. SEND_STRING(SS_LGUI(" "));
  286. SEND_STRING("iterm" SS_TAP(X_ENTER));
  287. }
  288. return false;
  289. break;
  290. case TYPE_FU:
  291. if (record->event.pressed) {
  292. SEND_STRING(SS_LGUI(" "));
  293. SEND_STRING("type fu" SS_TAP(X_ENTER));
  294. }
  295. return false;
  296. break;
  297. case VIM:
  298. if (record->event.pressed) {
  299. SEND_STRING(SS_LGUI(" "));
  300. SEND_STRING("macvim.app" SS_TAP(X_ENTER));
  301. }
  302. return false;
  303. break;
  304. case VS_CODE:
  305. if (record->event.pressed) {
  306. SEND_STRING(SS_LGUI(" "));
  307. SEND_STRING("visual studio code" SS_TAP(X_ENTER));
  308. }
  309. return false;
  310. break;
  311. case EMOJI:
  312. if (record->event.pressed) {
  313. register_code(KC_LGUI);
  314. register_code(KC_LCTL);
  315. register_code(KC_SPC);
  316. unregister_code(KC_LGUI);
  317. unregister_code(KC_LCTL);
  318. unregister_code(KC_SPC);
  319. }
  320. return false;
  321. break;
  322. }
  323. return true;
  324. }
  325. bool muse_mode = false;
  326. uint8_t last_muse_note = 0;
  327. uint16_t muse_counter = 0;
  328. uint8_t muse_offset = 70;
  329. uint16_t muse_tempo = 50;
  330. void matrix_scan_user(void) {
  331. #ifdef AUDIO_ENABLE
  332. if (muse_mode) {
  333. if (muse_counter == 0) {
  334. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  335. if (muse_note != last_muse_note) {
  336. stop_note(compute_freq_for_midi_note(last_muse_note));
  337. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  338. last_muse_note = muse_note;
  339. }
  340. }
  341. muse_counter = (muse_counter + 1) % muse_tempo;
  342. }
  343. #endif
  344. }
  345. void matrix_init_user(void) {
  346. set_unicode_input_mode(UC_OSX);
  347. }