How to get a program/instrument title from a specific chunk of a MIDI file in DryWetMidi library?

Viewed 291

I'm using DryWetMidi library in C# and trying to acquire a program/instrument title from a loaded chunk, but I fail to find such field that gives me the title. So far I just have:

var midiFile = MidiFile.Read("test.mid");
var tempoMap = midiFile.GetTempoMap();
var trackList = midiFile.GetTrackChunks().ToList();
var notes = trackList[0].GetNotes().ToList();

I expected to find something like:

var programNumber = trackList[0].ProgramNumber;

or

var programNumber = midiFile.GetProgramNumbers();

But I can't find such operations. Please let me know if there's any way to do this in DryWetMidi or in any external library.

1 Answers

TrackChunk has Events property which gives access to all MIDI events within a track chunk. Just find ProgramChangeEvent ones and collect program numbers:

var programNumbers = trackList[0]
    .Events
    .OfType<ProgramChangeEvent>()
    .Select(e => e.ProgramNumber)
    .ToArray();

DryWetMIDI has complete documentation. Please look into it to learn more: https://melanchall.github.io/drywetmidi.

Related