keymap.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 "hvp.c"
  17. #include QMK_KEYBOARD_H
  18. #include "muse.h"
  19. enum planck_layers {
  20. _QWERTY,
  21. _LOWER,
  22. _RAISE,
  23. _NAVI,
  24. _ADJUST
  25. };
  26. enum planck_keycodes {
  27. QWERTY = SAFE_RANGE
  28. };
  29. #define _QWERTY 0
  30. #define _RAISE 1
  31. #define _LOWER 2
  32. #define _NAVI 3
  33. #define _ADJUST 5
  34. #define LT3_ESC LT(3, KC_ESC)
  35. #define LT4_TAB LT(5, KC_TAB)
  36. #define LOWER MO(_LOWER)
  37. #define RAISE MO(_RAISE)
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39. [_QWERTY] = LAYOUT_planck_grid(
  40. LT4_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  41. LT3_ESC, KC_A, KC_S, KC_D, LT(3,KC_F), KC_G, KC_H, KC_J, KC_K, KC_L, TD(TD1), TD(TD2),
  42. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, TD(TD3), KC_SFTENT,
  43. KC_LCTL, KC_APP, KC_LGUI, KC_LALT, MO(2), KC_SPC, KC_SPC, MO(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  44. ),
  45. [_RAISE] = LAYOUT_planck_grid( /* Right */
  46. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  47. KC_DEL, _______, _______, _______, _______, _______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  48. _______, _______, _______, _______, _______, _______, _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  49. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END
  50. ),
  51. [_LOWER] = LAYOUT_planck_grid( /* Left */
  52. KC_TILDE, KC_EXCLAIM, KC_AT, KC_HASH, KC_DOLLAR, KC_PERCENT, KC_CIRCUMFLEX, KC_AMPERSAND, KC_ASTERISK, KC_LEFT_PAREN, KC_RIGHT_PAREN, KC_BSPC,
  53. KC_DEL, _______, _______, _______, _______, _______, _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_BSLS,
  54. _______, _______, _______, _______, _______, _______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_TILD,
  55. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END
  56. ),
  57. [_NAVI] = LAYOUT_planck_grid( /* Esc */
  58. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  59. _______, _______, _______, D_NAVI, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, _______, KC_PSCR,
  60. _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END, _______, _______,
  61. _______, _______, _______, _______, KC_MSTP, KC_MPLY, KC_MPLY, KC_MSTP, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT
  62. ),
  63. [_ADJUST] = LAYOUT_planck_grid( /* Tab */
  64. _______, _______, AG_NORM, AG_SWAP, _______, _______, _______, KC_7, KC_8, KC_9, KC_0, _______,
  65. _______, _______, MU_MOD, AU_ON, AU_OFF, _______, _______, KC_4, KC_5, KC_6, _______, _______,
  66. KC_PSCR, MUV_DE, MUV_IN, MU_ON, MU_OFF, _______, _______, KC_0, KC_1, KC_2, KC_3, _______,
  67. RESET, _______, TERM_ON, TERM_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______, DEBUG
  68. )};
  69. #ifdef AUDIO_ENABLE
  70. float plover_song[][2] = SONG(PLOVER_SOUND);
  71. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  72. #endif
  73. bool muse_mode = false;
  74. uint8_t last_muse_note = 0;
  75. uint16_t muse_counter = 0;
  76. uint8_t muse_offset = 70;
  77. uint16_t muse_tempo = 50;
  78. void encoder_update(bool clockwise) {
  79. if (muse_mode) {
  80. if (IS_LAYER_ON(_RAISE)) {
  81. if (clockwise) {
  82. muse_offset++;
  83. } else {
  84. muse_offset--;
  85. }
  86. } else {
  87. if (clockwise) {
  88. muse_tempo+=1;
  89. } else {
  90. muse_tempo-=1;
  91. }
  92. }
  93. } else {
  94. if (clockwise) {
  95. #ifdef MOUSEKEY_ENABLE
  96. tap_code(KC_MS_WH_DOWN);
  97. #else
  98. tap_code(KC_PGDN);
  99. #endif
  100. } else {
  101. #ifdef MOUSEKEY_ENABLE
  102. tap_code(KC_MS_WH_UP);
  103. #else
  104. tap_code(KC_PGUP);
  105. #endif
  106. }
  107. }
  108. }
  109. void dip_switch_update_user(uint8_t index, bool active) {
  110. switch (index) {
  111. case 0: {
  112. #ifdef AUDIO_ENABLE
  113. static bool play_sound = false;
  114. #endif
  115. if (active) {
  116. #ifdef AUDIO_ENABLE
  117. if (play_sound) { PLAY_SONG(plover_song); }
  118. #endif
  119. layer_on(_ADJUST);
  120. } else {
  121. #ifdef AUDIO_ENABLE
  122. if (play_sound) { PLAY_SONG(plover_gb_song); }
  123. #endif
  124. layer_off(_ADJUST);
  125. }
  126. #ifdef AUDIO_ENABLE
  127. play_sound = true;
  128. #endif
  129. break;
  130. }
  131. case 1:
  132. if (active) {
  133. muse_mode = true;
  134. } else {
  135. muse_mode = false;
  136. }
  137. }
  138. }
  139. void matrix_scan_user(void) {
  140. #ifdef AUDIO_ENABLE
  141. if (muse_mode) {
  142. if (muse_counter == 0) {
  143. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  144. if (muse_note != last_muse_note) {
  145. stop_note(compute_freq_for_midi_note(last_muse_note));
  146. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  147. last_muse_note = muse_note;
  148. }
  149. }
  150. muse_counter = (muse_counter + 1) % muse_tempo;
  151. } else {
  152. if (muse_counter) {
  153. stop_all_notes();
  154. muse_counter = 0;
  155. }
  156. }
  157. #endif
  158. }
  159. bool music_mask_user(uint16_t keycode) {
  160. switch (keycode) {
  161. case RAISE:
  162. case LOWER:
  163. return false;
  164. default:
  165. return true;
  166. }
  167. }