I am trying to predict the next musical instrument note pair in python using an RNN neural network. However, I am having trouble interpreting the music21 documentation for the part I am currently on.
In the code below I, am trying to extract the musical instrument.
Why am I getting multiple instruments? Ex: Instrument.Piano.Piano.
- My current theory is that each stream part is returning a different memory address or music21 has multiple variants of these differing instruments. If the second statement holds is there a way of getting uniqueness for each instrument variant?
Why do some instruments not have a name of any sort?
- I have a few ideas of why this is, but I want to confirm with the community to make sure I am still sane.
# Attempt to parse midi file
try:
midi = converter.parse(file)
except:
# Midi file couldn't be opened
return {"song_notes": [],
"note_count": [],
"small_file_check": False,
"corrupted": True}
# Stores all found instruments
instruments_in_song = set()
# Iterate through stream parts
for stream_part in midi.parts:
stream_instrument = instrument.partitionByInstrument(stream_part)
if stream_instrument:
for instr in stream_instrument.recurse().parts:
print("Instrument: {0}".format(instr.getInstrument()))
instruments_in_song.add(instr.getInstrument())
print(instruments_in_song)
My file output: