Frank
Frank

Reputation: 172

How to set ticks_per_beat under MIDO to a new MIDI file?

Reading ticks_per_beat under MIDO can be done via mid.ticks_per_beat. However, if I want to save the value of ticks_per_beat (e.g., 120 or 480) to a new MIDI file, how it can be done? (p.s. I can set "time signature" or "tempo" as follows. But, it seems to me that there is no relationship between these values and ticks_per_beat.)

track.append(MetaMessage('time_signature', numerator=4, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=0))

track.append(MetaMessage('set_tempo', tempo=100000, time=0))

Upvotes: 3

Views: 2423

Answers (1)

CL.
CL.

Reputation: 180210

The ticks per beat value is not stored with a MIDI message; it's a field in the MIDI file header.

The MidiFile constructor has a bunch of undocumented parameters:

class MidiFile(object):
    def __init__(self, filename=None, file=None,
                 type=1, ticks_per_beat=DEFAULT_TICKS_PER_BEAT,
                 charset='latin1',
                 debug=False,
                 clip=False
                 ):

Upvotes: 5

Related Questions