Cannot parse AudioKit MIDI file

16 Views Asked by At

I am unable to load and view a MIDI file that has only one track. This is the MIDI file I'm trying to parse (download -> download as MIDI).

The format of the file is 1. The AudioKit library assumes that it can drop the first track in this case:

    public var tracks: [MIDIFileTrack] {
        var tracks = trackChunks
        if format == 1 {
            tracks = Array(tracks.dropFirst()) // drop tempo track
        }
        return tracks.compactMap({ MIDIFileTrack(chunk: $0) })
    }

I haven't been able to workaround this. I can't manually create a MIDIFileTrack because its initializer is private.

public struct MIDIFileTrack {

    var chunk: MIDIFileTrackChunk

    ...

    /// Initialize with MIDI File Track Chunk
    /// - Parameter chunk: MIDI File Track Chunk
    init(chunk: MIDIFileTrackChunk) {
        self.chunk = chunk
    }
}

I can't create a MIDIEvent from a MIDIFileChunkEvent either.

How can I work around this? I will be working with many MIDI files that do not have the correct format specified.

0

There are 0 best solutions below