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.

241 lines
8.5 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. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  19. /* Default layer
  20. * ,-----------------------------------------------------------------------------------.
  21. * | Q | W | E | R | T | | | Y | U | I | O | P |
  22. * |------+------+------+------+------+------+------+------+------+------+------+------|
  23. * | A | S | D | F | G | | | H | J | K | L | ; |
  24. * |------+------+------+------+------+------+------+------+------+------+------+------|
  25. * | Z | X | C | V | B | ` | \ | N | M | , | . | / |
  26. * |------+------+------+------+------+------+------+------+------+------+------+------|
  27. * | Esc | Tab | GUI | Shift| Bksp | Ctrl | Alt |Space | Fun | - | ' |Enter |
  28. * `-----------------------------------------------------------------------------------'
  29. */
  30. [0] = LAYOUT_ortho_4x12(
  31. KC_Q, KC_W, KC_E, KC_R, KC_T, KC_NO, KC_NO, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_A, KC_S, KC_D, KC_F, KC_G, KC_NO, KC_NO, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_GRV, KC_BSLS, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ESC, KC_TAB, KC_LGUI, KC_LSFT, KC_BSPC, KC_LCTL, KC_LALT, KC_SPC, MO(1), KC_MINS, KC_QUOT, KC_ENT),
  32. /* Function layer
  33. * ,-----------------------------------------------------------------------------------.
  34. * | ! | @ | Up | $ | % | | | PgUp | 7 | 8 | 9 | Bksp |
  35. * |------+------+------+------+------+------+------+------+------+------+------+------|
  36. * | ( | Left | Down |Right | ) | | | PgDn | 4 | 5 | 6 | |
  37. * |------+------+------+------+------+------+------+------+------+------+------+------|
  38. * | [ | ] | # | { | } | ^ | & | * | 1 | 2 | 3 | + |
  39. * |------+------+------+------+------+------+------+------+------+------+------+------|
  40. * | Upper| Ins | | | | | | | | . | 0 | = |
  41. * `-----------------------------------------------------------------------------------'
  42. */
  43. [1] = LAYOUT_ortho_4x12(
  44. KC_EXLM, KC_AT, KC_UP, KC_DLR, KC_PERC, KC_NO, KC_NO, KC_PGUP, KC_7, KC_8, KC_9, KC_BSPC, KC_LPRN, KC_LEFT, KC_DOWN, KC_RGHT, KC_RPRN, KC_NO, KC_NO, KC_PGDN, KC_4, KC_5, KC_6, KC_NO, KC_LBRC, KC_RBRC, KC_HASH, KC_LCBR, KC_RCBR, KC_CIRC, KC_AMPR, KC_ASTR, KC_1, KC_2, KC_3, KC_PLUS, TG(2), KC_INS, KC_LGUI, KC_LSFT, KC_DEL, KC_LCTL, KC_LALT, KC_SPC, KC_TRNS, KC_DOT, KC_0, KC_EQL),
  45. /* Upper layer
  46. * ,-----------------------------------------------------------------------------------.
  47. * | Ins | Home | | End | PgUp | | | Up | F7 | F8 | F9 | F10 |
  48. * |------+------+------+------+------+------+------+------+------+------+------+------|
  49. * | Del | | | | PgDn | | | Down | F4 | F5 | F6 | F11 |
  50. * |------+------+------+------+------+------+------+------+------+------+------+------|
  51. * | | Vol+ | | | | | | | F1 | F2 | F3 | F12 |
  52. * |------+------+------+------+------+------+------+------+------+------+------+------|
  53. * | | Vol- | | | | | | | |PrtSc |ScrLk | Play |
  54. * `-----------------------------------------------------------------------------------'
  55. */
  56. [2] = LAYOUT_ortho_4x12(
  57. KC_INS, KC_HOME, KC_UP, KC_END, KC_PGUP, KC_NO, KC_NO, KC_UP, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL, KC_LEFT, KC_DOWN, KC_RGHT, KC_PGDN, KC_NO, KC_NO, KC_DOWN, KC_F4, KC_F5, KC_F6, KC_F11, KC_NO, KC_VOLU, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_F1, KC_F2, KC_F3, KC_F12, KC_NO, KC_VOLD, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, TO(0), KC_PSCR, KC_SLCK, KC_MPLY)
  58. };
  59. #ifdef AUDIO_ENABLE
  60. float plover_song[][2] = SONG(PLOVER_SOUND);
  61. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  62. #endif
  63. layer_state_t layer_state_set_user(layer_state_t state) {
  64. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  65. }
  66. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  67. switch (keycode) {
  68. case QWERTY:
  69. if (record->event.pressed) {
  70. print("mode just switched to qwerty and this is a huge string\n");
  71. set_single_persistent_default_layer(_QWERTY);
  72. }
  73. return false;
  74. break;
  75. case COLEMAK:
  76. if (record->event.pressed) {
  77. set_single_persistent_default_layer(_COLEMAK);
  78. }
  79. return false;
  80. break;
  81. case DVORAK:
  82. if (record->event.pressed) {
  83. set_single_persistent_default_layer(_DVORAK);
  84. }
  85. return false;
  86. break;
  87. case BACKLIT:
  88. if (record->event.pressed) {
  89. register_code(KC_RSFT);
  90. #ifdef BACKLIGHT_ENABLE
  91. backlight_step();
  92. #endif
  93. #ifdef KEYBOARD_planck_rev5
  94. writePinLow(E6);
  95. #endif
  96. } else {
  97. unregister_code(KC_RSFT);
  98. #ifdef KEYBOARD_planck_rev5
  99. writePinHigh(E6);
  100. #endif
  101. }
  102. return false;
  103. break;
  104. case PLOVER:
  105. if (record->event.pressed) {
  106. #ifdef AUDIO_ENABLE
  107. stop_all_notes();
  108. PLAY_SONG(plover_song);
  109. #endif
  110. layer_off(_RAISE);
  111. layer_off(_LOWER);
  112. layer_off(_ADJUST);
  113. layer_on(_PLOVER);
  114. if (!eeconfig_is_enabled()) {
  115. eeconfig_init();
  116. }
  117. keymap_config.raw = eeconfig_read_keymap();
  118. keymap_config.nkro = 1;
  119. eeconfig_update_keymap(keymap_config.raw);
  120. }
  121. return false;
  122. break;
  123. case EXT_PLV:
  124. if (record->event.pressed) {
  125. #ifdef AUDIO_ENABLE
  126. PLAY_SONG(plover_gb_song);
  127. #endif
  128. layer_off(_PLOVER);
  129. }
  130. return false;
  131. break;
  132. }
  133. return true;
  134. }
  135. bool muse_mode = false;
  136. uint8_t last_muse_note = 0;
  137. uint16_t muse_counter = 0;
  138. uint8_t muse_offset = 70;
  139. uint16_t muse_tempo = 50;
  140. bool encoder_update(bool clockwise) {
  141. if (muse_mode) {
  142. if (IS_LAYER_ON(_RAISE)) {
  143. if (clockwise) {
  144. muse_offset++;
  145. } else {
  146. muse_offset--;
  147. }
  148. } else {
  149. if (clockwise) {
  150. muse_tempo+=1;
  151. } else {
  152. muse_tempo-=1;
  153. }
  154. }
  155. } else {
  156. if (clockwise) {
  157. #ifdef MOUSEKEY_ENABLE
  158. tap_code(KC_MS_WH_DOWN);
  159. #else
  160. tap_code(KC_PGDN);
  161. #endif
  162. } else {
  163. #ifdef MOUSEKEY_ENABLE
  164. tap_code(KC_MS_WH_UP);
  165. #else
  166. tap_code(KC_PGUP);
  167. #endif
  168. }
  169. }
  170. return true;
  171. }
  172. bool dip_switch_update_user(uint8_t index, bool active) {
  173. switch (index) {
  174. case 0: {
  175. #ifdef AUDIO_ENABLE
  176. static bool play_sound = false;
  177. #endif
  178. if (active) {
  179. #ifdef AUDIO_ENABLE
  180. if (play_sound) { PLAY_SONG(plover_song); }
  181. #endif
  182. layer_on(_ADJUST);
  183. } else {
  184. #ifdef AUDIO_ENABLE
  185. if (play_sound) { PLAY_SONG(plover_gb_song); }
  186. #endif
  187. layer_off(_ADJUST);
  188. }
  189. #ifdef AUDIO_ENABLE
  190. play_sound = true;
  191. #endif
  192. break;
  193. }
  194. case 1:
  195. if (active) {
  196. muse_mode = true;
  197. } else {
  198. muse_mode = false;
  199. }
  200. }
  201. return true;
  202. }
  203. void matrix_scan_user(void) {
  204. #ifdef AUDIO_ENABLE
  205. if (muse_mode) {
  206. if (muse_counter == 0) {
  207. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  208. if (muse_note != last_muse_note) {
  209. stop_note(compute_freq_for_midi_note(last_muse_note));
  210. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  211. last_muse_note = muse_note;
  212. }
  213. }
  214. muse_counter = (muse_counter + 1) % muse_tempo;
  215. } else {
  216. if (muse_counter) {
  217. stop_all_notes();
  218. muse_counter = 0;
  219. }
  220. }
  221. #endif
  222. }
  223. bool music_mask_user(uint16_t keycode) {
  224. switch (keycode) {
  225. case RAISE:
  226. case LOWER:
  227. return false;
  228. default:
  229. return true;
  230. }
  231. }