kegel/bitwig.js

178 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-09-20 21:42:52 +02:00
const WebSocket = require('ws')
const osc = require('osc')
const wwIP = process.argv[2]
const bwIP = process.argv[3]
2022-09-20 21:42:52 +02:00
const DEBUG = {
osc: true
}
const oscWS = new osc.WebSocketPort({
url: `ws://${wwIP}:6676`,
2022-09-20 21:42:52 +02:00
metadata: false
})
const bwPortUkazi = 8000
const bwPortStanje = 9000
const oscBW = new osc.UDPPort({
2022-09-20 21:42:52 +02:00
localAddress: bwIP,
remotePort: bwPortUkazi,
2022-09-20 21:42:52 +02:00
localPort: bwPortStanje,
metadata: false
})
oscWS.on('ready', () => {
console.log(`Povezan sem na WW ${wwIP}`)
2022-09-20 21:42:52 +02:00
/*
setInterval(() => {
console.log('ping')
oscWS.send({ address: '/ping', args: [true]})
}, 500)
*/
})
oscBW.on('ready', () => {
console.log(`Povezan sem na bitwig ${bwIP}`)
2022-09-20 21:42:52 +02:00
})
2022-11-30 14:54:31 +01:00
oscWSstanje.on('error', () => console.log('napaka stanja', arguments))
2022-09-20 21:42:52 +02:00
const STANJE = {
predvajam: 0,
2022-10-25 21:08:43 +02:00
track: 1,
clip: 1,
trackCount: 2,
trackAbs: 1,
}
2022-09-20 21:42:52 +02:00
oscWS.on('message', ({ address, args }) => {
DEBUG.osc && console.log('MSG OSC', address, args.map(x => x.toFixed(4)))
// Wavey Wind sporočila
const re = /\/ww\/(\d+)\/([a-zA-Z]+)/
const m = address.match(re)
if (m) {
console.log(address, m)
let bwUkaz = '/' + address.split('/').splice(3).join('/')
if (STANJE.predvajam && bwUkaz == '/play') {
bwUkaz = '/stop'
2022-10-25 21:08:43 +02:00
oscBW.send({ address: bwUkaz })
} else {
oscBW.send({ address: bwUkaz })
}
2022-10-25 21:08:43 +02:00
switch (bwUkaz) {
case '/play':
if (STANJE.predvajam) {
bwUkaz = '/stop'
oscBW.send({ address: bwUkaz })
} else {
oscBW.send({ address: bwUkaz })
}
break
case '/track/next':
console.log("NASLEDNJI TRACK", STANJE.track+1)
var novTrack = STANJE.track + 1
if (novTrack > 8) {
bwUkaz = `/track/bank/+`
oscBW.send({ address: bwUkaz })
setTimeout(() => {
bwUkaz = `/track/${STANJE.track}/select`
oscBW.send({ address: bwUkaz })
bwUkaz = `/track/${STANJE.track}/clip/${STANJE.clip}/select`
oscBW.send({ address: bwUkaz })
}, 50)
} else {
bwUkaz = `/track/${novTrack}/select`
oscBW.send({ address: bwUkaz })
bwUkaz = `/track/${novTrack}/clip/${STANJE.clip}/select`
oscBW.send({ address: bwUkaz })
}
break
case '/track/previous':
console.log("PREJSNJI TRACK", STANJE.track-1)
var novTrack = STANJE.track - 1
if (novTrack >= 1) {
bwUkaz = `/track/${novTrack}/select`
console.log(bwUkaz)
oscBW.send({ address: bwUkaz })
bwUkaz = `/track/${novTrack}/clip/${STANJE.clip}/select`
oscBW.send({ address: bwUkaz })
console.log(bwUkaz)
} else {
bwUkaz = `/track/bank/-`
oscBW.send({ address: bwUkaz })
setTimeout(() => {
bwUkaz = `/track/${STANJE.track}/select`
oscBW.send({ address: bwUkaz })
bwUkaz = `/track/${STANJE.track}/clip/${STANJE.clip}/select`
oscBW.send({ address: bwUkaz })
}, 50)
}
break
case '/clip/next':
var novClip = STANJE.clip + 1
console.log("NASLEDNJI CLIP", novClip)
if (novClip > 8) {
} else {
bwUkaz = `/track/${STANJE.track}/clip/${novClip}/select`
console.log("POSILJAM", bwUkaz)
oscBW.send({ address: bwUkaz })
}
break
case '/clip/previous':
var novClip = STANJE.clip - 1
console.log("PREJSNJI CLIP", novClip)
if (STANJE.clip - 1 >= 1) {
bwUkaz = `/track/${STANJE.track}/clip/${novClip}/select`
oscBW.send({ address: bwUkaz })
} else {
}
break
}
2022-09-20 21:42:52 +02:00
}
})
oscBW.on('message', ({ address, args }) => {
DEBUG.osc && console.log('BITWIG OSC', address, args)
if (address == '/play') {
2022-10-25 21:08:43 +02:00
console.log('MENJAVA STANJA PLAY', args)
STANJE.predvajam = args[0]
}
2022-10-25 21:08:43 +02:00
let re = /\/track\/(\d+)\/clip\/(\d+)\/isSelected/
let m = address.match(re)
if (m) {
if (args[0]) {
STANJE.track = parseInt(m[1])
STANJE.clip = parseInt(m[2])
console.log('MENJAVA STANJA TRACKA', STANJE.track, STANJE.clip)
console.log(address, args)
}
}
re = /\/master\/position/
m = address.match(re)
if (m) {
STANJE.trackCount = args[0] - 1
console.log("STEVILO TRACKOV", STANJE.trackCount)
}
2022-10-25 21:08:43 +02:00
/*
re = /\/track\/selected\/clip\/(\d+)\/isSelected/
m = address.match(re)
if (m) {
if (args[0]) {
STANJE.clip = parseInt(m[1])
console.log('MENJAVA STANJA CLIPA', STANJE.clip, m)
}
console.log(address, args)
}
*/
2022-09-20 21:42:52 +02:00
})
oscWS.open()
oscBW.open()