File I/O

MIDI file I/O — read and write Standard MIDI Files.

midi.read_midifile(midifile)

Read a Standard MIDI File into a Pattern.

Parameters:

midifile (str | BinaryIO) – Path to a .mid file, or an open binary file object.

Return type:

Pattern

Returns:

A Pattern containing one Track per MIDI track in the file. Ticks are relative (delta times) by default.

Raises:

TypeError – If the file header is not valid MIDI.

midi.write_midifile(midifile, pattern)

Write a Pattern to a Standard MIDI File.

Parameters:
  • midifile (str | BinaryIO) – Destination file path or an open binary file object.

  • pattern (Pattern) – The Pattern to write.

Return type:

None