2
0

keymap.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. extern keymap_config_t keymap_config;
  19. enum planck_layers
  20. {
  21. _QWERTY,
  22. _LOWER,
  23. _RAISE,
  24. _ADJUST
  25. };
  26. enum planck_keycodes
  27. {
  28. QWERTY = SAFE_RANGE,
  29. BACKLIT,
  30. EXT_PLV,
  31. HASHRKT,
  32. CLNEQLS
  33. };
  34. #define RSE_ENT LT(_RAISE, KC_ENT)
  35. #define LWR_SPC LT(_LOWER, KC_SPC)
  36. #define ESC_CTL CTL_T(KC_ESCAPE)
  37. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  38. /* Qwerty
  39. * ,-----------------------------------------------------------------------------------.
  40. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  41. * |------+------+------+------+------+-------------+------+------+------+------+------|
  42. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  43. * |------+------+------+------+------+------|------+------+------+------+------+------|
  44. * | Shift| Z | X | C | V | B | N | M | , | . | / |Shift |
  45. * |------+------+------+------+------+------+------+------+------+------+------+------|
  46. * | Brite| Ctrl | Alt | GUI | Enter | Space | Left | Down | Up |Right |
  47. * `-----------------------------------------------------------------------------------'
  48. */
  49. [_QWERTY] = LAYOUT_planck_grid(
  50. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  51. ESC_CTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  52. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
  53. BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, KC_NO, RSE_ENT, KC_NO, LWR_SPC, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT),
  54. /* Lower
  55. * ,-----------------------------------------------------------------------------------.
  56. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  57. * |------+------+------+------+------+-------------+------+------+------+------+------|
  58. * |ESCCTL| := | | { | } | ( | ) | - | = | \ | ~ | GUI |
  59. * |------+------+------+------+------+------|------+------+------+------+------+------|
  60. * | | => | | [ | ] | | | _ | + | | | Home | End |
  61. * |------+------+------+------+------+------+------+------+------+------+------+------|
  62. * | | | | | | | Next | Vol- | Vol+ | Play |
  63. * `-----------------------------------------------------------------------------------'
  64. */
  65. [_LOWER] = LAYOUT_planck_grid(
  66. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  67. ESC_CTL, CLNEQLS, _______, KC_LCBR, KC_RCBR, KC_LPRN, KC_RPRN, KC_MINS, KC_EQL, KC_BSLS, KC_TILD, KC_RGUI,
  68. _______, HASHRKT, _______, KC_LBRC, KC_RBRC, _______, _______, KC_UNDS, KC_PLUS, KC_PIPE, KC_HOME, KC_END,
  69. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY),
  70. /* Raise
  71. * ,-----------------------------------------------------------------------------------.
  72. * | ` | | | Up | | | | 7 | 8 | 9 | 0 | Bksp |
  73. * |------+------+------+------+------+-------------+------+------+------+------+------|
  74. * |ESCCTL| | Left | Down | Right | | | 4 | 5 | 6 | | GUI |
  75. * |------+------+------+------+------+------|------+------+------+------+------+------|
  76. * | | | | | | | | 1 | 2 | 3 | | |
  77. * |------+------+------+------+------+------+------+------+------+------+------+------|
  78. * | | | | | | | Next | Vol- | Vol+ | Play |
  79. * `-----------------------------------------------------------------------------------'
  80. */
  81. [_RAISE] = LAYOUT_planck_grid(
  82. KC_GRV, _______, _______, KC_UP, _______, _______, _______, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  83. ESC_CTL, _______, KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, KC_4, KC_5, KC_6, _______, KC_RGUI,
  84. _______, _______, _______, _______, _______, _______, _______, KC_1, KC_2, KC_3, _______, _______,
  85. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY),
  86. /* Adjust (Lower + Raise)
  87. * ,-----------------------------------------------------------------------------------.
  88. * | | Reset| | | | | | | | | | Del |
  89. * |------+------+------+------+------+-------------+------+------+------+------+------|
  90. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| |
  91. * |------+------+------+------+------+------|------+------+------+------+------+------|
  92. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  93. * |------+------+------+------+------+------+------+------+------+------+------+------|
  94. * | | | | | | | | | | |
  95. * `-----------------------------------------------------------------------------------'
  96. */
  97. [_ADJUST] = LAYOUT_planck_grid(
  98. _______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL,
  99. _______, _______, MU_MOD, AU_ON, AU_OFF, _______, _______, QWERTY, _______, _______, _______, _______,
  100. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______,
  101. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______)
  102. };
  103. #ifdef AUDIO_ENABLE
  104. float plover_song[][2] = SONG(PLOVER_SOUND);
  105. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  106. #endif
  107. uint32_t layer_state_set_user(uint32_t state)
  108. {
  109. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  110. }
  111. bool process_record_user(uint16_t keycode, keyrecord_t *record)
  112. {
  113. switch (keycode)
  114. {
  115. case HASHRKT:
  116. if (record->event.pressed)
  117. {
  118. SEND_STRING("=>");
  119. }
  120. break;
  121. case CLNEQLS:
  122. if (record->event.pressed)
  123. {
  124. SEND_STRING(":=");
  125. }
  126. break;
  127. case QWERTY:
  128. if (record->event.pressed)
  129. {
  130. print("mode just switched to qwerty and this is a huge string\n");
  131. set_single_persistent_default_layer(_QWERTY);
  132. }
  133. return false;
  134. break;
  135. case BACKLIT:
  136. if (record->event.pressed)
  137. {
  138. register_code(KC_RSFT);
  139. #ifdef BACKLIGHT_ENABLE
  140. backlight_step();
  141. #endif
  142. #ifdef KEYBOARD_planck_rev5
  143. PORTE &= ~(1 << 6);
  144. #endif
  145. }
  146. else
  147. {
  148. unregister_code(KC_RSFT);
  149. #ifdef KEYBOARD_planck_rev5
  150. PORTE |= (1 << 6);
  151. #endif
  152. }
  153. return false;
  154. break;
  155. }
  156. return true;
  157. }
  158. bool muse_mode = false;
  159. uint8_t last_muse_note = 0;
  160. uint16_t muse_counter = 0;
  161. uint8_t muse_offset = 70;
  162. uint16_t muse_tempo = 50;
  163. void encoder_update(bool clockwise)
  164. {
  165. if (muse_mode)
  166. {
  167. if (IS_LAYER_ON(_RAISE))
  168. {
  169. if (clockwise)
  170. {
  171. muse_offset++;
  172. }
  173. else
  174. {
  175. muse_offset--;
  176. }
  177. }
  178. else
  179. {
  180. if (clockwise)
  181. {
  182. muse_tempo += 1;
  183. }
  184. else
  185. {
  186. muse_tempo -= 1;
  187. }
  188. }
  189. }
  190. else
  191. {
  192. if (clockwise)
  193. {
  194. #ifdef MOUSEKEY_ENABLE
  195. register_code(KC_MS_WH_DOWN);
  196. unregister_code(KC_MS_WH_DOWN);
  197. #else
  198. register_code(KC_PGDN);
  199. unregister_code(KC_PGDN);
  200. #endif
  201. }
  202. else
  203. {
  204. #ifdef MOUSEKEY_ENABLE
  205. register_code(KC_MS_WH_UP);
  206. unregister_code(KC_MS_WH_UP);
  207. #else
  208. register_code(KC_PGUP);
  209. unregister_code(KC_PGUP);
  210. #endif
  211. }
  212. }
  213. }
  214. void dip_update(uint8_t index, bool active)
  215. {
  216. switch (index)
  217. {
  218. case 0:
  219. if (active)
  220. {
  221. #ifdef AUDIO_ENABLE
  222. PLAY_SONG(plover_song);
  223. #endif
  224. layer_on(_ADJUST);
  225. }
  226. else
  227. {
  228. #ifdef AUDIO_ENABLE
  229. PLAY_SONG(plover_gb_song);
  230. #endif
  231. layer_off(_ADJUST);
  232. }
  233. break;
  234. case 1:
  235. if (active)
  236. {
  237. muse_mode = true;
  238. }
  239. else
  240. {
  241. muse_mode = false;
  242. #ifdef AUDIO_ENABLE
  243. stop_all_notes();
  244. #endif
  245. }
  246. }
  247. }
  248. void matrix_scan_user(void)
  249. {
  250. #ifdef AUDIO_ENABLE
  251. if (muse_mode)
  252. {
  253. if (muse_counter == 0)
  254. {
  255. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  256. if (muse_note != last_muse_note)
  257. {
  258. stop_note(compute_freq_for_midi_note(last_muse_note));
  259. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  260. last_muse_note = muse_note;
  261. }
  262. }
  263. muse_counter = (muse_counter + 1) % muse_tempo;
  264. }
  265. #endif
  266. }
  267. bool music_mask_user(uint16_t keycode)
  268. {
  269. switch (keycode)
  270. {
  271. case RAISE:
  272. case LOWER:
  273. return false;
  274. default:
  275. return true;
  276. }
  277. }