我试图用music21
从一个包含10个乐器的midi文件中提取音符、和弦和休止符,下面是post我可以为每个乐器得到这些:
file = 'example.mid'
midi = converter.parse(file)
parts = instrument.partitionByInstrument(midi)
notes_for_instruments = []
for i in range(len(parts.parts)):
notes_to_parse = parts.parts[i].recurse()
instr = parts.parts[i].getInstrument()
instruments.append(instr.instrumentName)
notes, quarters = [],[]
for element in notes_to_parse:
if isinstance(element, note.Note):
# if element is a note, extract pitch
notes.append(str(element.pitch))
elif(isinstance(element, chord.Chord)):
# if element is a chord, append the normal form of the
# chord (a list of integers) to the list of notes.
notes.append('.'.join(str(n) for n in element.normalOrder))
elif isinstance(element, note.Rest):
notes.append('Rest')
notes_for_instruments.append(notes)
这是每个乐器的音符、和弦和休止符的数量
^{pr2}$正如您所看到的,它们是非常不同的,这是因为我没有提取所有可用的信息。如何将这个结果进行同源化,以使和弦、音符和其他几种乐器同步?在
目前没有回答
相关问题 更多 >
编程相关推荐