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.

297 lines
9.2 KiB

  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. layer_state_t layer_state_set_user(layer_state_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. bool encoder_update_user(uint8_t index, bool clockwise) {
  164. if (muse_mode)
  165. {
  166. if (IS_LAYER_ON(_RAISE))
  167. {
  168. if (clockwise)
  169. {
  170. muse_offset++;
  171. }
  172. else
  173. {
  174. muse_offset--;
  175. }
  176. }
  177. else
  178. {
  179. if (clockwise)
  180. {
  181. muse_tempo += 1;
  182. }
  183. else
  184. {
  185. muse_tempo -= 1;
  186. }
  187. }
  188. }
  189. else
  190. {
  191. if (clockwise)
  192. {
  193. #ifdef MOUSEKEY_ENABLE
  194. register_code(KC_MS_WH_DOWN);
  195. unregister_code(KC_MS_WH_DOWN);
  196. #else
  197. register_code(KC_PGDN);
  198. unregister_code(KC_PGDN);
  199. #endif
  200. }
  201. else
  202. {
  203. #ifdef MOUSEKEY_ENABLE
  204. register_code(KC_MS_WH_UP);
  205. unregister_code(KC_MS_WH_UP);
  206. #else
  207. register_code(KC_PGUP);
  208. unregister_code(KC_PGUP);
  209. #endif
  210. }
  211. }
  212. return true;
  213. }
  214. bool encoder_update_user(uint8_t index, bool clockwise) {
  215. switch (index)
  216. {
  217. case 0:
  218. if (active)
  219. {
  220. #ifdef AUDIO_ENABLE
  221. PLAY_SONG(plover_song);
  222. #endif
  223. layer_on(_ADJUST);
  224. }
  225. else
  226. {
  227. #ifdef AUDIO_ENABLE
  228. PLAY_SONG(plover_gb_song);
  229. #endif
  230. layer_off(_ADJUST);
  231. }
  232. break;
  233. case 1:
  234. if (active)
  235. {
  236. muse_mode = true;
  237. }
  238. else
  239. {
  240. muse_mode = false;
  241. #ifdef AUDIO_ENABLE
  242. stop_all_notes();
  243. #endif
  244. }
  245. }
  246. return true;
  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. }