PortMidi v5.1.2 PortMidi View Source

The entry module of portmidi. Through this module you can open and close devices, listen on input devices, or write to output devices.

Link to this section Summary

Functions

Terminates the GenServer held by the device argument, and closes the PortMidi stream. If the type is an input, and listen/2 was called on it, it also shuts down the listening process. Using the given device after calling this method will raise an error

Returns a map with input and output devices, in the form of PortMidi.Device structs

Starts a listening process on the given input, and returns :ok. After calling this method, the process with the given pid will receive MIDI events in its mailbox as soon as they are emitted from the device

Opens a connection to the input device with name device_name

Opens a connection to the output device with name device_name

Starts the :portmidi application. Under the hood, starts the Portmidi.Listeners GenServer, that holds all the listeners to input devices

Writes a MIDI event to the given output device. message can be a tuple {status, note, velocity}, a tuple {{status, note, velocity}, timestamp} or a list [{{status, note, velocity}, timestamp}, ...]. Returns :ok on write

Link to this section Types

Link to this type

message() View Source
message() :: {byte(), byte(), byte()}

Link to this type

timestamp() View Source
timestamp() :: byte()

Link to this section Functions

Link to this function

close(device_type, device) View Source
close(atom(), pid()) :: :ok

Terminates the GenServer held by the device argument, and closes the PortMidi stream. If the type is an input, and listen/2 was called on it, it also shuts down the listening process. Using the given device after calling this method will raise an error.

Link to this function

devices() View Source
devices() :: %{
  input: [
    %PortMidi.Device{
      input: term(),
      interf: term(),
      name: term(),
      opened: term(),
      output: term()
    },
    ...
  ],
  output: [
    %PortMidi.Device{
      input: term(),
      interf: term(),
      name: term(),
      opened: term(),
      output: term()
    },
    ...
  ]
}

Returns a map with input and output devices, in the form of PortMidi.Device structs

Link to this function

listen(input, pid) View Source
listen(pid(), pid()) :: :ok

Starts a listening process on the given input, and returns :ok. After calling this method, the process with the given pid will receive MIDI events in its mailbox as soon as they are emitted from the device.

Link to this function

open(atom, device_name) View Source
open(:input, <<_::0>>) :: {:ok, pid()} | {:error, atom()}

Opens a connection to the input device with name device_name.

Returns the pid to the corresponding GenServer. Use this pid to call listen/2.

If Portmidi can't open the device, a tuple {:error, reason} is returned. Check src/portmidi_shared.c#makePmErrorAtom for all possible errors.

Link to this function

open(atom, device_name, latency \\ 0) View Source
open(:output, <<_::0>>, non_neg_integer()) :: {:ok, pid()} | {:error, atom()}

Opens a connection to the output device with name device_name.

Returns the pid to the corresponding GenServer. Use this pid to call write/2.

If Portmidi can't open the device, a tuple {:error, reason} is returned. Check src/portmidi_shared.c#makePmErrorAtom for all possible errors.

Starts the :portmidi application. Under the hood, starts the Portmidi.Listeners GenServer, that holds all the listeners to input devices.

Link to this function

write(output, message) View Source
write(pid(), message()) :: :ok
write(pid(), {message(), timestamp()}) :: :ok
write(pid(), [{message(), timestamp()}, ...]) :: :ok

Writes a MIDI event to the given output device. message can be a tuple {status, note, velocity}, a tuple {{status, note, velocity}, timestamp} or a list [{{status, note, velocity}, timestamp}, ...]. Returns :ok on write.