我需要以下帮助:我正在设计一个新的乐谱。我想读取一个 MIDI 文件并获得一个包含每个音符/开始-停止-时间/曲目的列表。期望的结果:
[[60, 0, 0.25, 1], [62, 0.25, 0.50, 1]]# the format is [note, start-time, stop-time, miditrack]
*更新 1 - 获取 [note, note_on(time), note_off(time), channel]
以下代码创建一个字典,其中增量时间转换为线性时间(但我不确定这是否是正确的方法):
from mido import MidiFile
mid = MidiFile('testsunvox.mid')
midimsgs = []
# Put all note on/off in midinote as dictionary
for i in mid:
if i.type == 'note_on' or i.type == 'note_off':
midimsgs.append(i.dict())
# change time values from delta to relative time # don't know for sure if this is the right way...
mem1=0
for i in midimsgs:
time = i['time'] + mem1
i['time'] = time
mem1 = i['time']
# put note, starttime, stoptime, as nested list in a list. # format is [note, start, stop, channel]
for i in midimsgs:
print (i)
我现在找不到正确的问题,但目标是:
[note, note_on(time), note_off(time), channel]
对于每个音符。但问题是有两条消息(音符开/关),我想把它变成一个。如果我找到它,我会发布我的解决方案。(或者也许有人知道 mido 库的一个非常简单的技巧来做到这一点......)