diff --git a/server.js b/server.js index 3d6c38e..592b2d8 100644 --- a/server.js +++ b/server.js @@ -24,6 +24,9 @@ const fs = require('fs') const midi = require('midi') +let midiOn = false +let midiNotes = {} + // Vzemi iz argumenta const tty = process.argv[2] @@ -241,7 +244,17 @@ const sendAll = (msg, info, oscWS, osclients) => { if (msg.address == '/accel') { if (msg.args[1] > 5000) { console.log("SEND MIDI!") - mo.sendMessage([176, 22, 1]) + const visina = Math.round((msg.args[1] - 5000) / 100) + midiNotes[visina] = true + mo.send([144, visina, 127]) + midiOn = true + } + + if (msg.args[1] < 5000 && midiOn) { + Object.keys(midiNotes).forEach(visina => { + mo.send([128, visina, 127]) + }) + midiOn = false } }