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

How to decide the duration of a note?

Open xcszbdnl opened this issue 7 years ago • 0 comments

I'm dealing with a lot of MIDI files. I want to show the note in each bar of one midi file. However, MIDI files are quite messy. For example, when there are some events listed below:

resolution == 384, denominator=4, numerator=4
midi.KeySignatureEvent(tick=0, data=[255, 0])
midi.NoteOnEvent(tick=960, channel=12, data=[72, 127])
midi.NoteOffEvent(tick=128, channel=12, data=[72, 127])
midi.NoteOnEvent(tick=64, channel=12, data=[77, 127])
midi.NoteOffEvent(tick=128, channel=12, data=[77, 127])
midi.NoteOnEvent(tick=64, channel=12, data=[79, 127])
midi.NoteOffEvent(tick=128, channel=12, data=[79, 127])
midi.NoteOnEvent(tick=64, channel=12, data=[81, 127])
...

The notes in the first bar should be 1/2 pause note + 1/8 pause note + 1/8 note (pitch=72) + 1/8 note (pitch=77) + 1/8 note (pitch=79)...

However, I also meet some events like this:

resolution == 384, denominator=4, numerator=4
midi.KeySignatureEvent(tick=0, data=[255, 0])
midi.NoteOnEvent(tick=768, channel=12, data=[72, 127])
midi.NoteOffEvent(tick=192, channel=12, data=[72, 127])
midi.NoteOnEvent(tick=192, channel=12, data=[77, 127])
midi.NoteOffEvent(tick=192, channel=12, data=[77, 127])
midi.NoteOnEvent(tick=0, channel=12, data=[79, 127])
midi.NoteOffEvent(tick=192, channel=12, data=[79, 127])
midi.NoteOnEvent(tick=0, channel=12, data=[81, 127])
...

The notes in the first bar should be 1/2 pause note + 1/8 note (pitch=72) + 1/8 pause note + 1/8 note (pitch=77) + 1/8 note (pitch=79)... Therefore, how to determine the note during the gap time before the next note on event is a note (the duration time should be 128 + 64 in the first example) or is a pause note (in the second example)?

xcszbdnl avatar Jul 16 '17 10:07 xcszbdnl