Package Exports
- pirate-midi-usb
Readme
pirate-midi-usb
Easily interact with Pirate Midi devices over USB from JavaScript
Install
npm install pirate-midi-usbUsage
import { getDevices } from 'pirate-midi-usb';
const devices = await getDevices();
await device[0].goToBank(2);API
This package implements the Pirate Midi Device API to interact with Bridge4 and Bridge6 devices, see the API documentation for the underlying details.
Use getDevices to retrieve available devices
Scans USB devices and returns a promise with an array of PirateMidiDevice instances (one per device) to interact with.
Note In the browser a dialog will be triggered for the user to select and give access to a single device. Currently only a single device will be returned.
import { getDevices } from 'pirate-midi-usb';
const devices = await getDevices();
const bridge6 = device.find(device => device.deviceName === 'Bridge6');Each instance of a device is returned with the deviceInfo prefetched. This information could be used to select a specific device when multiple are connected. When no devices are found an empty array will be returned
Use PirateMidiDevice methods to interact with the device
Check PirateMidiDevice.ts to see all implemented methods.
Managing the connection
Devices may be plugged out while your app/script is running. When a device it returned it is ready to use but you should monitor the connection and respond accordingly to avoid interacting with an unavailable device:
const [device] = await getDevices();
// Activate UI
device.on('disconnect', () => {
// Deactivate UI
});
// When the same device is plugged in again the instance will auto-reconnect and fire a "connect" event.
device.on('connect', () => {
// Activate UI
});Note This behaviour is only implemented for browsers at the moment.
Debugging
Use environment variables to enable logging:
DEBUG=pmu*- high level logsDEBUG=verbose:pmu*- verbose (large output!)
The logs can be filtered by keys, like pmu:runCommand*, see Debug docs.
Examples
See the examples folder, check out the intro example to get started!
Run examples by their filename:
npm run examples:introThanks
Thanks to Pirate Midi for the awesome devices and the openness.
This repo was started with typescript-npm-package-template