]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add Faux Clicking as subset of Audio feature (#2748)
authorDrashna Jaelre <drashna@live.com>
Thu, 19 Apr 2018 05:47:04 +0000 (22:47 -0700)
committerJack Humbert <jack.humb@gmail.com>
Thu, 19 Apr 2018 05:47:04 +0000 (01:47 -0400)
* Add Faux Clicky to main Audio feature

* Make clicky settings user configurable

* Add additional documentation

* Don't play when music mode is enabled (hopefully)

docs/feature_audio.md
keyboards/viterbi/keymaps/drashna/keymap.c
quantum/process_keycode/process_audio.c
quantum/quantum_keycodes.h
users/drashna/config.h
users/drashna/drashna.c
users/drashna/drashna.h

index eaaa2fe512fb7b4895657b0997e362b4e9068bc4..1b8ca86f4985293b71e2d3f86052e64d5e91b4be 100644 (file)
@@ -97,6 +97,36 @@ You can completely disable Music Mode as well. This is useful, if you're pressed
 
     #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
 
 This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
index b5a7c18f88bc55c159137cb10f98cc1913e9ecb8..78c60d1a68cc8fd67cf5216ecd4994c47b258a4b 100644 (file)
@@ -67,7 +67,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
   ),
 
   [_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,
       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,
index 32057ae8dc3ebf216659617a6e71695d4c8ee6b5..2d92e4064d2c587ec64942494f91339a7c343ee3 100644 (file)
@@ -10,6 +10,46 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG;
     #define PITCH_STANDARD_A 440.0f
 #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)
 {
     // https://en.wikipedia.org/wiki/MIDI_tuning_standard
@@ -49,6 +89,33 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
         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;
 }
 
@@ -65,4 +132,4 @@ void process_audio_all_notes_off(void) {
 }
 
 __attribute__ ((weak))
-void audio_on_user() {}
\ No newline at end of file
+void audio_on_user() {}
index d545440c99d099ef7e43e2d11fb1383e62439839..d6030284a9152aa85c5f67aae353d3401200e7e5 100644 (file)
@@ -140,6 +140,12 @@ enum quantum_keycodes {
     AU_OFF,
     AU_TOG,
 
+    // Faux clicky as part of main audio feature
+    CLICKY_TOGGLE,
+    CLICKY_UP,
+    CLICKY_DOWN,
+    CLICKY_RESET,
+
 #ifdef FAUXCLICKY_ENABLE
     // Faux clicky
     FC_ON,
@@ -561,6 +567,11 @@ enum quantum_keycodes {
 
 #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_SMOD RGB_MODE_FORWARD
 #define RGB_RMOD RGB_MODE_REVERSE
index 68394ee4dbba8e35edfd758323a28ee13460b790..f9b0d4d17a2a5f9f743ed503536102e3ab225fcc 100644 (file)
@@ -3,6 +3,7 @@
 
 
 #ifdef AUDIO_ENABLE
+#define AUDIO_CLICKY
 #define STARTUP_SONG SONG(E1M1_DOOM)
 #define GOODBYE_SONG  SONG(SONIC_RING)
 #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
index 170c320d3648e817a93e889bad0d69e38303c221..73bd249e4ce9ce770d8caf2841da2cd04cdaa857 100644 (file)
@@ -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);
 #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) {
   case KC_QWERTY:
@@ -398,11 +385,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
 #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
 #ifdef RGBLIGHT_ENABLE
     if (record->event.pressed) {
index 1086fa02ed0e0133ad94bea49548e4513dd894d5..b7cbaa44afb0a229f2e65ada0a3682419ad4c948 100644 (file)
@@ -83,7 +83,6 @@ enum userspace_custom_keycodes {
   KC_SECRET_3,
   KC_SECRET_4,
   KC_SECRET_5,
-  KC_FXCL,
   NEW_SAFE_RANGE //use "NEWPLACEHOLDER for keymap specific codes
 };