Last active
March 13, 2024 05:30
-
-
Save drart/ce01a8b7ce9b851b9e29 to your computer and use it in GitHub Desktop.
MIDI to OSC bridge using Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var midi = require('midi'); | |
var input = new midi.input(); | |
console.log(input.getPortCount()); | |
console.log(input.getPortName(1)); | |
// | |
input.openPort(0); | |
input.ignoreTypes(false, false, false); | |
// | |
input.on('message', function(deltaTime, message) { | |
midiMessageReceived(message); | |
}); | |
var osc = require('node-osc'); | |
var client = new osc.Client('127.0.0.1', 3333); | |
client.send('/oscAddress', 1, 1, 2, 3, 5, 8); | |
function midiMessageReceived( ev ) { | |
var cmd = ev[0] >> 4; | |
var channel = ev[0] & 0xf; | |
var noteNumber = ev[1]; | |
var velocity = ev[2]; | |
// | |
console.log(noteNumber); | |
if ( cmd==8 || ((cmd==9)&&(velocity==0)) ) { // with MIDI, note on with velocity zero is the same as note off | |
// // note off | |
} else if (cmd == 9) { | |
// note on | |
} else if (cmd == 11) { | |
// controller( noteNumber, velocity/127.0); | |
switch(noteNumber){ | |
case 1: | |
break; | |
case 2: | |
break; | |
case 3: | |
break; | |
case 4: | |
} | |
} | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "midibridge", | |
"version": "0.0.0", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"midi": "~0.9.0", | |
"node-osc": "~0.2.1" | |
}, | |
"devDependencies": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment