我有一个多声道midi文件,我正在与music21一起阅读:
import music21
f = music21.midi.MidiFile()
f.open('1079-02.mid')
f.read()
stream = music21.midi.translate.midiFileToStream(f).flat
note_filter = music21.stream.filters.ClassFilter('Note')
for n in stream.recurse().addFilter(note_filter):
offset = n.offset # offset from song start in beats
note = n.pitch # letter of the note, e.g. C4, F5
midi_note = n.pitch.midi # midi number of the pitch, e.g. 60, 72
duration = n.duration # duration of the note in beats
instrument = n.activeSite.getInstrument() # instrument voice我想弄清楚这条小溪里的每一个音符都属于哪个音符。例如,当我在GarageBand中打开文件时,这些注释被组织成不同的轨道:

在mido中,每个MidiFile都有一个tracks属性,其中包含每个曲目的注释列表。
有什么方法可以在music21中获得相同的结果吗?任何帮助都将不胜感激!
发布于 2020-12-19 02:24:00
音乐曲目被解析成单独的stream.Part对象,所以如果您避免将其扁平化(在这里,我刚刚用converter.parse()生成了一个流),您就可以遍历生成的stream.Score的各个部分了。
s = converter.parse('1079-02.mid')
for part in s.parts:
for note in part.recurse().notes:
print("I WAS IN PART ", part)或查找包含的部分:
s = converter.parse('1079-02.mid')
for note in s.recurse().notes:
part = note.sites.getObjByClass('Part')
print("I WAS IN PART ", part)我怀疑你真的需要把什么都压平。祝好运!
https://stackoverflow.com/questions/62332985
复制相似问题