aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-04-18 22:47:04 -0700
committerJack Humbert <jack.humb@gmail.com>2018-04-19 01:47:04 -0400
commit8b0b17a369be6d3dff4cb9bad4253960252a5e95 (patch)
tree11d453ef480983571de84147db3bc9c1bfcb5054
parent23b45710acc57ed147e006a8c79a1caf6fa57fd7 (diff)
downloadqmk_firmware-8b0b17a369be6d3dff4cb9bad4253960252a5e95.tar.gz
qmk_firmware-8b0b17a369be6d3dff4cb9bad4253960252a5e95.zip
Add Faux Clicking as subset of Audio feature (#2748)
* Add Faux Clicky to main Audio feature * Make clicky settings user configurable * Add additional documentation * Don't play when music mode is enabled (hopefully)
-rw-r--r--docs/feature_audio.md30
-rw-r--r--keyboards/viterbi/keymaps/drashna/keymap.c2
-rw-r--r--quantum/process_keycode/process_audio.c69
-rw-r--r--quantum/quantum_keycodes.h11
-rw-r--r--users/drashna/config.h1
-rw-r--r--users/drashna/drashna.c18
-rw-r--r--users/drashna/drashna.h1
7 files changed, 111 insertions, 21 deletions
diff --git a/docs/feature_audio.md b/docs/feature_audio.md
index eaaa2fe51..1b8ca86f4 100644
--- a/docs/feature_audio.md
+++ b/docs/feature_audio.md
@@ -97,6 +97,36 @@ You can completely disable Music Mode as well. This is useful, if you're pressed
97 97
98 #define NO_MUSIC_MODE 98 #define NO_MUSIC_MODE
99 99
100## Faux Click
101
102This adds a click sound each time you hit a button, to simulate click sounds from the keyboard. And the sounds are slightly different for each keypress, so it doesn't sound like a single long note, if you type rapidly.
103
104* `CK_TOGG` - Toggles the status (will play sound if enabled)
105* `CK_RST` - Resets the frequency to the default state
106* `CK_UP` - Increases the frequency of the clicks
107* `CK_DOWN` - Decreases the frequency of the clicks
108
109The feature is disabled by default, to save space. To enable it, add this to your `config.h`:
110
111 #define AUDIO_CLICKY
112
113Additionally, even when enabled, the feature is not enabled by default, so you would need to turn it on first. And since we don't use EEPROM to store the setting (yet), you can default this to on by adding this to your `config.h`:
114
115 #define AUDIO_CLICKY_ON
116
117You can configure the default, min and max frequencies, the stepping and built in randomness by defining these values:
118
119| Option | Default Value | Description |
120|--------|---------------|-------------|
121| `AUDIO_CLICKY_FREQ_DEFAULT` | 440.0f | Sets the default/starting audio frequency for the clicky sounds. |
122| `AUDIO_CLICKY_FREQ_MIN` | 65.0f | Sets the lowest frequency (under 60f are a bit buggy). |
123| `AUDIO_CLICKY_FREQ_MAX` | 1500.0f | Sets the the highest frequency. Too high may result in coworkers attacking you. |
124| `AUDIO_CLICKY_FREQ_FACTOR` | 1.18921f| Sets the stepping of UP/DOWN key codes. |
125| `AUDIO_CLICKY_FREQ_RANDOMNESS` | 0.05f | Sets a factor of randomness for the clicks, Setting this to `0f` will make each click identical. |
126
127
128
129
100## MIDI Functionality 130## MIDI Functionality
101 131
102This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile. 132This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
diff --git a/keyboards/viterbi/keymaps/drashna/keymap.c b/keyboards/viterbi/keymaps/drashna/keymap.c
index b5a7c18f8..78c60d1a6 100644
--- a/keyboards/viterbi/keymaps/drashna/keymap.c
+++ b/keyboards/viterbi/keymaps/drashna/keymap.c
@@ -67,7 +67,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
67 ), 67 ),
68 68
69 [_MEDIA] = LAYOUT_ortho_5x7( 69 [_MEDIA] = LAYOUT_ortho_5x7(
70 KC_MAKE, KC_RESET,MU_TOG, AUD_ON, AUD_OFF, KC_FXCL, RGB_SAD, 70 KC_MAKE, KC_RESET,MU_TOG, AUD_ON, AUD_OFF, CK_TOGG, RGB_SAD,
71 MEDIA, EPRM, KC_RGB_T,RGB_M_P, RGB_M_B, RGB_M_R, RGB_SAI, 71 MEDIA, EPRM, KC_RGB_T,RGB_M_P, RGB_M_B, RGB_M_R, RGB_SAI,
72 RGB_TOG, RGB_MOD, RGB_RMOD,RGB_M_SW,RGB_M_SN,RGB_M_K, RGB_HUD, 72 RGB_TOG, RGB_MOD, RGB_RMOD,RGB_M_SW,RGB_M_SN,RGB_M_K, RGB_HUD,
73 KC_MPLY, KC_MPRV, KC_MNXT, RGB_M_X, RGB_M_G, RGB_M_P, RGB_HUI, 73 KC_MPLY, KC_MPRV, KC_MNXT, RGB_M_X, RGB_M_G, RGB_M_P, RGB_HUI,
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c
index 32057ae8d..2d92e4064 100644
--- a/quantum/process_keycode/process_audio.c
+++ b/quantum/process_keycode/process_audio.c
@@ -10,6 +10,46 @@ 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
15bool clicky_enable = true;
16#else
17bool 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
35float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
36float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations
37
38#ifndef NO_MUSIC_MODE
39extern bool music_activated;
40extern bool midi_activated;
41#endif
42
43void 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
13static float compute_freq_for_midi_note(uint8_t note) 53static float compute_freq_for_midi_note(uint8_t note)
14{ 54{
15 // https://en.wikipedia.org/wiki/MIDI_tuning_standard 55 // https://en.wikipedia.org/wiki/MIDI_tuning_standard
@@ -49,6 +89,33 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
49 return false; 89 return false;
50 } 90 }
51 91
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 && keycode != CLICKY_TOGGLE) || (!clicky_enable && keycode == CLICKY_TOGGLE) ) {
112 if (record->event.pressed) {
113 stop_all_notes();
114 clicky_play();;
115 }
116 }
117#endif // AUDIO_CLICKY
118
52 return true; 119 return true;
53} 120}
54 121
@@ -65,4 +132,4 @@ void process_audio_all_notes_off(void) {
65} 132}
66 133
67__attribute__ ((weak)) 134__attribute__ ((weak))
68void audio_on_user() {} \ No newline at end of file 135void audio_on_user() {}
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index d545440c9..d6030284a 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -140,6 +140,12 @@ enum quantum_keycodes {
140 AU_OFF, 140 AU_OFF,
141 AU_TOG, 141 AU_TOG,
142 142
143 // Faux clicky as part of main audio feature
144 CLICKY_TOGGLE,
145 CLICKY_UP,
146 CLICKY_DOWN,
147 CLICKY_RESET,
148
143#ifdef FAUXCLICKY_ENABLE 149#ifdef FAUXCLICKY_ENABLE
144 // Faux clicky 150 // Faux clicky
145 FC_ON, 151 FC_ON,
@@ -561,6 +567,11 @@ enum quantum_keycodes {
561 567
562#define KC_GESC GRAVE_ESC 568#define KC_GESC GRAVE_ESC
563 569
570#define CK_TOGG CLICKY_TOGGLE
571#define CK_RST CLICKY_RESET
572#define CK_UP CLICKY_UP
573#define CK_DOWN CLICKY_DOWN
574
564#define RGB_MOD RGB_MODE_FORWARD 575#define RGB_MOD RGB_MODE_FORWARD
565#define RGB_SMOD RGB_MODE_FORWARD 576#define RGB_SMOD RGB_MODE_FORWARD
566#define RGB_RMOD RGB_MODE_REVERSE 577#define RGB_RMOD RGB_MODE_REVERSE
diff --git a/users/drashna/config.h b/users/drashna/config.h
index 68394ee4d..f9b0d4d17 100644
--- a/users/drashna/config.h
+++ b/users/drashna/config.h
@@ -3,6 +3,7 @@
3 3
4 4
5#ifdef AUDIO_ENABLE 5#ifdef AUDIO_ENABLE
6#define AUDIO_CLICKY
6#define STARTUP_SONG SONG(E1M1_DOOM) 7#define STARTUP_SONG SONG(E1M1_DOOM)
7#define GOODBYE_SONG SONG(SONIC_RING) 8#define GOODBYE_SONG SONG(SONIC_RING)
8#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \ 9#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
diff --git a/users/drashna/drashna.c b/users/drashna/drashna.c
index 170c320d3..73bd249e4 100644
--- a/users/drashna/drashna.c
+++ b/users/drashna/drashna.c
@@ -224,19 +224,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
224 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed); 224 xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
225#endif //CONSOLE_ENABLE 225#endif //CONSOLE_ENABLE
226 226
227 // Run custom faux click code, but only if faux clicky is enabled
228#ifdef AUDIO_ENABLE
229 if ( (faux_click_enabled && keycode != KC_FXCL) || (!faux_click_enabled && keycode == KC_FXCL) ) {
230 if (record->event.pressed) {
231 stop_all_notes();
232 PLAY_SONG(fauxclicky_pressed);
233 } else {
234 stop_all_notes();
235 PLAY_SONG(fauxclicky_released);
236 }
237 }
238#endif //AUDIO_ENABLE
239
240 227
241 switch (keycode) { 228 switch (keycode) {
242 case KC_QWERTY: 229 case KC_QWERTY:
@@ -398,11 +385,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
398#endif // TAP_DANCE_ENABLE 385#endif // TAP_DANCE_ENABLE
399 386
400 387
401 case KC_FXCL:
402 if (!record->event.pressed) { // Toggles the custom faux click code
403 faux_click_enabled = !faux_click_enabled;
404 }
405 return false; break;
406 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal 388 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
407#ifdef RGBLIGHT_ENABLE 389#ifdef RGBLIGHT_ENABLE
408 if (record->event.pressed) { 390 if (record->event.pressed) {
diff --git a/users/drashna/drashna.h b/users/drashna/drashna.h
index 1086fa02e..b7cbaa44a 100644
--- a/users/drashna/drashna.h
+++ b/users/drashna/drashna.h
@@ -83,7 +83,6 @@ enum userspace_custom_keycodes {
83 KC_SECRET_3, 83 KC_SECRET_3,
84 KC_SECRET_4, 84 KC_SECRET_4,
85 KC_SECRET_5, 85 KC_SECRET_5,
86 KC_FXCL,
87 NEW_SAFE_RANGE //use "NEWPLACEHOLDER for keymap specific codes 86 NEW_SAFE_RANGE //use "NEWPLACEHOLDER for keymap specific codes
88}; 87};
89 88