From 4a805e782c9b1e4b1b9cc8f9e35c91deff7b82a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Podgor=C5=A1ek?= Date: Sat, 23 Apr 2022 16:34:38 +0200 Subject: [PATCH] Midi on/off --- server.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 } }