0

I need to read MIDI files in order to do further processing with the notes.

I tried to do so with NAudio like this

MidiFile midi = new MidiFile("Test.mid");
foreach (MidiEvent note in midi.Events[1])
{
    Console.Write(note.AbsoluteTime.ToString().PadRight(10));
    Console.WriteLine(note.DeltaTime);
}

I was hoping to get the start of the note and the duration, but I get odd values, starting at 34654 (why?):

enter image description here

Question:

I need every MIDI note and

  • The start time
  • The length
  • The channel index

How can I get the correct values using NAudio? If you have suggestions for a different library, please feel free to suggest it.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
  • look at the Audio file explorer demo app that comes with the NAudio source code. This does exactly what you are after for MIDI files – Mark Heath Jun 02 '13 at 22:07
  • ^ http://naudio.codeplex.com/SourceControl/latest#AudioFileInspector/FileInspectors/MidiFileInspector.cs for anyone having trouble finding it. Also http://opensebj.blogspot.co.uk/2009/09/naudio-tutorial-7-basics-of-midi-files.html is a good resource. – P i Oct 28 '13 at 00:36

1 Answers1

2

The midi file spec works with delta-times for each event. So a delta time of 0 means at the same time as the previous event. How much actual time the delta-time represents depends on information in the midi file header.

Here is some info on the inner workings of midi files. http://home.roadrunner.com/~jgglatt/tech/midifile.htm

Hope it helps.

obiwanjacobi
  • 2,413
  • 17
  • 27