2

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

据我所知,在处理 .midi 之前,我需要先迭代文件中可用的所有消息。我从这个文件中拿了 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, 48, 49, 46, 49, 49, 46, 48, 57) time=0>
<meta message sequencer_specific data=(5, 15, 18, 0, 0, 127, 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, 15, 9, 64, 72) time=0>
<meta message sequencer_specific data=(5, 15, 6, 71, 101, 110, 101, 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 秒的块?在开始标记文件之前,我应该从文件中收集更多信息吗?

4

0 回答 0