0

我的 midifile 看起来像这样:

note_on channel=0 note=75 velocity=62 time=0
note_off channel=0 note=75 velocity=0 time=0.20833324999999997
note_on channel=0 note=76 velocity=62 time=0
note_off channel=0 note=76 velocity=0 time=0.20833324999999997
note_on channel=0 note=75 velocity=62 time=0
note_off channel=0 note=75 velocity=0 time=0.20833324999999997
note_on channel=0 note=76 velocity=62 time=0
note_off channel=0 note=76 velocity=0 time=0.20833324999999997

时间都是非常小的数字,但每拍的滴答声(tpb)是“384”。我在任何地方都读到“时间”数字以“滴答”(midi 中最小的时间单位)表示,所以我希望时间会是更大的数字。我指的是 Mido(readthedocs)。当他们说:

'时间是增量时间(以刻度为单位)'

在这种情况下,第一个音符应该在时间=192(季度=384/2),但它在 0.20833324999999997。我怎么了?

我确实理解增量时间的概念,但我不明白 tpb 与“时间”的关系。

4

1 回答 1

0

Ticks_per_beat 是每分钟的节拍数,时间以为单位显示。这就是为什么每拍的滴答声将是更大的数字。

MidiFile 有一个名为 length 的属性,它为您提供以秒为单位的总播放时间。这将通过遍历每个轨道中的每条消息并累加增量时间来计算。

通过改变每拍的节拍,消息的时间以及整个midifile的播放时间都会改变。ticks_per_beat 越小,播放时间越长,反之亦然。

这是 Python 中的一个小例子:

import mido

midifile = mido.MidiFile("yourMidoFileName.mid")

print(midifile.ticks_per_beat) # default ticks per beat of the file
print(midifile.length) # gives the total playback time in seconds

# change the ticks_per_beat
midifile.ticks_per_beat = 60 # change this number to play around
print(midifile.length) # the the total playback also changes


# play it to hear the difference:
with mido.open_output() as port:
    for msg in midifile.play():
        #print(msg)
        port.send(msg)
于 2020-09-01T19:42:05.517 回答