summaryrefslogtreecommitdiff
path: root/keyboards/preonic/keymaps/brauner/keymap.c
blob: 123a4fc215fc4942d530474238e15e0159bff5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/* Copyright 2015-2021 Jack Humbert
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include QMK_KEYBOARD_H
#include "muse.h"

enum preonic_layers {
    _QWERTY,
    _LOWER,
    _RAISE,
    _MOUSE,
    _MANAGE,
    _COMPOSITOR,
};

enum preonic_keycodes {
    QWERTY = SAFE_RANGE,
    LOWER,
    RAISE,
    MOUSE,
    MANAGE,
    COMPOSITOR,
};

#define MOD_TAP_LSFT_ESC LSFT_T(KC_ESC)
#define MOD_TAP_LSFT_ENT LSFT_T(KC_ENT)

#define LT_COPY_Y    LT(_QWERTY, KC_Y)
#define LT_CUT_X     LT(_QWERTY, KC_X)
#define LT_PASTE_P   LT(_QWERTY, KC_P)
#define LT_AE_A      LT(_QWERTY, KC_A)
#define LT_OE_O      LT(_QWERTY, KC_O)
#define LT_UE_U      LT(_QWERTY, KC_U)
#define LT_SZ_S      LT(_QWERTY, KC_S)
#define LT_LOWER_SPC LT(_LOWER,  KC_SPC)

#define LM_COMP_LALT      LM(_COMPOSITOR, MOD_LALT)

#define KO_LAYER_MASK_EXCEPT(layer) ((~0) & ~(1 << layer))

enum combos {
    COMBO_LPRN_RPRN, /* (|) */
    COMBO_LBRC_RBRC, /* [|] */
    COMBO_LCBR_RCBR, /* {|} */
    COMBO_LT_GT,     /* <|> */
    COMBO_MAX,
};

uint16_t COMBO_LEN = COMBO_MAX;

const uint16_t PROGMEM combo_lprn_rprn[] = {KC_LPRN, KC_RPRN, COMBO_END};
const uint16_t PROGMEM combo_lbrc_rbrc[] = {KC_LBRC, KC_RBRC, COMBO_END};
const uint16_t PROGMEM combo_lcbr_rcbr[] = {KC_LCBR, KC_RCBR, COMBO_END};
const uint16_t PROGMEM combo_lt_gt[]     = {KC_LT, KC_GT, COMBO_END};

combo_t key_combos[COMBO_MAX] = {
    [COMBO_LPRN_RPRN] = COMBO_ACTION(combo_lprn_rprn),
    [COMBO_LBRC_RBRC] = COMBO_ACTION(combo_lbrc_rbrc),
    [COMBO_LCBR_RCBR] = COMBO_ACTION(combo_lcbr_rcbr),
    [COMBO_LT_GT]     = COMBO_ACTION(combo_lt_gt),
};

void process_combo_event(uint16_t combo_index, bool pressed) {
    switch (combo_index) {
        case COMBO_LPRN_RPRN:
            if (pressed) {
                tap_code16(KC_LPRN);
                tap_code16(KC_RPRN);
                tap_code16(KC_LEFT);
            }
            break;
        case COMBO_LBRC_RBRC:
            if (pressed) {
                tap_code16(KC_LBRC);
                tap_code16(KC_RBRC);
                tap_code16(KC_LEFT);
            }
            break;
        case COMBO_LCBR_RCBR:
            if (pressed) {
                tap_code16(KC_LCBR);
                tap_code16(KC_RCBR);
                tap_code16(KC_LEFT);
            }
            break;
        case COMBO_LT_GT:
            if (pressed) {
                tap_code16(KC_LT);
                tap_code16(KC_GT);
                tap_code16(KC_LEFT);
            }
            break;
    }
}

const key_override_t nop_shift_quote = ko_make_with_layers(MOD_MASK_SHIFT, KC_QUOT, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR)); /* " */
const key_override_t nop_shift_dot   = ko_make_with_layers(MOD_MASK_SHIFT, KC_DOT, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));  /* < */
const key_override_t nop_shift_comma = ko_make_with_layers(MOD_MASK_SHIFT, KC_COMM, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR)); /* > */
const key_override_t nop_shift_slash = ko_make_with_layers(MOD_MASK_SHIFT, KC_SLSH, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR)); /* ? */
const key_override_t nop_shift_one   = ko_make_with_layers(MOD_MASK_SHIFT, KC_1, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* ! */
const key_override_t nop_shift_two   = ko_make_with_layers(MOD_MASK_SHIFT, KC_2, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override @ */
const key_override_t nop_shift_three = ko_make_with_layers(MOD_MASK_SHIFT, KC_3, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override # */
const key_override_t nop_shift_four  = ko_make_with_layers(MOD_MASK_SHIFT, KC_4, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override $ */
const key_override_t nop_shift_five  = ko_make_with_layers(MOD_MASK_SHIFT, KC_5, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override % */
const key_override_t nop_shift_six   = ko_make_with_layers(MOD_MASK_SHIFT, KC_6, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override ^ */
const key_override_t nop_shift_seven = ko_make_with_layers(MOD_MASK_SHIFT, KC_7, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override & */
const key_override_t nop_shift_eight = ko_make_with_layers(MOD_MASK_SHIFT, KC_8, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override * */
const key_override_t nop_shift_nine  = ko_make_with_layers(MOD_MASK_SHIFT, KC_9, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override ( */
const key_override_t nop_shift_zero  = ko_make_with_layers(MOD_MASK_SHIFT, KC_0, KC_NO, KO_LAYER_MASK_EXCEPT(_COMPOSITOR));    /* override ) */

const key_override_t **key_overrides = (const key_override_t *[]){
    &nop_shift_quote,
    &nop_shift_dot,
    &nop_shift_comma,
    &nop_shift_slash,
    &nop_shift_one,
    &nop_shift_two,
    &nop_shift_three,
    &nop_shift_four,
    &nop_shift_five,
    &nop_shift_six,
    &nop_shift_seven,
    &nop_shift_eight,
    &nop_shift_nine,
    &nop_shift_zero,
    NULL
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* Qwerty
     * ,----------------------------------------------------------------------------------------------------------.
     * | Caps Lock    |   1   |  2   |  3   |  4   |  5   |     6     |  7   |  8   |   9  |  0    | Leader       |
     * |--------------+-------+------+------+------+------+-----------+------+------+------+-------+--------------|
     * | Ctrl         |   Q   |  W   |  E   |  R   |  T   |   Y/Copy  | U/Ü  |  I   | O/Ö  |P/Paste| Ctrl         |
     * |--------------+-------+------+------+------+------+-----------+------+------+------+-------+--------------|
     * | Shift/Esc    |  A/Ä  | S/ß  |  D   |  F   |  G   |     H     |  J   |  K   |   L  |  '    | Shift/Enter  |
     * |--------------+-------+------+------+------+------+-----------+------+------+------+-------+--------------|
     * | Alt          |   Z   |X/Cut |  C   |  V   |  B   |     N     |  M   |  ,   |   .  |  /    | Alt          |
     * |--------------+-------+------+------+------+------+-----------+------+------+------+-------+--------------|
     * | Mouse        |       |      |      |Raise |Lower |Lower/Space|Raise |      |      |       | Manage       |
     * `----------------------------------------------------------------------------------------------------------'
     */
    [_QWERTY] = LAYOUT_preonic_grid(
      KC_CAPS,          KC_1,    KC_2,     KC_3,    KC_4,   KC_5,  KC_6,         KC_7,    KC_8,    KC_9,     KC_0,       QK_LEAD,
      KC_LCTL,          KC_Q,    KC_W,     KC_E,    KC_R,   KC_T,  LT_COPY_Y,    LT_UE_U, KC_I,    LT_OE_O,  LT_PASTE_P, KC_RCTL,
      MOD_TAP_LSFT_ESC, LT_AE_A, LT_SZ_S,  KC_D,    KC_F,   KC_G,  KC_H,         KC_J,    KC_K,    KC_L,     KC_QUOT,    MOD_TAP_LSFT_ENT,
      LM_COMP_LALT,     KC_Z,    LT_CUT_X, KC_C,    KC_V,   KC_B,  KC_N,         KC_M,    KC_COMM, KC_DOT,   KC_SLSH,    LM_COMP_LALT,
      TG(_MOUSE),       _______, _______,  _______, RAISE,  LOWER, LT_LOWER_SPC, RAISE,   _______,  _______, _______,    MANAGE
    ),
    /* Lower
     * ,-----------------------------------------------------------------------------------.
     * |      |      |      |      |      |      |      |      |      |      |      |      |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |  @   |  %   |  (   |   )  |      |      |  +   |  <   |  >   |      |      |
     * |------+------+------+------+------+-------------+------+------+------+------+------|
     * |      |  ~   |      |  [   |   ]  |      | Left | Down |  Up  |Right |  "   |      |
     * |------+------+------+------+------+------|------+------+------+------+------+------|
     * |      |      |      |  {   |   }  |      |      |      |  :   |   !  |  \   |      |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |      |      |      |      |      |      |      |      |      |      |      |
     * `-----------------------------------------------------------------------------------'
     */
    [_LOWER] = LAYOUT_preonic_grid(
      XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
      XXXXXXX, KC_AT,   KC_PERC, KC_LPRN, KC_RPRN, XXXXXXX, XXXXXXX, KC_PLUS, KC_LT,   KC_GT,   XXXXXXX, XXXXXXX,
      XXXXXXX, KC_TILD, XXXXXXX, KC_LBRC, KC_RBRC, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT, KC_DQUO, XXXXXXX,
      XXXXXXX, XXXXXXX, XXXXXXX, KC_LCBR, KC_RCBR, XXXXXXX, XXXXXXX, XXXXXXX, KC_COLN, KC_EXLM, KC_BSLS, XXXXXXX,
      XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
    ),
    /* Raise
     * ,-----------------------------------------------------------------------------------.
     * |      |      |      |      |      |      |      |      |      |      |      |      |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |  #   |  &   |      |      |      |      |   *  |  -   |  _   |  =   |      |
     * |------+------+------+------+------+-------------+------+------+------+------+------|
     * |      |  `   |      |      |      |      | Bspk |Pg Dn |Pg Up | Tab  |  $   | End  |
     * |------+------+------+------+------+------|------+------+------+------+------+------|
     * |      |      |      |      |      |      |      |      |  ;   |  ?   |  |   |      |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |      |      |      |      |      |      |      |      |      |      |      |
     * `-----------------------------------------------------------------------------------'
     */
    [_RAISE] = LAYOUT_preonic_grid(
      XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
      XXXXXXX, KC_HASH, KC_AMPR, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_ASTR, KC_MINS, KC_UNDS, KC_EQL,  XXXXXXX,
      XXXXXXX, KC_GRV,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BSPC, KC_PGDN, KC_PGUP, KC_TAB,  KC_DLR,  KC_END,
      XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_SCLN, KC_QUES, KC_PIPE, XXXXXXX,
      XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
    ),
    /* Mouse
     * ,-------------------------------------------------------------------------------------------------------------------------------------------------------.
     * |              |       |              |              |              |              |           |           |         |            |      |              |
     * |--------------+-------+--------------+--------------+--------------+--------------+-----------+-----------+---------+------------+------+--------------|
     * |              |       |              |              |              |              |Wheel Left |Wheel Down |Wheel Up |Wheel Right |      | Ctrl         |
     * |--------------+-------+--------------+--------------+--------------+--------------+-----------+-----------+---------+------------+------+--------------|
     * |              |       | Button 3     | Button 2     | Button 1     |              |Cursor Left|Cursor Down|Cursor Up|Cursor Right|      |              |
     * |--------------+-------+--------------+--------------+--------------+--------------+-----------+-----------+---------+------------+------+--------------|
     * |Compositor+Alt|       |              |              |              |              |           |           |         |            |      |Compositor+Alt|
     * |--------------+-------+--------------+--------------+--------------+--------------+-----------+-----------+---------+------------+------+--------------|
     * |Mouse         |       |              |Accelaration 2|Accelaration 1|Accelaration 0|           |           |         |            |      |              |
     * `-------------------------------------------------------------------------------------------------------------------------------------------------------'
     */
    [_MOUSE] = LAYOUT_preonic_grid(
      XXXXXXX, XXXXXXX, XXXXXXX,    XXXXXXX,      XXXXXXX,      XXXXXXX,      XXXXXXX,       XXXXXXX,       XXXXXXX,     XXXXXXX,        XXXXXXX, XXXXXXX,
      XXXXXXX, XXXXXXX, XXXXXXX,    XXXXXXX,      XXXXXXX,      XXXXXXX,      KC_MS_WH_LEFT, KC_MS_WH_DOWN, KC_MS_WH_UP, KC_MS_WH_RIGHT, XXXXXXX, _______,
      XXXXXXX, XXXXXXX, KC_MS_BTN3, KC_MS_BTN2,   KC_MS_BTN1,   XXXXXXX,      KC_MS_LEFT,    KC_MS_DOWN,    KC_MS_UP,    KC_MS_RIGHT,    XXXXXXX, XXXXXXX,
      _______, XXXXXXX, XXXXXXX,    XXXXXXX,      XXXXXXX,      XXXXXXX,      XXXXXXX,       XXXXXXX,       XXXXXXX,     XXXXXXX,        XXXXXXX, _______,
      _______, XXXXXXX, XXXXXXX,    KC_MS_ACCEL2, KC_MS_ACCEL1, KC_MS_ACCEL0, XXXXXXX,       XXXXXXX,       XXXXXXX,     XXXXXXX,        XXXXXXX, XXXXXXX
    ),
    /* Manage
     * ,---------------------------------------------------------------------------------------.
     * |  F1  |   F2   |   F3   |  F4  |  F5  |  F6  |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |
     * |------+--------+--------+------+------+------+------+------+------+------+------+------|
     * |      |        |        |      |      |      |      |      |      |      |      |      |
     * |------+--------+--------+------+------+-------------+------+------+------+------+------|
     * |      |Aud prev|Aud next|Aud on|AudOff|      |      |Qwerty|      |      |      |      |
     * |------+--------+--------+------+------+------|------+------+------+------+------+------|
     * |      |        |Mus next|Mus on|MusOff|      |      |      |      |      |      |      |
     * |------+--------+--------+------+------+------+------+------+------+------+------+------|
     * |Reset |        |        |      |      |      |      |      |      |      |      |      |
     * `---------------------------------------------------------------------------------------'
     */
    [_MANAGE] = LAYOUT_preonic_grid(
      KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,
      XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
      XXXXXXX, AU_PREV, AU_NEXT, AU_ON,   AU_OFF,  XXXXXXX, XXXXXXX, QWERTY,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
      XXXXXXX, XXXXXXX, MU_NEXT, MU_ON,   MU_OFF,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
      QK_BOOT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
    ),
    /* Compositor
     * ,-----------------------------------------------------------------------------------.
     * |      |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |      |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  |      |
     * |------+------+------+------+------+-------------+------+------+------+------+------|
     * |Shift |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   '  |Enter |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |   Z  |   X  |   C  |  V   |   B  |   N  |   M  |   ,  |   .  |   /  |      |
     * |------+------+------+------+------+------+------+------+------+------+------+------|
     * |      |      |      |      |      |      |Space |      |      |      |      |      |
     * `-----------------------------------------------------------------------------------'
     */
    [_COMPOSITOR] = LAYOUT_preonic_grid(
      XXXXXXX,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    XXXXXXX,
      XXXXXXX,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    XXXXXXX,
      _______,  KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_QUOT, _______,
      XXXXXXX,  KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, XXXXXXX,
      XXXXXXX,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_SPC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
    )
};

static inline bool base_layer_hold_key(uint16_t keycode, keyrecord_t *record) {
    if (!record->tap.count && record->event.pressed) {
        tap_code16(keycode);
        return false;
    }
    return true;
}

static inline bool toggle_layer(enum preonic_layers layer, keyrecord_t *record) {
    if (record->event.pressed) {
        layer_on(layer);
    } else {
        layer_off(layer);
    }
    return false;
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case QWERTY:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_QWERTY);
            }
            return false;
        case LOWER:
	    return toggle_layer(_LOWER, record);
        case RAISE:
	    return toggle_layer(_RAISE, record);
        case MANAGE:
	    return toggle_layer(_MANAGE, record);
        case COMPOSITOR:
	    return toggle_layer(_COMPOSITOR, record);
        case LT_CUT_X:
	    return base_layer_hold_key(C(KC_X), record); /* cut on hold */
        case LT_COPY_Y:
	    return base_layer_hold_key(C(KC_C), record); /* copy on hold */
        case LT_PASTE_P:
	    return base_layer_hold_key(C(KC_V), record); /* paste on hold */
        case LT_AE_A:
	    return base_layer_hold_key(RALT(KC_Q), record); /* 'ä' on hold */
        case LT_OE_O:
	    return base_layer_hold_key(RALT(KC_P), record); /* 'ö' on hold */
        case LT_UE_U:
	    return base_layer_hold_key(RALT(KC_Y), record); /* 'ü' on hold */
        case LT_SZ_S:
	    return base_layer_hold_key(RALT(KC_S), record); /* 'ß' on hold */
    }

    return true;
};

bool     muse_mode      = false;
uint8_t  last_muse_note = 0;
uint16_t muse_counter   = 0;
uint8_t  muse_offset    = 70;
uint16_t muse_tempo     = 50;

bool encoder_update_user(uint8_t index, bool clockwise) {
    if (muse_mode) {
        if (IS_LAYER_ON(_RAISE)) {
            if (clockwise) {
                muse_offset++;
            } else {
                muse_offset--;
            }
        } else {
            if (clockwise) {
                muse_tempo += 1;
            } else {
                muse_tempo -= 1;
            }
        }
    } else {
        if (clockwise) {
            tap_code(KC_PGDN);
        } else {
            tap_code(KC_PGUP);
        }
    }
    return true;
}

bool dip_switch_update_user(uint8_t index, bool active) {
    switch (index) {
        case 0:
            if (active) {
                layer_on(_MANAGE);
            } else {
                layer_off(_MANAGE);
            }
            break;
        case 1:
            if (active) {
                muse_mode = true;
            } else {
                muse_mode = false;
            }
    }
    return true;
}

LEADER_EXTERNS();

static inline void register_ctrl_sequence(uint16_t keycode) {
    tap_code16(RCTL(keycode));
}

static inline void leader_bindings(void) {
    LEADER_DICTIONARY() {
        leading = false;
        leader_end();

        SEQ_THREE_KEYS(KC_A, KC_C, KC_K) {
            SEND_STRING("Acked-by: Christian Brauner <brauner@kernel.org>");
        }

        SEQ_THREE_KEYS(KC_R, KC_V, KC_B) {
            SEND_STRING("Reviewed-by: Christian Brauner <brauner@kernel.org>");
        }

        SEQ_THREE_KEYS(KC_S, KC_O, KC_B) {
            SEND_STRING("Signed-off-by: Christian Brauner <brauner@kernel.org>");
        }

        /* Support vim-style copy. */
        SEQ_ONE_KEY(KC_Y) {
            tap_code16(C(S(KC_C)));
        }

        /* Support vim-style paste. */
        SEQ_ONE_KEY(KC_P) {
            tap_code16(C(S(KC_V)));
        }
    }
}

void matrix_scan_user(void) {
    leader_bindings();

#ifdef AUDIO_ENABLE
    if (muse_mode) {
        if (muse_counter == 0) {
            uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
            if (muse_note != last_muse_note) {
                stop_note(compute_freq_for_midi_note(last_muse_note));
                play_note(compute_freq_for_midi_note(muse_note), 0xF);
                last_muse_note = muse_note;
            }
        }
        muse_counter = (muse_counter + 1) % muse_tempo;
    } else {
        if (muse_counter) {
            stop_all_notes();
            muse_counter = 0;
        }
    }
#endif
}

bool music_mask_user(uint16_t keycode) {
    switch (keycode) {
        case RAISE:
        case LOWER:
            return false;
        default:
            return true;
    }
}