python - 使用 mido 库的绝对 MIDI 刻度值
问题描述
我正在使用Mido 库在 python 中读取一个简单的 MIDI 文件。
我的 MIDI 文件如下:https://www.dropbox.com/s/t80kg9l2k525g0h/file.mid?dl=0
这只是一个我用基本音符创建的虚拟 MIDI 文件。
我用 Mido 库打开它并打印它的内容:
from mido import MidiFile
mid = MidiFile('file.mid')
for i, track in enumerate(mid.tracks):
print('Track {}: {}'.format(i, track.name))
for msg in track:
print(msg)
这就是我得到的:
Track 0:
<meta message track_name name='\x00' time=0>
<meta message time_signature numerator=4 denominator=4 clocks_per_click=36 notated_32nd_notes_per_beat=8 time=0>
<meta message time_signature numerator=4 denominator=4 clocks_per_click=36 notated_32nd_notes_per_beat=8 time=0>
note_on channel=0 note=60 velocity=100 time=0
note_on channel=0 note=64 velocity=100 time=0
note_off channel=0 note=60 velocity=64 time=384
note_on channel=0 note=62 velocity=100 time=0
note_on channel=0 note=67 velocity=100 time=0
note_off channel=0 note=62 velocity=64 time=384
note_off channel=0 note=64 velocity=64 time=0
note_on channel=0 note=64 velocity=100 time=0
note_off channel=0 note=67 velocity=64 time=0
note_off channel=0 note=64 velocity=64 time=384
note_on channel=0 note=67 velocity=100 time=0
note_on channel=0 note=66 velocity=100 time=384
note_off channel=0 note=67 velocity=64 time=0
note_off channel=0 note=66 velocity=64 time=384
note_on channel=0 note=67 velocity=100 time=0
note_off channel=0 note=67 velocity=64 time=384
note_on channel=0 note=69 velocity=100 time=0
note_off channel=0 note=69 velocity=64 time=384
note_on channel=0 note=71 velocity=100 time=0
note_on channel=0 note=60 velocity=100 time=384
note_off channel=0 note=71 velocity=64 time=0
note_off channel=0 note=60 velocity=64 time=384
note_on channel=0 note=62 velocity=100 time=0
note_off channel=0 note=62 velocity=64 time=384
note_on channel=0 note=64 velocity=100 time=0
note_off channel=0 note=64 velocity=64 time=375
note_on channel=0 note=67 velocity=100 time=9
note_on channel=0 note=66 velocity=100 time=384
note_off channel=0 note=67 velocity=64 time=0
note_off channel=0 note=66 velocity=64 time=384
note_on channel=0 note=67 velocity=100 time=0
note_off channel=0 note=67 velocity=64 time=384
note_on channel=0 note=69 velocity=100 time=0
note_off channel=0 note=69 velocity=64 time=384
note_on channel=0 note=71 velocity=100 time=0
note_off channel=0 note=71 velocity=64 time=384
<meta message end_of_track time=0>
做一些实验我有点明白时间是用相对于前一个事件(note_on - note_off)的刻度表示的。
如何使用绝对时间参考(以滴答声)重新排序笔记?
我想有一个我的笔记的绝对时间线,但我不知道如何从我拥有的数据中“提取”它。
有没有其他库已经实现了这个功能?我看到了这个库:Python-midi,但不幸的是它只适用于 Python 2。
解决方案
增量时间与相应的音符开事件无关,而是与同一轨道中的前一个事件相关。
只需按顺序将所有增量时间相加即可。
推荐阅读
- asp.net-mvc - mvc剑道网格调整大小问题
- java - Selenium --> 如何从 li 类中选择按钮 [Java]
- swift - 使用 Alamofire 和 ObjectMapper 进行通用网络调用
- floating-point - 多个浮点数的锈蚀最大值?
- mysql - switch 语句中的奇怪结果
- typescript - Typescript 类属性初始化顺序
- search - 无法使用带有通配符的 solr 查询搜索电子邮件 ID 字段
- python-3.x - 如何使用 python 中的日志记录模块制作两个日志文件?
- xml - 无法使用 XSL 在 XML 中打印特殊(非英语)字符(拉丁语、德语等)
- firebase - 如何从 Firebase 存储控制台下载多个文件?