Skip to content

Instantly share code, notes, and snippets.

@tadfmac
Created January 19, 2019 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadfmac/6888e47f12bdb2ca68d26561e06aad52 to your computer and use it in GitHub Desktop.
Save tadfmac/6888e47f12bdb2ca68d26561e06aad52 to your computer and use it in GitHub Desktop.
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