← QMK song player

How to add songs to your keymap

Step 1. Of course, the keyboard needs a speaker. See the audio documentation for options. Also, be sure to enable the audio feature by adding in your rules.mk:

AUDIO_ENABLE = yes

Step 2. In the same folder as your keymap.c, create a file called user_song_list.h. Song definitions in this file location will be automatically included in the build.

In user_song_list.h, write a song definition like

#define MY_SONG H__NOTE(_C2), H__NOTE(_C3), H__NOTE(_C4), W__NOTE(_C5)

The song notes are written in QMK song syntax. Multiple songs may be defined similarly by writing each on its own line.

To parse correctly, the song name MY_SONG must be a valid code identifier and the definition must be either one long line or using backslashes \ for line continuation:

#define MY_SONG H__NOTE(_C2), H__NOTE(_C3), \
                H__NOTE(_C4), W__NOTE(_C5)

Step 3a. As explained in the songs documentation, QMK has default songs that play for certain events, such as STARTUP_SONG when the keyboard starts up. You can override the default songs in config.h as:

#ifdef AUDIO_ENABLE
#  define STARTUP_SONG SONG(MY_SONG)
#endif

Step 3b. Alternatively, to play the song at a particular time, do the following. In keymap.c, add a global definition near the top of the file with

float my_song[][2] = SONG(MY_SONG);

Then play the song as

PLAY_SONG(my_song);