2.3.0 • Published 1 month ago

web-midi-api v2.3.0

Weekly downloads
152
License
MIT
Repository
github
Last release
1 month ago

Web MIDI API for Node.js

nodejs windows macos linux raspberry pi
npm npm build Coverage

This package is deprecated and kept here for the old projects compatibility. It redirects to jzz:

// index.js:
module.exports = require('jzz');

If you are starting a new project, please consider using jzz directly.

Other versions

Usage

npm install web-midi-api

var navigator = require('web-midi-api');
// consider using var navigator = require('jzz');

var midi;
var inputs;
var outputs;

function onMIDIFailure(msg) {
  console.log('Failed to get MIDI access - ' + msg);
  process.exit(1);
}

function onMIDISuccess(midiAccess) {
  midi = midiAccess;
  inputs = midi.inputs;
  outputs = midi.outputs;
  setTimeout(testOutputs, 500);
}

function testOutputs() {
  console.log('Testing MIDI-Out ports...');
  outputs.forEach(function(port) {
    console.log('id:', port.id, 'manufacturer:', port.manufacturer, 'name:', port.name, 'version:', port.version);
    port.open();
    port.send([0x90, 60, 0x7f]);
  });
  setTimeout(stopOutputs, 1000);
}

function stopOutputs() {
  outputs.forEach(function(port) {
    port.send([0x80, 60, 0]);
  });
  testInputs();
}

function onMidiIn(ev) {
  var arr = [];
  for(var i = 0; i < ev.data.length; i++) {
    arr.push((ev.data[i] < 16 ? '0' : '') + ev.data[i].toString(16));
  }
  console.log('MIDI:', arr.join(' '));
}

function testInputs() {
  console.log('Testing MIDI-In ports...');
  inputs.forEach(function(port) {
    console.log('id:', port.id, 'manufacturer:', port.manufacturer, 'name:', port.name, 'version:', port.version);
    port.onmidimessage = onMidiIn;
  });
  setTimeout(stopInputs, 5000);
}

function stopInputs() {
  console.log('Thank you!');
  navigator.close(); // This will close MIDI inputs, otherwise Node.js will wait for MIDI input forever.
  process.exit(0);
}

navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure);
2.3.0

1 month ago

2.2.9

2 months ago

2.2.8

3 months ago

2.2.7

5 months ago

2.2.6

7 months ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.5

12 months ago

2.2.4

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.8

1 year ago

2.1.7

2 years ago

2.1.9

1 year ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.9

3 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.4

9 years ago

1.4.3

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago