示例#1
0
 public BufferByteReader(DiskReadProvider stream, int buffersize, long streamstart, long streamlen)
 {
     this.streamLen   = streamlen;
     this.stream      = stream;
     this.streamStart = streamstart;
     if (buffersize > streamlen)
     {
         isSingle        = true;
         buffersize      = (int)streamlen;
         this.bufferSize = buffersize;
         buffer          = new byte[buffersize];
         UpdateBufferSingle();
     }
     else
     {
         this.bufferSize = buffersize;
         buffer          = new byte[buffersize];
         bufferNext      = new byte[buffersize];
         UpdateBuffer(pos, true);
     }
 }
示例#2
0
 protected void Open()
 {
     MidiFileReader = File.Open(filepath, FileMode.Open);
     ReadProvider   = new DiskReadProvider(MidiFileReader);
     ParseHeaderChunk();
     while (MidiFileReader.Position < MidiFileReader.Length)
     {
         try
         {
             ParseTrackChunk();
         }
         catch
         {
             if (trackBeginnings.Count == 0)
             {
                 throw new Exception("Corrupt first track chunk header");
             }
             else
             {
                 ParseStatusText = "Chunk " + (trackcount - 1) + " has corrupt length\nCalculating length...";
                 var pos    = trackBeginnings.Last();
                 var reader = new BufferByteReader(ReadProvider, 1000000, pos, MidiFileReader.Length - pos);
                 try
                 {
                     var len = MIDITrackParser.GetCorruptChunkLength(reader);
                     trackLengths[trackLengths.Count - 1] = (uint)len;
                     MidiFileReader.Position = pos + len;
                 }
                 catch { throw new Exception("Could not determine length of corrupt chunk"); }
             }
         }
         ParseNumber += 2;
         cancel.ThrowIfCancellationRequested();
     }
     parsers = new MIDITrackParser[trackcount];
 }