Music for my game!

Haha thanks for the compliment :smiley:

This is how I make the songs in Arcade:

  1. First I find some sheet music and download it. I usually use the Musescore website to browse for sheet music.
  2. Then I open it in the Musescore software, make song adjustments as necessary, and export to the MIDI format. I usually check the .mid file in Audacity.
  3. After, I adjust my Python scripts to use the MIDI file I just exported. The first script opens and parses the MIDI with Mido and generates a JSON file that looks like this:
{
    "midi": [
        [
            {
                "note": 72,
                "name": "C5",
                "velocity": 80,
                "time": 0.24895833333333334
            },
            {
                "note": 48,
                "name": "C3",
                "velocity": 80,
                "time": 0.24895833333333334
            }
        ],
        [
            {
                "note": 67,
                "name": "G4",
                "velocity": 80,
                "time": 0.24895833333333334
            },
            {
                "note": 55,
                "name": "G3",
                "velocity": 80,
                "time": 0.24895833333333334
            }
        ],
        [
            {
                "note": 72,
                "name": "C5",
                "velocity": 80,
                "time": 0.4739583333333333
            },
            {
                "note": 48,
                "name": "C3",
                "velocity": 80,
                "time": 0.4739583333333333
            }
        ],
        // More notes
    ]
}
  1. I then run my second script to use this JSON and it produces a .ts file that looks like this: (I changed the speed to be I think 1.5x slower.)
function play_song() {
    // ['C5', 'C3']
    {
        music.setVolume(80)
        // C5
        timer.background(function() {
            music.playTone(523, 372.0)
        })
        // C3
        music.playTone(130, 373)
    }
    // ['G4', 'G3']
    {
        // G4
        timer.background(function() {
            music.playTone(391, 372.0)
        })
        // G3
        music.playTone(195, 373)
    }
    // ['C5', 'C3']
    {
        // C5
        timer.background(function() {
            music.playTone(523, 709.5)
        })
        // C3
        music.playTone(130, 710)
    }
    // More notes
}

play_song()

So I don’t do the songs by hand (I would have gone insane) but writing the scripts to generate the typescript took ages…

5 Likes