Skip to content

Instantly share code, notes, and snippets.

@tadfmac
Created Jan 19, 2019
Embed
What would you like to do?
midi 受ける側
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>MIDI Receiver (Distance) </title>
<script src="https://mz4u.net/libs/posnd/pomidi.js"></script>
<style>
p{
color:blue;
text-align: center;
font-size: 24px;
}
img{
display:block;
margin-left:auto;
margin-right:auto;
}
</style>
</head>
<body>
<p id="status">---</P>
<script>
'use strict';
(async function(){
const midi = await new pomidi(); // MIDI 読み込み
const elemStatus = document.getElementById("status");
midi.setHandler((e)=>{
console.log(e.data[0]+","+e.data[1]+","+e.data[2]);
if((e.data[0] & 0xf0) == 0x90){ // noteon
if((e.data[0] & 0x0f) == 0x05){ // ch:5
var distance = e.data[1];
elemStatus.innerHTML ="Distance="+e.data[1]+"cm";
if(distance > 20){
// takeSnapshot()
}
}
}
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment