protected bool OpenFile() { try { if (P.F.MidiFileBuffer == null) //read file from disk { if (!File.Exists(P.F.Project.MidiPath)) { MessageBox.Show("Midifile " + P.F.Project.MidiPath + " not found"); return(false); } FileStream stfile = new FileStream(P.F.Project.MidiPath, FileMode.Open, FileAccess.Read, FileShare.Read); //BinaryReader brfile = new BinaryReader(stfile); int len = (int)stfile.Length; P.F.MidiFileBuffer = new byte[len]; stfile.Read(P.F.MidiFileBuffer, 0, len); } MemoryStream stmem = new MemoryStream(P.F.MidiFileBuffer, false); BinaryReader brmem = new BinaryReader(stmem); MReaderFile = new clsMReader(brmem, stmem); return(true); } catch (Exception exc) { MessageBox.Show("Error loading Midifile: " + exc.Message); return(false); } //catch (FileNotFoundException ex) { // MessageBox.Show("Midifile Open Error: " + ex.Message); // return false; //} //catch (DirectoryNotFoundException ex) { // MessageBox.Show("Midifile Open Error: " + ex.Message); // return false; //} }
protected void InitTrack() { string head = MReaderFile.ReadStr(4); if (head != "MTrk") { MessageBox.Show("Unexpected Track Header: " + head); throw new MidiFileException(); } int trklen = (int)MReaderFile.ReadUIntF(4); Stream sttrk = new MemoryStream(trklen); byte[] trkbytes = MReaderFile.ReadBytes(trklen); if (trkbytes.Length < trklen) { MessageBox.Show("Invalid trk length"); throw new MidiFileException(); } sttrk.Write(trkbytes, 0, trklen); sttrk.Seek(0, SeekOrigin.Begin); BinaryReader brtrk = new BinaryReader(sttrk); MReaderTrk = new clsMReader(brtrk, sttrk); }