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)
This commit is contained in:
parent
23b45710ac
commit
8b0b17a369
7 changed files with 111 additions and 21 deletions
|
@ -97,6 +97,36 @@ You can completely disable Music Mode as well. This is useful, if you're pressed
|
||||||
|
|
||||||
#define NO_MUSIC_MODE
|
#define NO_MUSIC_MODE
|
||||||
|
|
||||||
|
## Faux Click
|
||||||
|
|
||||||
|
This 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.
|
||||||
|
|
||||||
|
* `CK_TOGG` - Toggles the status (will play sound if enabled)
|
||||||
|
* `CK_RST` - Resets the frequency to the default state
|
||||||
|
* `CK_UP` - Increases the frequency of the clicks
|
||||||
|
* `CK_DOWN` - Decreases the frequency of the clicks
|
||||||
|
|
||||||
|
The feature is disabled by default, to save space. To enable it, add this to your `config.h`:
|
||||||
|
|
||||||
|
#define AUDIO_CLICKY
|
||||||
|
|
||||||
|
Additionally, 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`:
|
||||||
|
|
||||||
|
#define AUDIO_CLICKY_ON
|
||||||
|
|
||||||
|
You can configure the default, min and max frequencies, the stepping and built in randomness by defining these values:
|
||||||
|
|
||||||
|
| Option | Default Value | Description |
|
||||||
|
|--------|---------------|-------------|
|
||||||
|
| `AUDIO_CLICKY_FREQ_DEFAULT` | 440.0f | Sets the default/starting audio frequency for the clicky sounds. |
|
||||||
|
| `AUDIO_CLICKY_FREQ_MIN` | 65.0f | Sets the lowest frequency (under 60f are a bit buggy). |
|
||||||
|
| `AUDIO_CLICKY_FREQ_MAX` | 1500.0f | Sets the the highest frequency. Too high may result in coworkers attacking you. |
|
||||||
|
| `AUDIO_CLICKY_FREQ_FACTOR` | 1.18921f| Sets the stepping of UP/DOWN key codes. |
|
||||||
|
| `AUDIO_CLICKY_FREQ_RANDOMNESS` | 0.05f | Sets a factor of randomness for the clicks, Setting this to `0f` will make each click identical. |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## MIDI Functionality
|
## MIDI Functionality
|
||||||
|
|
||||||
This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
|
This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
|
||||||
|
|
|
@ -67,7 +67,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
),
|
),
|
||||||
|
|
||||||
[_MEDIA] = LAYOUT_ortho_5x7(
|
[_MEDIA] = LAYOUT_ortho_5x7(
|
||||||
KC_MAKE, KC_RESET,MU_TOG, AUD_ON, AUD_OFF, KC_FXCL, RGB_SAD,
|
KC_MAKE, KC_RESET,MU_TOG, AUD_ON, AUD_OFF, CK_TOGG, RGB_SAD,
|
||||||
MEDIA, EPRM, KC_RGB_T,RGB_M_P, RGB_M_B, RGB_M_R, RGB_SAI,
|
MEDIA, EPRM, KC_RGB_T,RGB_M_P, RGB_M_B, RGB_M_R, RGB_SAI,
|
||||||
RGB_TOG, RGB_MOD, RGB_RMOD,RGB_M_SW,RGB_M_SN,RGB_M_K, RGB_HUD,
|
RGB_TOG, RGB_MOD, RGB_RMOD,RGB_M_SW,RGB_M_SN,RGB_M_K, RGB_HUD,
|
||||||
KC_MPLY, KC_MPRV, KC_MNXT, RGB_M_X, RGB_M_G, RGB_M_P, RGB_HUI,
|
KC_MPLY, KC_MPRV, KC_MNXT, RGB_M_X, RGB_M_G, RGB_M_P, RGB_HUI,
|
||||||
|
|
|
@ -10,6 +10,46 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG;
|
||||||
#define PITCH_STANDARD_A 440.0f
|
#define PITCH_STANDARD_A 440.0f
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef AUDIO_CLICKY
|
||||||
|
#ifdef AUDIO_CLICKY_ON
|
||||||
|
bool clicky_enable = true;
|
||||||
|
#else
|
||||||
|
bool clicky_enable = false;
|
||||||
|
#endif
|
||||||
|
#ifndef AUDIO_CLICKY_FREQ_DEFAULT
|
||||||
|
#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
|
||||||
|
#endif
|
||||||
|
#ifndef AUDIO_CLICKY_FREQ_MIN
|
||||||
|
#define AUDIO_CLICKY_FREQ_MIN 65.0f
|
||||||
|
#endif
|
||||||
|
#ifndef AUDIO_CLICKY_FREQ_MAX
|
||||||
|
#define AUDIO_CLICKY_FREQ_MAX 1500.0f
|
||||||
|
#endif
|
||||||
|
#ifndef AUDIO_CLICKY_FREQ_FACTOR
|
||||||
|
#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
|
||||||
|
#endif
|
||||||
|
#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
|
||||||
|
#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
|
||||||
|
float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations
|
||||||
|
|
||||||
|
#ifndef NO_MUSIC_MODE
|
||||||
|
extern bool music_activated;
|
||||||
|
extern bool midi_activated;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void clicky_play(void) {
|
||||||
|
#ifndef NO_MUSIC_MODE
|
||||||
|
if (music_activated || midi_activated) return;
|
||||||
|
#endif
|
||||||
|
clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
||||||
|
clicky_song[1][0] = clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
||||||
|
PLAY_SONG(clicky_song);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static float compute_freq_for_midi_note(uint8_t note)
|
static float compute_freq_for_midi_note(uint8_t note)
|
||||||
{
|
{
|
||||||
// https://en.wikipedia.org/wiki/MIDI_tuning_standard
|
// https://en.wikipedia.org/wiki/MIDI_tuning_standard
|
||||||
|
@ -49,6 +89,33 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AUDIO_CLICKY
|
||||||
|
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_enable = !clicky_enable; }
|
||||||
|
|
||||||
|
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; }
|
||||||
|
|
||||||
|
if (keycode == CLICKY_UP && record->event.pressed) {
|
||||||
|
float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
|
||||||
|
if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
|
||||||
|
clicky_freq = new_freq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keycode == CLICKY_TOGGLE && record->event.pressed) {
|
||||||
|
float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
|
||||||
|
if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
|
||||||
|
clicky_freq = new_freq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( (clicky_enable && keycode != CLICKY_TOGGLE) || (!clicky_enable && keycode == CLICKY_TOGGLE) ) {
|
||||||
|
if (record->event.pressed) {
|
||||||
|
stop_all_notes();
|
||||||
|
clicky_play();;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // AUDIO_CLICKY
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,4 +132,4 @@ void process_audio_all_notes_off(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__ ((weak))
|
__attribute__ ((weak))
|
||||||
void audio_on_user() {}
|
void audio_on_user() {}
|
||||||
|
|
|
@ -140,6 +140,12 @@ enum quantum_keycodes {
|
||||||
AU_OFF,
|
AU_OFF,
|
||||||
AU_TOG,
|
AU_TOG,
|
||||||
|
|
||||||
|
// Faux clicky as part of main audio feature
|
||||||
|
CLICKY_TOGGLE,
|
||||||
|
CLICKY_UP,
|
||||||
|
CLICKY_DOWN,
|
||||||
|
CLICKY_RESET,
|
||||||
|
|
||||||
#ifdef FAUXCLICKY_ENABLE
|
#ifdef FAUXCLICKY_ENABLE
|
||||||
// Faux clicky
|
// Faux clicky
|
||||||
FC_ON,
|
FC_ON,
|
||||||
|
@ -561,6 +567,11 @@ enum quantum_keycodes {
|
||||||
|
|
||||||
#define KC_GESC GRAVE_ESC
|
#define KC_GESC GRAVE_ESC
|
||||||
|
|
||||||
|
#define CK_TOGG CLICKY_TOGGLE
|
||||||
|
#define CK_RST CLICKY_RESET
|
||||||
|
#define CK_UP CLICKY_UP
|
||||||
|
#define CK_DOWN CLICKY_DOWN
|
||||||
|
|
||||||
#define RGB_MOD RGB_MODE_FORWARD
|
#define RGB_MOD RGB_MODE_FORWARD
|
||||||
#define RGB_SMOD RGB_MODE_FORWARD
|
#define RGB_SMOD RGB_MODE_FORWARD
|
||||||
#define RGB_RMOD RGB_MODE_REVERSE
|
#define RGB_RMOD RGB_MODE_REVERSE
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
|
#define AUDIO_CLICKY
|
||||||
#define STARTUP_SONG SONG(E1M1_DOOM)
|
#define STARTUP_SONG SONG(E1M1_DOOM)
|
||||||
#define GOODBYE_SONG SONG(SONIC_RING)
|
#define GOODBYE_SONG SONG(SONIC_RING)
|
||||||
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
|
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
|
||||||
|
|
|
@ -224,19 +224,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
|
xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
|
||||||
#endif //CONSOLE_ENABLE
|
#endif //CONSOLE_ENABLE
|
||||||
|
|
||||||
// Run custom faux click code, but only if faux clicky is enabled
|
|
||||||
#ifdef AUDIO_ENABLE
|
|
||||||
if ( (faux_click_enabled && keycode != KC_FXCL) || (!faux_click_enabled && keycode == KC_FXCL) ) {
|
|
||||||
if (record->event.pressed) {
|
|
||||||
stop_all_notes();
|
|
||||||
PLAY_SONG(fauxclicky_pressed);
|
|
||||||
} else {
|
|
||||||
stop_all_notes();
|
|
||||||
PLAY_SONG(fauxclicky_released);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif //AUDIO_ENABLE
|
|
||||||
|
|
||||||
|
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case KC_QWERTY:
|
case KC_QWERTY:
|
||||||
|
@ -398,11 +385,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
#endif // TAP_DANCE_ENABLE
|
#endif // TAP_DANCE_ENABLE
|
||||||
|
|
||||||
|
|
||||||
case KC_FXCL:
|
|
||||||
if (!record->event.pressed) { // Toggles the custom faux click code
|
|
||||||
faux_click_enabled = !faux_click_enabled;
|
|
||||||
}
|
|
||||||
return false; break;
|
|
||||||
case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
|
case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
|
||||||
#ifdef RGBLIGHT_ENABLE
|
#ifdef RGBLIGHT_ENABLE
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
|
|
|
@ -83,7 +83,6 @@ enum userspace_custom_keycodes {
|
||||||
KC_SECRET_3,
|
KC_SECRET_3,
|
||||||
KC_SECRET_4,
|
KC_SECRET_4,
|
||||||
KC_SECRET_5,
|
KC_SECRET_5,
|
||||||
KC_FXCL,
|
|
||||||
NEW_SAFE_RANGE //use "NEWPLACEHOLDER for keymap specific codes
|
NEW_SAFE_RANGE //use "NEWPLACEHOLDER for keymap specific codes
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue