Skip to content

"Playing" a midi file and calling a method every time a note plays #196

Answered by melanchall
ZacharyLaurin asked this question in Q&A
Discussion options

You must be logged in to vote

I don't completely understand why you have "playing" word in quotes. You can use Playback API of the library and set event handler on notes:

_playback = midiFile.GetPlayback();
_playback.EventPlayed += OnEventPlayed;
_playback.NotesPlaybackStarted += OnNotesPlaybackStarted;

// ...

private static void OnEventPlayed(object sender, MidiEventPlayedEventArgs e)
{
    if (e.Event.EventType == MidiEventType.ProgramChange)
        _program = ((ProgramChangeEvent)e.Event).ProgramNumber;
}

private static void OnNotesPlaybackStarted(object sender, NotesEventArgs e)
{
    // do smth with notes, use _program here
}

As you can see you need additional handler for MIDI events to store the current prog…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@melanchall
Comment options

@ZacharyLaurin
Comment options

Answer selected by ZacharyLaurin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Just question about the library
2 participants