2

I'm making a C# program that should read every note from a MIDI file and get the length and the velocity of the note, but I don't know how to do that...

I'm using the DryWetMidi library, but is there some other library?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mine_Stone
  • 169
  • 3
  • 13
  • 2
    And your question is? You should reformulate the question and also share the code mentioned. – javier_el_bene Jun 06 '17 at 17:50
  • I'm making a C# programm that should read every note from a midi file and get the length and the velocity of the note, but I don't know how to do that... _sorry I just noticed that I didn't really ask a question. Fixed it_ – Mine_Stone Jun 07 '17 at 11:16
  • Related: *[Reading notes from MIDI file using NAudio](https://stackoverflow.com/questions/23888692/)* – Peter Mortensen Aug 31 '21 at 15:32

2 Answers2

5

Starting with the DryWetMidi 1.1.0, all you need to get notes of a MIDI file is this code:

IEnumerable<Note> notes = midiFile.GetNotes();

The Note class contains all properties you need: NoteNumber, NoteName, Octave, Length, Time, Velocity, and OffVelocity.

To get Time as <hours,minutes,seconds> or <bars,beats>, you can use TimeAs extension method:

TempoMap tempoMap = midiFile.GetTempoMap();
MetricTimeSpan metricTime = note.TimeAs<MetricTimeSpan>(tempoMap);
BarBeatTicksTimeSpan musicalTime = note.TimeAs<BarBeatTicksTimeSpan>(tempoMap);

For Length, you can use LengthAs extension method:

TempoMap tempoMap = midiFile.GetTempoMap();
MetricTimeSpan metricLength = note.LengthAs<MetricTimeSpan>(tempoMap);
BarBeatTimeSpan metricLength = note.LengthAs<BarBeatTimeSpan>(tempoMap);

You can read more in the Time and length article of the library documentation.

Maxim
  • 1,995
  • 1
  • 19
  • 24
0

Please have a look at this Stack Overflow question.

Further information can be grabbed here.

DryWetMidi isn't really clear about the chunk sizes, apart from reading these notes out of the chunk, as far as I've looked into it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131