Midi relay za kegel

main
Jurij Podgoršek 2022-05-07 16:57:02 +02:00
parent 6c4f3fb032
commit b4645bf161
4 changed files with 2669 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
.*~undo-tree~
.~lock*#
.*.swp
node_modules

101
kegel.js 100644
View File

@ -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 generated 100644

File diff suppressed because it is too large Load Diff

13
package.json 100644
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"
}
}