vishnubob / python-midi

Python MIDI library
MIT License
1.51k stars 369 forks source link

SetTempoEvent to 120 bpm doesn't seem to align with my metronome or in my music software #179

Open LiamInJapan opened 4 years ago

LiamInJapan commented 4 years ago

Hi there,

Thanks very much for providing and supporting this library!

I am trying to create an automatic drum rudiment generator here: https://github.com/LiamInJapan/RudimentGenerator

https://github.com/LiamInJapan/RudimentGenerator/blob/master/generator_2.py < the guts are in here

But I'm having some problems with the library... Perhaps it's to do with my understanding of how NoteOn and NoteOff works...

Essentially I set up a track with BPM 120 and print out a bunch of notes. If I confirm the mpqn it seems to correctly set at 500000, which suggests that everything is good. The MIDI generates and I can play it out with timidity and it sounds approximately what I expect.

The problem is if I try and compare this with a metronome, or import it into a MIDI editor set at BPM 120. What I see is that each note introduces a little lag (e.g. the resultant output is ever so slightly slower than 120 BPM). An image is attached:

Screenshot 2020-01-29 at 19 33 13

(Interestingly it lines up again after 6 bars...)

I'm not really sure what's going on, whether this is an understanding of "resolution" (the output seems to say 220... Although I've no idea how I can affect that).

Any advice much appreciated!