从midi文件usign音乐中提取所有信息21

时间:2018-10-17 19:37:09

标签: python python-3.x music21

我正在尝试使用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)

这是每种乐器的音符,和弦和休息量

StringInstrument 2928
None 949
Taiko 29
Timpani 14
Trumpet 616
Flute 2938
Clarinet 2417
Violoncello 32
Oboe 1076
Horn 411
Bassoon 1749

如您所见,它们是非常不同的,这是因为我没有提取所有可用信息。如何使这个结果同质化,以使和弦,音符和其他乐器的其余部分保持同步?

0 个答案:

没有答案