[英]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.我正在使用 music21 来提取一堆 MIDI 文件的 MIDI 音高数字(按顺序)。
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?现在如何显示一系列midi数字? 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.请注意,
.notes
包括Chord
对象,它没有.pitch
属性。 So for complex scores you may need to separate out the chords from notes or iterate over p.pitches
.因此,对于复杂的乐谱,您可能需要从音符中分离出和弦或迭代
p.pitches
。 I think you'll want to go through the music21 User's Guide a bit more before continuing.我认为在继续之前,您需要多阅读一下music21 用户指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.