Namespace: MIDIEngine

MIDIEngine

MIDIEngine is a singleton object that provides an interface for interacting with the Web MIDI API. It allows initialization of MIDI access, enumeration of input/output ports, opening/closing ports, sending MIDI messages, and handling incoming MIDI messages via a callback.

Quick Navigation

Initialization

Input Methods

Output Methods

Source:

Examples

// Listen to MIDI messages
window._midi_callback = function(messageJson) {
  const message = JSON.parse(messageJson);
  console.log("MIDI received:", message.data);
};
await MIDIEngine.init();
MIDIEngine.open_input_port(0);
// Send MIDI messages
await MIDIEngine.init();
MIDIEngine.open_output_port(0);
MIDIEngine.send_message([0x90, 60, 127]);  // Note ON

Methods

(static) close_input_port() → {void}

Closes the currently open MIDI input port.

Source:
Returns:
Type
void

(static) close_output_port() → {void}

Closes the currently open MIDI output port.

Source:
Returns:
Type
void

(static) deinit() → {void}

Deinitializes MIDI, closes ports, and releases device references.

Source:
Returns:
Type
void

(static) get_input_port_count() → {number}

Returns the number of available MIDI input ports.

Source:
Returns:

The number of available MIDI input ports.

Type
number

(static) get_input_port_name(index) → {string}

Returns the name of the MIDI input port at the specified index.

Parameters:
Name Type Description
index number

Index of the input port.

Source:
Returns:

Name of the MIDI input port.

Type
string

(static) get_input_port_names() → {string}

Returns a JSON string array of all MIDI input port names.

Source:
Returns:

JSON string array of all MIDI input port names.

Type
string

(static) get_output_port_count() → {number}

Returns the number of available MIDI output ports.

Source:
Returns:

The number of available MIDI output ports.

Type
number

(static) get_output_port_name(index) → {string}

Returns the name of the MIDI output port at the specified index.

Parameters:
Name Type Description
index number

Index of the output port.

Source:
Returns:

Name of the MIDI output port.

Type
string

(static) get_output_port_names() → {string}

Returns a JSON string array of all MIDI output port names.

Source:
Returns:

JSON string array of all MIDI output port names.

Type
string

(static) init() → {Promise.<void>}

Initializes MIDI access and populates input/output port lists.

Source:
Returns:

Resolves when MIDI access is granted or logs error if denied.

Type
Promise.<void>

(static) is_input_port_open(index) → {boolean}

Checks if the MIDI input port at the specified index is connected.

Parameters:
Name Type Description
index number

Index of the input port.

Source:
Returns:

True if the MIDI input port is connected.

Type
boolean

(static) is_output_port_open(index) → {boolean}

Checks if the MIDI output port at the specified index is connected.

Parameters:
Name Type Description
index number

Index of the output port.

Source:
Returns:

True if the MIDI output port is connected.

Type
boolean

(static) open_input_port(index) → {void}

Opens the MIDI input port at the specified index and assigns a message callback.

Parameters:
Name Type Description
index number

Index of the input port to open.

Source:
Returns:
Type
void

(static) open_output_port(index) → {void}

Opens the MIDI output port at the specified index.

Parameters:
Name Type Description
index number

Index of the output port to open.

Source:
Returns:
Type
void

(static) refresh_devices() → {void}

Refreshes the list of available MIDI input and output devices.

Source:
Returns:
Type
void

(static) send_message(dataArray) → {void}

Sends a MIDI message (array of bytes) to the currently open output port.

Parameters:
Name Type Description
dataArray Array.<number>

MIDI message bytes to send.

Source:
Returns:
Type
void