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.

239 lines
8.8 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. _QWERTY,
  21. _LOWER,
  22. _RAISE,
  23. _ADJUST
  24. };
  25. enum planck_keycodes {
  26. QWERTY = SAFE_RANGE,
  27. BACKLIT,
  28. MY_PWD
  29. };
  30. #define LOWER MO(_LOWER)
  31. #define RAISE MO(_RAISE)
  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 | , | . | / |Enter |
  40. * |------+------+------+------+------+------+------+------+------+------+------+------|
  41. * | Ctrl | Alt | GUI |Brite |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. KC_ESC, 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, KC_ENT ,
  48. KC_LCTL, KC_LALT, KC_LGUI, BACKLIT, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  49. ),
  50. /* Lower
  51. * ,-----------------------------------------------------------------------------------.
  52. * | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  53. * |------+------+------+------+------+-------------+------+------+------+------+------|
  54. * | | Prev | Play | Next | | | * | 4 | 5 | 6 | - | Del |
  55. * |------+------+------+------+------+------|------+------+------+------+------+------|
  56. * | Pwd | Vol- | MUTE | Vol+ | | | / | 1 | 2 | 3 | + | PgUp |
  57. * |------+------+------+------+------+------+------+------+------+------+------+------|
  58. * | | | | | | | | 0 | . | = | PgDn |
  59. * `-----------------------------------------------------------------------------------'
  60. */
  61. [_LOWER] = LAYOUT_planck_grid(
  62. _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  63. _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, _______, KC_ASTR, KC_4, KC_5, KC_6, KC_MINS, KC_DEL,
  64. MY_PWD, KC_VOLD, KC_MUTE, KC_VOLU, _______, _______, KC_SLSH, KC_1, KC_2, KC_3, KC_PLUS, KC_PGUP,
  65. _______, _______, _______, _______, _______, _______, _______, _______, KC_0, KC_DOT, KC_EQL, KC_PGDN
  66. ),
  67. /* Raise
  68. * ,-----------------------------------------------------------------------------------.
  69. * | ` | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  70. * |------+------+------+------+------+-------------+------+------+------+------+------|
  71. * | | ~ | | / | { | [ | ] | } | \ | - | + | | |
  72. * |------+------+------+------+------+------|------+------+------+------+------+------|
  73. * | | | | | | | | | | _ | = | |
  74. * |------+------+------+------+------+------+------+------+------+------+------+------|
  75. * | | | | | | | | Home | PgDn | PgUp | End |
  76. * `-----------------------------------------------------------------------------------'
  77. */
  78. [_RAISE] = LAYOUT_planck_grid(
  79. KC_GRV, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  80. _______, KC_TILD, _______, KC_SLSH, KC_LCBR, KC_LBRC, KC_RBRC, KC_RCBR, KC_BSLS, KC_MINS, KC_PLUS, KC_PIPE,
  81. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_UNDS, KC_EQL, _______,
  82. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END
  83. ),
  84. /* Adjust (Lower + Raise)
  85. * ,-----------------------------------------------------------------------------------.
  86. * | | Reset| | | | | | | | | | Del |
  87. * |------+------+------+------+------+-------------+------+------+------+------+------|
  88. * | | | |Aud on|Audoff|AGnorm|AGswap| | | | | |
  89. * |------+------+------+------+------+------|------+------+------+------+------+------|
  90. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  91. * |------+------+------+------+------+------+------+------+------+------+------+------|
  92. * | | | | | | | | | | | |
  93. * `-----------------------------------------------------------------------------------'
  94. */
  95. [_ADJUST] = LAYOUT_planck_grid(
  96. _______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL ,
  97. _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______,
  98. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______,
  99. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  100. )
  101. };
  102. #ifdef AUDIO_ENABLE
  103. float plover_song[][2] = SONG(PLOVER_SOUND);
  104. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  105. #endif
  106. layer_state_t layer_state_set_user(layer_state_t state) {
  107. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  108. }
  109. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  110. switch (keycode) {
  111. case BACKLIT:
  112. if (record->event.pressed) {
  113. register_code(KC_RSFT);
  114. #ifdef BACKLIGHT_ENABLE
  115. backlight_step();
  116. #endif
  117. #ifdef KEYBOARD_planck_rev5
  118. PORTE &= ~(1<<6);
  119. #endif
  120. } else {
  121. unregister_code(KC_RSFT);
  122. #ifdef KEYBOARD_planck_rev5
  123. PORTE |= (1<<6);
  124. #endif
  125. }
  126. return false;
  127. break;
  128. case MY_PWD:
  129. if (record->event.pressed) {
  130. SEND_STRING("My secret password!");
  131. false;
  132. }
  133. break;
  134. }
  135. return true;
  136. }
  137. bool muse_mode = false;
  138. uint8_t last_muse_note = 0;
  139. uint16_t muse_counter = 0;
  140. uint8_t muse_offset = 70;
  141. uint16_t muse_tempo = 50;
  142. bool encoder_update_user(uint8_t index, bool clockwise) {
  143. if (muse_mode) {
  144. if (IS_LAYER_ON(_RAISE)) {
  145. if (clockwise) {
  146. muse_offset++;
  147. } else {
  148. muse_offset--;
  149. }
  150. } else {
  151. if (clockwise) {
  152. muse_tempo+=1;
  153. } else {
  154. muse_tempo-=1;
  155. }
  156. }
  157. } else {
  158. if (clockwise) {
  159. register_code(KC_PGDN);
  160. unregister_code(KC_PGDN);
  161. } else {
  162. register_code(KC_PGUP);
  163. unregister_code(KC_PGUP);
  164. }
  165. }
  166. return true;
  167. }
  168. bool dip_switch_update_user(uint8_t index, bool active) {
  169. switch (index) {
  170. case 0:
  171. if (active) {
  172. #ifdef AUDIO_ENABLE
  173. PLAY_SONG(plover_song);
  174. #endif
  175. layer_on(_ADJUST);
  176. } else {
  177. #ifdef AUDIO_ENABLE
  178. PLAY_SONG(plover_gb_song);
  179. #endif
  180. layer_off(_ADJUST);
  181. }
  182. break;
  183. case 1:
  184. if (active) {
  185. muse_mode = true;
  186. } else {
  187. muse_mode = false;
  188. #ifdef AUDIO_ENABLE
  189. stop_all_notes();
  190. #endif
  191. }
  192. }
  193. return true;
  194. }
  195. void matrix_scan_user(void) {
  196. #ifdef AUDIO_ENABLE
  197. if (muse_mode) {
  198. if (muse_counter == 0) {
  199. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  200. if (muse_note != last_muse_note) {
  201. stop_note(compute_freq_for_midi_note(last_muse_note));
  202. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  203. last_muse_note = muse_note;
  204. }
  205. }
  206. muse_counter = (muse_counter + 1) % muse_tempo;
  207. }
  208. #endif
  209. }
  210. bool music_mask_user(uint16_t keycode) {
  211. switch (keycode) {
  212. case RAISE:
  213. case LOWER:
  214. return false;
  215. default:
  216. return true;
  217. }
  218. }