No audio output for MIDI .mid sequence playback

Mac Simulator 1.12.0

local seq,err ="sounds/final_countdown.mid")
print(seq, err, seq:getLength(), seq:getTrackCount())

playdate.sound.sequence: 0x7fdf1e210d70 nil 41281 16

Both MIDI files I attached play fine in GarageBand. But when executing the lua code above, I don't hear anything.

  • note that the err variable was just something I tried, folling conventions from other loader funxctions in the sdk. For no error return argument is specified though.
  • From the print output, we can see that the file was found on disk. the length and number of tracks is non-zero. When I change the file path to the other midi file, values do change
  • my laptop's audio is OK. I can hear sound effects loaded with sampleplayer.

What am I missing? Should I load the sequence in a channel before playback or something? (7.2 KB)

Allright, I found the MidiPlayer sample project in the SDK; and when I plug my files in there, actual sound comes out. In the code, track 10 is mapped to a drums instrument. Is it convention in midi-land that track 10 is a drum track? Or was this sample project written with the bundled giveyouup.mid in mind?

The result is very rough/ old-skool though, because all tracks in the midi file, a saw-tooth instrument is created. The style actually suits the final countdown song, but in garageband, the cgmusic file sounds considerably richer

So it seems playdate needs to be told what instruments to use for each track though. Using track:getInstrument() returns nil initially after loading the midi file. GarageBand does an excellent job of gathering that info from just loading the file tho. So I guess the playdate sdk doesn't read that information.
Are these mappings available for playdate as well?

image: cgmusic.mid in GarageBand

As you can see from the above, I might benefit from some background info on how MIDI works in the first place :slight_smile:

edit: This reference document states that channel 10 contains drums: Standard MIDI file format, updated (appendix 1.4 and 1.5)

These sounds are the same for all MIDI Channels except Channel 10, which has only percussion sounds and some sound "effects".

So my question is: what Instrument should I load for which channel? Is sawtooth for all except 10 actually a generally good approach?

Yes! Many conventions in MIDI-land, very worth researching if you plan to do a lot of work with the standard.