]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/planck/keymaps/zrichard/keymap.c
Debounce refactor / API (#3720)
[qmk_firmware.git] / keyboards / planck / keymaps / zrichard / keymap.c
1 #pragma message "You may need to add LAYOUT_planck_grid to your keymap layers - see default for an example"
2 #include "planck.h"
3 #include "action_layer.h"
4 #include "eeconfig.h"
5 #include "led.h"
6 #include "mousekey.h"
7
8 #ifdef AUDIO_ENABLE
9     #include "audio.h"
10     #include "song_list.h"
11 #endif
12
13 enum keyboard_layers {
14   LAYER_QWERTY = 0,
15   LAYER_UPPER,
16   LAYER_LOWER,
17   LAYER_FUNCTION,
18   LAYER_MOUSE,
19   LAYER_ADJUST,
20 };
21 enum keyboard_macros {
22   MACRO_QWERTY = 0,
23   MACRO_UPPER,
24   MACRO_LOWER,
25   MACRO_FUNCTION,
26   MACRO_MOUSE,
27   MACRO_TIMBRE_1,
28   MACRO_TIMBRE_2,
29   MACRO_TIMBRE_3,
30   MACRO_TIMBRE_4,
31   MACRO_TEMPO_U,
32   MACRO_TEMPO_D,
33   MACRO_TONE_DEFAULT,
34   MACRO_MUSIC_TOGGLE,
35   MACRO_AUDIO_TOGGLE,
36   MACRO_INC_VOICE,
37   MACRO_DEC_VOICE,
38   MACRO_BACKLIGHT,
39   MACRO_BREATH_TOGGLE,
40   MACRO_BREATH_SPEED_INC,
41   MACRO_BREATH_SPEED_DEC,
42   MACRO_BREATH_DEFAULT,
43   MACRO_MOUSE_MOVE_UL,
44   MACRO_MOUSE_MOVE_UR,
45   MACRO_MOUSE_MOVE_DL,
46   MACRO_MOUSE_MOVE_DR,
47   MACRO_HELP_1,
48   MACRO_HELP_2,
49   MACRO_HELP_3,
50   MACRO_HELP_4,
51   MACRO_HELP_5,
52   MACRO_HELP_6,
53   MACRO_HELP_7,
54   MACRO_HELP_8,
55   MACRO_HELP_9,
56   MACRO_MINE,
57   //MACRO_SHENT,
58 };
59
60 enum {
61   TD_SPENT = 0
62 };
63
64 #define M_QWRTY             M(MACRO_QWERTY)
65 #define M_UPPER             M(MACRO_UPPER)
66 #define M_LOWER             M(MACRO_LOWER)
67 #define M_FUNCT             M(MACRO_FUNCTION)
68 #define M_MOUSE             M(MACRO_MOUSE)
69 #define TIMBR_1             M(MACRO_TIMBRE_1)
70 #define TIMBR_2             M(MACRO_TIMBRE_2)
71 #define TIMBR_3             M(MACRO_TIMBRE_3)
72 #define TIMBR_4             M(MACRO_TIMBRE_4)
73 #define TMPO_UP             M(MACRO_TEMPO_U)
74 #define TMPO_DN             M(MACRO_TEMPO_D)
75 #define TMPO_DF             M(MACRO_TONE_DEFAULT)
76 #define M_BACKL             M(MACRO_BACKLIGHT)
77 #define M_BRTOG             M(MACRO_BREATH_TOGGLE)
78 #define M_BSPDU             M(MACRO_BREATH_SPEED_INC)
79 #define M_BSPDD             M(MACRO_BREATH_SPEED_DEC)
80 #define M_BDFLT             M(MACRO_BREATH_DEFAULT)
81 #define M_MS_UL             M(MACRO_MOUSE_MOVE_UL)
82 #define M_MS_UR             M(MACRO_MOUSE_MOVE_UR)
83 #define M_MS_DL             M(MACRO_MOUSE_MOVE_DL)
84 #define M_MS_DR             M(MACRO_MOUSE_MOVE_DR)
85 #define M_HELP1             M(MACRO_HELP_1)
86 #define M_HELP2             M(MACRO_HELP_2)
87 #define M_HELP3             M(MACRO_HELP_3)
88 #define M_HELP4             M(MACRO_HELP_4)
89 #define M_HELP5             M(MACRO_HELP_5)
90 #define M_HELP6             M(MACRO_HELP_6)
91 #define M_HELP7             M(MACRO_HELP_7)
92 #define M_HELP8             M(MACRO_HELP_8)
93 #define M_HELP9             M(MACRO_HELP_9)
94 #define MY_MACRO            M(MACRO_MINE)
95 //#define M_SHENT                       M(MACRO_SHENT)
96
97
98 #define VC_UP               M(MACRO_INC_VOICE)
99 #define VC_DOWN             M(MACRO_DEC_VOICE)
100
101
102 #define SC_UNDO             LCTL(KC_Z)
103 #define SC_REDO             LCTL(KC_Y)
104 #define SC_CUT              LCTL(KC_X)
105 #define SC_COPY             LCTL(KC_C)
106 #define SC_PSTE             LCTL(KC_V)
107 #define SC_SELA             LCTL(KC_A)
108 #define SC_SAVE             LCTL(KC_S)
109 #define SC_OPEN             LCTL(KC_O)
110 #define SC_ACLS             LALT(KC_F4)
111 #define SC_CCLS             LCTL(KC_F4)
112
113 #define TG_NKRO             MAGIC_TOGGLE_NKRO
114 #define OS_SHFT             KC_FN0
115
116 #define _______             KC_TRNS
117 #define XXXXXXX             KC_NO
118 #define ________________    _______, _______
119 #define XXXXXXXXXXXXXXXX    XXXXXXX, XXXXXXX
120
121
122 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
123
124 /* LAYER = LAYER_QWERTY
125   .-----------------------------------------------------------------------------------------------------------.
126   | ESC    | Q      | W      | E      | R      | T      | Y      | U      | I      | O      | P      | BACKSP |
127   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
128   | TAB    | A      | S      | D      | F      | G      | H      | J      | K      | L      | ;      | '      |
129   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
130   | LSHIFT | Z      | X      | C      | V      | B      | N      | M      | ,      | .      | UP     | SH/ENT |
131   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
132   | LCTRL  | LWIN   | FN     | LALT   | LOWER  | SPACE  | SPACE  | UPPER  |  MENU  | LEFT   | DOWN   | RIGHT  |
133   '-----------------------------------------------------------------------------------------------------------'
134 */
135 [LAYER_QWERTY] = {
136   { KC_ESC , KC_Q   , KC_W   , KC_E   , KC_R   , KC_T   , KC_Y   , KC_U   , KC_I   , KC_O   , KC_P   , KC_BSPC },
137   { KC_TAB , KC_A   , KC_S   , KC_D   , KC_F   , KC_G   , KC_H   , KC_J   , KC_K   , KC_L   , KC_SCLN, KC_QUOT },
138   { KC_LSFT, KC_Z   , KC_X   , KC_C   , KC_V   , KC_B   , KC_N   , KC_M   , KC_COMM, KC_DOT , KC_UP  , KC_SFTENT /*M_SHENT*/ },
139   { KC_LCTL, KC_LGUI, M_FUNCT, KC_LALT, M_LOWER, KC_SPC , KC_SPC , M_UPPER, KC_APP , KC_LEFT, KC_DOWN, KC_RGHT }
140 },
141 /* LAYER = LAYER_UPPER
142   .-----------------------------------------------------------------------------------------------------------.
143   | PRINT  | F1     | F2     | F3     | F4     | NUM LK | KP /   | KP 7   | KP 8   | KP 9   | KP -   | DEL    |
144   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
145   | PAUSE  | F5     | F6     | F7     | F8     | SCR LK | KP *   | KP 4   | KP 5   | KP 6   | KP +   | HOME   |
146   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
147   | ______ | F9     | F10    | F11    | F12    | PAUSE  | KP 0   | KP 1   | KP 2   | KP 3   | KP ENT | END    |
148   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
149   | ______ | ______ | ______ | ______ | LOWER  | KP 0   | KP 0   | ______ | RALT   | KP 0   | KP ENT | RTCTRL |
150   '-----------------------------------------------------------------------------------------------------------'
151 */
152 [LAYER_UPPER] = {
153   { KC_PSCR, KC_F1  , KC_F2  , KC_F3  , KC_F4  , KC_NLCK, KC_PSLS, KC_KP_7, KC_KP_8, KC_KP_9, KC_PMNS, KC_DEL  },
154   { KC_PAUS, KC_F5  , KC_F6  , KC_F7  , KC_F8  , KC_SLCK, KC_PAST, KC_KP_4, KC_KP_5, KC_KP_6, KC_PPLS, KC_HOME },
155   { _______, KC_F9  , KC_F10 , KC_F11 , KC_F12 , KC_PAUS, KC_KP_0, KC_KP_1, KC_KP_2, KC_KP_3, KC_PENT, KC_END  },
156   { _______, _______, _______, _______, M_LOWER, KC_KP_0, KC_KP_0, _______, KC_KP_0, KC_PDOT, KC_PENT, KC_RCTL }
157 },
158 /* LAYER = LAYER_LOWER
159   .-----------------------------------------------------------------------------------------------------------.
160   | ______ | $      | {      | [      | (      | %      | #      | )      | ]      | }      | @      | PG UP  |
161   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
162   | ______ | ^      | *      | +      | -      | /      | \      | _      | '      | "      | `      | PG DN  |
163   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
164   | ______ | |      | &      | !      | ~      | ;      | :      | =      | <      | >      | ?      | HOME   |
165   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
166   | ______ | ______ | ______ | ______ | ______ | ______ | ______ | UPPER  | ______ | ______ | ______ | END    |
167   '-----------------------------------------------------------------------------------------------------------'
168 */
169 [LAYER_LOWER] = {
170   { _______, KC_DLR , KC_LCBR, KC_LBRC, KC_LPRN, KC_PERC, KC_HASH, KC_RPRN, KC_RBRC, KC_RCBR, KC_AT  , KC_PGUP },
171   { _______, KC_CIRC, KC_ASTR, KC_PLUS, KC_MINS, KC_SLSH, KC_BSLS, KC_UNDS, KC_QUOT, KC_DQT , KC_GRV , KC_PGDN },
172   { _______, KC_PIPE, KC_AMPR, KC_EXLM, KC_TILD, KC_SCLN, KC_COLN, KC_EQL , KC_LT  , KC_GT  , KC_QUES, KC_HOME },
173   { _______, _______, _______, _______, _______, _______, _______, M_UPPER, _______, _______, _______, KC_END  }
174 },
175 /* LAYER = LAYER_FUNCTION
176   .-----------------------------------------------------------------------------------------------------------.
177   | XXXXXX | F13    | F14    | F15    | F16    | NUM LK | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX |
178   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
179   | XXXXXX | F17    | F18    | F19    | F20    | SCR LK | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX |
180   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
181   | ______ | F21    | F22    | F23    | F24    | CAP LK | XXXXXX | XXXXXX | XXXXXX | XXXXXX | VOL UP | MUTE   |
182   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
183   | ______ | ______ | FN     | ______ | ______ | PLAY   | PLAY   | ______ | ______ | PREV   | VOL DN | NEXT   |
184   '-----------------------------------------------------------------------------------------------------------'
185 */
186 [LAYER_FUNCTION] = {
187   { XXXXXXX, KC_F13 , KC_F14 , KC_F15 , KC_F16 , KC_NLCK, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
188   { XXXXXXX, KC_F17 , KC_F18 , KC_F19 , KC_F20 , KC_SLCK, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
189   { _______, KC_F21 , KC_F22 , KC_F23 , KC_F24 , KC_CAPS, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_VOLU, KC_MUTE },
190   { _______, _______, M_FUNCT, _______, _______, KC_MPLY, KC_MPLY, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT }
191 },
192 /* LAYER = LAYER_MOUSE
193   .-----------------------------------------------------------------------------------------------------------.
194   | ESC    | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | MS UL  | MS U   | MS UR  | MS WHL | MS WHR |
195   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
196   | XXXXXX | MS BT5 | MS BT4 | MS BT3 | MS BT2 | XXXXXX | XXXXXX | MS L   | XXXXXX | MS R   | XXXXXX | MS WHU |
197   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
198   | ______ | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | MS DL  | MS D   | MS DR  | MS U   | MS WHD |
199   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
200   | ______ | ______ | ______ | ______ | ______ | MS BT1 | MS BT1 | ______ | ______ | MS L   | MS D   | MS R   |
201   '-----------------------------------------------------------------------------------------------------------'
202 */
203 [LAYER_MOUSE] = {
204   { KC_ESC , XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_MS_UL, KC_MS_U, M_MS_UR, KC_WH_L, KC_WH_R },
205   { XXXXXXX, KC_BTN5, KC_BTN4, KC_BTN3, KC_BTN2, XXXXXXX, XXXXXXX, KC_MS_L, XXXXXXX, KC_MS_R, XXXXXXX, KC_WH_U },
206   { _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_MS_DL, KC_MS_D, M_MS_DR, KC_MS_U, KC_WH_D },
207   { _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R }
208 },
209 /* LAYER = LAYER_ADJUST
210   .-----------------------------------------------------------------------------------------------------------.
211   | XXXXXX | HELP 1 | HELP 2 | HELP 3 | HELP 4 | HELP 5 | HELP 6 | HELP 7 | HELP 8 | HELP 9 | MUSIC  | AUDIO  |
212   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
213   | XXXXXX | BRTOG  | BRSPD+ | BRSPD- | BRDFLT | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX |
214   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
215   | XXXXXX | QWERTY | XXXXXX | XXXXXX | BACKLT | RESET  | XXXXXX | MOUSE  | XXXXXX | XXXXXX | VOICE+ | MACRO  |
216   |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
217   | XXXXXX | XXXXXX | XXXXXX | XXXXXX | LOWER  | XXXXXX | XXXXXX | UPPER  | XXXXXX | TEMPO- | VOICE- | TEMPO+ |
218   '-----------------------------------------------------------------------------------------------------------'
219 */
220 [LAYER_ADJUST] = {
221   { XXXXXXX, M_HELP1, M_HELP2, M_HELP3, M_HELP4, M_HELP5, M_HELP6, M_HELP7, M_HELP8, M_HELP9, MU_TOG , AU_TOG  },
222   { XXXXXXX, M_BRTOG, M_BSPDU, M_BSPDD, M_BDFLT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
223   { XXXXXXX, M_QWRTY, XXXXXXX, XXXXXXX, M_BACKL, RESET  , XXXXXXX, M_MOUSE, XXXXXXX, XXXXXXX, MUV_IN , MY_MACRO},
224   { XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_LOWER, XXXXXXX, XXXXXXX, M_UPPER, XXXXXXX, TMPO_DN, MUV_DE , TMPO_UP }
225 },
226
227 };
228
229 #ifdef AUDIO_ENABLE
230
231 float tone_my_startup[][2] = SONG(QWERTY_SOUND);
232 float tone_my_goodbye[][2] = SONG(QWERTY_SOUND);
233
234 float tone_audio_on[][2]   = SONG(CLOSE_ENCOUNTERS_5_NOTE);
235 float tone_music_on[][2]   = SONG(DOE_A_DEER);
236 float tone_caps_on[][2]    = SONG(CAPS_LOCK_ON_SOUND);
237 float tone_caps_off[][2]   = SONG(CAPS_LOCK_OFF_SOUND);
238 float tone_numlk_on[][2]   = SONG(NUM_LOCK_ON_SOUND);
239 float tone_numlk_off[][2]  = SONG(NUM_LOCK_OFF_SOUND);
240 float tone_scroll_on[][2]  = SONG(SCROLL_LOCK_ON_SOUND);
241 float tone_scroll_off[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
242 float music_scale[][2]     = SONG(MUSIC_SCALE_SOUND);
243
244 #endif /* AUDIO_ENABLE */
245
246 void persistant_default_layer_set(uint16_t default_layer)
247 {
248     eeconfig_update_default_layer(default_layer);
249     default_layer_set(default_layer);
250 }
251
252 const uint16_t PROGMEM fn_actions[] = {
253     [0] = ACTION_MODS_ONESHOT(MOD_RSFT),
254 };
255
256 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
257 {
258
259     // MACRODOWN only works in this function
260     switch(id)
261     {
262
263         case MACRO_HELP_1:
264             if (record->event.pressed)
265             {
266                                 //uprintf("1");
267             }
268             break;
269
270         case MACRO_HELP_2:
271             if (record->event.pressed)
272             {
273                                 //uprintf("2");
274             }
275             break;
276
277         case MACRO_HELP_3:
278             if (record->event.pressed)
279             {
280                                 //uprintf("3");
281             }
282             break;
283
284         case MACRO_HELP_4:
285             if (record->event.pressed)
286             {
287                                 //uprintf("4");
288             }
289             break;
290
291         case MACRO_HELP_5:
292             if (record->event.pressed)
293             {
294                                 //uprintf("5");
295             }
296             break;
297
298         case MACRO_HELP_6:
299             if (record->event.pressed)
300             {
301                                 //uprintf("6");
302             }
303             break;
304
305         case MACRO_HELP_7:
306             if (record->event.pressed)
307             {
308                                 //uprintf("7");
309             }
310             break;
311
312         case MACRO_HELP_8:
313             if (record->event.pressed)
314             {
315                                 //uprintf("8");
316             }
317             break;
318
319         case MACRO_HELP_9:
320             if (record->event.pressed)
321             {
322                                 //uprintf("9");
323             }
324             break;
325
326         case MACRO_BREATH_TOGGLE:
327             if (record->event.pressed)
328             {
329               #ifdef BACKLIGHT_BREATHING
330                 breathing_toggle();
331               #endif
332             }
333             break;
334
335         case MACRO_BREATH_SPEED_INC:
336             if (record->event.pressed)
337             {
338               #ifdef BACKLIGHT_BREATHING
339                 breathing_period_inc();
340               #endif
341             }
342             break;
343
344         case MACRO_BREATH_SPEED_DEC:
345             if (record->event.pressed)
346             {
347               #ifdef BACKLIGHT_BREATHING
348                 breathing_period_dec();
349               #endif
350             }
351             break;
352
353         case MACRO_BREATH_DEFAULT:
354             if (record->event.pressed)
355             {
356               #ifdef BACKLIGHT_BREATHING
357                 breathing_period_default();
358               #endif
359             }
360             break;
361
362         case MACRO_QWERTY:
363             if (record->event.pressed)
364             {
365                 persistant_default_layer_set(1UL<<LAYER_QWERTY);
366             }
367             break;
368
369         case MACRO_UPPER:
370             if (record->event.pressed)
371             {
372                 layer_on(LAYER_UPPER);
373                 #ifdef BACKLIGHT_BREATHING
374                   breathing_period_set(2);
375                   breathing_pulse();
376                 #endif
377                 update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST);
378             }
379             else
380             {
381                 layer_off(LAYER_UPPER);
382                 update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST);
383             }
384             break;
385
386         case MACRO_LOWER:
387             if (record->event.pressed)
388             {
389                 layer_on(LAYER_LOWER);
390                 #ifdef BACKLIGHT_BREATHING
391                   breathing_period_set(2);
392                   breathing_pulse();
393                 #endif
394                 update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST);
395             }
396             else
397             {
398                 layer_off(LAYER_LOWER);
399                 update_tri_layer(LAYER_LOWER, LAYER_UPPER, LAYER_ADJUST);
400             }
401             break;
402
403         case MACRO_FUNCTION:
404             if (record->event.pressed)
405             {
406                 #ifdef BACKLIGHT_BREATHING
407                   breathing_period_set(3);
408                   breathing_enable();
409                 #endif
410                 layer_on(LAYER_FUNCTION);
411             }
412             else
413             {
414                 #ifdef BACKLIGHT_BREATHING
415                   breathing_period_set(1);
416                   breathing_self_disable();
417                 #endif
418                 layer_off(LAYER_FUNCTION);
419             }
420             break;
421
422         case MACRO_MINE:
423                 if(record->event.pressed)
424                 {
425                         return MACRO( I(03), T(R), T(O), T(O), T(T), W(10), T(TAB), W(10), T(T), T(O), T(O), T(R), T(ENTER), END );
426                 }
427                 break;
428
429         /*
430         case MACRO_SHENT:
431                 if (record->event.pressed)
432                 {
433                         start = timer_read();
434                         return MACRO( D(LSHIFT), END );
435                 }
436                 else
437                 {
438                         if (timer_elapsed(start) > 100)
439                         {
440                                 return MACRO( U(LSHIFT), END);
441                         }
442                         else
443                         {
444                                 return MACRO( U(LSHIFT), T(ENTER), END);
445                         }
446                 }
447                 break;
448                 */
449
450
451 #ifdef BACKLIGHT_ENABLE
452                 case MACRO_BACKLIGHT:
453                         if (record->event.pressed)
454                         {
455                                 backlight_step();
456                         }
457 #endif
458
459 #ifdef MOUSEKEY_ENABLE
460
461         case MACRO_MOUSE:
462             if (record->event.pressed)
463             {
464                 layer_invert(LAYER_MOUSE);
465             }
466             break;
467
468         case MACRO_MOUSE_MOVE_UL:
469             if (record->event.pressed)
470             {
471               mousekey_on(KC_MS_UP);
472               mousekey_on(KC_MS_LEFT);
473             }
474             else
475             {
476               mousekey_off(KC_MS_UP);
477               mousekey_off(KC_MS_LEFT);
478             }
479             break;
480
481         case MACRO_MOUSE_MOVE_UR:
482             if (record->event.pressed)
483             {
484               mousekey_on(KC_MS_UP);
485               mousekey_on(KC_MS_RIGHT);
486             }
487             else
488             {
489               mousekey_off(KC_MS_UP);
490               mousekey_off(KC_MS_RIGHT);
491             }
492             break;
493
494         case MACRO_MOUSE_MOVE_DL:
495             if (record->event.pressed)
496             {
497               mousekey_on(KC_MS_DOWN);
498               mousekey_on(KC_MS_LEFT);
499             }
500             else
501             {
502               mousekey_off(KC_MS_DOWN);
503               mousekey_off(KC_MS_LEFT);
504             }
505             break;
506
507         case MACRO_MOUSE_MOVE_DR:
508             if (record->event.pressed)
509             {
510               mousekey_on(KC_MS_DOWN);
511               mousekey_on(KC_MS_RIGHT);
512             }
513             else
514             {
515               mousekey_off(KC_MS_DOWN);
516               mousekey_off(KC_MS_RIGHT);
517             }
518             break;
519
520 #endif /* MOUSEKEY_ENABLE */
521
522 #ifdef AUDIO_ENABLE
523
524         case MACRO_TIMBRE_1:
525             if (record->event.pressed) set_timbre(TIMBRE_12);
526             break;
527
528         case MACRO_TIMBRE_2:
529             if (record->event.pressed) set_timbre(TIMBRE_25);
530             break;
531
532         case MACRO_TIMBRE_3:
533             if (record->event.pressed) set_timbre(TIMBRE_50);
534             break;
535
536         case MACRO_TIMBRE_4:
537             if (record->event.pressed) set_timbre(TIMBRE_75);
538             break;
539
540         case MACRO_TEMPO_U:
541             if (record->event.pressed) increase_tempo(10);
542             break;
543
544         case MACRO_TEMPO_D:
545             if (record->event.pressed) decrease_tempo(10);
546             break;
547
548         case MACRO_TONE_DEFAULT:
549             if (record->event.pressed)
550             {
551                 set_timbre(TIMBRE_DEFAULT);
552                 set_tempo(TEMPO_DEFAULT);
553             }
554             break;
555
556 #endif /* AUDIO_ENABLE */
557
558         default:
559             break;
560
561     }
562     return MACRO_NONE;
563 };
564
565
566
567 #ifdef AUDIO_ENABLE
568
569 void matrix_init_user(void)
570 {
571     set_voice(default_voice);
572     startup_user();
573     println("Matrix Init");
574 }
575
576 void led_set_user(uint8_t usb_led)
577 {
578     static uint8_t old_usb_led = 0;
579
580     _delay_ms(10); // gets rid of tick
581
582     if ((usb_led & (1<<USB_LED_CAPS_LOCK)) && !(old_usb_led & (1<<USB_LED_CAPS_LOCK)))
583     {
584             // If CAPS LK LED is turning on...
585             PLAY_SONG(tone_caps_on);
586     }
587     else if (!(usb_led & (1<<USB_LED_CAPS_LOCK)) && (old_usb_led & (1<<USB_LED_CAPS_LOCK)))
588     {
589             // If CAPS LK LED is turning off...
590             PLAY_SONG(tone_caps_off);
591     }
592     else if ((usb_led & (1<<USB_LED_NUM_LOCK)) && !(old_usb_led & (1<<USB_LED_NUM_LOCK)))
593     {
594             // If NUM LK LED is turning on...
595             PLAY_SONG(tone_numlk_on);
596     }
597     else if (!(usb_led & (1<<USB_LED_NUM_LOCK)) && (old_usb_led & (1<<USB_LED_NUM_LOCK)))
598     {
599             // If NUM LED is turning off...
600             PLAY_SONG(tone_numlk_off);
601     }
602     else if ((usb_led & (1<<USB_LED_SCROLL_LOCK)) && !(old_usb_led & (1<<USB_LED_SCROLL_LOCK)))
603     {
604             // If SCROLL LK LED is turning on...
605             PLAY_SONG(tone_scroll_on);
606     }
607     else if (!(usb_led & (1<<USB_LED_SCROLL_LOCK)) && (old_usb_led & (1<<USB_LED_SCROLL_LOCK)))
608     {
609             // If SCROLL LED is turning off...
610             PLAY_SONG(tone_scroll_off);
611     }
612     old_usb_led = usb_led;
613 }
614
615
616 void startup_user()
617 {
618     _delay_ms(10); // gets rid of tick
619     PLAY_SONG(tone_my_startup);
620 }
621
622 void shutdown_user()
623 {
624     PLAY_SONG(tone_my_goodbye);
625     _delay_ms(2000);
626     stop_all_notes();
627 }
628
629 void audio_on_user(void)
630 {
631         PLAY_SONG(tone_audio_on);
632 }
633
634 void music_on_user(void)
635 {
636         PLAY_SONG(tone_music_on);
637 }
638
639 void music_scale_user(void)
640 {
641         PLAY_SONG(music_scale);
642 }
643
644 #endif /* AUDIO_ENABLE */