title: Using BinaryReader to read a midi file. (.net)
body: <p>How would I use a BinaryReader to read a midi file (specifications for the format are <a href="http://faydoc.tripod.com/formats/mid.htm" rel="nofollow">here</a>)</p>
  
  <p>I'm using vb.net, but I'm willing to see other code (mostly just C#, I can convert it).  I'm working on a large project and this comes as a bit of a speedbump.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>Private Function convertCharArrayToString(ByVal chars() As Char) As String
      Dim tReturn As String = ""
      For Each v As Char In chars
          tReturn &amp;= v
      Next
      Return tReturn
  End Function
  
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      midiStatus = "Reading..."
      Dim midiStream As New StreamReader(midiFile)
      Dim nBR As New BinaryReader(midiStream.BaseStream)
      midiStatus = "Validating Midi File..."
      Dim HeaderA As String = convertCharArrayToString(nBR.ReadChars(4))
      If Not HeaderA = "MThd" Then Return
      Dim HeaderB() As Byte = nBR.ReadBytes(4)
      'Get Track Type
      midiStatus = "Reading Header Data..."
      Dim TrackType1 As Integer = nBR.ReadInt16()
      Dim TrackType2 As Integer = nBR.ReadInt16()
      MsgBox(TrackType1 &amp; TrackType2)
  
  End Sub
  </code></pre>
  
  <p>Everything works find up to when I start reading the actual Header Data.  I'm absoultly lost as to how I'm to continue.  Any help or code examples would be nice!</p>