Why is ticks per beat a big number and time very small?

441 Views Asked by At

My midifile looks like this:

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

The time are all very small numbers but the ticks per beat(tpb) is '384'. Everywhere I read that the 'time' numbers are expressed in 'ticks'(the smallest time-unit in midi) so I would expect the time to be much larger numbers. I am refering to Mido(readthedocs). What do they mean when they say:

'time is in delta time(in ticks)'

In this case the first note off should be at time=192(quarter=384/2) but it is at 0.20833324999999997. What do I get wrong?

I do understand the concept of delta time but I dont get how the tpb relates to 'time'.

1

There are 1 best solutions below

0
On

Ticks_per_beat is the number of beats per minute, and the time is displayed in seconds. That's why the ticks per beats are going to be bigger numbers.

There is a property of the MidiFile called length, which gives you the the total playback time in seconds. This will be computed by going through every message in every track and adding up delta times.

By changing the ticks per beat, the time of the messages and therefore the playback time of the whole midifile changes. The smaller the ticks_per_beat the longer the playback time and vica versa.

Here is a small example in 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)