how to extract *just* note numbers from a complex MIDI file?

Brian Daurelle's icon

I'm trying to compile a sort of statistical heat map kinda thing using various standard classical repertoire, like feeding a Beethoven sonata into a histogram to see how the distribution of pitches falls. I have been avoiding learning how MIDI files work for a long time, but it seems like it's finally time. Thanks to this website
https://www.kunstderfuge.com/beethoven/sonatas.htm
I have found good MIDI 'transcriptions' of the whole Beethoven sonata cycle, and I just need to figure out how to strip everything away except the actual notes. Casting about in the dark, I have been half-successful with [seq]-->[midiflush]-->['cycle 3'], but this often gets thrown off because not every midi event is a 3-number string(?)

Basically, I need to strip everything away from this file (either while it plays or not) except for the note-on events (notes on and off would also be fine, I guess; I can divide by 2) to be able to feed only this data into a histogram. Any help understanding how the raw MIDI format works would be greatly appreciated!

-b

Brian Daurelle's icon
here is my current (very cavemanish) attempt

Roman Thilenius's icon

no need to deal with raw bytes, [midiparse] does it all.

otherwise, to split notes from the rest...

"144 60 100"

[unpack 0 0 0]
/
[split 144 159]

and then, if split outputs something, let "144 60 100" pass through.

Source Audio's icon

Maybe you need dump instead of listening in real time ?

note off could be real note off (status byte 128 -143 for 16 chans),

and not note on with velocity 0. (status byte 144 -159 for 16 chans)

Roman Thilenius's icon

[uzi] -> [detonate] to analyze up to 32 channels in nonrealtime.