import { EventEmitter } from './EventEmitter.js'; export namespace CONNECTION_EVENTS { let DEVICE_CHANGE: string; let IN_DEV_CONNECTED: string; let IN_DEV_DISCONNECTED: string; let OUT_DEV_CONNECTED: string; let OUT_DEV_DISCONNECTED: string; } /** * Low-level Web MIDI API connection handler. Manages: * - MIDI device access/request * - Device enumeration (inputs/outputs) * - Device connection/disconnection * - Hotplug detection and events * - Raw MIDI message sending/receiving * - SysEx message handling * - Connection state tracking * * NOTE: Typically used internally by MIDIController. Most applications * should use MIDIController instead for higher-level APIs. * @extends EventEmitter * * @example * // Basic usage * const connection = new MIDIConnection({ sysex: true }); * await connection.requestAccess(); * await connection.connect("My MIDI Device"); * connection.send([0x90, 60, 100]); // Note on * * @example * // Listening for device changes * connection.on(CONNECTION_EVENTS.DEVICE_CHANGE, ({ device, state }) => { * console.log(`${device.name} is now ${state}`); * }); */ export class MIDIConnection extends EventEmitter { /** * @param {Object} options * @param {boolean} [options.sysex=false] - Request SysEx access */ constructor(options?: { sysex?: boolean; }); options: { sysex: boolean; }; midiAccess: MIDIAccess; output: any; input: any; /** * Request MIDI access from the browser. Sets up hotplug detection and * emits events when devices connect/disconnect. * * @returns {Promise} * @throws {MIDIAccessError} If MIDI is not supported or access is denied * * @emits CONNECTION_EVENTS.DEVICE_CHANGE - When any MIDI device state changes * @emits CONNECTION_EVENTS.IN_DEV_CONNECTED - When an input device connects * @emits CONNECTION_EVENTS.IN_DEV_DISCONNECTED - When an input device disconnects * @emits CONNECTION_EVENTS.OUT_DEV_CONNECTED - When an output device connects * @emits CONNECTION_EVENTS.OUT_DEV_DISCONNECTED - When an output device disconnects * * @example * // Request basic MIDI access * await connection.requestAccess(); * * @example * // Request with SysEx support * const connection = new MIDIConnection({ sysex: true }); * await connection.requestAccess(); */ requestAccess(): Promise; /** * Connect to a MIDI output device. Can connect by index, name, or ID. * * @param {string|number} [device] - Device name, ID, or index (defaults to first available) * @returns {Promise} * @throws {MIDIConnectionError} If MIDI access not initialized * @throws {MIDIDeviceError} If device not found or index out of range * * @example * // Connect to first available device * await connection.connect(); * * @example * // Connect by index * await connection.connect(0); * * @example * // Connect by name * await connection.connect("My MIDI Keyboard"); * * @example * // Connect by device ID * await connection.connect("input-12345"); */ connect(device?: string | number): Promise; /** * Connect to a MIDI input device for receiving messages * @param {string|number} [device] - Device name, ID, or index (defaults to first available) * @param {Function} onMessage - Callback for incoming MIDI messages * @returns {Promise} * @throws {MIDIConnectionError} If MIDI access not initialized * @throws {MIDIValidationError} If onMessage is not a function * @throws {MIDIDeviceError} If device not found or index out of range */ connectInput(device?: string | number, onMessage: Function): Promise; /** * Disconnect from current output */ disconnectOutput(): void; /** * Disconnect from current input */ disconnectInput(): void; /** * Disconnect from both output and input */ disconnect(): void; /** * Check if currently connected to an output * @returns {boolean} */ isConnected(): boolean; /** * Get current output device info * @returns {Object|null} */ getCurrentOutput(): any | null; /** * Get current input device info * @returns {Object|null} */ getCurrentInput(): any | null; /** * Get all available MIDI outputs * @returns {Array<{id: string, name: string, manufacturer: string}>} */ getOutputs(): Array<{ id: string; name: string; manufacturer: string; }>; /** * Get all available MIDI inputs * @returns {Array<{id: string, name: string, manufacturer: string}>} */ getInputs(): Array<{ id: string; name: string; manufacturer: string; }>; /** * Send a MIDI message to the connected output. Automatically converts * Arrays to Uint8Array for Web MIDI API compatibility. * * @param {Uint8Array|Array} message - MIDI message bytes (e.g., [0x90, 60, 100]) * @param {number} [timestamp=performance.now()] - Optional timestamp for scheduled sending * @returns {void} * * @example * // Send a note on message (channel 1, note C4, velocity 100) * connection.send([0x90, 60, 100]); * * @example * // Send a note off message * connection.send([0x80, 60, 0]); * * @example * // Send a control change * connection.send([0xB0, 7, 64]); // Volume to 64 */ send(message: Uint8Array | Array, timestamp?: number): void; /** * Send a System Exclusive (SysEx) message. Requires sysex: true in constructor options. * * @param {Array} data - SysEx data bytes (without F0/F7 wrapper) * @param {boolean} [includeWrapper=false] - If true, wraps data with F0/F7 bytes * @returns {void} * * @example * // Send a basic SysEx message (will be wrapped with F0/F7) * connection.sendSysEx([0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F]); * * @example * // Send pre-wrapped SysEx message * connection.sendSysEx([0xF0, 0x41, 0x10, 0x42, 0xF7], false); */ sendSysEx(data: Array, includeWrapper?: boolean): void; } //# sourceMappingURL=MIDIConnection.d.ts.map