Constructor
new MIDIDeviceManager(options)
Create a new MIDIDeviceManager instance
Parameters:
| Name |
Type |
Description |
options |
Object
|
Configuration options
Properties
| Name |
Type |
Attributes |
Default |
Description |
midiController |
MIDIController
|
<optional>
|
|
MIDIController instance |
onStatusUpdate |
function
|
<optional>
|
|
Callback for status updates (message: string, state: string) |
onConnectionUpdate |
function
|
<optional>
|
|
Callback when connection status changes (outputDevice: Object, inputDevice: Object, midi: MIDIController) |
channel |
number
|
<optional>
|
1
|
Default MIDI channel |
|
- Source:
Example
// Setup with callback
const manager = new MIDIDeviceManager({
midiController: midi,
onStatusUpdate: (msg, state) => updateStatus(msg, state),
onConnectionUpdate: (output, input, midi) => {
console.log("Output:", output?.name);
console.log("Input:", input?.name);
}
});
// Setup all selectors with callbacks
const midi = await manager.setupSelectors(
{
output: document.getElementById("output-select"),
input: document.getElementById("input-select"),
channel: document.getElementById("channel-select")
},
{
onConnect: ({ midi, device, type }) => {
console.log(`${type} connected: ${device.name}`);
},
onDisconnect: ({ midi, type }) => {
console.log(`${type} disconnected`);
}
}
);
// Returns MIDI controller for immediate use
midi.channel.sendCC(1, 100);
Classes
- MIDIDeviceManager
Methods
(async) setupSelectors(selectors, optionsopt) → {Promise.<MIDIController>}
Set up all MIDI device selectors in one call. Handles population, connection
handling, channel selection, and automatic refresh on device changes.
Parameters:
| Name |
Type |
Attributes |
Description |
selectors |
Object
|
|
Selectors configuration
Properties
| Name |
Type |
Attributes |
Description |
output |
HTMLSelectElement
|
string
|
<optional>
|
Output device dropdown element or CSS selector |
input |
HTMLSelectElement
|
string
|
<optional>
|
Input device dropdown element or CSS selector |
channel |
HTMLSelectElement
|
string
|
<optional>
|
MIDI channel dropdown element or CSS selector |
|
options |
Object
|
<optional>
|
Configuration options
Properties
| Name |
Type |
Attributes |
Description |
onConnect |
function
|
<optional>
|
Called when device connects ({ midi, device, type }) |
onDisconnect |
function
|
<optional>
|
Called when device disconnects ({ midi, type }) |
onDeviceListChange |
function
|
<optional>
|
Called when device list changes (for custom UI updates) |
|
- Source:
Returns:
The MIDI controller instance for chaining
-
Type
-
Promise.<MIDIController>
updateConnectionStatus()
Update connection status
- Source:
updateStatus(message, stateopt) → {void}
Update status message and trigger status callback
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
message |
string
|
|
|
Status message to display |
state |
string
|
<optional>
|
""
|
Status state (e.g., "connected", "error", "warning") |
- Source:
Returns:
-
Type
-
void
Examples
manager.updateStatus("Connected to MIDI keyboard", "connected");
manager.updateStatus("Connection failed", "error");