New Song format

I just remembered that I promised @UnsignedArduino that I would make a post linking to the new song format! Well, better late than never.

The format of the song buffer is documented here:

That file also contains all of the code for encoding/decoding the songs from buffers (in this case, uint8Arrays). The default instruments are all defined in the getEmptySong function.

This code is mirrored in the arcade game engine here:

If I were, hypothetically, making a webapp that converted midi files into the new song format, then I would:

  1. Copy all of this file
  2. Also copy these two functions

there are also a bunch of utility functions for manipulating songs here:


Once I’m done doing hot fixes, I will write some proper docs explaining the format in more detail!


Thank you so much! I definitely did not waste an entire day converting that entire first file you linked to Python first. :clown_face: :clown_face: :clown_face:

1 Like

One other thing I just thought of, note events for tracks need to be sorted by the start tick (e.g. they need to be encoded in chronological order).

1 Like

Also one question: I have code like this:

                note=49,  # Lowest C in octave

Why is 49 “middle C?” Is it a MIDI note index? Or something else?

yup! the numbers are midi note numbers

1 Like

Hi @richard, sorry to bother you but right now, I’m having difficulty with the instrument octaves. I’m setting the octave to 2 here:

I’m using a test MIDI file that has a glissando of notes from MIDI note 21 to 108, the lowest and highest notes on a piano. For some reason, the notes appear to be “shifted” by a couple of octaves. You can hear it here:

Do you have any idea why? I’ve tried other octaves like 0, 1, and 3 but they all produce shifted ranges too. Do I have to split up the notes to separate tracks that handle instruments with different octaves?