API Docs

A module for enumerating, watching, and communicating with MIDI devices. IMPORTANT NOTE: This module has not had very much real-world testing yet. Please report positive or negative feedback via GitHub Issues.

Types

This module provides the following types:

Properties

hs.midi.commandTypes

{[key: string]: number}
A table mapping each MIDI command type name to a stable numeric identifier.

Methods

hs.midi.devices() -> string[]

Returns the names of all currently connected (online) physical MIDI devices.
hs.midi.devices() -> string[]
string[]
An array of device name strings
console.log(hs.midi.devices())

hs.midi.virtualSources() -> string[]

Returns the names of all available MIDI sources. This includes endpoints published by other apps (e.g. virtual instruments) as well as each individual port of a device (e.g. each IAC Driver bus, or each port of a multi-port MIDI interface), so a single port can be opened with `virtualSourceNamed()`.
hs.midi.virtualSources() -> string[]
string[]
An array of source name strings
console.log(hs.midi.virtualSources())

hs.midi.deviceCallback(fn) -> None

Sets or removes a callback fired whenever the set of connected MIDI devices or virtual sources changes. The callback receives two arguments: the current result of `devices()` and the current result of `virtualSources()`.
hs.midi.deviceCallback(fn) -> None
Name Type Description
fn JSValue The function to call on any MIDI setup change, or `null` to remove it
None
hs.midi.deviceCallback((devices, virtualSources) => {
    console.log("MIDI devices changed: " + devices.join(", "))
})

hs.midi.deviceNamed(deviceName) -> HSMIDIDevice

Creates an `hs.midi` object for a physical device. For a device with several ports, the callback receives messages from the device's first source, and `sendCommand()` sends to its first destination. `sendSysex()` and `identityRequest()` send to every destination on the device. To use a specific port, open it by name with `virtualSourceNamed()`. `new`/`alloc`/`copy`-prefixed method names, which have special meaning under Objective-C's ARC ownership conventions.
hs.midi.deviceNamed(deviceName) -> HSMIDIDevice
Name Type Description
deviceName string The name of the device, as returned by `devices()`
HSMIDIDevice
An `HSMIDIDevice` object, or `nil` if no device has that name
const kb = hs.midi.deviceNamed(hs.midi.devices()[0])

hs.midi.virtualSourceNamed(virtualSourceName) -> HSMIDIDevice

Creates an `hs.midi` object for a single MIDI source, such as one port of a multi-port device. Messages sent with `sendCommand()`, `sendSysex()` and `identityRequest()` go to the destination with the same name, if there is one. the same ARC-related reason as `deviceNamed()`.
hs.midi.virtualSourceNamed(virtualSourceName) -> HSMIDIDevice
Name Type Description
virtualSourceName string The name of the virtual source, as returned by `virtualSources()`
HSMIDIDevice
An `HSMIDIDevice` object, or `nil` if no virtual source has that name
const iac = hs.midi.virtualSourceNamed(hs.midi.virtualSources()[0])