Skip to content

Instantly share code, notes, and snippets.

@jhorology
Last active March 22, 2024 19:56
Show Gist options
  • Save jhorology/a8070cceeb20009aed7d2dbdad04011c to your computer and use it in GitHub Desktop.
Save jhorology/a8070cceeb20009aed7d2dbdad04011c to your computer and use it in GitHub Desktop.
Fake Garage Band for NIHostIntegrationAgent
var midi = require('midi');
var mdns = require('mdns');
var osc = require('node-osc');
var KK_OSC_SERVICE_NAME = 'KOMPLETE KONTROL S-Series';
var LISTEN_PORT = 7001;
var txtRecord = {
AppleLogic: 'GarageBand10'
};
// create OSC listener service
var oscServer = new osc.Server(LISTEN_PORT, '0.0.0.0');
oscServer.on("message", function (msg, rinfo) {
console.log("message:");
console.log(msg);
});
// create mDNS Advertisement for OSC listener service
var ad = mdns.createAdvertisement(mdns.udp('osc'), LISTEN_PORT, {txtRecord: txtRecord});
ad.on('error', function(error) {
console.warn(error);
});
ad.start();
// send sysex to activate NIHostIntegrationAgent
var midiOutput = new midi.output();
var midiPortCount = midiOutput.getPortCount();
for (var i = 0; i < midiPortCount; i++) {
midiOutput.openPort(i);
midiOutput.sendMessage([0xF0, 0x7E, 0x00, 0x06, 0x01, 0xF7]);
midiOutput.closePort();
}
// watch all OSC service to
// discover NIHostIntegration listen port
var browser = mdns.createBrowser(mdns.udp('osc'));
browser.on('serviceUp', function(service) {
console.log("service up: ", service);
if (service.name == KK_OSC_SERVICE_NAME) {
console.log("KK_OSC_SERVICE_PORT: ", service.port);
}
});
browser.on('serviceDown', function(service) {
console.log("service down: ", service);
});
browser.start();
// discover all available service types
// var all_the_types = mdns.browseThemAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment