Skip to content

winmidi: convert input timestamps from MidiClock ticks to nanoseconds - #263

Merged
jcelerier merged 1 commit into
celtera:masterfrom
yuki-is-taka:fix/winmidi-timestamp-ns
Sep 28, 2026
Merged

jcelerier merged 1 commit into
celtera:masterfrom
yuki-is-taka:fix/winmidi-timestamp-ns

Conversation

@yuki-is-taka

Copy link
Copy Markdown
Contributor

The winmidi input backend passes the Windows MIDI Services timestamp through as-is:

auto to_ns = [t = ump.Timestamp()] { return t; };

That value is in MidiClock ticks (100 ns on current Windows, see MidiClock::TimestampFrequency()), not nanoseconds, so on winmidi the Absolute/Relative timestamps come out 100x too small compared to the other backends.

This converts both callback paths to ns using TimestampFrequency(), read once in the constructor. The conversion is split into quotient/remainder so it can't overflow.

Tested on Windows 11 with a USB MIDI controller over Windows MIDI Services: with the change, timestamps match QueryPerformanceCounter converted to ns (within ~30 µs).

Windows MIDI Services timestamps are MidiClock ticks (100 ns on current
Windows), but libremidi timestamps are in ns, so they came out 100x too
small. Convert them using MidiClock::TimestampFrequency().
yuki-is-taka added a commit to yuki-is-taka/Libremidi4UE that referenced this pull request Sep 28, 2026
…#263

The tick-to-ns fix went upstream on its own rather than in the fork batch.
Once it is merged, bump the submodule and drop the ADR-0002 wrapper
correction in the same change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jcelerier

Copy link
Copy Markdown
Member

thanks for the patch !

@jcelerier
jcelerier merged commit 5c839a5 into celtera:master Sep 28, 2026
@yuki-is-taka
yuki-is-taka deleted the fix/winmidi-timestamp-ns branch October 3, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants