5 void matrix_init_kb(void) {}
8 void matrix_scan_kb(void) {}
10 __attribute__ ((weak))
11 bool process_action_kb(keyrecord_t *record) {
15 __attribute__ ((weak))
16 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
17 return process_record_user(keycode, record);
20 __attribute__ ((weak))
21 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
25 __attribute__ ((weak))
26 void leader_start(void) {}
28 __attribute__ ((weak))
29 void leader_end(void) {}
31 uint8_t starting_note = 0x0C;
36 bool music_activated = false;
39 static bool music_sequence_recording = false;
40 static bool music_sequence_playing = false;
41 static float music_sequence[16] = {0};
42 static uint8_t music_sequence_count = 0;
43 static uint8_t music_sequence_position = 0;
45 static uint16_t music_sequence_timer = 0;
46 static uint16_t music_sequence_interval = 100;
51 bool midi_activated = false;
56 uint16_t leader_time = 0;
58 uint16_t leader_sequence[3] = {0, 0, 0};
59 uint8_t leader_sequence_size = 0;
62 #define CHORDING_MAX 4
63 bool chording = false;
65 uint8_t chord_keys[CHORDING_MAX] = {0};
66 uint8_t chord_key_count = 0;
67 uint8_t chord_key_down = 0;
70 static uint8_t input_mode;
73 static bool shift_interrupted[2] = {0, 0};
75 bool keys_chord(uint8_t keys[]) {
76 uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
79 for (uint8_t i = 0; i < chord_key_count; i++) {
81 for (uint8_t j = 0; j < keys_size; j++) {
82 if (chord_keys[i] == (keys[j] & 0xFF)) {
83 in++; // detects key in chord
90 if (chord_keys[i] != 0) {
91 pass = false; // makes sure rest are blank
94 return (pass && (in == keys_size));
99 uint16_t hex_to_keycode(uint8_t hex)
103 } else if (hex < 0xA) {
104 return KC_1 + (hex - 0x1);
106 return KC_A + (hex - 0xA);
110 void set_unicode_mode(uint8_t os_target)
112 input_mode = os_target;
117 bool process_record_quantum(keyrecord_t *record) {
119 /* This gets the keycode from the key pressed */
120 keypos_t key = record->event.key;
123 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
126 if (record->event.pressed) {
127 layer = layer_switch_get_layer(key);
128 update_source_layers_cache(key, layer);
130 layer = read_source_layers_cache(key);
132 keycode = keymap_key_to_keycode(layer, key);
134 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
137 if (!process_record_kb(keycode, record))
140 // This is how you use actions here
141 // if (keycode == KC_LEAD) {
143 // action.code = ACTION_DEFAULT_LAYER_SET(0);
144 // process_action(record, action);
149 if (keycode == MI_ON && record->event.pressed) {
150 midi_activated = true;
155 if (keycode == MI_OFF && record->event.pressed) {
156 midi_activated = false;
157 midi_send_cc(&midi_device, 0, 0x7B, 0);
161 if (midi_activated) {
162 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
163 if (record->event.pressed) {
164 starting_note++; // Change key
165 midi_send_cc(&midi_device, 0, 0x7B, 0);
166 // midi_send_cc(&midi_device, 1, 0x7B, 0);
167 // midi_send_cc(&midi_device, 2, 0x7B, 0);
168 // midi_send_cc(&midi_device, 3, 0x7B, 0);
169 // midi_send_cc(&midi_device, 4, 0x7B, 0);
173 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
174 if (record->event.pressed) {
175 starting_note--; // Change key
176 midi_send_cc(&midi_device, 0, 0x7B, 0);
177 // midi_send_cc(&midi_device, 1, 0x7B, 0);
178 // midi_send_cc(&midi_device, 2, 0x7B, 0);
179 // midi_send_cc(&midi_device, 3, 0x7B, 0);
180 // midi_send_cc(&midi_device, 4, 0x7B, 0);
184 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
185 offset++; // Change scale
186 midi_send_cc(&midi_device, 0, 0x7B, 0);
187 // midi_send_cc(&midi_device, 1, 0x7B, 0);
188 // midi_send_cc(&midi_device, 2, 0x7B, 0);
189 // midi_send_cc(&midi_device, 3, 0x7B, 0);
190 // midi_send_cc(&midi_device, 4, 0x7B, 0);
193 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
194 offset--; // Change scale
195 midi_send_cc(&midi_device, 0, 0x7B, 0);
196 // midi_send_cc(&midi_device, 1, 0x7B, 0);
197 // midi_send_cc(&midi_device, 2, 0x7B, 0);
198 // midi_send_cc(&midi_device, 3, 0x7B, 0);
199 // midi_send_cc(&midi_device, 4, 0x7B, 0);
203 // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
205 // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
207 uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
209 // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
211 if (record->event.pressed) {
212 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
213 midi_send_noteon(&midi_device, 0, note, 127);
215 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
216 midi_send_noteoff(&midi_device, 0, note, 127);
219 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
225 if (keycode == AU_ON && record->event.pressed) {
230 if (keycode == AU_OFF && record->event.pressed) {
235 if (keycode == AU_TOG && record->event.pressed) {
247 if (keycode == MU_ON && record->event.pressed) {
252 if (keycode == MU_OFF && record->event.pressed) {
257 if (keycode == MU_TOG && record->event.pressed) {
269 if (keycode == MUV_IN && record->event.pressed) {
275 if (keycode == MUV_DE && record->event.pressed) {
281 if (music_activated) {
283 if (keycode == KC_LCTL && record->event.pressed) { // Start recording
285 music_sequence_recording = true;
286 music_sequence_playing = false;
287 music_sequence_count = 0;
291 if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
293 music_sequence_recording = false;
294 music_sequence_playing = false;
298 if (keycode == KC_LGUI && record->event.pressed) { // Start playing
300 music_sequence_recording = false;
301 music_sequence_playing = true;
302 music_sequence_position = 0;
303 music_sequence_timer = 0;
307 if (keycode == KC_UP) {
308 if (record->event.pressed)
309 music_sequence_interval-=10;
313 if (keycode == KC_DOWN) {
314 if (record->event.pressed)
315 music_sequence_interval+=10;
319 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
320 if (record->event.pressed) {
321 play_note(freq, 0xF);
322 if (music_sequence_recording) {
323 music_sequence[music_sequence_count] = freq;
324 music_sequence_count++;
330 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
335 #ifndef DISABLE_LEADER
337 if (record->event.pressed) {
338 if (!leading && keycode == KC_LEAD) {
341 leader_time = timer_read();
342 leader_sequence_size = 0;
343 leader_sequence[0] = 0;
344 leader_sequence[1] = 0;
345 leader_sequence[2] = 0;
348 if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
349 leader_sequence[leader_sequence_size] = keycode;
350 leader_sequence_size++;
356 #define DISABLE_CHORDING
357 #ifndef DISABLE_CHORDING
359 if (keycode >= 0x5700 && keycode <= 0x57FF) {
360 if (record->event.pressed) {
363 for (uint8_t i = 0; i < CHORDING_MAX; i++)
368 chord_keys[chord_key_count] = (keycode & 0xFF);
375 if (chord_key_down == 0) {
378 if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
380 unregister_code(KC_A);
383 for (uint8_t i = 0; i < chord_key_count; i++) {
384 register_code(chord_keys[i]);
385 unregister_code(chord_keys[i]);
395 #ifdef UNICODE_ENABLE
397 if (keycode > UNICODE(0) && record->event.pressed) {
398 uint16_t unicode = keycode & 0x7FFF;
401 register_code(KC_LALT);
404 register_code(KC_LCTL);
405 register_code(KC_LSFT);
407 unregister_code(KC_U);
410 register_code(KC_LALT);
411 register_code(KC_PPLS);
412 unregister_code(KC_PPLS);
415 for(int i = 3; i >= 0; i--) {
416 uint8_t digit = ((unicode >> (i*4)) & 0xF);
417 register_code(hex_to_keycode(digit));
418 unregister_code(hex_to_keycode(digit));
423 unregister_code(KC_LALT);
426 unregister_code(KC_LCTL);
427 unregister_code(KC_LSFT);
436 if (record->event.pressed) {
437 shift_interrupted[0] = false;
438 register_mods(MOD_BIT(KC_LSFT));
441 if (!shift_interrupted[0]) {
443 unregister_code(KC_9);
445 unregister_mods(MOD_BIT(KC_LSFT));
452 if (record->event.pressed) {
453 shift_interrupted[1] = false;
454 register_mods(MOD_BIT(KC_RSFT));
457 if (!shift_interrupted[1]) {
459 unregister_code(KC_0);
461 unregister_mods(MOD_BIT(KC_RSFT));
467 shift_interrupted[0] = true;
468 shift_interrupted[1] = true;
473 return process_action_kb(record);
476 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
477 0, 0, 0, 0, 0, 0, 0, 0,
478 0, 0, 0, 0, 0, 0, 0, 0,
479 0, 0, 0, 0, 0, 0, 0, 0,
480 0, 0, 0, 0, 0, 0, 0, 0,
481 0, 1, 1, 1, 1, 1, 1, 0,
482 1, 1, 1, 1, 0, 0, 0, 0,
483 0, 0, 0, 0, 0, 0, 0, 0,
484 0, 0, 1, 0, 1, 0, 1, 1,
485 1, 1, 1, 1, 1, 1, 1, 1,
486 1, 1, 1, 1, 1, 1, 1, 1,
487 1, 1, 1, 1, 1, 1, 1, 1,
488 1, 1, 1, 0, 0, 0, 1, 1,
489 0, 0, 0, 0, 0, 0, 0, 0,
490 0, 0, 0, 0, 0, 0, 0, 0,
491 0, 0, 0, 0, 0, 0, 0, 0,
492 0, 0, 0, 1, 1, 1, 1, 0
495 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
496 0, 0, 0, 0, 0, 0, 0, 0,
497 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
498 0, 0, 0, 0, 0, 0, 0, 0,
499 0, 0, 0, KC_ESC, 0, 0, 0, 0,
500 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
501 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
502 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
503 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
504 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
505 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
506 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
507 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
508 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
509 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
510 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
511 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
514 /* for users whose OSes are set to Colemak */
516 #include "keymap_colemak.h"
518 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
519 0, 0, 0, 0, 0, 0, 0, 0,
520 0, 0, 0, 0, 0, 0, 0, 0,
521 0, 0, 0, 0, 0, 0, 0, 0,
522 0, 0, 0, 0, 0, 0, 0, 0,
523 0, 1, 1, 1, 1, 1, 1, 0,
524 1, 1, 1, 1, 0, 0, 0, 0,
525 0, 0, 0, 0, 0, 0, 0, 0,
526 0, 0, 1, 0, 1, 0, 1, 1,
527 1, 1, 1, 1, 1, 1, 1, 1,
528 1, 1, 1, 1, 1, 1, 1, 1,
529 1, 1, 1, 1, 1, 1, 1, 1,
530 1, 1, 1, 0, 0, 0, 1, 1,
531 0, 0, 0, 0, 0, 0, 0, 0,
532 0, 0, 0, 0, 0, 0, 0, 0,
533 0, 0, 0, 0, 0, 0, 0, 0,
534 0, 0, 0, 1, 1, 1, 1, 0
537 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
538 0, 0, 0, 0, 0, 0, 0, 0,
539 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
540 0, 0, 0, 0, 0, 0, 0, 0,
541 0, 0, 0, KC_ESC, 0, 0, 0, 0,
542 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
543 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
544 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
545 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
546 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
547 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
548 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
549 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
550 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
551 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
552 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
553 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
558 void send_string(const char *str) {
561 uint8_t ascii_code = pgm_read_byte(str);
562 if (!ascii_code) break;
563 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
564 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
565 register_code(KC_LSFT);
566 register_code(keycode);
567 unregister_code(keycode);
568 unregister_code(KC_LSFT);
571 register_code(keycode);
572 unregister_code(keycode);
579 void matrix_init_quantum() {
583 void matrix_scan_quantum() {
585 if (music_sequence_playing) {
586 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
587 music_sequence_timer = timer_read();
588 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
589 play_note(music_sequence[music_sequence_position], 0xF);
590 music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
599 bool is_music_on(void) {
600 return (music_activated != 0);
603 void music_toggle(void) {
604 if (!music_activated) {
611 void music_on(void) {
616 void music_off(void) {
623 //------------------------------------------------------------------------------
624 // Override these functions in your keymap file to play different tunes on
625 // different events such as startup and bootloader jump
627 __attribute__ ((weak))
628 void startup_user() {}
630 __attribute__ ((weak))
631 void shutdown_user() {}
633 __attribute__ ((weak))
634 void music_on_user() {}
636 __attribute__ ((weak))
637 void audio_on_user() {}
639 __attribute__ ((weak))
640 void music_scale_user() {}
642 //------------------------------------------------------------------------------