Ločeni thresholdi na keglih

main
Tjaž 2022-09-17 14:25:02 +02:00
parent b8e87c8ae0
commit 1f55fe5df8
1 changed files with 37 additions and 16 deletions

View File

@ -32,10 +32,10 @@ oscWS.on('ready', () => {
*/
})
const zaznava = 0.8
const utisaj_vse = 0.1
let cakaj = false
const zaznava = [2, 2.5, 2, 2, 2, 2]
const utisaj_vse = 0.2
let utisaj_c = [0, 0, 0, 0, 0, 0]
let cakaj = [false, false, false, false, false, false]
const cakajInterval = 1 / 5
const razponTona = [0.1, 0.5]
@ -51,7 +51,7 @@ oscWS.on('message', ({ address, args }) => {
const m = address.match(re)
if (m) {
const index = m[1]
const index = parseInt(m[1])
const addr = m[2]
if (addr == 'euler') {
@ -67,22 +67,22 @@ oscWS.on('message', ({ address, args }) => {
const acZ = args[2]
// Y os je kegel po dolgem - ignoriramo
const vsota = acX + acZ
const vsota = Math.abs(acX) + Math.abs(acZ)
if (vsota > zaznava && !cakaj) {
if (vsota > zaznava[index] && !cakaj[index]) {
cakaj = true
cakaj[index] = true
// Pavza
setTimeout(() => {
//console.log("nehaj cakat")
cakaj = false
cakaj[index] = false
}, cakajInterval * 1000)
const midiKanal = 144 + parseInt(index)
const midiKanal = 144 + index
// Od 24 do 48
const accval = Math.sin((vsota - zaznava) / 3)
const accval = Math.sin((vsota - zaznava[index]) / 3)
//console.log(acX, accval)
// Acc visina
const visina = (midiKanal == 0)
@ -106,6 +106,7 @@ oscWS.on('message', ({ address, args }) => {
// Ugasni cez en cas
let izklop = razponTona[0] + Math.random() * (razponTona[1] - razponTona[0])
console.log('izklopim', midiKanal, visina, 'cez', izklop)
setTimeout(() => {
oscWS.send({
address: '/midi',
@ -116,13 +117,33 @@ oscWS.on('message', ({ address, args }) => {
}
// Ce izrazito ni gibanja, utisaj vse!
if (!utisaj_c[index]) {
utisaj_c[index] = 0
}
if (vsota < utisaj_vse) {
console.log("UTISAJ")
if (utisaj_c[index] > 10) {
const midiKanal = 144 + index
const visina = (midiKanal == 0)
? 24
: 48
const visina_razpon = (midiKanal == 0)
? 36
: 72
console.log("UTISAJ", index)
for (let i = visina; i < visina + visina_razpon; i++) {
oscWS.send({
address: '/midi',
args: [120, 0, 0]
args: [midiKanal, i, 0]
})
}
utisaj_c[index] = 0
} else {
// console.log('.')
utisaj_c[index] += 1
}
} else {
utisaj_c[index] = 0
}
}
} else {
console.log(address)