Time durations of notes in MIDI file?

Hi, I’ve imported a MIDI file and want to find the total time duration every note was played. For example, I want to know how long A4 was played throughout the entire file.

I’ve found the SoundNote function which lists the note, start time, and endtime, but do not know how to proceed.

I’ve shown each step explicitly, but you could obviously bundle all this up into a function that would perform the computation for whatever note value you provided.

Thank you.