我按照这里的指示解析MIDI文件。我的代码如下:
from music21 import converter,instrument # or import *
file = converter.parse('sample.mid')
components = []
for element in file.recurse():
components.append(element)
组件列表现在包含以下数据:
components
。<music21.stream.Score 0x7f50314ca390>,
<music21.stream.Part 0x7f50314caf10>,
<music21.instrument.Instrument Acoustic Guitar>,
<music21.instrument.Instrument Acoustic Guitar>,
<music21.tempo.MetronomeMark allegro moderato Quarter=130.0>,
<music21.meter.TimeSignature 4/4>,
<music21.note.Note E>,
<music21.note.Note B>,
<music21.note.Note E>,
<music21.note.Note B>,
<music21.note.Note E>,
<music21.note.Rest rest>,
.
.
.
<music21.chord.Chord B3 E3>,
<music21.chord.Chord B3 E3>,
<music21.chord.Chord B3 E3>,
<music21.chord.Chord B3 E3>,
<music21.chord.Chord B3 E3>,
<music21.chord.Chord B3 E3>,
<music21.chord.Chord D4 F#3>,
<music21.chord.Chord D4 F#3>,
<music21.chord.Chord D4 F#3>,
.
.
.
<music21.stream.Part 0x7f50309b99d0>,
<music21.instrument.Instrument Electric Guitar>,
<music21.instrument.Instrument Electric Guitar>,
<music21.meter.TimeSignature 4/4>,
<music21.note.Rest rest>,
<music21.note.Note E>,
<music21.note.Note F#>,
<music21.note.Note G>,
<music21.note.Note A>,
<music21.note.Note G>,
<music21.note.Note E>,
<music21.note.Rest rest>,
我的目标是根据每个乐器列在标签中的方式,将音符分类。比如像
<music21.instrument.Instrument Electric Guitar>
。我该怎么做?