lxndio

Journal of my ideas, thoughts and projects.


Programming your Planck #3 - Getting the melody

The Planck keyboard is able to play melodies on its internal speaker - if you've bought or built one with a speaker. Today I am showing you how to create your own melodies.

First, please make sure you've read part #1 and part #2 of this series.

This time, we'll start with another file at quantum/audio/song_list.h. Even though the file is in another folder, you still compile the file from the same folder as always!

You'll see some definitions of songs there. This for example are the melodies I've composed for switching to the number layer and exiting it:

#define NUMBERS_SOUND \
    E__NOTE(_C6  ),   \
    E__NOTE(_DS6 ),   \
    E__NOTE(_DS6 ),   \
    S__NOTE(_REST),   \
    ED_NOTE(_C6  ),   \
    S__NOTE(_REST),   \
    ED_NOTE(_F6  ),

#define NUMBERS_GOODBYE_SOUND \
    E__NOTE(_C6  ),   \
    E__NOTE(_DS6 ),   \
    E__NOTE(_DS6 ),   \
    S__NOTE(_REST),   \
    ED_NOTE(_F6  ),   \
    S__NOTE(_REST),   \
    ED_NOTE(_C6  ),

I can't tell you how to compose melodies as I am not a very good composer myself but I can offer you the advice to take a look at the file at quantum/audio/musical_notes.h where all notes are listed and a little description is given.

Now let's set the new melodies as the melodies for opening and exiting the numbers layer we've created in part #2. Therefore, please open the keymap.c file.
In my file the song definition are below the layer definitions. The are starts with #ifdef AUDIO_ENABLE to make sure it only gets executed if audio is enabled for that keyboard. More on that later. Now add those definitions:

float tone_numbers[][2]    = SONG(NUMBERS_SOUND);  
float tone_numbers_gb[][2] = SONG(NUMBERS_GOODBYE_SOUND);  

The last step is to replace the current melodies with these in the code we've written in part #2.

If this is not working but you have a speaker on your keyboard and can exclude any wiring issues, open the Makefile in the same folder as the keymap.c file. There will be a variable called AUDIO_ENABLE. Set it to yes. If the variable does not exist, try creating it.

As always, feel free to contact me via Reddit (/u/lxndio) or Telegram (@lxndio). Thank you for reading this.

Till then,
lxndio