python-rtmidi icon indicating copy to clipboard operation
python-rtmidi copied to clipboard

delta timestamps are broken on macOS in current release (1.5.8)

Open dklghub opened this issue 1 year ago • 3 comments

on macOS, when rtmidi receives midi packages containing multiple midi messages, the callback is called multiple times with the same delta time value. this was fixed a couple of months ago in rtmidi here: https://github.com/thestk/rtmidi/commit/eafe2f72a6492e7156c6a4f2771eb7ceb264e97b

this is a major issue for code that requires accurate timing so a new release might be motivated.

dklghub avatar Jun 11 '24 14:06 dklghub

Would you happen to have test case for this?

SpotlightKid avatar Jun 11 '24 16:06 SpotlightKid

my tests involve a hardware sequencer that play a pattern. sometimes several midi note events are transmitted within the same usb midi package. the package are split into separate messages by rtmidi and a callback are invoked several times, currently with the same delta time over and over. using a simple callback to print midi message and delta time:

def onMessage(self, message, deltatime):
	global  last_time
	t = time.time()
	mydelta = t - last_time
	print("deltatime: %.8f, real delta: %.8f"%(deltatime, mydelta), message)
	last_time = t

creates this output:

deltatime: 0.02554864, real delta: 0.02556992 [248]
deltatime: 0.02551050, real delta: 0.02551007 [248]
deltatime: 0.02386400, real delta: 0.02386785 [144, 53, 127]
deltatime: 0.02386400, real delta: 0.00003815 [146, 53, 100]   <--- deltatime should be 0
deltatime: 0.02386400, real delta: 0.00000906 [147, 43, 115]   <--- deltatime should be 0
deltatime: 0.02386400, real delta: 0.00000572 [150, 60, 92]    <--- deltatime should be 0
deltatime: 0.00161525, real delta: 0.00154710 [248]
deltatime: 0.02549727, real delta: 0.02550602 [248]
deltatime: 0.02386724, real delta: 0.02387094 [134, 60, 0]
deltatime: 0.00166769, real delta: 0.00164723 [248]

dklghub avatar Jun 12 '24 08:06 dklghub

midiout.send_message() seems to be limited to a single message which prevents local testing

actually this is a strange limitation within rtmidi as midi is just a data stream and i might want to be able to send 100 note on messages at the same time.

dklghub avatar Jun 12 '24 09:06 dklghub

The rtmidi sub-module was updated in e81ec0bea542ea67c043a0020273765d87b3f7e2 to latest upstream. This should include the fix mentioned in the issue description.

SpotlightKid avatar Apr 17 '25 17:04 SpotlightKid