2

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.

  1. 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?
  2. 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:

My file output

  • The music21 instruments collection is closer to the instrument collection in MusicXML than it is in MIDI. There are MIDI patches that do not refer to instruments in the commonly known sense ("helicopter", "goblins"), and those tend not to get translated. And there are instruments (BassClarinet) that are more specific than MIDI covers. – Michael Scott Asato Cuthbert Dec 26 '18 at 20:58
  • The music21 repr for an instrument has the instrument class and then the name of the instrument in the score. instrument.Piano Piano might seem redundant, but instrument.Clarinet Klarinette 2 in A, explains the difference. – Michael Scott Asato Cuthbert Dec 26 '18 at 20:59
  • Thanks, guys that really helped! Sorry about the question being a little silly just wanted to ask to get more context! – Eric Cacciavillani Dec 27 '18 at 01:19
  • But I guess that brings up a good point though. If I want to use those objects that don't have a name how do I call them in instrument.fromString or should I be generating my instruments differently? – Eric Cacciavillani Dec 27 '18 at 04:29

0 Answers0