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.

346 lines
12 KiB

  1. /* Copyright 2015-2017 Jack Humbert, Christoffer Holmberg
  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 "keymap_swedish.h"
  18. #include "muse.h"
  19. extern keymap_config_t keymap_config;
  20. enum planck_layers {
  21. _DEFAULT,
  22. _LOWER,
  23. _RAISE,
  24. _UTILITY,
  25. _ADJUST
  26. };
  27. enum planck_keycodes {
  28. DEFAULT = SAFE_RANGE,
  29. RAISE,
  30. LOWER,
  31. UTILITY,
  32. BACKLIT,
  33. S1, S2, S3, S4, S5, S6, S7, S8, S9
  34. };
  35. #define ESC_LOW LT(_LOWER, KC_ESC)
  36. #define BSP_RAI LT(_RAISE, KC_BSPC)
  37. #define LFT_CTR CTL_T(SE_QUOT)
  38. #define RGT_CTR CTL_T(KC_TILD)
  39. #define UTILITY MO(_UTILITY)
  40. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  41. /* Qwerty
  42. * ,-----------------------------------------------------------------------------------.
  43. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Å |
  44. * |------+------+------+------+------+-------------+------+------+------+------+------|
  45. * | Fn | A | S | D | F | G | H | J | K | L | Ö | Ä |
  46. * |------+------+------+------+------+------|------+------+------+------+------+------|
  47. * | Shift| Z | X | C | V | B | N | M | , | . | - |Shift |
  48. * |------+------+------+------+------+------+------+------+------+------+------+------|
  49. * | Ctrl | Super| Alt | |L/Esc | Ret | Space|R/Bspc| |AltGr | * | ¨ |
  50. * `-----------------------------------------------------------------------------------'
  51. */
  52. [_DEFAULT] = LAYOUT_planck_grid(
  53. KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , SE_ARNG,
  54. UTILITY, KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , SE_ODIA, SE_ADIA,
  55. KC_LSPO, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , SE_MINS, KC_RSPC,
  56. LFT_CTR, KC_LALT, KC_LGUI, SE_AT , ESC_LOW, KC_ENT , KC_SPC , BSP_RAI, _______, KC_ALGR, SE_ASTR, RGT_CTR
  57. ),
  58. /* Raise
  59. * ,-----------------------------------------------------------------------------------.
  60. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | + |
  61. * |------+------+------+------+------+-------------+------+------+------+------+------|
  62. * | | | | | | | | | | | | |
  63. * |------+------+------+------+------+------|------+------+------+------+------+------|
  64. * | | | | | | | | | | | | |
  65. * |------+------+------+------+------+------+------+------+------+------+------+------|
  66. * | | | | | | | | | | | | |
  67. * `-----------------------------------------------------------------------------------'
  68. */
  69. [_RAISE] = LAYOUT_planck_grid(
  70. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PLUS,
  71. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  72. _______, SE_RABK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  73. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  74. ),
  75. /* Lower
  76. * ,-----------------------------------------------------------------------------------.
  77. * | | | | | | | | | | | | |
  78. * |------+------+------+------+------+-------------+------+------+------+------+------|
  79. * | | | | | | | | | | | | |
  80. * |------+------+------+------+------+------|------+------+------+------+------+------|
  81. * | | | | | | | | | | | | |
  82. * |------+------+------+------+------+------+------+------+------+------+------+------|
  83. * | | | | | | | | | | | | |
  84. * `-----------------------------------------------------------------------------------'
  85. */
  86. [_LOWER] = LAYOUT_planck_grid(
  87. SE_HALF, LSFT(KC_1), SE_DQUO, LSFT(KC_3), SE_CURR, LSFT(KC_5), SE_AMPR, SE_SLSH, SE_LPRN, SE_RPRN, SE_EQL , SE_QUES,
  88. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  89. _______, SE_LABK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  90. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  91. ),
  92. /* Utility layer
  93. * ,-----------------------------------------------------------------------------------.
  94. * | | | up | | | | | | S1 | S2 | S3 | |
  95. * |------+------+------+------+------+-------------+------+------+------+------+------|
  96. * | | left | down | right| | | | | S4 | S5 | S6 | |
  97. * |------+------+------+------+------+------|------+------+------+------+------+------|
  98. * | | | | | | | | | S7 | S8 | S9 | |
  99. * |------+------+------+------+------+------+------+------+------+------+------+------|
  100. * | | | | | | | | Del | | | | |
  101. * `-----------------------------------------------------------------------------------'
  102. */
  103. [_UTILITY] = LAYOUT_planck_grid(
  104. _______, _______, KC_UP , _______, _______, _______, _______, _______, S1 , S2 , S3 , _______,
  105. _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, S4 , S5 , S6 , _______,
  106. _______, _______, _______, _______, _______, _______, _______, _______, S7 , S8 , S9 , _______,
  107. _______, _______, _______, _______, _______, _______, _______, KC_DEL , _______, _______, _______, _______
  108. ),
  109. /* Adjust (Lower + Raise)
  110. * ,-----------------------------------------------------------------------------------.
  111. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  112. * |------+------+------+------+------+-------------+------+------+------+------+------|
  113. * | |Reset | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | |Utilit| |
  114. * |------+------+------+------+------+------|------+------+------+------+------+------|
  115. * | | | | | | | | | | | | |
  116. * |------+------+------+------+------+------+------+------+------+------+------+------|
  117. * | | | | | | | | | | | | |
  118. * `-----------------------------------------------------------------------------------'
  119. */
  120. [_ADJUST] = LAYOUT_planck_grid(
  121. KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 ,
  122. _______, RESET , MU_MOD , AU_ON , AU_OFF , AG_NORM, AG_SWAP, DEFAULT, XXXXXXX , XXXXXXX, UTILITY, _______,
  123. _______, SE_PIPE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  124. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  125. )
  126. };
  127. #ifdef AUDIO_ENABLE
  128. float plover_song[][2] = SONG(PLOVER_SOUND);
  129. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  130. float s1[][2] = SONG(NUMBER_ONE);
  131. float s2[][2] = SONG(ZELDA_PUZZLE);
  132. float s3[][2] = SONG(ZELDA_TREASURE);
  133. float s4[][2] = SONG(OVERWATCH_THEME);
  134. float s5[][2] = SONG(IMPERIAL_MARCH);
  135. float s6[][2] = SONG(E1M1_DOOM);
  136. float s7[][2] = SONG(COIN_SOUND);
  137. float s8[][2] = SONG(ONE_UP_SOUND);
  138. float s9[][2] = SONG(SONIC_RING);
  139. #endif
  140. layer_state_t layer_state_set_user(layer_state_t state) {
  141. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  142. }
  143. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  144. switch (keycode) {
  145. case DEFAULT:
  146. if (record->event.pressed) {
  147. set_single_persistent_default_layer(_DEFAULT);
  148. }
  149. return false;
  150. break;
  151. case BACKLIT:
  152. if (record->event.pressed) {
  153. register_code(KC_RSFT);
  154. #ifdef BACKLIGHT_ENABLE
  155. backlight_step();
  156. #endif
  157. #ifdef KEYBOARD_planck_rev5
  158. PORTE &= ~(1<<6);
  159. #endif
  160. } else {
  161. unregister_code(KC_RSFT);
  162. #ifdef KEYBOARD_planck_rev5
  163. PORTE |= (1<<6);
  164. #endif
  165. }
  166. return false;
  167. break;
  168. case S1:
  169. if (record->event.pressed) {
  170. #ifdef AUDIO_ENABLE
  171. PLAY_SONG(s1);
  172. #endif //AUDIO_ENABLE
  173. }
  174. return false;
  175. break;
  176. case S2:
  177. if (record->event.pressed) {
  178. #ifdef AUDIO_ENABLE
  179. PLAY_SONG(s2);
  180. #endif //AUDIO_ENABLE
  181. }
  182. return false;
  183. break;
  184. case S3:
  185. if (record->event.pressed) {
  186. #ifdef AUDIO_ENABLE
  187. PLAY_SONG(s3);
  188. #endif //AUDIO_ENABLE
  189. }
  190. return false;
  191. break;
  192. case S4:
  193. if (record->event.pressed) {
  194. #ifdef AUDIO_ENABLE
  195. PLAY_SONG(s4);
  196. #endif //AUDIO_ENABLE
  197. }
  198. return false;
  199. break;
  200. case S5:
  201. if (record->event.pressed) {
  202. #ifdef AUDIO_ENABLE
  203. PLAY_SONG(s5);
  204. #endif //AUDIO_ENABLE
  205. }
  206. return false;
  207. break;
  208. case S6:
  209. if (record->event.pressed) {
  210. #ifdef AUDIO_ENABLE
  211. PLAY_SONG(s6);
  212. #endif //AUDIO_ENABLE
  213. }
  214. return false;
  215. break;
  216. case S7:
  217. if (record->event.pressed) {
  218. #ifdef AUDIO_ENABLE
  219. PLAY_SONG(s7);
  220. #endif //AUDIO_ENABLE
  221. }
  222. return false;
  223. break;
  224. case S8:
  225. if (record->event.pressed) {
  226. #ifdef AUDIO_ENABLE
  227. PLAY_SONG(s8);
  228. #endif //AUDIO_ENABLE
  229. }
  230. return false;
  231. break;
  232. case S9:
  233. if (record->event.pressed) {
  234. #ifdef AUDIO_ENABLE
  235. PLAY_SONG(s9);
  236. #endif //AUDIO_ENABLE
  237. }
  238. return false;
  239. break;
  240. }
  241. return true;
  242. }
  243. bool muse_mode = false;
  244. uint8_t last_muse_note = 0;
  245. uint16_t muse_counter = 0;
  246. uint8_t muse_offset = 70;
  247. uint16_t muse_tempo = 50;
  248. bool encoder_update_user(uint8_t index, bool clockwise) {
  249. if (muse_mode) {
  250. if (IS_LAYER_ON(_RAISE)) {
  251. if (clockwise) {
  252. muse_offset++;
  253. } else {
  254. muse_offset--;
  255. }
  256. } else {
  257. if (clockwise) {
  258. muse_tempo+=1;
  259. } else {
  260. muse_tempo-=1;
  261. }
  262. }
  263. } else {
  264. if (clockwise) {
  265. register_code(KC_PGDN);
  266. unregister_code(KC_PGDN);
  267. } else {
  268. register_code(KC_PGUP);
  269. unregister_code(KC_PGUP);
  270. }
  271. }
  272. return true;
  273. }
  274. bool dip_switch_update_user(uint8_t index, bool active) {
  275. switch (index) {
  276. case 0:
  277. if (active) {
  278. #ifdef AUDIO_ENABLE
  279. PLAY_SONG(plover_song);
  280. #endif
  281. layer_on(_ADJUST);
  282. } else {
  283. #ifdef AUDIO_ENABLE
  284. PLAY_SONG(plover_gb_song);
  285. #endif
  286. layer_off(_ADJUST);
  287. }
  288. break;
  289. case 1:
  290. if (active) {
  291. muse_mode = true;
  292. } else {
  293. muse_mode = false;
  294. #ifdef AUDIO_ENABLE
  295. stop_all_notes();
  296. #endif
  297. }
  298. }
  299. return true;
  300. }
  301. void matrix_scan_user(void) {
  302. #ifdef AUDIO_ENABLE
  303. if (muse_mode) {
  304. if (muse_counter == 0) {
  305. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  306. if (muse_note != last_muse_note) {
  307. stop_note(compute_freq_for_midi_note(last_muse_note));
  308. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  309. last_muse_note = muse_note;
  310. }
  311. }
  312. muse_counter = (muse_counter + 1) % muse_tempo;
  313. }
  314. #endif
  315. }
  316. bool music_mask_user(uint16_t keycode) {
  317. switch (keycode) {
  318. case RAISE:
  319. case LOWER:
  320. return false;
  321. default:
  322. return true;
  323. }
  324. }