Boddlnagg / midir

Cross-platform realtime MIDI processing in Rust.
MIT License
610 stars 76 forks source link

Correct timestamps when messages are ignored #23

Closed Boddlnagg closed 6 years ago

Boddlnagg commented 7 years ago

Currently (at least on some platforms) relative timestamps are computed between messages, even when some messages are ignored and not forwarded to the user. For example:

This could be fixed by either updating the "previous" timestamp only if the message is actually delivered to the user (and not ignored), or by switching to absolute timestamps altogether.

Currently I tend towards absolute timestamps (counting from some unspecified time in the past), because that's what the platforms provide, and it's also what WebMIDI uses.

Is there any strong argument for keeping relative timestamps? It seems to me that going from absolute to relative is something the user can do if it's needed, but going from relative to absolute (even if the bug described here is fixed) always involves some inaccuracies due to rounding, etc.

Boddlnagg commented 7 years ago

We could also return absolute timestamps as std::time::Duration, if the backends' timestamps can be converted easily.

Boddlnagg commented 7 years ago

Actually I think I'd prefer absolute timestamps. You can always go from absolute to relative, but the other way around inevitably introduces rounding errors ...

Boddlnagg commented 6 years ago

For reference: I checked what kind of timestamps the platforms actually give us, this is:

Furthermore, PortMidi uses timestamps in milliseconds as u32 (see https://github.com/xlab/portmidi/blob/a2cf51204affa3600b0e6e15c7174cd5cbde463b/pm/portmidi.h#L265-L269)

From these considerations, I think that providing timestamps in microseconds as u64 (as an absolute time span from an undefined starting point) is reasonable as an abstraction over these different formats. Comments?