Browse Source

dva kegla na razlicnih kanalih

main
Jurij Podgoršek 1 month ago
parent
commit
19d267da3c
  1. 85
      kegel.js

85
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,100 +44,72 @@ 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) {
cakajX = true
// Pavza
setTimeout(() => {
//console.log("nehaj cakat")
cakajX = false
}, cakajInterval * 1000)
// Y os je kegel po dolgem - ignoriramo
const vsota = acX + acZ
if (vsota > zaznava && !cakaj) {
// Od 24 do 48
const accval = Math.sin((acX - zaznava) / 3)
console.log(acX, accval)
// Acc visina
const visina = 24 + Math.round((accval / 2.5) * 72)
//const visina = rotVisina
//console.log('posiljam midi', [144, visina, 127])
/*
oscWS.send({
address: '/midi',
args: [192, 0, 127]
})
*/
oscWS.send({
address: '/midi',
args: [144, 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: [144, visina, 0]
})
console.log('izklopi', visina)
}, izklop * 1000)
}
if (acZ > zaznava && !cakajZ) {
cakajZ = true
cakaj = true
// Pavza
setTimeout(() => {
//console.log("nehaj cakat")
cakajZ = false
cakaj = false
}, cakajInterval * 1000)
const midiKanal = 144 + parseInt(index)
// Od 24 do 48
const accval = Math.sin((acZ - zaznava) / 3)
console.log(acZ, accval)
const accval = Math.sin((vsota - zaznava) / 3)
//console.log(acX, accval)
// Acc visina
const visina = 56 + 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])
/*
oscWS.send({
address: '/midi',
args: [192, 1, 127]
args: [192, 0, 127]
})
*/
oscWS.send({
address: '/midi',
args: [145, 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: [145, visina, 0]
args: [midiKanal, visina, 0]
})
console.log('izklopi', visina)
console.log('izklopi', midiKanal, visina)
}, izklop * 1000)
}
}

Loading…
Cancel
Save