diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/process_keycode/process_clicky.c | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'quantum/process_keycode/process_clicky.c')
-rw-r--r-- | quantum/process_keycode/process_clicky.c | 131 |
1 files changed, 69 insertions, 62 deletions
diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c index 43b803afe..6ab382d4a 100644 --- a/quantum/process_keycode/process_clicky.c +++ b/quantum/process_keycode/process_clicky.c | |||
@@ -3,104 +3,111 @@ | |||
3 | 3 | ||
4 | #ifdef AUDIO_CLICKY | 4 | #ifdef AUDIO_CLICKY |
5 | 5 | ||
6 | #ifndef AUDIO_CLICKY_DELAY_DURATION | 6 | # ifndef AUDIO_CLICKY_DELAY_DURATION |
7 | #define AUDIO_CLICKY_DELAY_DURATION 1 | 7 | # define AUDIO_CLICKY_DELAY_DURATION 1 |
8 | #endif // !AUDIO_CLICKY_DELAY_DURATION | 8 | # endif // !AUDIO_CLICKY_DELAY_DURATION |
9 | #ifndef AUDIO_CLICKY_FREQ_DEFAULT | 9 | # ifndef AUDIO_CLICKY_FREQ_DEFAULT |
10 | #define AUDIO_CLICKY_FREQ_DEFAULT 440.0f | 10 | # define AUDIO_CLICKY_FREQ_DEFAULT 440.0f |
11 | #endif // !AUDIO_CLICKY_FREQ_DEFAULT | 11 | # endif // !AUDIO_CLICKY_FREQ_DEFAULT |
12 | #ifndef AUDIO_CLICKY_FREQ_MIN | 12 | # ifndef AUDIO_CLICKY_FREQ_MIN |
13 | #define AUDIO_CLICKY_FREQ_MIN 65.0f | 13 | # define AUDIO_CLICKY_FREQ_MIN 65.0f |
14 | #endif // !AUDIO_CLICKY_FREQ_MIN | 14 | # endif // !AUDIO_CLICKY_FREQ_MIN |
15 | #ifndef AUDIO_CLICKY_FREQ_MAX | 15 | # ifndef AUDIO_CLICKY_FREQ_MAX |
16 | #define AUDIO_CLICKY_FREQ_MAX 1500.0f | 16 | # define AUDIO_CLICKY_FREQ_MAX 1500.0f |
17 | #endif // !AUDIO_CLICKY_FREQ_MAX | 17 | # endif // !AUDIO_CLICKY_FREQ_MAX |
18 | #ifndef AUDIO_CLICKY_FREQ_FACTOR | 18 | # ifndef AUDIO_CLICKY_FREQ_FACTOR |
19 | #define AUDIO_CLICKY_FREQ_FACTOR 1.18921f | 19 | # define AUDIO_CLICKY_FREQ_FACTOR 1.18921f |
20 | #endif // !AUDIO_CLICKY_FREQ_FACTOR | 20 | # endif // !AUDIO_CLICKY_FREQ_FACTOR |
21 | #ifndef AUDIO_CLICKY_FREQ_RANDOMNESS | 21 | # ifndef AUDIO_CLICKY_FREQ_RANDOMNESS |
22 | #define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f | 22 | # define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f |
23 | #endif // !AUDIO_CLICKY_FREQ_RANDOMNESS | 23 | # endif // !AUDIO_CLICKY_FREQ_RANDOMNESS |
24 | 24 | ||
25 | float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; | 25 | float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; |
26 | float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS; | 26 | float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS; |
27 | 27 | ||
28 | // the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky" | 28 | // the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky" |
29 | 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 | 29 | 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 |
30 | 30 | ||
31 | extern audio_config_t audio_config; | 31 | extern audio_config_t audio_config; |
32 | 32 | ||
33 | #ifndef NO_MUSIC_MODE | 33 | # ifndef NO_MUSIC_MODE |
34 | extern bool music_activated; | 34 | extern bool music_activated; |
35 | extern bool midi_activated; | 35 | extern bool midi_activated; |
36 | #endif // !NO_MUSIC_MODE | 36 | # endif // !NO_MUSIC_MODE |
37 | 37 | ||
38 | void clicky_play(void) { | 38 | void clicky_play(void) { |
39 | #ifndef NO_MUSIC_MODE | 39 | # ifndef NO_MUSIC_MODE |
40 | if (music_activated || midi_activated || !audio_config.enable) return; | 40 | if (music_activated || midi_activated || !audio_config.enable) return; |
41 | #endif // !NO_MUSIC_MODE | 41 | # endif // !NO_MUSIC_MODE |
42 | clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); | 42 | clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); |
43 | clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); | 43 | clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); |
44 | PLAY_SONG(clicky_song); | 44 | PLAY_SONG(clicky_song); |
45 | } | 45 | } |
46 | 46 | ||
47 | void clicky_freq_up(void) { | 47 | void clicky_freq_up(void) { |
48 | float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; | 48 | float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; |
49 | if (new_freq < AUDIO_CLICKY_FREQ_MAX) { | 49 | if (new_freq < AUDIO_CLICKY_FREQ_MAX) { |
50 | clicky_freq = new_freq; | 50 | clicky_freq = new_freq; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | void clicky_freq_down(void) { | 54 | void clicky_freq_down(void) { |
55 | float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; | 55 | float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; |
56 | if (new_freq > AUDIO_CLICKY_FREQ_MIN) { | 56 | if (new_freq > AUDIO_CLICKY_FREQ_MIN) { |
57 | clicky_freq = new_freq; | 57 | clicky_freq = new_freq; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | void clicky_freq_reset(void) { | 61 | void clicky_freq_reset(void) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; } |
62 | clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; | ||
63 | } | ||
64 | 62 | ||
65 | void clicky_toggle(void) { | 63 | void clicky_toggle(void) { |
66 | audio_config.clicky_enable ^= 1; | 64 | audio_config.clicky_enable ^= 1; |
67 | eeconfig_update_audio(audio_config.raw); | 65 | eeconfig_update_audio(audio_config.raw); |
68 | } | 66 | } |
69 | 67 | ||
70 | void clicky_on(void) { | 68 | void clicky_on(void) { |
71 | audio_config.clicky_enable = 1; | 69 | audio_config.clicky_enable = 1; |
72 | eeconfig_update_audio(audio_config.raw); | 70 | eeconfig_update_audio(audio_config.raw); |
73 | } | 71 | } |
74 | 72 | ||
75 | void clicky_off(void) { | 73 | void clicky_off(void) { |
76 | audio_config.clicky_enable = 0; | 74 | audio_config.clicky_enable = 0; |
77 | eeconfig_update_audio(audio_config.raw); | 75 | eeconfig_update_audio(audio_config.raw); |
78 | } | 76 | } |
79 | 77 | ||
80 | bool is_clicky_on(void) { | 78 | bool is_clicky_on(void) { return (audio_config.clicky_enable != 0); } |
81 | return (audio_config.clicky_enable != 0); | ||
82 | } | ||
83 | 79 | ||
84 | bool process_clicky(uint16_t keycode, keyrecord_t *record) { | 80 | bool process_clicky(uint16_t keycode, keyrecord_t *record) { |
85 | if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); } | 81 | if (keycode == CLICKY_TOGGLE && record->event.pressed) { |
86 | 82 | clicky_toggle(); | |
87 | if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); } | 83 | } |
88 | if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); } | ||
89 | 84 | ||
90 | if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); } | 85 | if (keycode == CLICKY_ENABLE && record->event.pressed) { |
86 | clicky_on(); | ||
87 | } | ||
88 | if (keycode == CLICKY_DISABLE && record->event.pressed) { | ||
89 | clicky_off(); | ||
90 | } | ||
91 | 91 | ||
92 | if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); } | 92 | if (keycode == CLICKY_RESET && record->event.pressed) { |
93 | if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); } | 93 | clicky_freq_reset(); |
94 | } | ||
94 | 95 | ||
96 | if (keycode == CLICKY_UP && record->event.pressed) { | ||
97 | clicky_freq_up(); | ||
98 | } | ||
99 | if (keycode == CLICKY_DOWN && record->event.pressed) { | ||
100 | clicky_freq_down(); | ||
101 | } | ||
95 | 102 | ||
96 | if (audio_config.enable && audio_config.clicky_enable) { | 103 | if (audio_config.enable && audio_config.clicky_enable) { |
97 | if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound | 104 | if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound |
98 | if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM | 105 | if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM |
99 | clicky_play(); | 106 | clicky_play(); |
100 | } | 107 | } |
108 | } | ||
101 | } | 109 | } |
102 | } | 110 | return true; |
103 | return true; | ||
104 | } | 111 | } |
105 | 112 | ||
106 | #endif //AUDIO_CLICKY | 113 | #endif // AUDIO_CLICKY |