微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python:如何使用 MIDO 库标记 .midi 文件

如何解决Python:如何使用 MIDO 库标记 .midi 文件

我有这些 .midi files 并且我想用每 0.032 秒的音高(以 MIDI 数字表示)标记它们。可以找到我想要的标签示例here在这个任务中,我使用 Python mido 库,文档可以在 here 中找到。

据我所知,在处理 .midi 之前,我需要先迭代文件中的所有可用消息。我从这个 file 中取了 1 个例子,这是代码 + 结果。

# Code to iterate .midi message
import mido
from mido import MidiFile
from mido import Message
mid_14 = MidiFile('00014 Twinkle,Twinkle,Little Star.mid',clip=True)
for i,track in enumerate(mid_14.tracks):
    print('Track {}: {}'.format(i,track.name))
    print("-"*100)
    for msg in track: #print message in tracks
        print(msg)
    print("="*100)
# Result
Track 0: untitled
----------------------------------------------------------------------------------------------------
<Meta message track_name name='untitled' time=0>
<Meta message time_signature numerator=4 denominator=4 clocks_per_click=24 notated_32nd_notes_per_beat=8 time=0>
<Meta message key_signature key='C' time=0>
<Meta message set_tempo tempo=500000 time=0>
<Meta message sequencer_specific data=(5,15,28,50,48,49,46,57) time=0>
<Meta message sequencer_specific data=(5,18,127,0) time=0>
<Meta message end_of_track time=0>
====================================================================================================
Track 1: MAJOR_TRACK
----------------------------------------------------------------------------------------------------
<Meta message track_name name='MAJOR_TRACK' time=0>
program_change channel=0 program=0 time=0
<Meta message sequencer_specific data=(5,9,64,72) time=0>
<Meta message sequencer_specific data=(5,6,71,101,110,114,97,108,32,77,73,68,73) time=0>
note_on channel=0 note=60 veLocity=110 time=0
note_on channel=0 note=60 veLocity=0 time=480
note_on channel=0 note=60 veLocity=110 time=0
note_on channel=0 note=60 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=69 veLocity=110 time=0
note_on channel=0 note=69 veLocity=0 time=480
note_on channel=0 note=69 veLocity=110 time=0
note_on channel=0 note=69 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=960
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=62 veLocity=110 time=0
note_on channel=0 note=62 veLocity=0 time=480
note_on channel=0 note=62 veLocity=110 time=0
note_on channel=0 note=62 veLocity=0 time=480
note_on channel=0 note=60 veLocity=110 time=0
note_on channel=0 note=60 veLocity=0 time=960
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=62 veLocity=110 time=0
note_on channel=0 note=62 veLocity=0 time=960
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=62 veLocity=110 time=0
note_on channel=0 note=62 veLocity=0 time=960
note_on channel=0 note=60 veLocity=110 time=0
note_on channel=0 note=60 veLocity=0 time=480
note_on channel=0 note=60 veLocity=110 time=0
note_on channel=0 note=60 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=480
note_on channel=0 note=69 veLocity=110 time=0
note_on channel=0 note=69 veLocity=0 time=480
note_on channel=0 note=69 veLocity=110 time=0
note_on channel=0 note=69 veLocity=0 time=480
note_on channel=0 note=67 veLocity=110 time=0
note_on channel=0 note=67 veLocity=0 time=960
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=65 veLocity=110 time=0
note_on channel=0 note=65 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=64 veLocity=110 time=0
note_on channel=0 note=64 veLocity=0 time=480
note_on channel=0 note=62 veLocity=110 time=0
note_on channel=0 note=62 veLocity=0 time=480
note_on channel=0 note=62 veLocity=110 time=0
note_on channel=0 note=62 veLocity=0 time=480
note_on channel=0 note=60 veLocity=110 time=0
note_on channel=0 note=60 veLocity=0 time=960
<Meta message end_of_track time=0>
====================================================================================================

我的问题是:如何将它们分成 0.032 秒的块,并提供可用的信息(速度、速度)?在开始标记文件之前,我是否应该从文件中收集更多信息?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。