"Playing" a midi file and calling a method every time a note plays #196
-
I am making a rhythm game in Unity and I was wondering how I could go about "playing" a midi file in sync with an mp3 file and calling a method every time a note plays with it's instrument, velocity, length, etc.? I tried using AtTime() and running it every frame but it only works if the playback time of the mp3 is exactly the same as the time of the note, which is rarely ever the case. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I don't completely understand why you have "playing" word in quotes. You can use _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 program (instrument) and then you can use it in More info about |
Beta Was this translation helpful? Give feedback.
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:As you can see you need additional handler for MIDI events to store the current prog…