ExMidi.MidiFile (ex_midi v0.1.0)

Copy Markdown View Source

Standard MIDI File (SMF) reader and writer.

Supports Format 0, 1, and 2 MIDI files with full meta message support.

Data structures

  • File: {:midi_file, type, division, tracks}
  • Track: {:track, events}
  • Event: {name, delta_time, values} where values is a list or a string

Examples

iex> midi = ExMidi.MidiFile.read("song.mid")
iex> for track <- ExMidi.MidiFile.tracks(midi) do
...>   for event <- track do
...>     IO.inspect(event)
...>   end
...> end

Inspired by mido's MidiFile with play/1 support:

iex> midi = ExMidi.MidiFile.read("song.mid")
iex> for msg <- ExMidi.MidiFile.play(midi) do
...>   IO.inspect(msg)
...> end

Summary

Functions

Return the time division of a MIDI file.

Return the format type (0, 1, or 2) of a MIDI file.

Iterate through all messages in the file, merging tracks and yielding messages with absolute time. Similar to mido's MidiFile.play().

Read a MIDI file from the given path.

Return the length of the longest track in ticks.

Return the tracks of a MIDI file.

Write a MIDI file to the given path.

Functions

division(arg)

Return the time division of a MIDI file.

format(arg)

Return the format type (0, 1, or 2) of a MIDI file.

play(arg)

Iterate through all messages in the file, merging tracks and yielding messages with absolute time. Similar to mido's MidiFile.play().

Yields {:midi, payload} tuples.

read(path)

Read a MIDI file from the given path.

track_length(arg)

Return the length of the longest track in ticks.

tracks(arg)

Return the tracks of a MIDI file.

write(arg, path)

Write a MIDI file to the given path.