Created
January 25, 2021 15:26
-
-
Save DanielOaks/a6b19a98f6fec8493eafcf8ef8da43ae to your computer and use it in GitHub Desktop.
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
<!-- | |
this helps me work out which numbers I should put in the effects column of an | |
XM file to make the chords I've just played. I keep it open on a separate | |
screen while I'm editing the file with milkytracker. whoo~ | |
--> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/webmidi"></script> | |
<script> | |
var pressedKeys = []; | |
function updateKeys() { | |
if (pressedKeys.length < 2) { | |
return; | |
} | |
pressedKeys.sort(); | |
// console.log('currently pressed:', pressedKeys); | |
var firstIndex = null; | |
var output = ' ' | |
for (const key of pressedKeys) { | |
if (firstIndex === null) { | |
firstIndex = key; | |
} | |
var char = (key - firstIndex).toString(16); | |
if (1 < char.length) { | |
console.log("Keys are too far apart"); | |
return; | |
} | |
output += char; | |
} | |
console.log(output); | |
} | |
WebMidi.enable(function (err) { | |
console.log(WebMidi.inputs); | |
console.log(WebMidi.outputs); | |
var input = WebMidi.getInputByName('A-PRO 1'); | |
input.addListener('noteon', 'all', | |
function (e) { | |
// console.log("Received 'noteon' message (" + e.note.name + e.note.octave + ' ' + e.note.number + ")."); | |
pressedKeys.push(e.note.number); | |
updateKeys(); | |
} | |
); | |
input.addListener('noteoff', 'all', | |
function (e) { | |
// console.log("Received 'noteoff' message (" + e.note.name + e.note.octave + ' ' + e.note.number + ")."); | |
if (pressedKeys.includes(e.note.number)) { | |
pressedKeys.splice(pressedKeys.indexOf(e.note.number), 1) | |
} | |
// updateKeys(); | |
} | |
); | |
}); | |
</script> | |
</head> | |
<body> | |
hi | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment