move osc code to separate file

This commit is contained in:
ngradwohl 2019-07-20 20:35:46 +02:00
parent e65f266aca
commit 9d11b5ba89
3 changed files with 32 additions and 22 deletions

View File

@ -9,6 +9,8 @@
<script type="text/javascript" src="scripts/surface.js"></script>
<script type="text/javascript" src="scripts/lisp.js"></script>
<script type="text/javascript" src="scripts/library.js"></script>
<script type="text/javascript" src="scripts/osc.js"></script>
<link rel="stylesheet" type="text/css" href="links/reset.css"/>
<link rel="stylesheet" type="text/css" href="links/fonts.css"/>
<link rel="stylesheet" type="text/css" href="links/main.css"/>

View File

@ -0,0 +1,27 @@
'use strict'
function Osc (ronin) {
const osc = require('osc')
this.oscMsg = {}
this.start = function () {
var udpPort = new osc.UDPPort({
localAddress: "0.0.0.0",
localPort: 12940,
metadata: true
});
udpPort.on("message", this.onOscMsg)
udpPort.open();
this.ronin.log("osc started")
}
this.onOscMsg = (oscMsg, timeTag, info) => {
this.oscMsg = oscMsg;
this.ronin.log("An OSC message just arrived!", oscMsg)
this.ronin.log("Remote info is: ", info);
}
}

View File

@ -1,5 +1,3 @@
const osc = require('osc')
function Ronin () {
const defaultTheme = {
background: '#111',
@ -21,6 +19,7 @@ function Ronin () {
this.commander = new Commander(this)
this.surface = new Surface(this)
this.library = new Library(this)
this.osc = new Osc(this)
this.oscMsg = {}
// Parameters
@ -46,29 +45,11 @@ function Ronin () {
this.source.start()
this.commander.start()
this.surface.start()
var udpPort = new osc.UDPPort({
localAddress: "0.0.0.0",
localPort: 57121,
metadata: true
});
udpPort.on("message", this.onOscMsg)
udpPort.open();
this.log("started")
console.log('Ronin', 'Started')
}
this.onOscMsg = (oscMsg, timeTag, info) => {
this.oscMsg = oscMsg;
console.log("An OSC message just arrived!", oscMsg)
this.log("Remote info is: ", info);
this.osc.start()
}
this.getOsc = function() {
return this.oscMsg;
return this.osc.oscMsg;
}
this.reset = function () {