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?
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?
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.
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.