as MIDI is a streaming protocol, how would that even be possible?
When I hit a note on a keyboard, a “note on” message must be sent.
But how would it be possible to know at that moment already when I am going to release that note (which will happen sometime in the future)?
Only when you release the key on the keyboard, a “note off” message can be sent, so there is no way to know the duration of a note at the moment you start it.
For playing back from pre-recorded musical/MIDI sequences, that might be possible, but for MIDI in general as a streaming protocol, it’s not.
If you want to know the duration of a particular note after it stopped, you’ll need to keep track of when the start for that note happened in the past and calculate the time difference (either in musical time (ticks) or wall-clock time (seconds), depending on what you need).