I have looked into this now, it's kind of a two step thing and I think this is how to do it:
Musical offset of a note: Check out how many midi clock ticks a quarter note has via parser->header.time_division, and each midi event has the vtime which specifies the offset to the last in midi clock ticks. With this, you can calculate each note's exact offset easily in relation to musical quarter notes as e.g. a fractional double number.
Find out how long a quarter note length is in seconds: You have to track tempo change events yourself and compute how long each quarter note is yourself from that at any point in the song, and multiply that with your musical offset. (I know this sounds strongly simplified, and can be a bit involved with multiple tempo changes, but I think it's the simplest approach.)
Maybe there is a way to add all of this into the parser itself some day, due to how simple it is it basically just returns all the above pieces as-is from the midi file and leaves the rest to you. Midi is just very musically oriented, so it usually doesn't have direct seconds timing offsets but its all via the abstract midi clock/quarter notes.
I have looked into this now, it's kind of a two step thing and I think this is how to do it:
Musical offset of a note: Check out how many midi clock ticks a quarter note has via
parser->header.time_division
, and each midi event has thevtime
which specifies the offset to the last in midi clock ticks. With this, you can calculate each note's exact offset easily in relation to musical quarter notes as e.g. a fractionaldouble
number.Find out how long a quarter note length is in seconds: You have to track tempo change events yourself and compute how long each quarter note is yourself from that at any point in the song, and multiply that with your musical offset. (I know this sounds strongly simplified, and can be a bit involved with multiple tempo changes, but I think it's the simplest approach.)
Maybe there is a way to add all of this into the parser itself some day, due to how simple it is it basically just returns all the above pieces as-is from the midi file and leaves the rest to you. Midi is just very musically oriented, so it usually doesn't have direct seconds timing offsets but its all via the abstract midi clock/quarter notes.