how to connect Web Midi API to native application (like Ableton live)
I found the documentation for the Web MIDI API a bit confusing, so I tried webmidi
instead (it's built on top of the Web MIDI API, so everything it does should be implementable using the "raw" API as well).
To receive MIDI messages, this works for me:
WebMidi.enable(function(err) {
if (err) throw err;
console.log("WebMidi enabled!");
WebMidi.getInputByName('IAC Driver Bus 1').addListener('noteon', 'all', function(e) {
console.log('note on', e);
});
});
In Ableton, "Midi To" needs to point to the IAC device (if it doesn't show up, you may need to open the MIDI preferences and enable it as an output device):
Caveat: I found that this only works for MIDI tracks that don't have any instruments attached to them (see this page).
EDIT: I assume that the device is named similarly on your Mac, otherwise here's the code I used to enumerate input and output devices:
WebMidi.enable(function(err) {
if (err) throw err;
WebMidi.inputs.forEach(input => {
console.log('- id :', input.id);
console.log('- name:', input.name);
console.log('- manu:', input.manufacturer);
console.log('- conn:', input.connection);
console.log('---');
});
console.log('outputs:', WebMidi.outputs);
WebMidi.outputs.forEach(output => {
console.log('- id :', output.id);
console.log('- name:', output.name);
console.log('- manu:', output.manufacturer);
console.log('- conn:', output.connection);
console.log('---');
});
});
In order to send midi events from Ableton into the Web MIDI API on OSX you need to do the following:
1) Run the built-in OSX app called 'Audio MIDI Setup'. Select 'MIDI Studio'. Double Click 'IAC Driver'. Then check the 'Device is Online' checkbox.
2) Go to Ableton -> Preferences -> MIDI. At the bottom for 'Input: IAC Driver (Bus 1)' enable 'Track' and 'Remote'. For 'Output: IAC Driver (Bus 1)' enable 'Track'.
3) Now in the the Ableton midi track you want to send notes from, Select 'IAC Driver' as the midi output.
4) Now 'IAC Driver (Bus 1)' should appear as a Midi Input via the Web MIDI API.
This process is described here: https://www.youtube.com/watch?v=MkWZ4rtRybQ