Improving OSC reading

This commit is contained in:
Devine Lu Linvega 2019-07-21 17:54:46 +09:00
parent 07ff69e14a
commit 76994ad373
5 changed files with 18 additions and 23 deletions

View File

@ -72,7 +72,7 @@ function Commander (ronin) {
// Logs
if (msg && msg !== this._log.textContent) {
this._log.textContent = `${msg}`
console.log(msg)
// console.log(msg)
}
// Source
const _source = `${ronin.source} ${this._input.value.split('\n').length} lines`

View File

@ -7,7 +7,7 @@ function Library (ronin) {
this.export = (path, format = 'image/png', quality = 1.0) => { // Exports a graphic file with format.
if (!path) { console.warn('Missing export path'); return path }
var dataUrl = ronin.surface.el.toDataURL(format, quality)
const dataUrl = ronin.surface.el.toDataURL(format, quality)
const data = dataUrl.replace(/^data:image\/png;base64,/, '').replace(/^data:image\/jpeg;base64,/, '')
fs.writeFileSync(path, data, 'base64')
return path
@ -350,6 +350,11 @@ function Library (ronin) {
return arg
}
this.log = (arg) => {
console.log(arg)
return arg
}
this.time = (rate = 1) => { // Returns timestamp in milliseconds.
return (Date.now() * rate)
}
@ -378,13 +383,9 @@ function Library (ronin) {
return result
}
// osc
// IO
this.osc = (...args) => { // Returns a rect of the frame.
if (args.length >= 1) {
return ronin.getOsc()[args[0]]
} else {
return ronin.getOsc()
}
this.osc = (path) => { // Returns the latest osc message at path
return path ? ronin.osc.msg[path] : ronin.osc.msg
}
}

View File

@ -3,24 +3,21 @@
function Osc (ronin) {
const osc = require('osc')
this.oscMsg = {}
this.msg = {}
this.start = function () {
var udpPort = new osc.UDPPort({
const udpPort = new osc.UDPPort({
localAddress: '0.0.0.0',
localPort: 49162,
metadata: true
})
udpPort.on('message', this.onOscMsg)
udpPort.on('message', this.onMsg)
udpPort.open()
ronin.log('osc started')
ronin.log('OSC','Started.')
}
this.onOscMsg = (oscMsg, timeTag, info) => {
this.oscMsg[oscMsg.address] = oscMsg
ronin.log('An OSC message just arrived!', oscMsg)
ronin.log('Remote info is: ', info)
this.onMsg = (msg, timeTag, info) => {
this.msg[msg.address] = msg.args
// ronin.log(`${info.address}:${info.port} > ${msg.args}`, info)
}
}

View File

@ -49,10 +49,6 @@ function Ronin () {
this.osc.start()
}
this.getOsc = function () {
return this.osc.oscMsg
}
this.reset = function () {
this.theme.reset()
}

1
examples/orca.lisp Normal file
View File

@ -0,0 +1 @@
(log (of (osc "/a") 0 "value"))