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;
26 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
29 static bool music_sequence_recording = false;
30 static bool music_sequence_playing = false;
31 static float music_sequence[16] = {0};
32 static uint8_t music_sequence_count = 0;
33 static uint8_t music_sequence_position = 0;
35 static uint16_t music_sequence_timer = 0;
36 static uint16_t music_sequence_interval = 100;
41 bool midi_activated = false;
46 uint16_t leader_time = 0;
48 uint16_t leader_sequence[3] = {0, 0, 0};
49 uint8_t leader_sequence_size = 0;
52 #define CHORDING_MAX 4
53 bool chording = false;
55 uint8_t chord_keys[CHORDING_MAX] = {0};
56 uint8_t chord_key_count = 0;
57 uint8_t chord_key_down = 0;
60 static uint8_t input_mode;
63 bool keys_chord(uint8_t keys[]) {
64 uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
67 for (uint8_t i = 0; i < chord_key_count; i++) {
69 for (uint8_t j = 0; j < keys_size; j++) {
70 if (chord_keys[i] == (keys[j] & 0xFF)) {
71 in++; // detects key in chord
78 if (chord_keys[i] != 0) {
79 pass = false; // makes sure rest are blank
82 return (pass && (in == keys_size));
87 uint16_t hex_to_keycode(uint8_t hex)
91 } else if (hex < 0xA) {
92 return KC_1 + (hex - 0x1);
94 return KC_A + (hex - 0xA);
98 void set_unicode_mode(uint8_t os_target)
100 input_mode = os_target;
105 bool process_record_quantum(keyrecord_t *record) {
107 /* This gets the keycode from the key pressed */
108 keypos_t key = record->event.key;
111 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
114 if (record->event.pressed) {
115 layer = layer_switch_get_layer(key);
116 update_source_layers_cache(key, layer);
118 layer = read_source_layers_cache(key);
120 keycode = keymap_key_to_keycode(layer, key);
122 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
125 // This is how you use actions here
126 // if (keycode == KC_LEAD) {
128 // action.code = ACTION_DEFAULT_LAYER_SET(0);
129 // process_action(record, action);
134 if (keycode == MI_ON && record->event.pressed) {
135 midi_activated = true;
140 if (keycode == MI_OFF && record->event.pressed) {
141 midi_activated = false;
142 midi_send_cc(&midi_device, 0, 0x7B, 0);
146 if (midi_activated) {
147 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
148 if (record->event.pressed) {
149 starting_note++; // Change key
150 midi_send_cc(&midi_device, 0, 0x7B, 0);
151 // midi_send_cc(&midi_device, 1, 0x7B, 0);
152 // midi_send_cc(&midi_device, 2, 0x7B, 0);
153 // midi_send_cc(&midi_device, 3, 0x7B, 0);
154 // midi_send_cc(&midi_device, 4, 0x7B, 0);
158 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
159 if (record->event.pressed) {
160 starting_note--; // Change key
161 midi_send_cc(&midi_device, 0, 0x7B, 0);
162 // midi_send_cc(&midi_device, 1, 0x7B, 0);
163 // midi_send_cc(&midi_device, 2, 0x7B, 0);
164 // midi_send_cc(&midi_device, 3, 0x7B, 0);
165 // midi_send_cc(&midi_device, 4, 0x7B, 0);
169 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
170 offset++; // Change scale
171 midi_send_cc(&midi_device, 0, 0x7B, 0);
172 // midi_send_cc(&midi_device, 1, 0x7B, 0);
173 // midi_send_cc(&midi_device, 2, 0x7B, 0);
174 // midi_send_cc(&midi_device, 3, 0x7B, 0);
175 // midi_send_cc(&midi_device, 4, 0x7B, 0);
178 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
179 offset--; // Change scale
180 midi_send_cc(&midi_device, 0, 0x7B, 0);
181 // midi_send_cc(&midi_device, 1, 0x7B, 0);
182 // midi_send_cc(&midi_device, 2, 0x7B, 0);
183 // midi_send_cc(&midi_device, 3, 0x7B, 0);
184 // midi_send_cc(&midi_device, 4, 0x7B, 0);
188 // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
190 // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
192 uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
194 // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
196 if (record->event.pressed) {
197 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
198 midi_send_noteon(&midi_device, 0, note, 127);
200 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
201 midi_send_noteoff(&midi_device, 0, note, 127);
204 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
210 if (keycode == AU_ON && record->event.pressed) {
215 if (keycode == AU_OFF && record->event.pressed) {
220 if (keycode == AU_TOG && record->event.pressed) {
232 if (keycode == MU_ON && record->event.pressed) {
237 if (keycode == MU_OFF && record->event.pressed) {
242 if (keycode == MU_TOG && record->event.pressed) {
254 if (keycode == MUV_IN && record->event.pressed) {
260 if (keycode == MUV_DE && record->event.pressed) {
266 if (music_activated) {
268 if (keycode == KC_LCTL && record->event.pressed) { // Start recording
270 music_sequence_recording = true;
271 music_sequence_playing = false;
272 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;
281 if (keycode == KC_LGUI && record->event.pressed) { // Start playing
283 music_sequence_recording = false;
284 music_sequence_playing = true;
285 music_sequence_position = 0;
286 music_sequence_timer = 0;
290 if (keycode == KC_UP) {
291 if (record->event.pressed)
292 music_sequence_interval-=10;
295 if (keycode == KC_DOWN) {
296 if (record->event.pressed)
297 music_sequence_interval+=10;
301 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));
302 if (record->event.pressed) {
303 play_note(freq, 0xF);
304 if (music_sequence_recording) {
305 music_sequence[music_sequence_count] = freq;
306 music_sequence_count++;
312 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
317 #ifndef DISABLE_LEADER
319 if (record->event.pressed) {
320 if (!leading && keycode == KC_LEAD) {
323 leader_time = timer_read();
324 leader_sequence_size = 0;
325 leader_sequence[0] = 0;
326 leader_sequence[1] = 0;
327 leader_sequence[2] = 0;
330 if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
331 leader_sequence[leader_sequence_size] = keycode;
332 leader_sequence_size++;
338 #define DISABLE_CHORDING
339 #ifndef DISABLE_CHORDING
341 if (keycode >= 0x5700 && keycode <= 0x57FF) {
342 if (record->event.pressed) {
345 for (uint8_t i = 0; i < CHORDING_MAX; i++)
350 chord_keys[chord_key_count] = (keycode & 0xFF);
357 if (chord_key_down == 0) {
360 if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
362 unregister_code(KC_A);
365 for (uint8_t i = 0; i < chord_key_count; i++) {
366 register_code(chord_keys[i]);
367 unregister_code(chord_keys[i]);
377 #ifdef UNICODE_ENABLE
379 if (keycode > UNICODE(0) && record->event.pressed) {
380 uint16_t unicode = keycode & 0x7FFF;
383 register_code(KC_LALT);
386 register_code(KC_LCTL);
387 register_code(KC_LSFT);
389 unregister_code(KC_U);
392 register_code(KC_LALT);
393 register_code(KC_PPLS);
394 unregister_code(KC_PPLS);
397 for(int i = 3; i >= 0; i--) {
398 uint8_t digit = ((unicode >> (i*4)) & 0xF);
399 register_code(hex_to_keycode(digit));
400 unregister_code(hex_to_keycode(digit));
405 unregister_code(KC_LALT);
408 unregister_code(KC_LCTL);
409 unregister_code(KC_LSFT);
416 return process_action_kb(record);
419 void matrix_init_quantum() {
423 void matrix_scan_quantum() {
425 if (music_sequence_playing) {
426 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
427 music_sequence_timer = timer_read();
428 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
429 play_note(music_sequence[music_sequence_position], 0xF);
430 music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
439 bool is_music_on(void) {
440 return (music_activated != 0);
443 void music_toggle(void) {
444 if (!music_activated) {
451 void music_on(void) {
456 void music_off(void) {
462 __attribute__ ((weak))
463 void music_on_user() {}