Skip to content

Commit

Permalink
Merge pull request #4 from jpetazzo/note-on-velocity-0
Browse files Browse the repository at this point in the history
Handle "Note On" events with velocity 0
  • Loading branch information
notwaldorf authored Feb 20, 2020
2 parents e779393 + 67ccbd1 commit 268b57d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions client/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ async function onKeydown(e) {
async function onMidiIn(msg) {
const command = msg.data[0];
const pitch = msg.data[1];
const velocity = msg.data[2];
const basePitch = pitch % 12;
const button = document.querySelector(`.pitch-${basePitch}`);

switch (command) {
case 0x90: // note on
if (command === 0x90 && velocity > 0) {
// note on
notePressed(pitch);
button.classList.add('down');
break;
case 0x80: // note off
} else if (command === 0x80 || (command === 0x90 && velocity === 0)) {
// note off
button.classList.remove('down');
break;
}
}

Expand Down

0 comments on commit 268b57d

Please sign in to comment.