2

I am using music21 to extract the midi pitch numbers (in order) for a bunch of midi files.

I have been reading through the documentation and I can load one file like this:

from music21 import *
sBach = corpus.parse('bach/bwv7.7')

Now how do I show a sequence of midi numbers? I am sure this is possible but I can't find the function in the documentation.

And is there a way to do it for multiple files at the same time?

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
dorien
  • 5,265
  • 10
  • 57
  • 116
  • 1
    The "Plotting pitches and durations continuously in music21" example at http://web.mit.edu/music21/ shows how to read note numbers. See also http://web.mit.edu/music21/doc/moduleReference/moduleStream.html#music21.stream.Stream.notes – Нет войне Mar 25 '14 at 21:30

1 Answers1

3
from music21 import *
sBach = corpus.parse('bach/bwv7.7')
for p in sBach.parts:
    print("Part: ", p.id)
    for n in p.flat.notes:
        print(n.pitch.midi)

Note that .notes includes Chord objects, which don't have a .pitch property. So for complex scores you may need to separate out the chords from notes or iterate over p.pitches. I think you'll want to go through the music21 User's Guide a bit more before continuing.