DatBunnyBoi

Fun Stuff - A Planck Keymap

Oct 3rd, 2018
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.92 KB | None | 0 0
  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.  
  17. #include "planck.h"
  18. #include "action_layer.h"
  19. #include "muse.h"
  20.  
  21. extern keymap_config_t keymap_config;
  22.  
  23. enum planck_layers {
  24. _QWERTY,
  25. _LOWER,
  26. _RAISE,
  27. _ADJUST,
  28. _GREEK_LOWER,
  29. _GREEK_UPPER,
  30. _MIDI_FOR_FUN
  31. };
  32.  
  33. enum planck_keycodes {
  34. QWERTY = SAFE_RANGE,
  35. BACKLIT
  36. };
  37.  
  38. #define LOWER MO(_LOWER)
  39. #define RAISE MO(_RAISE)
  40.  
  41. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  42.  
  43. /* Qwerty
  44. * ,-----------------------------------------------------------------------------------.
  45. * | ~/Esc| Q | W | E | R | T | Y | U | I | O | P | Bksp |
  46. * |------+------+------+------+------+-------------+------+------+------+------+------|
  47. * | Tab | A | S | D | F | G | H | J | K | L | ; | " |
  48. * |------+------+------+------+------+------|------+------+------+------+------+------|
  49. * |KeyLok| Z | X | C | V | B | N | M | , | . | Up |Enter |
  50. * |------+------+------+------+------+------+------+------+------+------+------+------|
  51. * |OSSHFT| Ctrl | Alt | GUI |Lower | Space |Raise | / | Left | Down |Right |
  52. * `-----------------------------------------------------------------------------------'
  53. */
  54. [_QWERTY] = LAYOUT_planck_grid(
  55. KC_GESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  56. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  57. KC_LOCK, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_ENT ,
  58. OSM(MOD_LSFT), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_SLSH, KC_LEFT, KC_DOWN, KC_RGHT
  59. ),
  60.  
  61. /* Lower
  62. * ,-----------------------------------------------------------------------------------.
  63. * | Greek| ! | @ | # | $ | % | ^ | & | * | ( | ) | Del |
  64. * |------+------+------+------+------+-------------+------+------+------+------+------|
  65. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  66. * |------+------+------+------+------+------|------+------+------+------+------+------|
  67. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | |Buton1|MouseU| |
  68. * |------+------+------+------+------+------+------+------+------+------+------+------|
  69. * | | | | MIDI | | | | Next |MouseL|MouseD|MouseR|
  70. * `-----------------------------------------------------------------------------------'
  71. */
  72. [_LOWER] = LAYOUT_planck_grid(
  73. TT(_GREEK_LOWER), KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  74. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  75. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_BTN1, KC_MS_U, _______,
  76. _______, _______, _______, TG(_MIDI_FOR_FUN), _______, _______, _______, _______, KC_MNXT, KC_MS_L, KC_MS_D, KC_MS_R
  77. ),
  78.  
  79. /* Raise
  80. * ,-----------------------------------------------------------------------------------.
  81. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del |
  82. * |------+------+------+------+------+-------------+------+------+------+------+------|
  83. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  84. * |------+------+------+------+------+------|------+------+------+------+------+------|
  85. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up | Vol+ | |
  86. * |------+------+------+------+------+------+------+------+------+------+------+------|
  87. * | | | | | | | | Next |Pg Dwn| Vol+ | Play |
  88. * `-----------------------------------------------------------------------------------'
  89. */
  90. [_RAISE] = LAYOUT_planck_grid(
  91. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  92. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  93. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_VOLU, _______,
  94. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_PGDN, KC_VOLD, KC_MPLY
  95. ),
  96.  
  97. /* Adjust (Lower + Raise)
  98. * ,-----------------------------------------------------------------------------------.
  99. * | | Reset| | | | | | | | | | Del |
  100. * |------+------+------+------+------+-------------+------+------+------+------+------|
  101. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | |
  102. * |------+------+------+------+------+------|------+------+------+------+------+------|
  103. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  104. * |------+------+------+------+------+------+------+------+------+------+------+------|
  105. * | | | | | | | | | | | |
  106. * `-----------------------------------------------------------------------------------'
  107. */
  108. [_ADJUST] = LAYOUT_planck_grid(
  109. _______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL ,
  110. _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______,
  111. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______,
  112. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  113. ),
  114.  
  115. /* Unicode Greek Letters (Lowercase)
  116. * ,-----------------------------------------------------------------------------------.
  117. * | | rho | psi|epsilon|sigma|upsilon| | phi | iota|omicron| pi | Bksp |
  118. * |------+------+------+------+------+-------------+------+------+------+------+------|
  119. * | Union| alpha| tao | delta| zeta | eta | theta| kappa|lambda| mu | | |
  120. * |------+------+------+------+------+------|------+------+------+------+------+------|
  121. * |Intsct| | omega| gamma| chi | beta | xi | nu | | | Up |Enter |
  122. * |------+------+------+------+------+------+------+------+------+------+------+------|
  123. * |OS-caps| | | | | Space | | | Left | Down |Right |
  124. * `-----------------------------------------------------------------------------------'
  125. */
  126. /* [_GREEK_LOWER] = LAYOUT_planck_grid(
  127. TT(_GREEK_LOWER), UC(0x03C1), UC(0x03C8), UC(0x03B5), UC(0x03C3), UC(0x03C5),XXXXXXX, UC(0x03C6), UC(0x03B9), UC(0x03BF), UC(0x03C0), KC_BSPC,
  128. UC(0x22C3), UC(0x03B1), UC(0x03C4), UC(0x03B4), UC(0x03B6), UC(0x03B7), UC(0x03B8), UC(0x03BA), UC(0x03BB), UC(0x03BC),XXXXXXX,XXXXXXX,
  129. UC(0x22C2),XXXXXXX, UC(0x03C9), UC(0x03B3), UC(0x03C7), UC(0x03B2), UC(0x03BE), UC(0x03BD), XXXXXXX, XXXXXXX, KC_UP, KC_ENT ,
  130. OSL(_GREEK_UPPER),XXXXXXX,XXXXXXX,XXXXXXX,XXXXXXX, KC_SPC, KC_SPC,XXXXXXX,XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT
  131. ), */
  132. [_GREEK_LOWER] = LAYOUT_planck_grid(
  133. _______, X(17), X(23), X(5), X(18), X(20),XXXXXXX, X(21), X(9), X(15), X(16), KC_BSPC,
  134. X(49), X(1), X(19), X(4), X(6), X(7), X(8), X(10), X(11), X(12),XXXXXXX,XXXXXXX,
  135. X(50),XXXXXXX, X(24), X(3), X(22), X(2), X(14), X(13), XXXXXXX, XXXXXXX, KC_UP, KC_ENT ,
  136. OSL(_GREEK_UPPER),XXXXXXX,XXXXXXX,XXXXXXX,XXXXXXX, KC_SPC, KC_SPC,XXXXXXX,XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT
  137. ),
  138.  
  139. /* Unicode Greek Letters (Uppercase)
  140. * ,-----------------------------------------------------------------------------------.
  141. * | | Rho | Psi|Epsilon|Sigma|Upsilon| | Phi | Iota|Omicron| Pi | Bksp |
  142. * |------+------+------+------+------+-------------+------+------+------+------+------|
  143. * | Union| Alpha| Tao | Delta| Zeta | Eta | Theta| Kappa|Lambda| Mu | | |
  144. * |------+------+------+------+------+------|------+------+------+------+------+------|
  145. * |Intsct| | Omega| Gamma| Chi | Beta | Xi | Nu | | | Up |Enter |
  146. * |------+------+------+------+------+------+------+------+------+------+------+------|
  147. * | | | | | | Space | | | Left | Down |Right |
  148. * `-----------------------------------------------------------------------------------'
  149. */
  150. /* [_GREEK_UPPER] = LAYOUT_planck_grid(
  151. XXXXXXX, UC(0x03A1), UC(0x03A8), UC(0x0395), UC(0x03A3), UC(0x03A5),XXXXXXX, UC(0x03A6), UC(0x0399), UC(0x30A0), UC(0x03A0), KC_BSPC,
  152. UC(0x22C3), UC(0x0391), UC(0x03A4), UC(0x0394), UC(0x0396), UC(0x0397), UC(0x0398), UC(0x039A), UC(0x039B), UC(0x039C),XXXXXXX,XXXXXXX,
  153. UC(0x22C2),XXXXXXX, UC(0x03A9), UC(0x0393), UC(0x03A7), UC(0x0392), UC(0x039E), UC(0x039D), XXXXXXX, XXXXXXX, KC_UP, KC_ENT ,
  154. OSL(_GREEK_UPPER),XXXXXXX,XXXXXXX,XXXXXXX,XXXXXXX, KC_SPC, KC_SPC,XXXXXXX,XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT
  155. ), */
  156.  
  157. [_GREEK_UPPER] = LAYOUT_planck_grid(
  158. TT(_GREEK_LOWER), X(41), X(47), X(29), X(42), X(44),XXXXXXX, X(45), X(33), X(39), X(40), KC_BSPC,
  159. X(49), X(25), X(43), X(28), X(30), X(31), X(32), X(34), X(35), X(36),XXXXXXX,XXXXXXX,
  160. X(50),XXXXXXX, X(48), X(27), X(46), X(26), X(38), X(37), XXXXXXX, XXXXXXX, KC_UP, KC_ENT ,
  161. OSL(_GREEK_UPPER),XXXXXXX,XXXXXXX,XXXXXXX,XXXXXXX, KC_SPC, KC_SPC,XXXXXXX,XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT
  162. ),
  163.  
  164. /* MIDI Layer (for FuUuUuN!)
  165. * ,-----------------------------------------------------------------------------------.
  166. * | Exit | C# | D# | | F# | G# | A# | | C# | D# | | |
  167. * |------+------+------+------+------+-------------+------+------+------+------+------|
  168. * | | C | D | E | F | G | A | B | C | D | E | F |
  169. * |------+------+------+------+------+------|------+------+------+------+------+------|
  170. * | | Vel1 | Vel2 | Vel3 | Vel4 | Vel5 | Vel6 | Vel7 | Vel8 | Vel9 | Vel10| | Mod changes the instrument.
  171. * |------+------+------+------+------+------+------+------+------+------+------+------| Velocity changes volume (and tone I think)
  172. * | MOD | | | | Oct- | Sustain | Oct+ | | | | | of the note.
  173. * `-----------------------------------------------------------------------------------'
  174. */
  175. [_MIDI_FOR_FUN] = LAYOUT_planck_grid(
  176. TG(_MIDI_FOR_FUN), MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX,
  177. XXXXXXX, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1,
  178. XXXXXXX, MI_VEL_1, MI_VEL_2, MI_VEL_3, MI_VEL_4, MI_VEL_5, MI_VEL_6, MI_VEL_7, MI_VEL_8, MI_VEL_9, MI_VEL_10, XXXXXXX,
  179. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
  180. ),
  181.  
  182. };
  183.  
  184. //Unicode Mapping Table, for future
  185. #ifdef UNICODEMAP_ENABLE
  186. const uint32_t PROGMEM unicode_map[] = {0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba,
  187. 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x0391,
  188. 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039f, 0x03a0, 0x03a1,
  189. 0x03a0, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x22c3, 0x22c2};
  190. #endif
  191.  
  192. #ifdef AUDIO_ENABLE
  193. float plover_song[][2] = SONG(PLOVER_SOUND);
  194. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  195. #endif
  196.  
  197. uint32_t layer_state_set_user(uint32_t state) {
  198. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  199. }
  200.  
  201. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  202. switch (keycode) {
  203. case QWERTY:
  204. if (record->event.pressed) {
  205. set_single_persistent_default_layer(_QWERTY);
  206. }
  207. return false;
  208. break;
  209. case BACKLIT:
  210. if (record->event.pressed) {
  211. register_code(KC_LSFT);
  212. #ifdef BACKLIGHT_ENABLE
  213. backlight_step();
  214. #endif
  215. #ifdef KEYBOARD_planck_rev5
  216. PORTE &= ~(1<<6);
  217. #endif
  218. } else {
  219. unregister_code(KC_LSFT);
  220. #ifdef KEYBOARD_planck_rev5
  221. PORTE |= (1<<6);
  222. #endif
  223. }
  224. return false;
  225. break;
  226. }
  227. return true;
  228. }
  229.  
  230. bool muse_mode = false;
  231. uint8_t last_muse_note = 0;
  232. uint16_t muse_counter = 0;
  233. uint8_t muse_offset = 70;
  234. uint16_t muse_tempo = 50;
  235.  
  236. void encoder_update(bool clockwise) {
  237. if (muse_mode) {
  238. if (IS_LAYER_ON(_RAISE)) {
  239. if (clockwise) {
  240. muse_offset++;
  241. } else {
  242. muse_offset--;
  243. }
  244. } else {
  245. if (clockwise) {
  246. muse_tempo+=1;
  247. } else {
  248. muse_tempo-=1;
  249. }
  250. }
  251. }
  252. else {
  253. if (IS_LAYER_ON(_RAISE) || IS_LAYER_ON(_LOWER)) {
  254. if (clockwise){
  255. register_code(KC_VOLU);
  256. unregister_code(KC_VOLU);
  257. }
  258. else {
  259. register_code(KC_VOLD);
  260. unregister_code(KC_VOLD);
  261. }
  262. }
  263. else{
  264. if (clockwise){
  265. register_code(KC_PGUP);
  266. unregister_code(KC_PGUP);
  267. }
  268. else{
  269. register_code(KC_PGDN);
  270. unregister_code(KC_PGDN);
  271. }
  272. }
  273. }
  274. }
  275.  
  276. void dip_update(uint8_t index, bool active) {
  277. switch (index) {
  278. case 0:
  279. if (active) {
  280. #ifdef AUDIO_ENABLE
  281. PLAY_SONG(plover_song);
  282. #endif
  283. layer_on(_ADJUST);
  284. } else {
  285. #ifdef AUDIO_ENABLE
  286. PLAY_SONG(plover_gb_song);
  287. #endif
  288. layer_off(_ADJUST);
  289. }
  290. break;
  291. case 1:
  292. if (active) {
  293. muse_mode = true;
  294. } else {
  295. muse_mode = false;
  296. #ifdef AUDIO_ENABLE
  297. stop_all_notes();
  298. #endif
  299. }
  300. }
  301. }
  302.  
  303. void matrix_scan_user(void) {
  304. #ifdef AUDIO_ENABLE
  305. if (muse_mode) {
  306. if (muse_counter == 0) {
  307. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  308. if (muse_note != last_muse_note) {
  309. stop_note(compute_freq_for_midi_note(last_muse_note));
  310. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  311. last_muse_note = muse_note;
  312. }
  313. }
  314. muse_counter = (muse_counter + 1) % muse_tempo;
  315. }
  316. #endif
  317. }
  318.  
  319. bool music_mask_user(uint16_t keycode) {
  320. switch (keycode) {
  321. case RAISE:
  322. case LOWER:
  323. return false;
  324. default:
  325. return true;
  326. }
  327. }
Advertisement
Add Comment
Please, Sign In to add comment