Skip to content

sequencer: Tracks not closed when exporting Song to SMF1

Hi, I've been tinkering with this library for a while, went through v1->v2 migration and discovered some issues.

When exporting a Song to SMF1, there is a problem that the library can't read back its own exported SMF: https://go.dev/play/p/UemUWdv5vuT

I see that there is an idea of closing the tracks in SMF.WriteTo() but it doesn't work: https://gitlab.com/gomidi/midi/-/blob/master/v2/smf/smf.go#L261-268

The tr loop variable is a copy of smf.Track (which is a []Event), after the loop the original tracks are still not closed. I initially changed Tracks []Track to Tracks []*Track in SMF struct and that worked but thought it doesn't make sense, writing out the SMF shouldn't modify it.

I think this non-working loop should be removed and the tracks should be closed during Song.ToSMF1(), just before https://gitlab.com/gomidi/midi/-/blob/master/v2/sequencer/song.go#L169

EDIT: it is also the case that sm.Add(t) returns the error that track was not closed but it is ignored.

Edited by Magnus Kokk