keymap.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. #include "keymap_swedish.h"
  19. extern keymap_config_t keymap_config;
  20. enum planck_layers {
  21. _COLEMAK,
  22. _LOWER,
  23. _RAISE,
  24. _ADJUST
  25. };
  26. #define LOWER MO(_LOWER)
  27. #define RAISE MO(_RAISE)
  28. /* These definitions can be removed once keymap_swe is properly vetted against MacOS */
  29. #define SE_DLR_MAC_V ALGR(LALT(KC_4))
  30. #define SE_AT_MAC_V ALGR(LALT(KC_2))
  31. /* Esc when pressed, ctrl when used as a modifier */
  32. #define KC_ECTL MT(MOD_LCTL, KC_ESC)
  33. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  34. /* Colemak_se
  35. * ,-----------------------------------------------------------------------------------.
  36. * | Tab | Q | W | F | P | G | J | L | U | Y | Ö | Å |
  37. * |------+------+------+------+------+-------------+------+------+------+------+------|
  38. * | ECTR | A | R | S | T | D | H | N | E | I | O | Ä |
  39. * |------+------+------+------+------+------|------+------+------+------+------+------|
  40. * | SCSHE| Z | X | C | V | B | K | M | , | . | - |SCSHE |
  41. * |------+------+------+------+------+------+------+------+------+------+------+------|
  42. * | esc | CTRL | Alt | CMD |Lower |Space |Bksp |Raise | CMD | RALT | HYPER| MEH |
  43. * `-----------------------------------------------------------------------------------'
  44. */
  45. [_COLEMAK] = LAYOUT_planck_grid
  46. (
  47. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, SE_OSLH, SE_AA,
  48. KC_ECTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, SE_AE,
  49. KC_SFTENT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, SE_MINS, KC_SFTENT,
  50. KC_ESC, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_BSPC, RAISE, KC_RGUI, KC_RALT, KC_HYPR, KC_MEH
  51. ),
  52. /* Lower
  53. * ,-----------------------------------------------------------------------------------.
  54. * | | PIPE | ' | @ | & | | DOWN | | RIGHT| ` | ´ | ~ |
  55. * |------+------+------+------+------+-------------+------+------+------+------+------|
  56. * | | ! | " | # | ? | % | LEFT | / | \ | = | + | * |
  57. * |------+------+------+------+------+------|------+------+------+------+------+------|
  58. * | | | | [ | { | | UP | } | ] | | | |
  59. * |------+------+------+------+------+------+------+------+------+------+------+------|
  60. * | | | | | | | DEL | | Next | Vol- | Vol+ | Play |
  61. * `-----------------------------------------------------------------------------------'
  62. */
  63. [_LOWER] = LAYOUT_planck_grid
  64. (
  65. _______, SE_PIPE_MAC, SE_APOS, SE_AT_MAC_V, SE_AMPR, _______, KC_DOWN, KC_NO, KC_RGHT, SE_GRV, SE_GRV, SE_TILD,
  66. _______, KC_EXLM, SE_QUO2, KC_HASH, SE_QUES, KC_PERC, KC_LEFT, SE_SLSH, SE_BSLS_MAC, SE_EQL, KC_PPLS, KC_PAST,
  67. _______, KC_NO, KC_NO, SE_LBRC, SE_LCBR_MAC, KC_NO, KC_UP, SE_RCBR_MAC, SE_RBRC, KC_NO, KC_NO, _______,
  68. _______, _______, _______, _______, _______, _______, KC_DEL, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  69. ),
  70. /* Raise
  71. * ,-----------------------------------------------------------------------------------.
  72. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  73. * |------+------+------+------+------+-------------+------+------+------+------+------|
  74. * | ^ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | $ |
  75. * |------+------+------+------+------+------|------+------+------+------+------+------|
  76. * | | | | < | ( | | | ) | > |Pg Up |Pg Dn | |
  77. * |------+------+------+------+------+------+------+------+------+------+------+------|
  78. * | | | | | | | | Next | Vol- | Vol+ | Play |
  79. * `-----------------------------------------------------------------------------------'
  80. */
  81. [_RAISE] = LAYOUT_planck_grid
  82. (
  83. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  84. SE_CIRC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SE_DLR_MAC_V,
  85. _______, KC_NO, KC_NO, SE_LESS_MAC, SE_LPRN, KC_NO, KC_NO, SE_RPRN, SE_GRTR_MAC, KC_PGUP, KC_PGDN, KC_NO,
  86. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  87. ),
  88. /* Adjust (Lower + Raise)
  89. * ,-----------------------------------------------------------------------------------.
  90. * | | Reset| Debug| | | | | | | | | |
  91. * |------+------+------+------+------+-------------+------+------+------+------+------|
  92. * | | | |Aud on|Audoff|AGnorm|AGswap| | | | | |
  93. * |------+------+------+------+------+------|------+------+------+------+------+------|
  94. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof|TRMon |TRMoff| | | |
  95. * |------+------+------+------+------+------+------+------+------+------+------+------|
  96. * | | | | | | | | | | | |
  97. * `-----------------------------------------------------------------------------------'
  98. */
  99. [_ADJUST] = LAYOUT_planck_grid
  100. (
  101. _______, RESET, DEBUG, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  102. _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______,
  103. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______,
  104. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  105. )
  106. };
  107. uint32_t layer_state_set_user(uint32_t state) {
  108. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  109. }
  110. bool muse_mode = false;
  111. uint8_t last_muse_note = 0;
  112. uint16_t muse_counter = 0;
  113. uint8_t muse_offset = 70;
  114. uint16_t muse_tempo = 50;
  115. void encoder_update(bool clockwise) {
  116. if (muse_mode) {
  117. if (IS_LAYER_ON(_RAISE)) {
  118. if (clockwise) {
  119. muse_offset++;
  120. } else {
  121. muse_offset--;
  122. }
  123. } else {
  124. if (clockwise) {
  125. muse_tempo+=1;
  126. } else {
  127. muse_tempo-=1;
  128. }
  129. }
  130. } else {
  131. if (clockwise) {
  132. #ifdef MOUSEKEY_ENABLE
  133. register_code(KC_MS_WH_DOWN);
  134. unregister_code(KC_MS_WH_DOWN);
  135. #else
  136. register_code(KC_PGDN);
  137. unregister_code(KC_PGDN);
  138. #endif
  139. } else {
  140. #ifdef MOUSEKEY_ENABLE
  141. register_code(KC_MS_WH_UP);
  142. unregister_code(KC_MS_WH_UP);
  143. #else
  144. register_code(KC_PGUP);
  145. unregister_code(KC_PGUP);
  146. #endif
  147. }
  148. }
  149. }
  150. void dip_update(uint8_t index, bool active) {
  151. switch (index) {
  152. case 0:
  153. if (active) {
  154. layer_on(_ADJUST);
  155. } else {
  156. layer_off(_ADJUST);
  157. }
  158. break;
  159. case 1:
  160. if (active) {
  161. muse_mode = true;
  162. } else {
  163. muse_mode = false;
  164. #ifdef AUDIO_ENABLE
  165. stop_all_notes();
  166. #endif
  167. }
  168. }
  169. }
  170. void matrix_scan_user(void) {
  171. #ifdef AUDIO_ENABLE
  172. if (muse_mode) {
  173. if (muse_counter == 0) {
  174. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  175. if (muse_note != last_muse_note) {
  176. stop_note(compute_freq_for_midi_note(last_muse_note));
  177. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  178. last_muse_note = muse_note;
  179. }
  180. }
  181. muse_counter = (muse_counter + 1) % muse_tempo;
  182. }
  183. #endif
  184. }
  185. bool music_mask_user(uint16_t keycode) {
  186. switch (keycode) {
  187. case RAISE:
  188. case LOWER:
  189. return false;
  190. default:
  191. return true;
  192. }
  193. }