From 19d267da3c292d49fddf1b7c083e477131cbd3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Podgor=C5=A1ek?= Date: Fri, 27 May 2022 13:23:36 +0200 Subject: [PATCH] dva kegla na razlicnih kanalih --- kegel.js | 85 +++++++++++++++++++------------------------------------- 1 file changed, 28 insertions(+), 57 deletions(-) diff --git a/kegel.js b/kegel.js index f66147e..f495b21 100644 --- a/kegel.js +++ b/kegel.js @@ -34,8 +34,7 @@ oscWS.on('ready', () => { const zaznava = 0.8 -let cakajX = false -let cakajZ = false +let cakaj = false const cakajInterval = 1 / 5 const razponTona = [0.1, 0.5] @@ -45,35 +44,49 @@ let rotVisina = 0 oscWS.on('message', ({ address, args }) => { DEBUG.osc && console.log('MSG OSC', address, args.map(x => x.toFixed(4))) - if (address == '/euler') { + + //const re = /\/ww\/(d+)\/([a-zA-Z]+)/ + const re = /\/ww\/(\d+)\/([a-zA-Z]+)/ + const m = address.match(re) + + const index = m[1] + const addr = m[2] + + if (addr == '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') { + if (addr == 'accel') { const acX = args[0] const acY = args[1] const acZ = args[2] - const vsota = acX + acY + acZ - if (acX > zaznava && !cakajX) { + // Y os je kegel po dolgem - ignoriramo + const vsota = acX + acZ - cakajX = true + if (vsota > zaznava && !cakaj) { + + cakaj = true // Pavza setTimeout(() => { //console.log("nehaj cakat") - cakajX = false + cakaj = false }, cakajInterval * 1000) + const midiKanal = 144 + parseInt(index) // Od 24 do 48 - const accval = Math.sin((acX - zaznava) / 3) - console.log(acX, accval) + const accval = Math.sin((vsota - zaznava) / 3) + //console.log(acX, accval) // Acc visina - const visina = 24 + Math.round((accval / 2.5) * 72) + const visina = (midiKanal == 0) + ? 24 + Math.round((accval / 2.5) * 36) + : 48 + Math.round((accval / 2.5) * 72) + //const visina = rotVisina //console.log('posiljam midi', [144, visina, 127]) @@ -85,60 +98,18 @@ oscWS.on('message', ({ address, args }) => { */ oscWS.send({ address: '/midi', - args: [144, visina, 127] + args: [midiKanal, visina, 127] }) - console.log('vklopi', visina) + console.log('vklopi', midiKanal, visina) // Ugasni cez en cas let izklop = razponTona[0] + Math.random() * (razponTona[1] - razponTona[0]) setTimeout(() => { oscWS.send({ address: '/midi', - args: [144, visina, 0] + args: [midiKanal, visina, 0] }) - console.log('izklopi', visina) - }, izklop * 1000) - } - - if (acZ > zaznava && !cakajZ) { - - cakajZ = true - - // Pavza - setTimeout(() => { - //console.log("nehaj cakat") - cakajZ = false - }, cakajInterval * 1000) - - - // Od 24 do 48 - const accval = Math.sin((acZ - zaznava) / 3) - console.log(acZ, accval) - // Acc visina - const visina = 56 + Math.round((accval / 2.5) * 72) - //const visina = rotVisina - - //console.log('posiljam midi', [144, visina, 127]) - /* - oscWS.send({ - address: '/midi', - args: [192, 1, 127] - }) - */ - oscWS.send({ - address: '/midi', - args: [145, visina, 127] - }) - console.log('vklopi', visina) - - // Ugasni cez en cas - let izklop = razponTona[0] + Math.random() * (razponTona[1] - razponTona[0]) - setTimeout(() => { - oscWS.send({ - address: '/midi', - args: [145, visina, 0] - }) - console.log('izklopi', visina) + console.log('izklopi', midiKanal, visina) }, izklop * 1000) } }