Popravljena logika

main
Jurij Podgoršek 2022-05-22 16:08:51 +02:00
parent b4645bf161
commit 163ca09a8a
1 changed files with 32 additions and 27 deletions

View File

@ -3,6 +3,11 @@ const osc = require('osc')
const ip = process.argv[2]
const DEBUG = {
midi: true,
osc: false
}
//const ws = new WebSocket(`ws://${ip}:6676`)
/*
@ -28,41 +33,53 @@ oscWS.on('ready', () => {
})
let midiOn = false
let midiNotes = {}
const zaznava = 2000
const zaznava = 0.5
let cakaj = false
const cakajInterval = 1 / 5
//const razponTona = [0.1, 0.5]
const razponTona = [0.001, 0.002]
const razponTona = [0.1, 0.5]
//const razponTona = [0.001, 0.002]
let rotVisina = 0
oscWS.on('message', ({ address, args }) => {
//console.log('GGOT MSG OSC', address, args)
const acX = args[1]
DEBUG.osc && console.log('MSG OSC', address, args.map(x => x.toFixed(4)))
if (address == '/euler') {
//const eVisina = Math.sin(args[0] + args[1])
const eVisina = Math.sin(args[2])
rotVisina = 24 + Math.round(((eVisina / 2) + 0.5) * 24)
//console.log("rotVisina", rotVisina)
}
if (address == '/accel') {
const acX = args[0]
const acY = args[1]
const acZ = args[2]
const vsota = acX + acY + acZ
if (cakaj) {
//console.log("CAKAM!")
return
}
if (acX > zaznava && !cakaj) {
if (cakaj) {
console.log("CAKAM!")
return
}
cakaj = true
// Pavza
setTimeout(() => {
console.log("nehaj cakat")
//console.log("nehaj cakat")
cakaj = false
}, cakajInterval * 1000)
console.log("SEND MIDI!")
// Od 24 do 48
const accval = Math.sin((args[1] - zaznava) / 1000)
const visina = 24 + Math.round(((accval / 2) + 0.5) * 24)
const accval = Math.sin((acX - zaznava) / 3)
// Acc visina
const visina = 24 + Math.round(((accval / 2.5) + 0.5) * 48)
//const visina = rotVisina
midiNotes[visina] = true
//console.log('posiljam midi', [144, visina, 127])
oscWS.send({
address: '/midi',
@ -82,18 +99,6 @@ oscWS.on('message', ({ address, args }) => {
console.log('izklopi', visina)
}, izklop * 1000)
}
/*
if (args[1] < zaznava && midiOn) {
Object.keys(midiNotes).forEach(visina => {
oscWS.send({
address: '/midi',
args: [128, visina, 127]
})
})
midiOn = false
}
*/
}
})