How to use webmidi - 10 common examples

To help you get started, we’ve selected a few webmidi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NERDDISCO / luminave / src / components / midi-manager / index.js View on Github external
constructor() {
    super()

    // Web MIDI is disabled
    store.dispatch(enableMidi(false))

    // Enable Web MIDI
    WebMidi.enable(err => {

      if (err) {
        console.error('Web MIDI API could not be enabled:', err)
      } else {
        // MIDI input / output ports (from a single device) are connected to the computer
        WebMidi.addListener('connected', e => {
          const { manufacturer, name, id, type } = e.port
          console.log('MIDIController added:', 'Manufacturer:', manufacturer, '| Name:', name, '| ID:', id, '| Type:', type)
        })

        WebMidi.addListener('disconnected', e => {
          const { manufacturer, name, type, id } = e.port
          console.log('MIDIController removed:', 'Manufacturer:', manufacturer, '| Name:', name, '| ID:', id, '| Type:', type)
        })

        // Web MIDI is enabled
github garrensmith / abletonpush / src / index.js View on Github external
constructor (opts = {}) {
    super();

    const options = Object.assign(opts, {logging: true});
    log.enabled = options.logging;
    this.activePads = [];
    this.batchCommands = []; // batch commands in case something is called before web midi is enabled
    this.midiEnabled = false;
    this.pushConnected = false;

    WebMidi.enable((err) => {
      if (err) {
        log('WebMidi could not be enabled.');
        return;
      }

      this.midiEnabled = true;
      log('WebMidi enabled!');

      WebMidi.addListener('connected', (...args) => {
        if (this.pushConnected) {
          return;
        }
        this.pushConnected = true;
        this.setupPush();
        log('CONNECTED', args);
        this.emit('push:connected');
github garrensmith / abletonpush / src / index.js View on Github external
setupPush () {
    const push = this;
    push.output = WebMidi.getOutputByName('Ableton Push 2 User Port');
    push.input = WebMidi.getInputByName('Ableton Push 2 User Port');
    if (!push.input || !push.output) {
      log('push not connected');
      push.emit('push:failed');
      return;
    }

    push.input.addListener('sysex', 'all', (e) => {
      log('sysex', e);
    });

    // Listen to control change message on all channels
    push.input.addListener('controlchange', 'all', (e) => {
      log('Received \'controlchange\' message.', e);
      if (e.controller) {
        const name = e.controller.name;
github garrensmith / abletonpush / src / index.js View on Github external
setupPush () {
    const push = this;
    push.output = WebMidi.getOutputByName('Ableton Push 2 User Port');
    push.input = WebMidi.getInputByName('Ableton Push 2 User Port');
    if (!push.input || !push.output) {
      log('push not connected');
      push.emit('push:failed');
      return;
    }

    push.input.addListener('sysex', 'all', (e) => {
      log('sysex', e);
    });

    // Listen to control change message on all channels
    push.input.addListener('controlchange', 'all', (e) => {
      log('Received \'controlchange\' message.', e);
      if (e.controller) {
        const name = e.controller.name;
        const number = e.controller.number;
github NERDDISCO / luminave / src / components / midi-controller / index.js View on Github external
midiEnabledChanged() {
    if (this.midiEnabled) {
      // MIDI input / output ports (from a single device) are connected to the computer
      WebMidi.addListener('connected', e => {

        const { port } = e
        const { name, type } = port

        // The connected event is triggered twice for input, that's why we need to check
        // if this.input is already defined or not, @see https://github.com/NERDDISCO/luminave/issues/14
        if (name === this.inputname && type === 'input' && this.input === null) {
          this.input = port

          // Listen to "noteon" events
          this.input.addListener('noteon', 'all', this.noteon.bind(this))

          // Listen to "controlchange" events
          this.input.addListener('controlchange', 'all', this.controlchange.bind(this))

          // Controller is connected
github NERDDISCO / luminave / src / components / midi-controller / index.js View on Github external
// Listen to "noteon" events
          this.input.addListener('noteon', 'all', this.noteon.bind(this))

          // Listen to "controlchange" events
          this.input.addListener('controlchange', 'all', this.controlchange.bind(this))

          // Controller is connected
          this.connected = true

        } else if (name === this.outputname && type === 'output') {
          this.output = port
        }
      })

      // MIDI input / output ports (from a single device) are disconnected to the computer
      WebMidi.addListener('disconnected', e => {
        const { name, type } = e.port

        if (name === this.inputname && type === 'input') {
          // Remove all listener
          this.input.removeListener()

          this.input = null
        } else if (name === this.outputname && type === 'output') {
          this.output = null
        }

        this.connected = false
      })

    }
  }
github jupyter-widgets / midicontrols / src / widget.ts View on Github external
initialize(attributes: any, options: any) {
    super.initialize(attributes, options);
    if (!midi.enabled) {
      throw new Error('WebMidi library not enabled');
    }

    const input = midi.inputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
    if (input === -1) {
      throw new Error("Could not find Behringer X-TOUCH MINI input");
    }

    const output = midi.outputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
    if (output === -1) {
      throw new Error("Could not find Behringer X-TOUCH MINI output");
    }

    this.set('_controller_input', input);
    this.set('_controller_output', output);


    // Make sure we are in MCU protocol mode
    midi.outputs[output].sendChannelMode(
      127,
github ambewas / react-audio-tools / src / lib / components / inputs / MidiController / MidiController.js View on Github external
requestMidiAccess = () => {
    webmidi.enable(err => {
      if (err) {
        this.canAccessMidi = false;
        alert("No midi support in your browser."); // eslint-disable-line
      } else {
        this.canAccessMidi = true;
        this.initializeMidi();
      }
    });
  }
github jupyter-widgets / midicontrols / src / widget.ts View on Github external
const input = midi.inputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
    if (input === -1) {
      throw new Error("Could not find Behringer X-TOUCH MINI input");
    }

    const output = midi.outputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
    if (output === -1) {
      throw new Error("Could not find Behringer X-TOUCH MINI output");
    }

    this.set('_controller_input', input);
    this.set('_controller_output', output);


    // Make sure we are in MCU protocol mode
    midi.outputs[output].sendChannelMode(
      127,
      1 /* MCU mode */,
      1 /* global channel */
    );
    this.setup().then((controls: any) => {
      this.set(controls);
      this.save_changes();
    });
  }
github jupyter-widgets / midicontrols / src / enableMIDI.ts View on Github external
export default async function enableMIDI() {
  if (midi.enabled) {
    return;
  }

  const midiEnabled = new PromiseDelegate();
  midi.enable(function(err) {
    if (err) {
      midiEnabled.reject(err);
    } else {
      midiEnabled.resolve(undefined);
    }
  });  
  await midiEnabled.promise;
  // if (!(midi.inputs[1] && midi.outputs[1])) {
  //   throw new Error("Could not find MIDI device");
  // }
}

webmidi

WEBMIDI.js makes it easy to talk to MIDI instruments from a browser or from Node.js. It simplifies the control of external or virtual MIDI instruments with functions such as playNote(), sendPitchBend(), sendControlChange(), etc. It also allows reacting to

Apache-2.0
Latest version published 3 months ago

Package Health Score

84 / 100
Full package analysis