web-midi-emitter

easy Web MIDI message handler

Usage no npm install needed!

<script type="module">
  import webMidiEmitter from 'https://cdn.skypack.dev/web-midi-emitter';
</script>

README

web-midi-emitter

Build Status NPM Version License

easy Web MIDI message handler

Installation

npm install --save web-midi-emitter

API

WebMIDIEmitter

  • constructor(access, deviceNameMatcher)
    • access: MIDIAccess
    • deviceNameMatcher: string or RegExp

Instance methods

  • send(data: number[], [ timestamp: number ]): void
    • send midi data to the midi device
  • clear(): void

Events

  • statechange
    • emitted when change the state of the midi device
  • midimessage
    • emitted when receive midi data from the midi device

How to use

const WebMIDIEmitter = require("web-midi-emitter");

window.navigator.requestMIDIAccess().then((access) => {
  const device = new WebMIDIEmitter(access, "Launch Control");

  device.on("statechange", (e) => {
    console.log(e);
  });

  device.on("midimessage", (e) => {
    console.log(e.data);
  });

  device.send([ 0x90, 0x64, 0x7f ]);
});

License

MIT