我正在尝试使用 10 种乐器从 MIDI 文件中提取音符、和弦和休止符music21
,在这篇文章之后,我可以为每种乐器获取这些:
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)
这是每个乐器的音符、和弦和休止符的数量
StringInstrument 2928
None 949
Taiko 29
Timpani 14
Trumpet 616
Flute 2938
Clarinet 2417
Violoncello 32
Oboe 1076
Horn 411
Bassoon 1749
如您所见,它们非常不同,这是因为我没有提取所有可用信息。如何认证这个结果以同步和弦、音符和其他几种乐器?