ExMidi.MidiMessage (ex_midi v0.1.0)

Copy Markdown View Source

Frozen (immutable) MIDI message struct with rich API.

Inspired by mido's Message class. Messages are immutable and provide copy/2, to_bytes/1, to_hex/1, to_string/1, to_map/1, and from_map/1.

Examples

iex> msg = ExMidi.MidiMessage.new(:note_on, channel: 1, pitch: 60, velocity: 100)
iex> ExMidi.MidiMessage.to_bytes(msg)
<<144, 60, 100>>
iex> ExMidi.MidiMessage.to_hex(msg)
"90 3C 64"
iex> msg2 = ExMidi.MidiMessage.copy(msg, channel: 2)
iex> ExMidi.MidiMessage.to_bytes(msg2)
<<146, 60, 100>>

Summary

Functions

Create a copy of the message with overridden attributes.

Create a message from a binary.

Create a message from a hex string.

Create a message from a map.

Check if message is a control change for the given control number.

Check if message is a system realtime message.

Create a new MIDI message. Channel is 1-based (1-16).

Encode message to a binary.

Encode message to a hex string.

Convert message to a map.

Convert message to a human-readable string.

Types

t()

@type t() :: %ExMidi.MidiMessage{
  channel: term(),
  control: term(),
  data: term(),
  frame_type: term(),
  frame_value: term(),
  note: term(),
  pitch: term(),
  pos: term(),
  program: term(),
  song: term(),
  time: term(),
  type: term(),
  value: term(),
  velocity: term()
}

Functions

copy(msg, overrides)

@spec copy(
  t(),
  keyword()
) :: t()

Create a copy of the message with overridden attributes.

from_bytes(bytes, time \\ 0)

@spec from_bytes(binary(), integer()) :: t()

Create a message from a binary.

from_hex(hex_string, time \\ 0)

@spec from_hex(String.t(), integer()) :: t()

Create a message from a hex string.

from_map(map)

@spec from_map(map()) :: t()

Create a message from a map.

is_cc(arg1, ctrl)

@spec is_cc(t(), non_neg_integer() | nil) :: boolean()

Check if message is a control change for the given control number.

is_realtime(midi_message)

@spec is_realtime(t()) :: boolean()

Check if message is a system realtime message.

new(type, opts \\ [])

@spec new(
  atom(),
  keyword()
) :: t()

Create a new MIDI message. Channel is 1-based (1-16).

to_bytes(msg)

@spec to_bytes(t()) :: binary()

Encode message to a binary.

to_hex(msg, sep \\ " ")

@spec to_hex(t(), String.t()) :: String.t()

Encode message to a hex string.

to_map(msg)

@spec to_map(t()) :: map()

Convert message to a map.

to_string(msg)

@spec to_string(t()) :: String.t()

Convert message to a human-readable string.