HSMIDIDevice
TypeA MIDI device or virtual source, created via hs.midi.deviceNamed() or
hs.midi.virtualSourceNamed().
Properties
isVirtual
boolean
Whether this is a virtual source (created via `hs.midi.virtualSourceNamed()`)
rather than a physical device.
Methods
setCallback(fn) -> HSMIDIDevice
Sets or removes the callback fired when a MIDI message is received.
The callback receives five arguments: this device object, the device's name,
the command type as a string (e.g. `"noteOn"`, `"controlChange"`,
`"systemExclusive"` — see `hs.midi.commandTypes` for the full set), a
human-readable description, and a metadata table of command-specific fields.
when released, but some send `noteOn` with `velocity` 0 instead of `noteOff`.
Declaration
setCallback(fn) -> HSMIDIDevice
Parameters
| Name | Type | Description |
|---|---|---|
| fn | JSValue | The function to call on each received message, or `null` to remove it |
Returns
HSMIDIDevice
This device object, for chaining
Example
kb.setCallback((device, deviceName, commandType, description, metadata) => {
if (commandType === "noteOn") console.log("Note " + metadata.note + " velocity " + metadata.velocity)
})
sendCommand(commandType, metadata) -> boolean
Sends a MIDI command to the device.
Declaration
sendCommand(commandType, metadata) -> boolean
Parameters
| Name | Type | Description |
|---|---|---|
| commandType | string | The command type string |
| metadata | {[key: string]: any} | A table of command-specific fields |
Returns
boolean
`true` if the command was sent, `false` if the device has no
Example
kb.sendCommand("noteOn", { note: 60, velocity: 100, channel: 0 })
sendSysex(command) -> None
Sends a System Exclusive command to the device.
Declaration
sendSysex(command) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| command | string | A hex string (whitespace ignored), e.g. `"F0 7E 7F 06 01 F7"` |
Returns
None
Example
kb.sendSysex("F0 7E 7F 06 01 F7")
identityRequest() -> None
Sends a MIDI Identity Request. The device's reply, if any, arrives via the
callback set with `setCallback()` as a `systemExclusive` message.
Declaration
identityRequest() -> None
Returns
None
Example
kb.identityRequest()
destroy() -> None
Stops receiving from and releases all resources held by this device object.
Called automatically when Hammerspoon reloads.
Declaration
destroy() -> None
Returns
None
Example
kb.destroy()