public static MidiFileInfo Parse(Stream reader) { var info = new MidiFileInfo(); ParseHeaderChunk(reader, info); var tracks = new List <MidiChunkPointer>(); while (reader.Position < reader.Length) { ParseTrackChunk(reader, tracks); } info.Tracks = tracks.ToArray(); info.TrackCount = tracks.Count; return(info); }
static void ParseHeaderChunk(Stream reader, MidiFileInfo info) { AssertText(reader, "MThd"); uint length = (uint)ReadInt32(reader); if (length != 6) { throw new Exception("Header chunk size isn't 6"); } info.Format = ReadInt16(reader); ReadInt16(reader); info.Division = ReadInt16(reader); if (info.Format == 2) { throw new Exception("Midi type 2 not supported"); } if (info.Division < 0) { throw new Exception("Division < 0 not supported"); } }