Random Preonic sounds
June 11, 2024I kind of warned you about making sounds with the Preonic keyboard, because 80s beeps will never go out of fashion, and these clicky switches aren’t noisier enough anyway. Check the previous post if you need to, this is a follow up.
Playing sounds is very simple with QMK, thanks to the cute PLAY_SONG
macro, to make the board play very geeky boops.
Since we started from the default keymap and config for the v3 preonic, we already have audio enabled on the board. There’s nothing else to configure: as far as I know we can already beep to our heart’s content.
In QMK, we have a C macro SONG(list of notes)
. It gives us back an
array, that we can feed to PLAY_SONG
to actually play sounds. Of
course these are C macros, so we can’t really inline things like this:
PLAY_SONG(SONG(TADAAA))
. NOPE!
No big deal. We’ll use an intermediate variable to store the “song”,
and feed that to PLAY_SONG
. For our purpose, let’s reuse a song from
song_list.h
(this file). Writing your own stuff is fun,
but it’ll keep this post short.
I’ll use the CAPS_LOCK_ON_SOUND
(and off) sounds, which seem
half-appropriate.
Let’s declare these two songs in keymap.c
:
#ifdef AUDIO_ENABLE
static float caps_word_on_song[][2] = SONG(CAPS_LOCK_ON_SOUND);
static float caps_word_off_song[][2] = SONG(CAPS_LOCK_OFF_SOUND);
#endif
Now, we could update the previous post’s tap-dance callback to play
sounds, but the caps-word feature is more ergonomic than that. Just
use the caps_word_set_user
callback. It gets a “bool” to
indicate the current state. Again, in keymap.c
:
#ifdef AUDIO_ENABLE
void caps_word_set_user(bool active) {
if (active) {
(caps_word_on_song);
PLAY_SONG} else {
(caps_word_off_song);
PLAY_SONG}
}
#endif
The whole #ifdef
wrapping isn’t essential here, but the function
only matters when audio is enabled in my case. YMMV.
That’s it. See, THAT WAS NOT THAT HARD. Sorry, just testing. :)