4 changed files with 2669 additions and 0 deletions
-
1.gitignore
-
101kegel.js
-
2554package-lock.json
-
13package.json
@ -0,0 +1,101 @@ |
|||
const WebSocket = require('ws') |
|||
const osc = require('osc') |
|||
|
|||
const ip = process.argv[2] |
|||
|
|||
//const ws = new WebSocket(`ws://${ip}:6676`)
|
|||
|
|||
/* |
|||
const wsp = new osc.WebsocketClientPlugin({ |
|||
host: ip, |
|||
port: 6676 |
|||
}) |
|||
*/ |
|||
const oscWS = new osc.WebSocketPort({ |
|||
url: `ws://${ip}:6676`, |
|||
metadata: false |
|||
}) |
|||
|
|||
oscWS.on('ready', () => { |
|||
console.log(`Povezan sem na ${ip}`) |
|||
|
|||
/* |
|||
setInterval(() => { |
|||
console.log('ping') |
|||
oscWS.send({ address: '/ping', args: [true]}) |
|||
}, 500) |
|||
*/ |
|||
}) |
|||
|
|||
let midiOn = false |
|||
let midiNotes = {} |
|||
|
|||
const zaznava = 2000 |
|||
|
|||
let cakaj = false |
|||
const cakajInterval = 1 / 5 |
|||
//const razponTona = [0.1, 0.5]
|
|||
const razponTona = [0.001, 0.002] |
|||
|
|||
|
|||
oscWS.on('message', ({ address, args }) => { |
|||
//console.log('GGOT MSG OSC', address, args)
|
|||
const acX = args[1] |
|||
if (address == '/accel') { |
|||
if (acX > zaznava && !cakaj) { |
|||
if (cakaj) { |
|||
console.log("CAKAM!") |
|||
return |
|||
} |
|||
|
|||
cakaj = true |
|||
|
|||
// Pavza
|
|||
setTimeout(() => { |
|||
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) |
|||
|
|||
midiNotes[visina] = true |
|||
//console.log('posiljam midi', [144, visina, 127])
|
|||
oscWS.send({ |
|||
address: '/midi', |
|||
args: [144, visina, 127] |
|||
}) |
|||
console.log('vklopi', visina) |
|||
|
|||
midiOn = true |
|||
|
|||
// Ugasni cez en cas
|
|||
let izklop = razponTona[0] + Math.random() * (razponTona[1] - razponTona[0]) |
|||
setTimeout(() => { |
|||
oscWS.send({ |
|||
address: '/midi', |
|||
args: [128, visina, 127] |
|||
}) |
|||
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 |
|||
} |
|||
*/ |
|||
} |
|||
}) |
|||
|
|||
|
|||
oscWS.open() |
2554
package-lock.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,13 @@ |
|||
{ |
|||
"name": "kegel", |
|||
"version": "0.1.0", |
|||
"description": "kiberkegel", |
|||
"dependencies": { |
|||
"nodemon": "^2.0.16", |
|||
"osc": "^2.4.2", |
|||
"ws": "^7.3.1" |
|||
}, |
|||
"scripts": { |
|||
"start": "npx nodemon kegel.js" |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue