From 2a231457bd494079c36cf3e07c9b887016adb491 Mon Sep 17 00:00:00 2001 From: Aapo Saaristo Date: Tue, 16 Jul 2019 08:53:04 +0300 Subject: Add user-overridable callback for cancelling UCIS input (#5564) * Add user-overridable callback for cancelling UCIS input To clean up things from qk_ucis_start_user() for instance. * restore lost newline to quantum/process_keycode/process_ucis.c Co-Authored-By: shinmai --- quantum/process_keycode/process_ucis.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 5de2e41fc3..fd4508b535 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -64,6 +64,10 @@ void qk_ucis_symbol_fallback (void) { } } +__attribute__((weak)) +void qk_ucis_cancel(void) { +} + void register_ucis(const char *hex) { for(int i = 0; hex[i]; i++) { uint8_t kc = 0; @@ -130,6 +134,7 @@ bool process_ucis (uint16_t keycode, keyrecord_t *record) { if (keycode == KC_ESC) { qk_ucis_state.in_progress = false; + qk_ucis_cancel(); return false; } -- cgit v1.2.3 From 09f5767072b65d98371199ab03981940d132b123 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 15 Jul 2019 23:56:34 -0700 Subject: Add out of bound check for Leader Key sequence array (#5840) * Add out of bound check for Leader Key sequence array * A shot at advanced C stuff for Leader Key optimization * Revert most changes * Change default back * Include string.h if compiling for ARM * Use sizeof instead of a number --- quantum/process_keycode/process_leader.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index 897e9eabf6..ee8099ca21 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -17,6 +17,9 @@ #ifdef LEADER_ENABLE #include "process_leader.h" +#ifdef __arm__ +# include +#endif #ifndef LEADER_TIMEOUT #define LEADER_TIMEOUT 300 @@ -41,11 +44,7 @@ void qk_leader_start(void) { leading = true; leader_time = timer_read(); leader_sequence_size = 0; - leader_sequence[0] = 0; - leader_sequence[1] = 0; - leader_sequence[2] = 0; - leader_sequence[3] = 0; - leader_sequence[4] = 0; + memset(leader_sequence, 0, sizeof(leader_sequence)); } bool process_leader(uint16_t keycode, keyrecord_t *record) { @@ -58,8 +57,13 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) { keycode = keycode & 0xFF; } #endif // LEADER_KEY_STRICT_KEY_PROCESSING - leader_sequence[leader_sequence_size] = keycode; - leader_sequence_size++; + if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) { + leader_sequence[leader_sequence_size] = keycode; + leader_sequence_size++; + } else { + leading = false; + leader_end(); + } #ifdef LEADER_PER_KEY_TIMING leader_time = timer_read(); #endif -- cgit v1.2.3 From c44fc68297029da87233777aff6978d39caebbb1 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 16 Jul 2019 01:37:19 -0700 Subject: Allow Combo feature to be enabled/disabled live (#6318) * Add ability to enable/disable combos * Update documentation for Combo feature * Change keycodes for appeasement * Simplify combo_toggle function * Update names * Update combo docs to use tables --- quantum/process_keycode/process_combo.c | 43 ++++++++++++++++++++++++++++++++- quantum/process_keycode/process_combo.h | 5 ++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2c6c9d0d5f..d3c3b1673c 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -28,6 +28,7 @@ static uint16_t timer = 0; static uint8_t current_combo_index = 0; static bool drop_buffer = false; static bool is_active = false; +static bool b_combo_enable = true; // defaults to enabled static uint8_t buffer_size = 0; #ifdef COMBO_ALLOW_ACTION_KEYS @@ -128,6 +129,23 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { drop_buffer = false; bool no_combo_keys_pressed = true; + if (keycode == CMB_ON && record->event.pressed) { + combo_enable(); + return true; + } + + if (keycode == CMB_OFF && record->event.pressed) { + combo_disable(); + return true; + } + + if (keycode == CMB_TOG && record->event.pressed) { + combo_toggle(); + return true; + } + + if (!is_combo_enabled()) { return true; } + for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { combo_t *combo = &key_combos[current_combo_index]; @@ -166,7 +184,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { } void matrix_scan_combo(void) { - if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) { + if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { /* This disables the combo, meaning key events for this * combo will be handled by the next processors in the chain @@ -175,3 +193,26 @@ void matrix_scan_combo(void) { dump_key_buffer(true); } } + +void combo_enable(void) { + b_combo_enable = true; +} + +void combo_disable(void) { + b_combo_enable = is_active = false; + timer = 0; + dump_key_buffer(true); + +} + +void combo_toggle(void) { + if (b_combo_enable) { + combo_disable(); + } else { + combo_enable(); + } +} + +bool is_combo_enabled(void) { + return b_combo_enable; +} diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index f06d2d3454..aab2849572 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -58,4 +58,9 @@ bool process_combo(uint16_t keycode, keyrecord_t *record); void matrix_scan_combo(void); void process_combo_event(uint8_t combo_index, bool pressed); +void combo_enable(void); +void combo_disable(void); +void combo_toggle(void); +bool is_combo_enabled(void); + #endif -- cgit v1.2.3 From e5d2cb8f98fb4dbec3c64e19acfaa4e6db57e257 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 16 Jul 2019 09:22:29 -0700 Subject: Fix Preprocessor check for Leader Keys --- quantum/process_keycode/process_leader.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index ee8099ca21..f787e6b017 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -17,9 +17,7 @@ #ifdef LEADER_ENABLE #include "process_leader.h" -#ifdef __arm__ -# include -#endif +#include #ifndef LEADER_TIMEOUT #define LEADER_TIMEOUT 300 -- cgit v1.2.3 From 009d45d4d75310e0c4c4b5678e2e4f0200d0d606 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Tue, 6 Aug 2019 14:26:28 -0400 Subject: MIDI: Fix basic noteon: send correct velocity (#6476) --- quantum/process_keycode/process_midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index a67f736285..be6455ee94 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -24,7 +24,7 @@ void process_midi_basic_noteon(uint8_t note) { - midi_send_noteon(&midi_device, 0, note, 128); + midi_send_noteon(&midi_device, 0, note, 127); } void process_midi_basic_noteoff(uint8_t note) -- cgit v1.2.3 From 406f03bb0ceeaf7fda7d04da2379c1f197b5cc6d Mon Sep 17 00:00:00 2001 From: fauxpark Date: Fri, 9 Aug 2019 07:15:34 +1000 Subject: Mask off TD() parameter properly (#6143) * Mask off TD() parameter properly * More parentheses --- quantum/process_keycode/process_tap_dance.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index ca12f4746e..00d70cbc59 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -34,7 +34,7 @@ typedef struct bool finished; } qk_tap_dance_state_t; -#define TD(n) (QK_TAP_DANCE + n) +#define TD(n) (QK_TAP_DANCE | ((n) & 0xFF)) typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data); -- cgit v1.2.3 From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- quantum/process_keycode/process_audio.c | 31 +- quantum/process_keycode/process_auto_shift.c | 296 ++++++++------- quantum/process_keycode/process_auto_shift.h | 2 +- quantum/process_keycode/process_clicky.c | 131 +++---- quantum/process_keycode/process_combo.c | 259 +++++++------ quantum/process_keycode/process_combo.h | 28 +- quantum/process_keycode/process_key_lock.c | 48 ++- quantum/process_keycode/process_key_lock.h | 2 +- quantum/process_keycode/process_leader.c | 86 ++--- quantum/process_keycode/process_leader.h | 7 +- quantum/process_keycode/process_midi.c | 115 +++--- quantum/process_keycode/process_midi.h | 30 +- quantum/process_keycode/process_music.c | 354 +++++++++--------- quantum/process_keycode/process_music.h | 28 +- quantum/process_keycode/process_printer.c | 443 +++++++++++------------ quantum/process_keycode/process_printer_bb.c | 435 +++++++++++----------- quantum/process_keycode/process_space_cadet.c | 175 +++++---- quantum/process_keycode/process_steno.c | 208 +++++------ quantum/process_keycode/process_steno.h | 8 +- quantum/process_keycode/process_tap_dance.c | 268 +++++++------- quantum/process_keycode/process_tap_dance.h | 113 +++--- quantum/process_keycode/process_terminal.c | 271 +++++++------- quantum/process_keycode/process_terminal.h | 2 +- quantum/process_keycode/process_ucis.c | 213 ++++++----- quantum/process_keycode/process_ucis.h | 24 +- quantum/process_keycode/process_unicode.c | 12 +- quantum/process_keycode/process_unicode_common.c | 321 ++++++++-------- quantum/process_keycode/process_unicode_common.h | 246 ++++++------- quantum/process_keycode/process_unicodemap.c | 95 ++--- quantum/process_keycode/process_unicodemap.h | 4 +- 30 files changed, 2028 insertions(+), 2227 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index 0a25aa5354..3b5fa8490b 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c @@ -2,30 +2,28 @@ #include "process_audio.h" #ifndef VOICE_CHANGE_SONG - #define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND) +# define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND) #endif float voice_change_song[][2] = VOICE_CHANGE_SONG; #ifndef PITCH_STANDARD_A - #define PITCH_STANDARD_A 440.0f +# define PITCH_STANDARD_A 440.0f #endif -float compute_freq_for_midi_note(uint8_t note) -{ +float compute_freq_for_midi_note(uint8_t note) { // https://en.wikipedia.org/wiki/MIDI_tuning_standard return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A; } bool process_audio(uint16_t keycode, keyrecord_t *record) { - if (keycode == AU_ON && record->event.pressed) { - audio_on(); - return false; + audio_on(); + return false; } if (keycode == AU_OFF && record->event.pressed) { - audio_off(); - return false; + audio_off(); + return false; } if (keycode == AU_TOG && record->event.pressed) { @@ -52,17 +50,10 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { return true; } -void process_audio_noteon(uint8_t note) { - play_note(compute_freq_for_midi_note(note), 0xF); -} +void process_audio_noteon(uint8_t note) { play_note(compute_freq_for_midi_note(note), 0xF); } -void process_audio_noteoff(uint8_t note) { - stop_note(compute_freq_for_midi_note(note)); -} +void process_audio_noteoff(uint8_t note) { stop_note(compute_freq_for_midi_note(note)); } -void process_audio_all_notes_off(void) { - stop_all_notes(); -} +void process_audio_all_notes_off(void) { stop_all_notes(); } -__attribute__ ((weak)) -void audio_on_user() {} +__attribute__((weak)) void audio_on_user() {} diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 0d0930ee67..4ae3fe446e 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -16,195 +16,185 @@ #ifdef AUTO_SHIFT_ENABLE -#include +# include -#include "process_auto_shift.h" +# include "process_auto_shift.h" -#define TAP(key) \ - register_code(key); \ - unregister_code(key) +# define TAP(key) \ + register_code(key); \ + unregister_code(key) -#define TAP_WITH_MOD(mod, key) \ - register_code(mod); \ - register_code(key); \ - unregister_code(key); \ - unregister_code(mod) +# define TAP_WITH_MOD(mod, key) \ + register_code(mod); \ + register_code(key); \ + unregister_code(key); \ + unregister_code(mod) -uint16_t autoshift_time = 0; +uint16_t autoshift_time = 0; uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; uint16_t autoshift_lastkey = KC_NO; void autoshift_timer_report(void) { - char display[8]; + char display[8]; - snprintf(display, 8, "\n%d\n", autoshift_timeout); + snprintf(display, 8, "\n%d\n", autoshift_timeout); - send_string((const char *)display); + send_string((const char *)display); } void autoshift_on(uint16_t keycode) { - autoshift_time = timer_read(); - autoshift_lastkey = keycode; + autoshift_time = timer_read(); + autoshift_lastkey = keycode; } void autoshift_flush(void) { - if (autoshift_lastkey != KC_NO) { - uint16_t elapsed = timer_elapsed(autoshift_time); + if (autoshift_lastkey != KC_NO) { + uint16_t elapsed = timer_elapsed(autoshift_time); - if (elapsed > autoshift_timeout) { - register_code(KC_LSFT); - } + if (elapsed > autoshift_timeout) { + register_code(KC_LSFT); + } - register_code(autoshift_lastkey); - unregister_code(autoshift_lastkey); + register_code(autoshift_lastkey); + unregister_code(autoshift_lastkey); - if (elapsed > autoshift_timeout) { - unregister_code(KC_LSFT); - } + if (elapsed > autoshift_timeout) { + unregister_code(KC_LSFT); + } - autoshift_time = 0; - autoshift_lastkey = KC_NO; - } + autoshift_time = 0; + autoshift_lastkey = KC_NO; + } } bool autoshift_enabled = true; -void autoshift_enable(void) { - autoshift_enabled = true; -} +void autoshift_enable(void) { autoshift_enabled = true; } void autoshift_disable(void) { - autoshift_enabled = false; - autoshift_flush(); -} - -void autoshift_toggle(void) { - if (autoshift_enabled) { autoshift_enabled = false; autoshift_flush(); - } - else { - autoshift_enabled = true; - } } -bool autoshift_state(void) { - return autoshift_enabled; +void autoshift_toggle(void) { + if (autoshift_enabled) { + autoshift_enabled = false; + autoshift_flush(); + } else { + autoshift_enabled = true; + } } -bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { -#ifndef AUTO_SHIFT_MODIFIERS - static uint8_t any_mod_pressed; -#endif - - if (record->event.pressed) { - switch (keycode) { - case KC_ASUP: - autoshift_timeout += 5; - return false; - - case KC_ASDN: - autoshift_timeout -= 5; - return false; - - case KC_ASRP: - autoshift_timer_report(); - return false; - - case KC_ASTG: - autoshift_toggle(); - return false; - case KC_ASON: - autoshift_enable(); - return false; - case KC_ASOFF: - autoshift_disable(); - return false; - -#ifndef NO_AUTO_SHIFT_ALPHA - case KC_A: - case KC_B: - case KC_C: - case KC_D: - case KC_E: - case KC_F: - case KC_G: - case KC_H: - case KC_I: - case KC_J: - case KC_K: - case KC_L: - case KC_M: - case KC_N: - case KC_O: - case KC_P: - case KC_Q: - case KC_R: - case KC_S: - case KC_T: - case KC_U: - case KC_V: - case KC_W: - case KC_X: - case KC_Y: - case KC_Z: -#endif -#ifndef NO_AUTO_SHIFT_NUMERIC - case KC_1: - case KC_2: - case KC_3: - case KC_4: - case KC_5: - case KC_6: - case KC_7: - case KC_8: - case KC_9: - case KC_0: -#endif -#ifndef NO_AUTO_SHIFT_SPECIAL - case KC_MINUS: - case KC_EQL: - case KC_TAB: - case KC_LBRC: - case KC_RBRC: - case KC_BSLS: - case KC_SCLN: - case KC_QUOT: - case KC_COMM: - case KC_DOT: - case KC_SLSH: - case KC_GRAVE: - case KC_NONUS_BSLASH: - case KC_NONUS_HASH: -#endif +bool autoshift_state(void) { return autoshift_enabled; } - autoshift_flush(); - if (!autoshift_enabled) return true; - -#ifndef AUTO_SHIFT_MODIFIERS - any_mod_pressed = get_mods() & ( - MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)| - MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)| - MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)| - MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT) - ); - - if (any_mod_pressed) { - return true; +bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { +# ifndef AUTO_SHIFT_MODIFIERS + static uint8_t any_mod_pressed; +# endif + + if (record->event.pressed) { + switch (keycode) { + case KC_ASUP: + autoshift_timeout += 5; + return false; + + case KC_ASDN: + autoshift_timeout -= 5; + return false; + + case KC_ASRP: + autoshift_timer_report(); + return false; + + case KC_ASTG: + autoshift_toggle(); + return false; + case KC_ASON: + autoshift_enable(); + return false; + case KC_ASOFF: + autoshift_disable(); + return false; + +# ifndef NO_AUTO_SHIFT_ALPHA + case KC_A: + case KC_B: + case KC_C: + case KC_D: + case KC_E: + case KC_F: + case KC_G: + case KC_H: + case KC_I: + case KC_J: + case KC_K: + case KC_L: + case KC_M: + case KC_N: + case KC_O: + case KC_P: + case KC_Q: + case KC_R: + case KC_S: + case KC_T: + case KC_U: + case KC_V: + case KC_W: + case KC_X: + case KC_Y: + case KC_Z: +# endif +# ifndef NO_AUTO_SHIFT_NUMERIC + case KC_1: + case KC_2: + case KC_3: + case KC_4: + case KC_5: + case KC_6: + case KC_7: + case KC_8: + case KC_9: + case KC_0: +# endif +# ifndef NO_AUTO_SHIFT_SPECIAL + case KC_MINUS: + case KC_EQL: + case KC_TAB: + case KC_LBRC: + case KC_RBRC: + case KC_BSLS: + case KC_SCLN: + case KC_QUOT: + case KC_COMM: + case KC_DOT: + case KC_SLSH: + case KC_GRAVE: + case KC_NONUS_BSLASH: + case KC_NONUS_HASH: +# endif + + autoshift_flush(); + if (!autoshift_enabled) return true; + +# ifndef AUTO_SHIFT_MODIFIERS + any_mod_pressed = get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT) | MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL) | MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)); + + if (any_mod_pressed) { + return true; + } +# endif + + autoshift_on(keycode); + return false; + + default: + autoshift_flush(); + return true; } -#endif - - autoshift_on(keycode); - return false; - - default: + } else { autoshift_flush(); - return true; } - } else { - autoshift_flush(); - } - return true; + return true; } #endif diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index a4abf04145..083325d8e3 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -20,7 +20,7 @@ #include "quantum.h" #ifndef AUTO_SHIFT_TIMEOUT - #define AUTO_SHIFT_TIMEOUT 175 +# define AUTO_SHIFT_TIMEOUT 175 #endif bool process_auto_shift(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c index 43b803afe7..6ab382d4aa 100644 --- a/quantum/process_keycode/process_clicky.c +++ b/quantum/process_keycode/process_clicky.c @@ -3,104 +3,111 @@ #ifdef AUDIO_CLICKY -#ifndef AUDIO_CLICKY_DELAY_DURATION -#define AUDIO_CLICKY_DELAY_DURATION 1 -#endif // !AUDIO_CLICKY_DELAY_DURATION -#ifndef AUDIO_CLICKY_FREQ_DEFAULT -#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f -#endif // !AUDIO_CLICKY_FREQ_DEFAULT -#ifndef AUDIO_CLICKY_FREQ_MIN -#define AUDIO_CLICKY_FREQ_MIN 65.0f -#endif // !AUDIO_CLICKY_FREQ_MIN -#ifndef AUDIO_CLICKY_FREQ_MAX -#define AUDIO_CLICKY_FREQ_MAX 1500.0f -#endif // !AUDIO_CLICKY_FREQ_MAX -#ifndef AUDIO_CLICKY_FREQ_FACTOR -#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f -#endif // !AUDIO_CLICKY_FREQ_FACTOR -#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS -#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f -#endif // !AUDIO_CLICKY_FREQ_RANDOMNESS +# ifndef AUDIO_CLICKY_DELAY_DURATION +# define AUDIO_CLICKY_DELAY_DURATION 1 +# endif // !AUDIO_CLICKY_DELAY_DURATION +# ifndef AUDIO_CLICKY_FREQ_DEFAULT +# define AUDIO_CLICKY_FREQ_DEFAULT 440.0f +# endif // !AUDIO_CLICKY_FREQ_DEFAULT +# ifndef AUDIO_CLICKY_FREQ_MIN +# define AUDIO_CLICKY_FREQ_MIN 65.0f +# endif // !AUDIO_CLICKY_FREQ_MIN +# ifndef AUDIO_CLICKY_FREQ_MAX +# define AUDIO_CLICKY_FREQ_MAX 1500.0f +# endif // !AUDIO_CLICKY_FREQ_MAX +# ifndef AUDIO_CLICKY_FREQ_FACTOR +# define AUDIO_CLICKY_FREQ_FACTOR 1.18921f +# endif // !AUDIO_CLICKY_FREQ_FACTOR +# ifndef AUDIO_CLICKY_FREQ_RANDOMNESS +# define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f +# endif // !AUDIO_CLICKY_FREQ_RANDOMNESS float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS; // the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky" -float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations +float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations extern audio_config_t audio_config; -#ifndef NO_MUSIC_MODE +# ifndef NO_MUSIC_MODE extern bool music_activated; extern bool midi_activated; -#endif // !NO_MUSIC_MODE +# endif // !NO_MUSIC_MODE void clicky_play(void) { -#ifndef NO_MUSIC_MODE - if (music_activated || midi_activated || !audio_config.enable) return; -#endif // !NO_MUSIC_MODE - clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); - clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); - PLAY_SONG(clicky_song); +# ifndef NO_MUSIC_MODE + if (music_activated || midi_activated || !audio_config.enable) return; +# endif // !NO_MUSIC_MODE + clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); + clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); + PLAY_SONG(clicky_song); } void clicky_freq_up(void) { - float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; - if (new_freq < AUDIO_CLICKY_FREQ_MAX) { - clicky_freq = new_freq; - } + float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; + if (new_freq < AUDIO_CLICKY_FREQ_MAX) { + clicky_freq = new_freq; + } } void clicky_freq_down(void) { - float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; - if (new_freq > AUDIO_CLICKY_FREQ_MIN) { - clicky_freq = new_freq; - } + float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; + if (new_freq > AUDIO_CLICKY_FREQ_MIN) { + clicky_freq = new_freq; + } } -void clicky_freq_reset(void) { - clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; -} +void clicky_freq_reset(void) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; } void clicky_toggle(void) { - audio_config.clicky_enable ^= 1; - eeconfig_update_audio(audio_config.raw); + audio_config.clicky_enable ^= 1; + eeconfig_update_audio(audio_config.raw); } void clicky_on(void) { - audio_config.clicky_enable = 1; - eeconfig_update_audio(audio_config.raw); + audio_config.clicky_enable = 1; + eeconfig_update_audio(audio_config.raw); } void clicky_off(void) { - audio_config.clicky_enable = 0; - eeconfig_update_audio(audio_config.raw); + audio_config.clicky_enable = 0; + eeconfig_update_audio(audio_config.raw); } -bool is_clicky_on(void) { - return (audio_config.clicky_enable != 0); -} +bool is_clicky_on(void) { return (audio_config.clicky_enable != 0); } bool process_clicky(uint16_t keycode, keyrecord_t *record) { - if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); } - - if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); } - if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); } + if (keycode == CLICKY_TOGGLE && record->event.pressed) { + clicky_toggle(); + } - if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); } + if (keycode == CLICKY_ENABLE && record->event.pressed) { + clicky_on(); + } + if (keycode == CLICKY_DISABLE && record->event.pressed) { + clicky_off(); + } - if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); } - if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); } + if (keycode == CLICKY_RESET && record->event.pressed) { + clicky_freq_reset(); + } + if (keycode == CLICKY_UP && record->event.pressed) { + clicky_freq_up(); + } + if (keycode == CLICKY_DOWN && record->event.pressed) { + clicky_freq_down(); + } - if (audio_config.enable && audio_config.clicky_enable) { - if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound - if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM - clicky_play(); - } + if (audio_config.enable && audio_config.clicky_enable) { + if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound + if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM + clicky_play(); + } + } } - } - return true; + return true; } -#endif //AUDIO_CLICKY +#endif // AUDIO_CLICKY diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index d3c3b1673c..f40ca74525 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -21,14 +21,13 @@ __attribute__((weak)) combo_t key_combos[COMBO_COUNT] = { }; -__attribute__((weak)) void process_combo_event(uint8_t combo_index, - bool pressed) {} +__attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {} -static uint16_t timer = 0; -static uint8_t current_combo_index = 0; -static bool drop_buffer = false; -static bool is_active = false; -static bool b_combo_enable = true; // defaults to enabled +static uint16_t timer = 0; +static uint8_t current_combo_index = 0; +static bool drop_buffer = false; +static bool is_active = false; +static bool b_combo_enable = true; // defaults to enabled static uint8_t buffer_size = 0; #ifdef COMBO_ALLOW_ACTION_KEYS @@ -38,171 +37,163 @@ static uint16_t key_buffer[MAX_COMBO_LENGTH]; #endif static inline void send_combo(uint16_t action, bool pressed) { - if (action) { - if (pressed) { - register_code16(action); + if (action) { + if (pressed) { + register_code16(action); + } else { + unregister_code16(action); + } } else { - unregister_code16(action); + process_combo_event(current_combo_index, pressed); } - } else { - process_combo_event(current_combo_index, pressed); - } } static inline void dump_key_buffer(bool emit) { - if (buffer_size == 0) { - return; - } + if (buffer_size == 0) { + return; + } - if (emit) { - for (uint8_t i = 0; i < buffer_size; i++) { + if (emit) { + for (uint8_t i = 0; i < buffer_size; i++) { #ifdef COMBO_ALLOW_ACTION_KEYS - const action_t action = store_or_get_action(key_buffer[i].event.pressed, - key_buffer[i].event.key); - process_action(&(key_buffer[i]), action); + const action_t action = store_or_get_action(key_buffer[i].event.pressed, key_buffer[i].event.key); + process_action(&(key_buffer[i]), action); #else - register_code16(key_buffer[i]); - send_keyboard_report(); + register_code16(key_buffer[i]); + send_keyboard_report(); #endif + } } - } - buffer_size = 0; + buffer_size = 0; } #define ALL_COMBO_KEYS_ARE_DOWN (((1 << count) - 1) == combo->state) -#define KEY_STATE_DOWN(key) \ - do { \ - combo->state |= (1 << key); \ - } while (0) -#define KEY_STATE_UP(key) \ - do { \ - combo->state &= ~(1 << key); \ - } while (0) - -static bool process_single_combo(combo_t *combo, uint16_t keycode, - keyrecord_t *record) { - uint8_t count = 0; - uint8_t index = -1; - /* Find index of keycode and number of combo keys */ - for (const uint16_t *keys = combo->keys;; ++count) { - uint16_t key = pgm_read_word(&keys[count]); - if (keycode == key) - index = count; - if (COMBO_END == key) - break; - } - - /* Continue processing if not a combo key */ - if (-1 == (int8_t)index) - return false; - - bool is_combo_active = is_active; - - if (record->event.pressed) { - KEY_STATE_DOWN(index); - - if (is_combo_active) { - if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */ - send_combo(combo->keycode, true); - drop_buffer = true; - } +#define KEY_STATE_DOWN(key) \ + do { \ + combo->state |= (1 << key); \ + } while (0) +#define KEY_STATE_UP(key) \ + do { \ + combo->state &= ~(1 << key); \ + } while (0) + +static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) { + uint8_t count = 0; + uint8_t index = -1; + /* Find index of keycode and number of combo keys */ + for (const uint16_t *keys = combo->keys;; ++count) { + uint16_t key = pgm_read_word(&keys[count]); + if (keycode == key) index = count; + if (COMBO_END == key) break; } - } else { - if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */ - send_combo(combo->keycode, false); + + /* Continue processing if not a combo key */ + if (-1 == (int8_t)index) return false; + + bool is_combo_active = is_active; + + if (record->event.pressed) { + KEY_STATE_DOWN(index); + + if (is_combo_active) { + if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */ + send_combo(combo->keycode, true); + drop_buffer = true; + } + } } else { - /* continue processing without immediately returning */ - is_combo_active = false; + if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */ + send_combo(combo->keycode, false); + } else { + /* continue processing without immediately returning */ + is_combo_active = false; + } + + KEY_STATE_UP(index); } - KEY_STATE_UP(index); - } - - return is_combo_active; + return is_combo_active; } #define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state) bool process_combo(uint16_t keycode, keyrecord_t *record) { - bool is_combo_key = false; - drop_buffer = false; - bool no_combo_keys_pressed = true; - - if (keycode == CMB_ON && record->event.pressed) { - combo_enable(); - return true; - } - - if (keycode == CMB_OFF && record->event.pressed) { - combo_disable(); - return true; - } - - if (keycode == CMB_TOG && record->event.pressed) { - combo_toggle(); - return true; - } - - if (!is_combo_enabled()) { return true; } - - for (current_combo_index = 0; current_combo_index < COMBO_COUNT; - ++current_combo_index) { - combo_t *combo = &key_combos[current_combo_index]; - is_combo_key |= process_single_combo(combo, keycode, record); - no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN; - } - - if (drop_buffer) { - /* buffer is only dropped when we complete a combo, so we refresh the timer - * here */ - timer = timer_read(); - dump_key_buffer(false); - } else if (!is_combo_key) { - /* if no combos claim the key we need to emit the keybuffer */ - dump_key_buffer(true); + bool is_combo_key = false; + drop_buffer = false; + bool no_combo_keys_pressed = true; + + if (keycode == CMB_ON && record->event.pressed) { + combo_enable(); + return true; + } - // reset state if there are no combo keys pressed at all - if (no_combo_keys_pressed) { - timer = 0; - is_active = true; + if (keycode == CMB_OFF && record->event.pressed) { + combo_disable(); + return true; } - } else if (record->event.pressed && is_active) { - /* otherwise the key is consumed and placed in the buffer */ - timer = timer_read(); - if (buffer_size < MAX_COMBO_LENGTH) { + if (keycode == CMB_TOG && record->event.pressed) { + combo_toggle(); + return true; + } + + if (!is_combo_enabled()) { + return true; + } + + for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) { + combo_t *combo = &key_combos[current_combo_index]; + is_combo_key |= process_single_combo(combo, keycode, record); + no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN; + } + + if (drop_buffer) { + /* buffer is only dropped when we complete a combo, so we refresh the timer + * here */ + timer = timer_read(); + dump_key_buffer(false); + } else if (!is_combo_key) { + /* if no combos claim the key we need to emit the keybuffer */ + dump_key_buffer(true); + + // reset state if there are no combo keys pressed at all + if (no_combo_keys_pressed) { + timer = 0; + is_active = true; + } + } else if (record->event.pressed && is_active) { + /* otherwise the key is consumed and placed in the buffer */ + timer = timer_read(); + + if (buffer_size < MAX_COMBO_LENGTH) { #ifdef COMBO_ALLOW_ACTION_KEYS - key_buffer[buffer_size++] = *record; + key_buffer[buffer_size++] = *record; #else - key_buffer[buffer_size++] = keycode; + key_buffer[buffer_size++] = keycode; #endif + } } - } - return !is_combo_key; + return !is_combo_key; } void matrix_scan_combo(void) { - if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { - - /* This disables the combo, meaning key events for this - * combo will be handled by the next processors in the chain - */ - is_active = false; - dump_key_buffer(true); - } + if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) { + /* This disables the combo, meaning key events for this + * combo will be handled by the next processors in the chain + */ + is_active = false; + dump_key_buffer(true); + } } -void combo_enable(void) { - b_combo_enable = true; -} +void combo_enable(void) { b_combo_enable = true; } void combo_disable(void) { b_combo_enable = is_active = false; - timer = 0; + timer = 0; dump_key_buffer(true); - } void combo_toggle(void) { @@ -213,6 +204,4 @@ void combo_toggle(void) { } } -bool is_combo_enabled(void) { - return b_combo_enable; -} +bool is_combo_enabled(void) { return b_combo_enable; } diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index aab2849572..e21ee19609 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -22,36 +22,36 @@ #include #ifdef EXTRA_EXTRA_LONG_COMBOS -#define MAX_COMBO_LENGTH 32 +# define MAX_COMBO_LENGTH 32 #elif EXTRA_LONG_COMBOS -#define MAX_COMBO_LENGTH 16 +# define MAX_COMBO_LENGTH 16 #else -#define MAX_COMBO_LENGTH 8 +# define MAX_COMBO_LENGTH 8 #endif typedef struct { - const uint16_t *keys; - uint16_t keycode; + const uint16_t *keys; + uint16_t keycode; #ifdef EXTRA_EXTRA_LONG_COMBOS - uint32_t state; + uint32_t state; #elif EXTRA_LONG_COMBOS - uint16_t state; + uint16_t state; #else - uint8_t state; + uint8_t state; #endif } combo_t; -#define COMBO(ck, ca) \ - { .keys = &(ck)[0], .keycode = (ca) } -#define COMBO_ACTION(ck) \ - { .keys = &(ck)[0] } +#define COMBO(ck, ca) \ + { .keys = &(ck)[0], .keycode = (ca) } +#define COMBO_ACTION(ck) \ + { .keys = &(ck)[0] } #define COMBO_END 0 #ifndef COMBO_COUNT -#define COMBO_COUNT 0 +# define COMBO_COUNT 0 #endif #ifndef COMBO_TERM -#define COMBO_TERM TAPPING_TERM +# define COMBO_TERM TAPPING_TERM #endif bool process_combo(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_key_lock.c b/quantum/process_keycode/process_key_lock.c index 50cc0a5ccb..602127a74b 100644 --- a/quantum/process_keycode/process_key_lock.c +++ b/quantum/process_keycode/process_key_lock.c @@ -19,36 +19,33 @@ #include "process_key_lock.h" #define BV_64(shift) (((uint64_t)1) << (shift)) -#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : \ - ((code) < 0x80) ? key_state[1] : \ - ((code) < 0xC0) ? key_state[2] : key_state[3]) -#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : \ - ((code) < 0x80) ? (code) - 0x40 : \ - ((code) < 0xC0) ? (code) - 0x80 : (code) - 0xC0) -#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code)) -#define SET_KEY_ARRAY_STATE(code, val) do { \ - switch (code) { \ - case 0x00 ... 0x3F: \ - key_state[0] = (val); \ - break; \ - case 0x40 ... 0x7F: \ - key_state[1] = (val); \ - break; \ - case 0x80 ... 0xBF: \ - key_state[2] = (val); \ - break; \ - case 0xC0 ... 0xFF: \ - key_state[3] = (val); \ - break; \ - } \ -} while(0) +#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : ((code) < 0x80) ? key_state[1] : ((code) < 0xC0) ? key_state[2] : key_state[3]) +#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : ((code) < 0x80) ? (code)-0x40 : ((code) < 0xC0) ? (code)-0x80 : (code)-0xC0) +#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code)) +#define SET_KEY_ARRAY_STATE(code, val) \ + do { \ + switch (code) { \ + case 0x00 ... 0x3F: \ + key_state[0] = (val); \ + break; \ + case 0x40 ... 0x7F: \ + key_state[1] = (val); \ + break; \ + case 0x80 ... 0xBF: \ + key_state[2] = (val); \ + break; \ + case 0xC0 ... 0xFF: \ + key_state[3] = (val); \ + break; \ + } \ + } while (0) #define SET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code) | BV_64(GET_CODE_INDEX(code)))) #define UNSET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code)) & ~(BV_64(GET_CODE_INDEX(code)))) #define IS_STANDARD_KEYCODE(code) ((code) <= 0xFF) // Locked key state. This is an array of 256 bits, one for each of the standard keys supported qmk. -uint64_t key_state[4] = { 0x0, 0x0, 0x0, 0x0 }; -bool watching = false; +uint64_t key_state[4] = {0x0, 0x0, 0x0, 0x0}; +bool watching = false; // Translate any OSM keycodes back to their unmasked versions. static inline uint16_t translate_keycode(uint16_t keycode) { @@ -135,4 +132,3 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record) { return !(IS_STANDARD_KEYCODE(translated_keycode) && KEY_STATE(translated_keycode)); } } - diff --git a/quantum/process_keycode/process_key_lock.h b/quantum/process_keycode/process_key_lock.h index 876db4a324..a8e110a4bf 100644 --- a/quantum/process_keycode/process_key_lock.h +++ b/quantum/process_keycode/process_key_lock.h @@ -21,4 +21,4 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record); -#endif // PROCESS_KEY_LOCK_H +#endif // PROCESS_KEY_LOCK_H diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index f787e6b017..58a615d85a 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -16,64 +16,64 @@ #ifdef LEADER_ENABLE -#include "process_leader.h" -#include +# include "process_leader.h" +# include -#ifndef LEADER_TIMEOUT - #define LEADER_TIMEOUT 300 -#endif +# ifndef LEADER_TIMEOUT +# define LEADER_TIMEOUT 300 +# endif -__attribute__ ((weak)) -void leader_start(void) {} +__attribute__((weak)) void leader_start(void) {} -__attribute__ ((weak)) -void leader_end(void) {} +__attribute__((weak)) void leader_end(void) {} // Leader key stuff -bool leading = false; +bool leading = false; uint16_t leader_time = 0; -uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; -uint8_t leader_sequence_size = 0; +uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; +uint8_t leader_sequence_size = 0; void qk_leader_start(void) { - if (leading) { return; } - leader_start(); - leading = true; - leader_time = timer_read(); - leader_sequence_size = 0; - memset(leader_sequence, 0, sizeof(leader_sequence)); + if (leading) { + return; + } + leader_start(); + leading = true; + leader_time = timer_read(); + leader_sequence_size = 0; + memset(leader_sequence, 0, sizeof(leader_sequence)); } bool process_leader(uint16_t keycode, keyrecord_t *record) { - // Leader key set-up - if (record->event.pressed) { - if (leading) { - if (timer_elapsed(leader_time) < LEADER_TIMEOUT) { -#ifndef LEADER_KEY_STRICT_KEY_PROCESSING - if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { - keycode = keycode & 0xFF; - } -#endif // LEADER_KEY_STRICT_KEY_PROCESSING - if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) { - leader_sequence[leader_sequence_size] = keycode; - leader_sequence_size++; + // Leader key set-up + if (record->event.pressed) { + if (leading) { + if (timer_elapsed(leader_time) < LEADER_TIMEOUT) { +# ifndef LEADER_KEY_STRICT_KEY_PROCESSING + if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { + keycode = keycode & 0xFF; + } +# endif // LEADER_KEY_STRICT_KEY_PROCESSING + if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) { + leader_sequence[leader_sequence_size] = keycode; + leader_sequence_size++; + } else { + leading = false; + leader_end(); + } +# ifdef LEADER_PER_KEY_TIMING + leader_time = timer_read(); +# endif + return false; + } } else { - leading = false; - leader_end(); + if (keycode == KC_LEAD) { + qk_leader_start(); + } } -#ifdef LEADER_PER_KEY_TIMING - leader_time = timer_read(); -#endif - return false; - } - } else { - if (keycode == KC_LEAD) { - qk_leader_start(); - } } - } - return true; + return true; } #endif diff --git a/quantum/process_keycode/process_leader.h b/quantum/process_keycode/process_leader.h index 15bccc3f67..e0edf57b32 100644 --- a/quantum/process_keycode/process_leader.h +++ b/quantum/process_keycode/process_leader.h @@ -19,7 +19,6 @@ #include "quantum.h" - bool process_leader(uint16_t keycode, keyrecord_t *record); void leader_start(void); @@ -32,7 +31,11 @@ void qk_leader_start(void); #define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0) #define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5)) -#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[5]; extern uint8_t leader_sequence_size +#define LEADER_EXTERNS() \ + extern bool leading; \ + extern uint16_t leader_time; \ + extern uint16_t leader_sequence[5]; \ + extern uint8_t leader_sequence_size #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) #endif diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index be6455ee94..b2fb902eb4 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -16,86 +16,65 @@ #include "process_midi.h" #ifdef MIDI_ENABLE -#include -#include "midi.h" -#include "qmk_midi.h" +# include +# include "midi.h" +# include "qmk_midi.h" -#ifdef MIDI_BASIC +# ifdef MIDI_BASIC -void process_midi_basic_noteon(uint8_t note) -{ - midi_send_noteon(&midi_device, 0, note, 127); -} +void process_midi_basic_noteon(uint8_t note) { midi_send_noteon(&midi_device, 0, note, 127); } -void process_midi_basic_noteoff(uint8_t note) -{ - midi_send_noteoff(&midi_device, 0, note, 0); -} +void process_midi_basic_noteoff(uint8_t note) { midi_send_noteoff(&midi_device, 0, note, 0); } -void process_midi_all_notes_off(void) -{ - midi_send_cc(&midi_device, 0, 0x7B, 0); -} +void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); } -#endif // MIDI_BASIC +# endif // MIDI_BASIC -#ifdef MIDI_ADVANCED +# ifdef MIDI_ADVANCED -#include "timer.h" +# include "timer.h" static uint8_t tone_status[MIDI_TONE_COUNT]; -static uint8_t midi_modulation; -static int8_t midi_modulation_step; +static uint8_t midi_modulation; +static int8_t midi_modulation_step; static uint16_t midi_modulation_timer; -midi_config_t midi_config; +midi_config_t midi_config; -inline uint8_t compute_velocity(uint8_t setting) -{ - return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); -} +inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); } -void midi_init(void) -{ - midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; - midi_config.transpose = 0; - midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); - midi_config.channel = 0; +void midi_init(void) { + midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; + midi_config.transpose = 0; + midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); + midi_config.channel = 0; midi_config.modulation_interval = 8; - for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) - { + for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { tone_status[i] = MIDI_INVALID_NOTE; } - midi_modulation = 0; - midi_modulation_step = 0; + midi_modulation = 0; + midi_modulation_step = 0; midi_modulation_timer = 0; } -uint8_t midi_compute_note(uint16_t keycode) -{ - return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; -} +uint8_t midi_compute_note(uint16_t keycode) { return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; } -bool process_midi(uint16_t keycode, keyrecord_t *record) -{ +bool process_midi(uint16_t keycode, keyrecord_t *record) { switch (keycode) { - case MIDI_TONE_MIN ... MIDI_TONE_MAX: - { - uint8_t channel = midi_config.channel; - uint8_t tone = keycode - MIDI_TONE_MIN; + case MIDI_TONE_MIN ... MIDI_TONE_MAX: { + uint8_t channel = midi_config.channel; + uint8_t tone = keycode - MIDI_TONE_MIN; uint8_t velocity = compute_velocity(midi_config.velocity); if (record->event.pressed) { uint8_t note = midi_compute_note(keycode); midi_send_noteon(&midi_device, channel, note, velocity); dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); tone_status[tone] = note; - } - else { + } else { uint8_t note = tone_status[tone]; - if (note != MIDI_INVALID_NOTE) - { + if (note != MIDI_INVALID_NOTE) { midi_send_noteoff(&midi_device, channel, note, velocity); dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); } @@ -137,8 +116,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { const bool positive = midi_config.transpose > 0; midi_config.transpose++; - if (positive && midi_config.transpose < 0) - midi_config.transpose--; + if (positive && midi_config.transpose < 0) midi_config.transpose--; dprintf("midi transpose %d\n", midi_config.transpose); } return false; @@ -211,8 +189,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed) { midi_config.modulation_interval++; // prevent overflow - if (midi_config.modulation_interval == 0) - midi_config.modulation_interval--; + if (midi_config.modulation_interval == 0) midi_config.modulation_interval--; dprintf("midi modulation interval %d\n", midi_config.modulation_interval); } return false; @@ -226,8 +203,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed) { midi_send_pitchbend(&midi_device, midi_config.channel, -0x2000); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, -0x2000); - } - else { + } else { midi_send_pitchbend(&midi_device, midi_config.channel, 0); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0); } @@ -236,8 +212,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) if (record->event.pressed) { midi_send_pitchbend(&midi_device, midi_config.channel, 0x1fff); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0x1fff); - } - else { + } else { midi_send_pitchbend(&midi_device, midi_config.channel, 0); dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0); } @@ -247,35 +222,29 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) return true; } -#endif // MIDI_ADVANCED +# endif // MIDI_ADVANCED -void midi_task(void) -{ +void midi_task(void) { midi_device_process(&midi_device); -#ifdef MIDI_ADVANCED - if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) - return; +# ifdef MIDI_ADVANCED + if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) return; midi_modulation_timer = timer_read(); - if (midi_modulation_step != 0) - { + if (midi_modulation_step != 0) { dprintf("midi modulation %d\n", midi_modulation); midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation); if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) { - midi_modulation = 0; + midi_modulation = 0; midi_modulation_step = 0; return; } midi_modulation += midi_modulation_step; - if (midi_modulation > 127) - midi_modulation = 127; + if (midi_modulation > 127) midi_modulation = 127; } -#endif +# endif } - - -#endif // MIDI_ENABLE +#endif // MIDI_ENABLE diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index 1968fbe3fa..0007b3ed25 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -21,24 +21,24 @@ #ifdef MIDI_ENABLE -#ifdef MIDI_BASIC +# ifdef MIDI_BASIC void process_midi_basic_noteon(uint8_t note); void process_midi_basic_noteoff(uint8_t note); void process_midi_all_notes_off(void); -#endif +# endif void midi_task(void); -#ifdef MIDI_ADVANCED +# ifdef MIDI_ADVANCED typedef union { - uint32_t raw; - struct { - uint8_t octave :4; - int8_t transpose :4; - uint8_t velocity :4; - uint8_t channel :4; - uint8_t modulation_interval :4; - }; + uint32_t raw; + struct { + uint8_t octave : 4; + int8_t transpose : 4; + uint8_t velocity : 4; + uint8_t channel : 4; + uint8_t modulation_interval : 4; + }; } midi_config_t; extern midi_config_t midi_config; @@ -46,12 +46,12 @@ extern midi_config_t midi_config; void midi_init(void); bool process_midi(uint16_t keycode, keyrecord_t *record); -#define MIDI_INVALID_NOTE 0xFF -#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) +# define MIDI_INVALID_NOTE 0xFF +# define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) uint8_t midi_compute_note(uint16_t keycode); -#endif // MIDI_ADVANCED +# endif // MIDI_ADVANCED -#endif // MIDI_ENABLE +#endif // MIDI_ENABLE #endif diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 697aa237fa..b61a16e878 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -16,103 +16,91 @@ #include "process_music.h" #ifdef AUDIO_ENABLE -#include "process_audio.h" +# include "process_audio.h" #endif #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) -#include "process_midi.h" +# include "process_midi.h" #endif #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) -bool music_activated = false; -bool midi_activated = false; +bool music_activated = false; +bool midi_activated = false; uint8_t music_starting_note = 0x0C; -int music_offset = 7; -uint8_t music_mode = MUSIC_MODE_MAJOR; +int music_offset = 7; +uint8_t music_mode = MUSIC_MODE_MAJOR; // music sequencer -static bool music_sequence_recording = false; -static bool music_sequence_recorded = false; -static bool music_sequence_playing = false; -static uint8_t music_sequence[16] = {0}; -static uint8_t music_sequence_count = 0; -static uint8_t music_sequence_position = 0; - -static uint16_t music_sequence_timer = 0; +static bool music_sequence_recording = false; +static bool music_sequence_recorded = false; +static bool music_sequence_playing = false; +static uint8_t music_sequence[16] = {0}; +static uint8_t music_sequence_count = 0; +static uint8_t music_sequence_position = 0; + +static uint16_t music_sequence_timer = 0; static uint16_t music_sequence_interval = 100; -#ifdef AUDIO_ENABLE - #ifndef MUSIC_ON_SONG - #define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND) - #endif - #ifndef MUSIC_OFF_SONG - #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) - #endif - #ifndef MIDI_ON_SONG - #define MIDI_ON_SONG SONG(MUSIC_ON_SOUND) - #endif - #ifndef MIDI_OFF_SONG - #define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND) - #endif - #ifndef CHROMATIC_SONG - #define CHROMATIC_SONG SONG(CHROMATIC_SOUND) - #endif - #ifndef GUITAR_SONG - #define GUITAR_SONG SONG(GUITAR_SOUND) - #endif - #ifndef VIOLIN_SONG - #define VIOLIN_SONG SONG(VIOLIN_SOUND) - #endif - #ifndef MAJOR_SONG - #define MAJOR_SONG SONG(MAJOR_SOUND) - #endif - float music_mode_songs[NUMBER_OF_MODES][5][2] = { - CHROMATIC_SONG, - GUITAR_SONG, - VIOLIN_SONG, - MAJOR_SONG - }; - float music_on_song[][2] = MUSIC_ON_SONG; - float music_off_song[][2] = MUSIC_OFF_SONG; - float midi_on_song[][2] = MIDI_ON_SONG; - float midi_off_song[][2] = MIDI_OFF_SONG; -#endif +# ifdef AUDIO_ENABLE +# ifndef MUSIC_ON_SONG +# define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND) +# endif +# ifndef MUSIC_OFF_SONG +# define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND) +# endif +# ifndef MIDI_ON_SONG +# define MIDI_ON_SONG SONG(MUSIC_ON_SOUND) +# endif +# ifndef MIDI_OFF_SONG +# define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND) +# endif +# ifndef CHROMATIC_SONG +# define CHROMATIC_SONG SONG(CHROMATIC_SOUND) +# endif +# ifndef GUITAR_SONG +# define GUITAR_SONG SONG(GUITAR_SOUND) +# endif +# ifndef VIOLIN_SONG +# define VIOLIN_SONG SONG(VIOLIN_SOUND) +# endif +# ifndef MAJOR_SONG +# define MAJOR_SONG SONG(MAJOR_SOUND) +# endif +float music_mode_songs[NUMBER_OF_MODES][5][2] = {CHROMATIC_SONG, GUITAR_SONG, VIOLIN_SONG, MAJOR_SONG}; +float music_on_song[][2] = MUSIC_ON_SONG; +float music_off_song[][2] = MUSIC_OFF_SONG; +float midi_on_song[][2] = MIDI_ON_SONG; +float midi_off_song[][2] = MIDI_OFF_SONG; +# endif static void music_noteon(uint8_t note) { - #ifdef AUDIO_ENABLE - if (music_activated) - process_audio_noteon(note); - #endif - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - if (midi_activated) - process_midi_basic_noteon(note); - #endif +# ifdef AUDIO_ENABLE + if (music_activated) process_audio_noteon(note); +# endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + if (midi_activated) process_midi_basic_noteon(note); +# endif } static void music_noteoff(uint8_t note) { - #ifdef AUDIO_ENABLE - if (music_activated) - process_audio_noteoff(note); - #endif - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - if (midi_activated) - process_midi_basic_noteoff(note); - #endif +# ifdef AUDIO_ENABLE + if (music_activated) process_audio_noteoff(note); +# endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + if (midi_activated) process_midi_basic_noteoff(note); +# endif } void music_all_notes_off(void) { - #ifdef AUDIO_ENABLE - if (music_activated) - process_audio_all_notes_off(); - #endif - #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) - if (midi_activated) - process_midi_all_notes_off(); - #endif +# ifdef AUDIO_ENABLE + if (music_activated) process_audio_all_notes_off(); +# endif +# if defined(MIDI_ENABLE) && defined(MIDI_BASIC) + if (midi_activated) process_midi_all_notes_off(); +# endif } bool process_music(uint16_t keycode, keyrecord_t *record) { - if (keycode == MU_ON && record->event.pressed) { music_on(); return false; @@ -152,110 +140,101 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } if (keycode == MU_MOD && record->event.pressed) { - music_mode_cycle(); - return false; + music_mode_cycle(); + return false; } if (music_activated || midi_activated) { - if (record->event.pressed) { - if (keycode == KC_LCTL) { // Start recording - music_all_notes_off(); - music_sequence_recording = true; - music_sequence_recorded = false; - music_sequence_playing = false; - music_sequence_count = 0; - return false; - } - - if (keycode == KC_LALT) { // Stop recording/playing - music_all_notes_off(); - if (music_sequence_recording) { // was recording - music_sequence_recorded = true; - } - music_sequence_recording = false; - music_sequence_playing = false; - return false; - } - - if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing - music_all_notes_off(); - music_sequence_recording = false; - music_sequence_playing = true; - music_sequence_position = 0; - music_sequence_timer = 0; - return false; - } - - if (keycode == KC_UP) { - music_sequence_interval-=10; - return false; + if (record->event.pressed) { + if (keycode == KC_LCTL) { // Start recording + music_all_notes_off(); + music_sequence_recording = true; + music_sequence_recorded = false; + music_sequence_playing = false; + music_sequence_count = 0; + return false; + } + + if (keycode == KC_LALT) { // Stop recording/playing + music_all_notes_off(); + if (music_sequence_recording) { // was recording + music_sequence_recorded = true; + } + music_sequence_recording = false; + music_sequence_playing = false; + return false; + } + + if (keycode == KC_LGUI && music_seq