本文介绍了Music21:从 MIDI 文件中获取每个乐器的所有音符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在按照指示解析 MIDI 文件 此处.我的代码如下所示:
I am parsing a MIDI file as instructed here. My code looks like this:
from music21 import converter,instrument # or import *
file = converter.parse('sample.mid')
components = []
for element in file.recurse():
components.append(element)
components
列表现在包含如下数据:
The components
list now contains data as follows:
<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>,
我的目标是根据每个乐器分离音符,这些乐器在等标签中列出.我如何实现这一目标?
My aim is to segregate notes according to each instrument which is listed in a tag like <music21.instrument.Instrument Electric Guitar>
. How do I achieve this?
推荐答案
我想你会想要 instrument.partitionByInstrument()
函数,它会根据乐器将你的流分成不同的部分.
I think you'll want the instrument.partitionByInstrument()
function, which will separate your stream into different parts according to the instrument.
这篇关于Music21:从 MIDI 文件中获取每个乐器的所有音符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!