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 void leader_start(void) {}
18 __attribute__ ((weak))
19 void leader_end(void) {}
21 uint8_t starting_note = 0x0C;
25 bool music_activated = false;
28 static bool music_sequence_recording = false;
29 static bool music_sequence_playing = false;
30 static float music_sequence[16] = {0};
31 static uint8_t music_sequence_count = 0;
32 static uint8_t music_sequence_position = 0;
34 static uint16_t music_sequence_timer = 0;
35 static uint16_t music_sequence_interval = 100;
40 bool midi_activated = false;
45 uint16_t leader_time = 0;
47 uint16_t leader_sequence[3] = {0, 0, 0};
48 uint8_t leader_sequence_size = 0;
51 #define CHORDING_MAX 4
52 bool chording = false;
54 uint8_t chord_keys[CHORDING_MAX] = {0};
55 uint8_t chord_key_count = 0;
56 uint8_t chord_key_down = 0;
59 static uint8_t input_mode;
62 bool keys_chord(uint8_t keys[]) {
63 uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
66 for (uint8_t i = 0; i < chord_key_count; i++) {
68 for (uint8_t j = 0; j < keys_size; j++) {
69 if (chord_keys[i] == (keys[j] & 0xFF)) {
70 in++; // detects key in chord
77 if (chord_keys[i] != 0) {
78 pass = false; // makes sure rest are blank
81 return (pass && (in == keys_size));
86 uint16_t hex_to_keycode(uint8_t hex)
90 } else if (hex < 0xA) {
91 return KC_1 + (hex - 0x1);
93 return KC_A + (hex - 0xA);
97 void set_unicode_mode(uint8_t os_target)
99 input_mode = os_target;
104 bool process_record_quantum(keyrecord_t *record) {
106 /* This gets the keycode from the key pressed */
107 keypos_t key = record->event.key;
110 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
113 if (record->event.pressed) {
114 layer = layer_switch_get_layer(key);
115 update_source_layers_cache(key, layer);
117 layer = read_source_layers_cache(key);
119 keycode = keymap_key_to_keycode(layer, key);
121 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
124 // This is how you use actions here
125 // if (keycode == KC_LEAD) {
127 // action.code = ACTION_DEFAULT_LAYER_SET(0);
128 // process_action(record, action);
133 if (keycode == MI_ON && record->event.pressed) {
134 midi_activated = true;
139 if (keycode == MI_OFF && record->event.pressed) {
140 midi_activated = false;
141 midi_send_cc(&midi_device, 0, 0x7B, 0);
145 if (midi_activated) {
146 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
147 if (record->event.pressed) {
148 starting_note++; // Change key
149 midi_send_cc(&midi_device, 0, 0x7B, 0);
150 // midi_send_cc(&midi_device, 1, 0x7B, 0);
151 // midi_send_cc(&midi_device, 2, 0x7B, 0);
152 // midi_send_cc(&midi_device, 3, 0x7B, 0);
153 // midi_send_cc(&midi_device, 4, 0x7B, 0);
157 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
158 if (record->event.pressed) {
159 starting_note--; // Change key
160 midi_send_cc(&midi_device, 0, 0x7B, 0);
161 // midi_send_cc(&midi_device, 1, 0x7B, 0);
162 // midi_send_cc(&midi_device, 2, 0x7B, 0);
163 // midi_send_cc(&midi_device, 3, 0x7B, 0);
164 // midi_send_cc(&midi_device, 4, 0x7B, 0);
168 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
169 offset++; // Change scale
170 midi_send_cc(&midi_device, 0, 0x7B, 0);
171 // midi_send_cc(&midi_device, 1, 0x7B, 0);
172 // midi_send_cc(&midi_device, 2, 0x7B, 0);
173 // midi_send_cc(&midi_device, 3, 0x7B, 0);
174 // midi_send_cc(&midi_device, 4, 0x7B, 0);
177 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
178 offset--; // Change scale
179 midi_send_cc(&midi_device, 0, 0x7B, 0);
180 // midi_send_cc(&midi_device, 1, 0x7B, 0);
181 // midi_send_cc(&midi_device, 2, 0x7B, 0);
182 // midi_send_cc(&midi_device, 3, 0x7B, 0);
183 // midi_send_cc(&midi_device, 4, 0x7B, 0);
187 // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
189 // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
191 uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
193 // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
195 if (record->event.pressed) {
196 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
197 midi_send_noteon(&midi_device, 0, note, 127);
199 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
200 midi_send_noteoff(&midi_device, 0, note, 127);
203 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
209 if (keycode == AU_ON && record->event.pressed) {
214 if (keycode == AU_OFF && record->event.pressed) {
219 if (keycode == AU_TOG && record->event.pressed) {
231 if (keycode == MU_ON && record->event.pressed) {
236 if (keycode == MU_OFF && record->event.pressed) {
241 if (keycode == MU_TOG && record->event.pressed) {
253 if (keycode == MUV_IN && record->event.pressed) {
259 if (keycode == MUV_DE && record->event.pressed) {
265 if (music_activated) {
267 if (keycode == KC_LCTL && record->event.pressed) { // Start recording
269 music_sequence_recording = true;
270 music_sequence_playing = false;
271 music_sequence_count = 0;
275 if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
277 music_sequence_recording = false;
278 music_sequence_playing = false;
282 if (keycode == KC_LGUI && record->event.pressed) { // Start playing
284 music_sequence_recording = false;
285 music_sequence_playing = true;
286 music_sequence_position = 0;
287 music_sequence_timer = 0;
291 if (keycode == KC_UP) {
292 if (record->event.pressed)
293 music_sequence_interval-=10;
297 if (keycode == KC_DOWN) {
298 if (record->event.pressed)
299 music_sequence_interval+=10;
303 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));
304 if (record->event.pressed) {
305 play_note(freq, 0xF);
306 if (music_sequence_recording) {
307 music_sequence[music_sequence_count] = freq;
308 music_sequence_count++;
314 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
319 #ifndef DISABLE_LEADER
321 if (record->event.pressed) {
322 if (!leading && keycode == KC_LEAD) {
325 leader_time = timer_read();
326 leader_sequence_size = 0;
327 leader_sequence[0] = 0;
328 leader_sequence[1] = 0;
329 leader_sequence[2] = 0;
332 if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
333 leader_sequence[leader_sequence_size] = keycode;
334 leader_sequence_size++;
340 #define DISABLE_CHORDING
341 #ifndef DISABLE_CHORDING
343 if (keycode >= 0x5700 && keycode <= 0x57FF) {
344 if (record->event.pressed) {
347 for (uint8_t i = 0; i < CHORDING_MAX; i++)
352 chord_keys[chord_key_count] = (keycode & 0xFF);
359 if (chord_key_down == 0) {
362 if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
364 unregister_code(KC_A);
367 for (uint8_t i = 0; i < chord_key_count; i++) {
368 register_code(chord_keys[i]);
369 unregister_code(chord_keys[i]);
379 #ifdef UNICODE_ENABLE
381 if (keycode > UNICODE(0) && record->event.pressed) {
382 uint16_t unicode = keycode & 0x7FFF;
385 register_code(KC_LALT);
388 register_code(KC_LCTL);
389 register_code(KC_LSFT);
391 unregister_code(KC_U);
394 register_code(KC_LALT);
395 register_code(KC_PPLS);
396 unregister_code(KC_PPLS);
399 for(int i = 3; i >= 0; i--) {
400 uint8_t digit = ((unicode >> (i*4)) & 0xF);
401 register_code(hex_to_keycode(digit));
402 unregister_code(hex_to_keycode(digit));
407 unregister_code(KC_LALT);
410 unregister_code(KC_LCTL);
411 unregister_code(KC_LSFT);
418 return process_action_kb(record);
421 void matrix_init_quantum() {
425 void matrix_scan_quantum() {
427 if (music_sequence_playing) {
428 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
429 music_sequence_timer = timer_read();
430 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
431 play_note(music_sequence[music_sequence_position], 0xF);
432 music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
441 bool is_music_on(void) {
442 return (music_activated != 0);
445 void music_toggle(void) {
446 if (!music_activated) {
453 void music_on(void) {
458 void music_off(void) {
465 //------------------------------------------------------------------------------
466 // Override these functions in your keymap file to play different tunes on
467 // different events such as startup and bootloader jump
469 __attribute__ ((weak))
470 void startup_user() {}
472 __attribute__ ((weak))
473 void shutdown_user() {}
475 __attribute__ ((weak))
476 void music_on_user() {}
478 __attribute__ ((weak))
479 void audio_on_user() {}
481 __attribute__ ((weak))
482 void music_scale_user() {}
484 //------------------------------------------------------------------------------