Skip to content

Instantly share code, notes, and snippets.

@arnar
Created September 24, 2013 22:58
Show Gist options
  • Save arnar/6692485 to your computer and use it in GitHub Desktop.
Save arnar/6692485 to your computer and use it in GitHub Desktop.
var spawn = require('child_process').spawn;
var midi = require('midi');
// Set up a new input.
var input = new midi.input();
var sharpnames = ['c', 'cis', 'd', 'dis', 'e', 'f', 'fis', 'g', 'gis', 'a', 'ais', 'b'];
var flatnames = ['c', 'des', 'd', 'es', 'e', 'f', 'ges', 'g', 'as', 'a', 'bes', 'b'];
var notenames = flatnames;
var prevnote = 60; // start with middle c
// Configure a callback.
input.on('message', function(deltaTime, message) {
if (message[0] == 144) {
var note = message[1];
var notename = notenames[note % notenames.length];
var diff = prevnote - note;
if (diff > 5) {
notename += ",,,,,,,,,,,,,,,,".substring(0, Math.floor((diff - 6) / 12) + 1);
} else if (diff < -5) {
notename += "''''''''''''''''".substring(0, Math.floor((-diff - 6) / 12) + 1);
}
console.log('sending note:' + notename);
spawn("mvim", ["--servername", "lily", "--remote-send", " " + notename]);
prevnote = note;
}
});
// Open the first available input port.
input.openPort(2);
// Sysex, timing, and active sensing messages are ignored
// by default. To enable these message types, pass false for
// the appropriate type in the function below.
// Order: (Sysex, Timing, Active Sensing)
input.ignoreTypes(true, true, false);
@gudmundur
Copy link

buh, L21-23... dafuq?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment