libmidi.types.header

MIDI header.

Classes

Header(format, ntrks, division)

Class representing a MIDI header.

class libmidi.types.header.Header(format: int, ntrks: int, division: int)

Class representing a MIDI header.

A MIDI header is a chunk that starts with the string ‘MThd’ and contains the following data: - format: Overall organization of MIDI file.

0: single multi-channel track 1: one or more simultaneous tracks (or MIDI outputs) of a sequence 2: one or more sequentially independent single-track patterns

  • ntrks: Number of tracks in the file.

  • division: The number of ticks per quarter note.

HEADER = b'MThd'
__init__(format: int, ntrks: int, division: int)

Initialize header.

classmethod from_bytes(data: bytes) Tuple[Header, bytes]
classmethod from_stream(stream: BufferedReader) Header

Read header from stream.

to_bytes() bytes

Return header as bytes.

to_stream(stream: BufferedWriter) int

Write header to stream.

Returns the number of bytes written.