public static MidiFileAsset Load(byte [] data)
        {
            var reader = new MidiDataStreamReader(data);

            // Chunk type
            if (reader.ReadChars(4) != "MThd")
            {
                throw new FormatException("Can't find header chunk.");
            }

            // Chunk length
            if (reader.ReadBEUInt32() != 6u)
            {
                throw new FormatException("Length of header chunk must be 6.");
            }

            // Format (unused)
            reader.Advance(2);

            // Number of tracks
            var trackCount = reader.ReadBEUInt16();

            // Ticks per quarter note
            var tpqn = reader.ReadBEUInt16();

            if ((tpqn & 0x8000u) != 0)
            {
                throw new FormatException("SMPTE time code is not supported.");
            }

            // Tracks
            var tracks = new MidiAnimationAsset [trackCount];

            for (var i = 0; i < trackCount; i++)
            {
                tracks[i] = ReadTrack(reader, tpqn);
            }

            // Asset instantiation
            var asset = ScriptableObject.CreateInstance <MidiFileAsset>();

            asset.tracks = tracks;
            return(asset);
        }