keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 planck_layers {
  19. _QWERTY,
  20. _COLEMAK,
  21. _LOWER,
  22. _RAISE,
  23. _ADJUST
  24. };
  25. enum planck_keycodes {
  26. QWERTY = SAFE_RANGE,
  27. COLEMAK
  28. };
  29. #define LOWER MO(_LOWER)
  30. #define RAISE MO(_RAISE)
  31. #define SHENT MT(MOD_RSFT, KC_ENT)
  32. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  33. /* Qwerty
  34. * ,-----------------------------------------------------------------------------------.
  35. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  36. * |------+------+------+------+------+------+------+------+------+------+------+------|
  37. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  38. * |------+------+------+------+------+------+------+------+------+------+------+------|
  39. * | Shift| Z | X | C | V | B | N | M | , | . | / |shent |
  40. * |------+------+------+------+------+------+------+------+------+------+------+------|
  41. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  42. * `-----------------------------------------------------------------------------------'
  43. */
  44. [_QWERTY] = LAYOUT_planck_grid(
  45. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  46. QK_GESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  47. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SHENT ,
  48. _______,KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  49. ),
  50. /* Colemak
  51. * ,-----------------------------------------------------------------------------------.
  52. * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
  53. * |------+------+------+------+------+------+------+------+------+------+------+------|
  54. * | Esc | A | R | S | T | D | H | N | E | I | O | " |
  55. * |------+------+------+------+------+------+------+------+------+------+------+------|
  56. * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
  57. * |------+------+------+------+------+------+------+------+------+------+------+------|
  58. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  59. * `-----------------------------------------------------------------------------------'
  60. */
  61. [_COLEMAK] = LAYOUT_planck_grid(
  62. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
  63. QK_GESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
  64. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, SHENT ,
  65. _______,KC_LCTL, KC_LALT,KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  66. ),
  67. /* Lower
  68. * ,-----------------------------------------------------------------------------------.
  69. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  70. * |------+------+------+------+------+------+------+------+------+------+------+------|
  71. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  72. * |------+------+------+------+------+------+------+------+------+------+------+------|
  73. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | |
  74. * |------+------+------+------+------+------+------+------+------+------+------+------|
  75. * | | | | | | | | Next | Vol- | Vol+ | Play |
  76. * `-----------------------------------------------------------------------------------'
  77. */
  78. [_LOWER] = LAYOUT_planck_grid(
  79. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  80. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  81. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______,
  82. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  83. ),
  84. /* Raise
  85. * ,-----------------------------------------------------------------------------------.
  86. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  87. * |------+------+------+------+------+------+------+------+------+------+------+------|
  88. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  89. * |------+------+------+------+------+------+------+------+------+------+------+------|
  90. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | |
  91. * |------+------+------+------+------+------+------+------+------+------+------+------|
  92. * | | | | | | | | Next | Vol- | Vol+ | Play |
  93. * `-----------------------------------------------------------------------------------'
  94. */
  95. [_RAISE] = LAYOUT_planck_grid(
  96. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  97. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  98. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______,
  99. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  100. ),
  101. /* Adjust (Lower + Raise)
  102. * v------------------------RGB CONTROL--------------------v
  103. * ,-----------------------------------------------------------------------------------.
  104. * | | Reset|Debug | RGB |RGBMOD| HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-| Del |
  105. * |------+------+------+------+------+------+------+------+------+------+------+------|
  106. * | | |MUSmod|Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk| | | |
  107. * |------+------+------+------+------+------+------+------+------+------+------+------|
  108. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  109. * |------+------+------+------+------+------+------+------+------+------+------+------|
  110. * | | | | | | | | | | | |
  111. * `-----------------------------------------------------------------------------------'
  112. */
  113. [_ADJUST] = LAYOUT_planck_grid(
  114. _______, QK_BOOT, DB_TOGG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL ,
  115. _______, _______, MU_NEXT, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, _______, _______, _______,
  116. _______, AU_PREV, AU_NEXT, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______,
  117. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  118. )
  119. };
  120. #ifdef AUDIO_ENABLE
  121. float plover_song[][2] = SONG(PLOVER_SOUND);
  122. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  123. #endif
  124. layer_state_t layer_state_set_user(layer_state_t state) {
  125. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  126. }
  127. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  128. switch (keycode) {
  129. case QWERTY:
  130. if (record->event.pressed) {
  131. print("mode just switched to qwerty and this is a huge string\n");
  132. set_single_persistent_default_layer(_QWERTY);
  133. }
  134. return false;
  135. break;
  136. case COLEMAK:
  137. if (record->event.pressed) {
  138. set_single_persistent_default_layer(_COLEMAK);
  139. }
  140. return false;
  141. break;
  142. }
  143. return true;
  144. }
  145. bool muse_mode = false;
  146. uint8_t last_muse_note = 0;
  147. uint16_t muse_counter = 0;
  148. uint8_t muse_offset = 70;
  149. uint16_t muse_tempo = 50;
  150. bool encoder_update(bool clockwise) {
  151. if (muse_mode) {
  152. if (IS_LAYER_ON(_RAISE)) {
  153. if (clockwise) {
  154. muse_offset++;
  155. } else {
  156. muse_offset--;
  157. }
  158. } else {
  159. if (clockwise) {
  160. muse_tempo+=1;
  161. } else {
  162. muse_tempo-=1;
  163. }
  164. }
  165. } else {
  166. if (clockwise) {
  167. #ifdef MOUSEKEY_ENABLE
  168. tap_code(KC_MS_WH_DOWN);
  169. #else
  170. tap_code(KC_PGDN);
  171. #endif
  172. } else {
  173. #ifdef MOUSEKEY_ENABLE
  174. tap_code(KC_MS_WH_UP);
  175. #else
  176. tap_code(KC_PGUP);
  177. #endif
  178. }
  179. }
  180. return true;
  181. }
  182. bool dip_switch_update_user(uint8_t index, bool active) {
  183. switch (index) {
  184. case 0: {
  185. #ifdef AUDIO_ENABLE
  186. static bool play_sound = false;
  187. #endif
  188. if (active) {
  189. #ifdef AUDIO_ENABLE
  190. if (play_sound) { PLAY_SONG(plover_song); }
  191. #endif
  192. layer_on(_ADJUST);
  193. } else {
  194. #ifdef AUDIO_ENABLE
  195. if (play_sound) { PLAY_SONG(plover_gb_song); }
  196. #endif
  197. layer_off(_ADJUST);
  198. }
  199. #ifdef AUDIO_ENABLE
  200. play_sound = true;
  201. #endif
  202. break;
  203. }
  204. case 1:
  205. if (active) {
  206. muse_mode = true;
  207. } else {
  208. muse_mode = false;
  209. }
  210. }
  211. return true;
  212. }
  213. void matrix_scan_user(void) {
  214. #ifdef AUDIO_ENABLE
  215. if (muse_mode) {
  216. if (muse_counter == 0) {
  217. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  218. if (muse_note != last_muse_note) {
  219. stop_note(compute_freq_for_midi_note(last_muse_note));
  220. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  221. last_muse_note = muse_note;
  222. }
  223. }
  224. muse_counter = (muse_counter + 1) % muse_tempo;
  225. } else {
  226. if (muse_counter) {
  227. stop_all_notes();
  228. muse_counter = 0;
  229. }
  230. }
  231. #endif
  232. }
  233. bool music_mask_user(uint16_t keycode) {
  234. switch (keycode) {
  235. case RAISE:
  236. case LOWER:
  237. return false;
  238. default:
  239. return true;
  240. }
  241. }