[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Determining note duration from midi input



Hi,

I'm trying to write a simple little sight-reading trainer using midi
input. So far I have found pygame.midi (from v 1.9.1) to be great for
determining note values. I can't quite figure out how to do time
values though.

I initially assumed that the difference in timestamps on the key-up
and key-down events could be used to calculate duration, but it does
not seem to work like that. Instead, the timestamps seem to be roughly
equal all the time. I've never done any midi programming before so
there is a good chance I have a fundamental misunderstanding
somewhere.

If the midi timestamps can't be used, the only way I can see to get
duration info is to have a busy-waiting loop polling a
pygame.midi.Input object and manually saving pygame.midi.time()
timestamps each time a midi event is received. This seems to have two
disadvantages: 1) 100% CPU utilisation 2) timing accuracy is
determined by the latency of event handling of my code.

Is there a (much?) better way that I am missing?

Thanks
Neilen

P.S. Busy waiting loops always make me hanker for the "good" old days
of DOS machines where these loops weren't really a problem. Who cares
how hard you smoked your 8088, not like you could have gotten any
better use out of it :)