Skip to content Skip to sidebar Skip to footer

Music21 Manipulating Specific Instrument

I am using Music21 in Python to read from a MIDI file and I want to only deal with the tracks that use a certain instrument. For example, if, in my MIDI file I have two tracks that

Solution 1:

Here's what I was trying to do:

def printInstrument(self, strm, inst):
    s2 = instrument.partitionByInstrument(strm)
    if s2 is not None:
    #print all the notes the instrument plays
        for i in s2.recurse().parts:
            if i.partName == inst:
                iNotes = i.notesAndRests.stream()
                for j in iNotes.elements:
                    if type(j) == chord.Chord:
                        #handle chords
                    elif j.name == "rest":
                        #handle rests
                    else:
                        #handle notes

Post a Comment for "Music21 Manipulating Specific Instrument"