简体   繁体   中英

Showing midi pitch numbers from Mid file with music21

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM