midify

0.1.1 • Public • Published

midify NPM version Dependency Status

Makes working with Web MIDI more palatable.

Install via npm:

npm install midify

What it does

midify is a package that combines node's event emitter with the browser's web midi api, to make working with midi messages more palatable. It is supposed to be used in combination with modules that expose input and output objects, so that clients can send events such as deckA.play.on (to light up the play button's LED), and to allow consuming modules to listen to events such as crossfader.change, which will call back with the value of the crossfader, as an example.

Note that midify is a work in progress, and currently only two devices are supported as they are all that I have access to. I'm hoping that those who are working with Web MIDI can help me to build up a library of easily consumable maps, so that we as developers can easily build MIDI applications to run on a wide range of devices, using a common format.

Compatible controllers are:

If you've created a map for your controller that is compatible with midify, please open an issue and it will be added to the list.

Example

Bundle this code with browserify. Note that Web MIDI is currently available behind a flag in Chrome, and remains unsupported in other browsers. To enable it in Chrome, go to chrome://flags and ensure that the Web MIDI option is on. As of this writing, MIDI support in Chrome is not quite plug and play capable, so you'll need to shut down Chrome and plug your device in before testing any code.

var Midify = require('midify');
var mixtrack = require('midify-numark-mixtrack-pro');
 
navigator.requestMIDIAccess().then(function(midiAccess) {
    var midiIn;
    var midiOut;
 
    // For brevity, we are just assuming one MIDI device is connected
    for (var input of midiAccess.inputs.values()) {
        midiIn = input;
    }
 
    for (var output of midiAccess.outputs.values()) {
        midiOut = output;
    }
 
    var midify = new Midify({
        midiIn: midiIn,
        midiOut: midiOut,
        controller: mixtrack
    });
 
    midify.on('*', function(event) {
        console.log('triggered', event, 'event');
    });
 
}, function() { console.error('MIDI access unavailable'); });

API

var midify = new Midify(options)

Construct a new midify instance. It takes an options object with three parameters; midiIn and midiOut should be retrieved from the midiAccess object, as per the example above, and the controller parameter accepts a module which exposes inputs and outputs objects.

midify.getLEDs()

Get an array of all the LED outputs; useful if you need to reset all of the lights on the controller:

midify.getLEDs().forEach(function(led) {
    midify.send(led + '.off');
});

midify.send()

Send a message to the controller. See the documentation for your controller to see which messages you can send.

midify.send('deckA.play.on');

midify.on()

midify just inherits from event emitter, so you can listen to events from your controller:

midify.on('masterGain.change', function(value) {
    console.log('volume changed', value);
});

As well as the namespaced events, midify will also emit *, so that you can listen to all messages for debugging purposes:

midify.on('*', function(event, value) {
    console.log(event, value);
});

Both of these events will also emit the full MIDI message object as the final parameter in the callback function; so to access the raw data you can also do:

midify.on('*', function(event, value, raw) {
    console.log(event, value, raw);
});

License

MIT © Ben Briggs

Package Sidebar

Install

npm i midify

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • beneb