title: Playing a Midi file with time offset in C#
body: <p>I'm currently trying to walk through a midi file as a song plays, with the midi file "playing" a few milliseconds ahead of the song. In greater detail, I'm visualizing the notes of the song by sliding said notes from the right to the left of the screen. I create the visualizations of the notes, just off of the right of the screen, upon a signal from the midi file, and then start translating them to the left. I would like them to pass the center of the screen at the same time that the note actually plays in the song.</p>
  
  <p>I can play the midi file just fine using this code:</p>
  
  <pre><code> if (counter &lt; _file.Events[track].Count)
          {
              double s_ms = Microsoft.Xna.Framework.Media.MediaPlayer.PlayPosition.TotalMilliseconds;
              double m_ms = _file.Events[track][counter].AbsoluteTime / _pulses_per_millisecond;
              if (s_ms + offset &gt; m_ms)
              {
                  counter++;
                  if (_file.Events[track][counter].CommandCode == NAudio.Midi.MidiCommandCode.NoteOn)
                  {
                      Console.Beep(777, 25);
                      Console.Write("Beep ");
                  }
              }
          }
  </code></pre>
  
  <p>The offset effectively makes the midi file play a burst of notes and then return to the track position it would be at if the offset wasn't used at all.</p>
  
  <p>I'm stumped and would really appreciate any help. I'm using XNA 3.1 and NAudio. The midi plays in time with the song just fine. Of course, I need the play speed of the midi to remain the same as the song.</p>