keymap.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Copyright 2015-2017 Jack Humbert
  2. * Updated for VIA 2021 George Wietor
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include QMK_KEYBOARD_H
  18. #include "muse.h"
  19. enum preonic_layers {
  20. _QWERTY,
  21. _LOWER,
  22. _RAISE,
  23. _ADJUST
  24. };
  25. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. /* Qwerty
  27. * ,-----------------------------------------------------------------------------------.
  28. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  29. * |------+------+------+------+------+------+------+------+------+------+------+------|
  30. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Del |
  31. * |------+------+------+------+------+-------------+------+------+------+------+------|
  32. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  33. * |------+------+------+------+------+------|------+------+------+------+------+------|
  34. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  35. * |------+------+------+------+------+------+------+------+------+------+------+------|
  36. * | | Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  37. * `-----------------------------------------------------------------------------------'
  38. */
  39. [_QWERTY] = LAYOUT_preonic_grid(
  40. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  41. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL,
  42. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  43. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT,
  44. _______, KC_LCTL, KC_LALT, KC_LGUI, FN_MO13, KC_SPC, KC_SPC, FN_MO23, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  45. ),
  46. /* Lower
  47. * ,-----------------------------------------------------------------------------------.
  48. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  49. * |------+------+------+------+------+-------------+------+------+------+------+------|
  50. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del |
  51. * |------+------+------+------+------+-------------+------+------+------+------+------|
  52. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  53. * |------+------+------+------+------+------|------+------+------+------+------+------|
  54. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | | |
  55. * |------+------+------+------+------+------+------+------+------+------+------+------|
  56. * | | | | | | | | Next | Vol- | Vol+ | Play |
  57. * `-----------------------------------------------------------------------------------'
  58. */
  59. [_LOWER] = LAYOUT_preonic_grid(
  60. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  61. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  62. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  63. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),KC_HOME, KC_END, _______,
  64. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  65. ),
  66. /* Raise
  67. * ,-----------------------------------------------------------------------------------.
  68. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  69. * |------+------+------+------+------+------+------+------+------+------+------+------|
  70. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del |
  71. * |------+------+------+------+------+-------------+------+------+------+------+------|
  72. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  73. * |------+------+------+------+------+------|------+------+------+------+------+------|
  74. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | | |
  75. * |------+------+------+------+------+------+------+------+------+------+------+------|
  76. * | | | | | | | | Next | Vol- | Vol+ | Play |
  77. * `-----------------------------------------------------------------------------------'
  78. */
  79. [_RAISE] = LAYOUT_preonic_grid(
  80. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  81. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  82. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  83. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______,
  84. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  85. ),
  86. /* Adjust (Lower + Raise)
  87. * ,-----------------------------------------------------------------------------------.
  88. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  89. * |------+------+------+------+------+------+------+------+------+------+------+------|
  90. * | | Reset| Debug| | | | | | | | | Del |
  91. * |------+------+------+------+------+-------------+------+------+------+------+------|
  92. * | | |Mu Mod|Aud on|AudOff| | | | | | | |
  93. * |------+------+------+------+------+------|------+------+------+------+------+------|
  94. * | | | |Mus on|MusOff| | | | | | | |
  95. * |------+------+------+------+------+------+------+------+------+------+------+------|
  96. * | | | | | | | | | | | |
  97. * `-----------------------------------------------------------------------------------'
  98. */
  99. [_ADJUST] = LAYOUT_preonic_grid(
  100. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  101. _______, QK_BOOT, DEBUG, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
  102. _______, _______, MU_MOD, AU_ON, AU_OFF, _______, _______, _______, _______, _______, _______, _______,
  103. _______, _______, _______, MU_ON, MU_OFF, _______, _______, _______, _______, _______, _______, _______,
  104. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  105. )
  106. };
  107. bool muse_mode = false;
  108. uint8_t last_muse_note = 0;
  109. uint16_t muse_counter = 0;
  110. uint8_t muse_offset = 70;
  111. uint16_t muse_tempo = 50;
  112. bool encoder_update_user(uint8_t index, bool clockwise) {
  113. if (muse_mode) {
  114. if (IS_LAYER_ON(_RAISE)) {
  115. if (clockwise) {
  116. muse_offset++;
  117. } else {
  118. muse_offset--;
  119. }
  120. } else {
  121. if (clockwise) {
  122. muse_tempo+=1;
  123. } else {
  124. muse_tempo-=1;
  125. }
  126. }
  127. } else {
  128. if (clockwise) {
  129. register_code(KC_PGDN);
  130. unregister_code(KC_PGDN);
  131. } else {
  132. register_code(KC_PGUP);
  133. unregister_code(KC_PGUP);
  134. }
  135. }
  136. return true;
  137. }
  138. bool dip_switch_update_user(uint8_t index, bool active) {
  139. switch (index) {
  140. case 0:
  141. if (active) {
  142. layer_on(_ADJUST);
  143. } else {
  144. layer_off(_ADJUST);
  145. }
  146. break;
  147. case 1:
  148. if (active) {
  149. muse_mode = true;
  150. } else {
  151. muse_mode = false;
  152. }
  153. }
  154. return true;
  155. }
  156. void matrix_scan_user(void) {
  157. #ifdef AUDIO_ENABLE
  158. if (muse_mode) {
  159. if (muse_counter == 0) {
  160. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  161. if (muse_note != last_muse_note) {
  162. stop_note(compute_freq_for_midi_note(last_muse_note));
  163. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  164. last_muse_note = muse_note;
  165. }
  166. }
  167. muse_counter = (muse_counter + 1) % muse_tempo;
  168. } else {
  169. if (muse_counter) {
  170. stop_all_notes();
  171. muse_counter = 0;
  172. }
  173. }
  174. #endif
  175. }
  176. bool music_mask_user(uint16_t keycode) {
  177. switch (keycode) {
  178. case FN_MO13:
  179. case FN_MO23:
  180. return false;
  181. default:
  182. return true;
  183. }
  184. }