Search code examples
pythonmidimusic21

cannot divide file into parts using partitionByInstrument


Using music21 cannot divide file into parts using partitionByInstrument.

from music21 import *

song = converter.parse("/Nottingham/train/ashover_simple_chords_12.mid")
print(len(song.parts)) # prints 2
parts = instrument.partitionByInstrument(song)
print(parts.parts[0].id)

Shows fallowing error

print(parts.parts[0].id)
AttributeError: 'NoneType' object has no attribute 'parts'

Also when I check what song object contains song.show("text") I can see that there are parts. Raw paste here.

This issue happens on all Nottingham midi dataset. When I tried on different midi files everything was okay and partitionByInstrument worked as it should


Solution

  • The documentation says:

    partition into a Part for each unique Instrument

    But this file does not specify any instrument, so there is no partition to put the data into. In this case, partitionByInstrument() apparently returns None.