I'm trying to print out the note attribute in each message output by mido in a .mid file. Right now, my code looks like this:
for msg in mid.tracks[1]:
if not msg.is_meta:
print(msg.note)
But, upon running the code, I get the error:
AttributeError: 'Message' object has no attribute 'note'
I'm confused, as the documentation shows the same "msg.note" syntax working just fine. Any help would be much appreciated.
There are many different types of MIDI messages, and not all of them have a note number.
If you want to print out all notes, you have to check the message type first. If you want to print out all messages, you cannot rely on the
note
field being there.