From e65f266acabb1cd13dfc2c87ce4f9d367cb3314f Mon Sep 17 00:00:00 2001 From: ngradwohl Date: Sat, 20 Jul 2019 16:02:51 +0200 Subject: [PATCH 1/3] first osc msg tests --- desktop/main.js | 1 + desktop/package.json | 7 ++++++- desktop/sources/scripts/library.js | 7 +++++++ desktop/sources/scripts/ronin.js | 25 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/desktop/main.js b/desktop/main.js index 33934bd..d0cfba2 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -1,6 +1,7 @@ const { app, BrowserWindow, webFrame, Menu } = require('electron') const path = require('path') const url = require('url') +const osc = require('osc') const shell = require('electron').shell let isShown = true diff --git a/desktop/package.json b/desktop/package.json index fd78a06..b846576 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -4,6 +4,7 @@ "main": "main.js", "scripts": { "start": "electron .", + "install": "electron-rebuild", "clean": "rm -r ~/Desktop/Ronin-darwin-x64/ ; rm -r ~/Desktop/Ronin-linux-x64/ ; rm -r ~/Desktop/Ronin-win32-x64/ ; echo 'cleaned build location'", "build_osx": "electron-packager . Ronin --platform=darwin --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.icns ; echo 'Built for OSX'", "build_linux": "electron-packager . Ronin --platform=linux --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.ico ; echo 'Built for LINUX'", @@ -16,8 +17,12 @@ "push_status": "~/butler status hundredrabbits/ronin", "push": "npm run build ; npm run push_theme ; npm run push_osx ; npm run push_linux ; npm run push_win ; npm run clean ; npm run push_status" }, + "dependencies": { + "osc": "^2.3.1" + }, "devDependencies": { "electron": "^5.0.6", - "electron-packager": "^13.1.1" + "electron-packager": "^13.1.1", + "electron-rebuild": "^1.8.5" } } diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index ea3483a..39167f9 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -374,4 +374,11 @@ function Library (ronin) { console.log(`time taken: ${Date.now() - start}ms`) return result } + + // osc + + this.osc = () => { // Returns a rect of the frame. + return ronin.getOsc() + } + } diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index 1e229c7..b492a9c 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -1,3 +1,5 @@ +const osc = require('osc') + function Ronin () { const defaultTheme = { background: '#111', @@ -20,6 +22,7 @@ function Ronin () { this.surface = new Surface(this) this.library = new Library(this) + this.oscMsg = {} // Parameters this.always = false @@ -43,9 +46,31 @@ 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.getOsc = function() { + return this.oscMsg; + } + this.reset = function () { this.theme.reset() } From 9d11b5ba89807d324204b8bab9b6254cbe337cc8 Mon Sep 17 00:00:00 2001 From: ngradwohl Date: Sat, 20 Jul 2019 20:35:46 +0200 Subject: [PATCH 2/3] move osc code to separate file --- desktop/sources/index.html | 2 ++ desktop/sources/scripts/osc.js | 27 +++++++++++++++++++++++++++ desktop/sources/scripts/ronin.js | 25 +++---------------------- 3 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 desktop/sources/scripts/osc.js diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 955ce4b..ce0e6c2 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -9,6 +9,8 @@ + + diff --git a/desktop/sources/scripts/osc.js b/desktop/sources/scripts/osc.js new file mode 100644 index 0000000..21e87d2 --- /dev/null +++ b/desktop/sources/scripts/osc.js @@ -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); + } +} diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index b492a9c..7f13811 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -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 () { From 70c8625db7007488dd3a894a8be85c7762c5733e Mon Sep 17 00:00:00 2001 From: ngradwohl Date: Sun, 21 Jul 2019 04:06:12 +0200 Subject: [PATCH 3/3] add example, update readme --- README.md | 1 + examples/osc1.lisp | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 examples/osc1.lisp diff --git a/README.md b/README.md index b1251db..8bd3240 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Additional functions can be found in the [includes](https://github.com/hundredra - `(js)` Javascript interop. - `(test name a b)` - `(benchmark fn)` logs time taken to execute a function. +- `(osc ~address)` returns the last received osc msg on port 12940 ## Extras diff --git a/examples/osc1.lisp b/examples/osc1.lisp new file mode 100644 index 0000000..70e1e6f --- /dev/null +++ b/examples/osc1.lisp @@ -0,0 +1,11 @@ +(clear) +(def x (of (osc "/test") "args" "0" "value")) +(def y (of (osc "/test") "args" "1" "value")) +(def r (of (osc "/test") "args" "2" "value")) + +(fill +(circle x y r) +"red") +(stroke +(circle x y r) +5 "white")