python - Python:从midi文件中获取正确的开始和结束
问题描述
我正在玩 python mido 库,我正在尝试获取笔记数据,但我不明白。
我的代码:
# open midi file
midi = str(MidiFile('./midi/piano/WA_Mozart_Marche_Turque_Turkish_March_fingered.mid', clip=True))
# copy content of midi file to text file for easier work
midiTextFile = open("midi.txt", "w")
midiTextFile.write(midi)
输出的一些示例部分
Message('note_on', channel=0, note=80, velocity=96, time=1),
Message('note_on', channel=0, note=80, velocity=0, time=119),
Message('note_on', channel=0, note=64, velocity=96, time=1),
Message('note_on', channel=0, note=64, velocity=0, time=119),
Message('note_on', channel=0, note=76, velocity=96, time=1),
Message('note_on', channel=0, note=76, velocity=0, time=119),
MetaMessage('time_signature', numerator=1, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=1),
Message('note_on', channel=0, note=69, velocity=96, time=0),
Message('note_on', channel=0, note=81, velocity=96, time=0),
MetaMessage('set_tempo', tempo=500000, time=479),
Message('note_on', channel=0, note=69, velocity=0, time=0),
Message('note_on', channel=0, note=81, velocity=0, time=0),
MetaMessage('key_signature', key='A', time=1),
Message('note_on', channel=0, note=69, velocity=96, time=0),
Message('note_on', channel=0, note=69, velocity=0, time=119),
Message('note_on', channel=0, note=81, velocity=96, time=1),
Message('note_on', channel=0, note=81, velocity=0, time=119),
Message('note_on', channel=0, note=71, velocity=96, time=1),
Message('note_on', channel=0, note=71, velocity=0, time=119),
Message('note_on', channel=0, note=83, velocity=96, time=1),
Message('note_on', channel=0, note=83, velocity=0, time=119),
MetaMessage('time_signature', numerator=2, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=1),
Message('note_on', channel=0, note=73, velocity=96, time=0),
Message('note_on', channel=0, note=73, velocity=0, time=119),
Message('note_on', channel=0, note=85, velocity=96, time=1),
Message('note_on', channel=0, note=85, velocity=0, time=119),
Message('note_on', channel=0, note=69, velocity=96, time=241),
Message('note_on', channel=0, note=69, velocity=0, time=119),
Message('note_on', channel=0, note=81, velocity=96, time=1),
Message('note_on', channel=0, note=81, velocity=0, time=119),
Message('note_on', channel=0, note=71, velocity=96, time=1),
现在我不确定几件事。这部分意味着音符 64 开始于 1 毫秒并结束于 119 毫秒?如果是的话,有没有比这更好的方法来开始和结束笔记?
Message('note_on', channel=0, note=64, velocity=96, time=1),
Message('note_on', channel=0, note=64, velocity=0, time=119),
我不明白的另一件事是midi编辑器中的歌曲有3分钟,而在这个midi文本文件中没有时间值更大time=500
谢谢你的帮助。
解决方案
推荐阅读
- shell - while 循环正在为变量赋值,我稍后将使用它但不确定
- rust - 使用 Kuchiki 解析字节时出现“预期切片,发现 u8”错误
- excel - Power Query 可能的匹配项
- javascript - 如何从 JS/Node.js 获取 Unix 风格的日期?
- php - Php 和 ajax:为什么我的可靠下拉列表不起作用?
- android - 当我通过终端使用 ADB 运行深度链接时,它没有正确打开
- cdn - 有没有办法将 CDN 库从 JSFiddle 中的小提琴复制或导出到 HTML 或剪贴板
- python - 在 Ubuntu 18.04 上为 Python 3.6 安装 CNTK
- r - R中的Separate()函数不根据选择的字符分隔符进行拆分
- python - 如何将两个不同字典中的值相乘