diff options
author | Drashna Jaelre <drashna@live.com> | 2018-04-21 09:30:10 -0700 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-04-21 12:30:10 -0400 |
commit | 33fdd1d2551591a5c295c6dc68ccf52c4698b9c1 (patch) | |
tree | 8d8134cecf3121fad4e81c2f16d1804ae233edb2 /quantum/process_keycode | |
parent | d1c3419d2ade6341bb7eba130bf8c77005705519 (diff) | |
download | qmk_firmware-33fdd1d2551591a5c295c6dc68ccf52c4698b9c1.tar.gz qmk_firmware-33fdd1d2551591a5c295c6dc68ccf52c4698b9c1.zip |
Fix Audio Clicky sub-feature (#2784)
* Fix Audio Clicky feature
* Add to features
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r-- | quantum/process_keycode/process_audio.c | 65 | ||||
-rw-r--r-- | quantum/process_keycode/process_clicky.c | 72 | ||||
-rw-r--r-- | quantum/process_keycode/process_clicky.h | 7 |
3 files changed, 79 insertions, 65 deletions
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index fc0f23ee3..e9b20512e 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c | |||
@@ -10,45 +10,7 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG; | |||
10 | #define PITCH_STANDARD_A 440.0f | 10 | #define PITCH_STANDARD_A 440.0f |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #ifdef AUDIO_CLICKY | ||
14 | #ifdef AUDIO_CLICKY_ON | ||
15 | bool clicky_enable = true; | ||
16 | #else | ||
17 | bool clicky_enable = false; | ||
18 | #endif | ||
19 | #ifndef AUDIO_CLICKY_FREQ_DEFAULT | ||
20 | #define AUDIO_CLICKY_FREQ_DEFAULT 440.0f | ||
21 | #endif | ||
22 | #ifndef AUDIO_CLICKY_FREQ_MIN | ||
23 | #define AUDIO_CLICKY_FREQ_MIN 65.0f | ||
24 | #endif | ||
25 | #ifndef AUDIO_CLICKY_FREQ_MAX | ||
26 | #define AUDIO_CLICKY_FREQ_MAX 1500.0f | ||
27 | #endif | ||
28 | #ifndef AUDIO_CLICKY_FREQ_FACTOR | ||
29 | #define AUDIO_CLICKY_FREQ_FACTOR 1.18921f | ||
30 | #endif | ||
31 | #ifndef AUDIO_CLICKY_FREQ_RANDOMNESS | ||
32 | #define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f | ||
33 | #endif | ||
34 | |||
35 | float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; | ||
36 | float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations | ||
37 | 13 | ||
38 | #ifndef NO_MUSIC_MODE | ||
39 | extern bool music_activated; | ||
40 | extern bool midi_activated; | ||
41 | #endif | ||
42 | |||
43 | void clicky_play(void) { | ||
44 | #ifndef NO_MUSIC_MODE | ||
45 | if (music_activated || midi_activated) return; | ||
46 | #endif | ||
47 | clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); | ||
48 | clicky_song[1][0] = clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); | ||
49 | PLAY_SONG(clicky_song); | ||
50 | } | ||
51 | #endif | ||
52 | 14 | ||
53 | static float compute_freq_for_midi_note(uint8_t note) | 15 | static float compute_freq_for_midi_note(uint8_t note) |
54 | { | 16 | { |
@@ -89,33 +51,6 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { | |||
89 | return false; | 51 | return false; |
90 | } | 52 | } |
91 | 53 | ||
92 | #ifdef AUDIO_CLICKY | ||
93 | if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_enable = !clicky_enable; } | ||
94 | |||
95 | if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; } | ||
96 | |||
97 | if (keycode == CLICKY_UP && record->event.pressed) { | ||
98 | float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; | ||
99 | if (new_freq < AUDIO_CLICKY_FREQ_MAX) { | ||
100 | clicky_freq = new_freq; | ||
101 | } | ||
102 | } | ||
103 | if (keycode == CLICKY_TOGGLE && record->event.pressed) { | ||
104 | float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; | ||
105 | if (new_freq > AUDIO_CLICKY_FREQ_MIN) { | ||
106 | clicky_freq = new_freq; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | |||
111 | if ( clicky_enable ) { | ||
112 | if (record->event.pressed) { | ||
113 | stop_all_notes(); | ||
114 | clicky_play();; | ||
115 | } | ||
116 | } | ||
117 | #endif // AUDIO_CLICKY | ||
118 | |||
119 | return true; | 54 | return true; |
120 | } | 55 | } |
121 | 56 | ||
diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c new file mode 100644 index 000000000..2b9d8a0f7 --- /dev/null +++ b/quantum/process_keycode/process_clicky.c | |||
@@ -0,0 +1,72 @@ | |||
1 | #include "audio.h" | ||
2 | #include "process_clicky.h" | ||
3 | |||
4 | #ifdef AUDIO_CLICKY | ||
5 | |||
6 | #ifdef AUDIO_CLICKY_ON | ||
7 | bool clicky_enable = true; | ||
8 | #else // AUDIO_CLICKY_ON | ||
9 | bool clicky_enable = false; | ||
10 | #endif // AUDIO_CLICKY_ON | ||
11 | #ifndef AUDIO_CLICKY_FREQ_DEFAULT | ||
12 | #define AUDIO_CLICKY_FREQ_DEFAULT 440.0f | ||
13 | #endif // !AUDIO_CLICKY_FREQ_DEFAULT | ||
14 | #ifndef AUDIO_CLICKY_FREQ_MIN | ||
15 | #define AUDIO_CLICKY_FREQ_MIN 65.0f | ||
16 | #endif // !AUDIO_CLICKY_FREQ_MIN | ||
17 | #ifndef AUDIO_CLICKY_FREQ_MAX | ||
18 | #define AUDIO_CLICKY_FREQ_MAX 1500.0f | ||
19 | #endif // !AUDIO_CLICKY_FREQ_MAX | ||
20 | #ifndef AUDIO_CLICKY_FREQ_FACTOR | ||
21 | #define AUDIO_CLICKY_FREQ_FACTOR 1.18921f | ||
22 | #endif // !AUDIO_CLICKY_FREQ_FACTOR | ||
23 | #ifndef AUDIO_CLICKY_FREQ_RANDOMNESS | ||
24 | #define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f | ||
25 | #endif // !AUDIO_CLICKY_FREQ_RANDOMNESS | ||
26 | |||
27 | float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; | ||
28 | float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations | ||
29 | |||
30 | #ifndef NO_MUSIC_MODE | ||
31 | extern bool music_activated; | ||
32 | extern bool midi_activated; | ||
33 | #endif // !NO_MUSIC_MODE | ||
34 | |||
35 | void clicky_play(void) { | ||
36 | #ifndef NO_MUSIC_MODE | ||
37 | if (music_activated || midi_activated) return; | ||
38 | #endif // !NO_MUSIC_MODE | ||
39 | clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); | ||
40 | clicky_song[1][0] = clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) ); | ||
41 | PLAY_SONG(clicky_song); | ||
42 | } | ||
43 | |||
44 | bool process_clicky(uint16_t keycode, keyrecord_t *record) { | ||
45 | if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_enable = !clicky_enable; } | ||
46 | |||
47 | if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; } | ||
48 | |||
49 | if (keycode == CLICKY_UP && record->event.pressed) { | ||
50 | float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR; | ||
51 | if (new_freq < AUDIO_CLICKY_FREQ_MAX) { | ||
52 | clicky_freq = new_freq; | ||
53 | } | ||
54 | } | ||
55 | if (keycode == CLICKY_TOGGLE && record->event.pressed) { | ||
56 | float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR; | ||
57 | if (new_freq > AUDIO_CLICKY_FREQ_MIN) { | ||
58 | clicky_freq = new_freq; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | |||
63 | if ( clicky_enable ) { | ||
64 | if (record->event.pressed) { | ||
65 | stop_all_notes(); | ||
66 | clicky_play();; | ||
67 | } | ||
68 | } | ||
69 | return true; | ||
70 | } | ||
71 | |||
72 | #endif //AUDIO_CLICKY | ||
diff --git a/quantum/process_keycode/process_clicky.h b/quantum/process_keycode/process_clicky.h new file mode 100644 index 000000000..e274af56f --- /dev/null +++ b/quantum/process_keycode/process_clicky.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #ifndef PROCESS_CLICKY_H | ||
2 | #define PROCESS_CLICKY_H | ||
3 | |||
4 | void clicky_play(void); | ||
5 | bool process_clicky(uint16_t keycode, keyrecord_t *record); | ||
6 | |||
7 | #endif | ||