【发布时间】:2021-05-09 18:38:23
【问题描述】:
我正在尝试将带有 music21 的 musicxml 文件读入列表。我保持非常简单。 sheetmusic
我已经尝试了下面的代码,但即使它毫无问题地添加了注释,它也会跳过其余的。
def xml_to_list():
fn = "Untitled.xml"
xml_data = m12.converter.parse(fn)
score = []
for part in xml_data.parts:
instrument = part.getInstrument().instrumentName
for note in part.recurse().notes:
start = note.offset
duration = note.quarterLength
pitch = note.pitch.ps
score.append([start, duration, pitch, instrument])
print(score)
我目前的输出是这样的:
[[0.0, 1.0, 72.0, 'Piano'], [1.0, 1.0, 74.0, 'Piano'], [2.0, 1.0, 76.0, 'Piano'], [0.0, 1.0, 79.0, 'Piano'], [1.0, 1.0, 79.0, 'Piano'], [2.0, 1.0, 79.0, 'Piano'], [3.0, 1.0, 77.0, 'Piano']]
我怎样才能改变它,以便我也能得到关于其余部分的信息?
【问题讨论】: