Commit 0bf7116b authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

Add OSC sending

The presencesketch now sends OSC data via WebSockets to
ws://localhost:8080 where a bridge can translate the data to UDP

see https://github.com/adzialocha/osc-js/wiki/PureData-&-MaxMSP for the
example this was built on
parent 493a3ddd
......@@ -8,11 +8,12 @@
"dependencies": {
"interface": "git://github.com/charlieroberts/interface.js.git",
"jquery": ">= 2.1",
"osc": "^2.2.0",
"osc-js": "^1.0.2",
"p5": "^0.5.8",
"phoenix": "file:deps/phoenix",
"phoenix_html": "file:deps/phoenix_html",
"underscore": "~ 1.8.3"
"underscore": "~ 1.8.3",
"ws": "^2.3.1"
},
"devDependencies": {
"babel-brunch": "~6.0.0",
......
import p5 from "p5";
import _ from "underscore";
import OSC from "osc-js";
import {Socket, Presence} from "phoenix";
......@@ -256,6 +259,7 @@ Boid.prototype.render_star = function() {
function Master(p, x, y, type) {
Boid.call(this, p, x, y, null);
this.master = true;
this.radius = 48;
this.type = type;
this.cohesion_f = 6;
......@@ -276,12 +280,33 @@ Master.prototype.run = function(boids) {
this.update();
this.borders();
this.render();
this.send_osc();
}
Master.prototype.send_osc = function() {
let v = this.velocity.array();
//let v = this.position.array();
var message = new OSC.Message('/webosc/gyro/' + this.type, v[0], v[1] );
if ((this.p.frameCount % 30.0) == 0) {
if (PresenceSketch.osc.status() === OSC.STATUS.IS_OPEN) {
PresenceSketch.osc.send(message);
}
}
}
Boid.prototype.adjust_radius = function() {
if (this.radius > this.norm_radius) { this.radius = this.radius - 1; };
}
Master.prototype.adjust_radius = function() {
}
Boid.prototype.render = function() {
this.p.fill((this.radius));
this.p.fill((this.radius * 8) -1);
this.p.stroke(200);
this.p.push();
......@@ -300,6 +325,7 @@ Boid.prototype.render = function() {
}
this.p.pop();
this.adjust_radius();
}
......@@ -315,6 +341,7 @@ let PresenceSketch = {
boids: {},
p5: null,
presences: {},
osc: {},
masters: {}, // holds the four main instruments
......@@ -423,6 +450,24 @@ let PresenceSketch = {
return;
}
PresenceSketch.osc = new OSC();
PresenceSketch.osc.open(); // connect to ws://localhost:8080
console.log("OSC openend");
PresenceSketch.osc.on("open",() => {
console.log("osc ws connection open");
});
PresenceSketch.osc.on("close",() => {
console.log("osc ws connection closed");
PresenceSketch.osc.open(); // connect to ws://localhost:8080
});
PresenceSketch.osc.on("error",(err) => {
console.log("osc ws connection error", err);
});
new p5(this.sketch, domId);
}
......
......@@ -26,7 +26,6 @@
</div> <!-- /container -->
<script>window.userToken = "<%= assigns[:user_token] %>"</script>
<script src="<%= static_path(@conn, "/js/myp5.js") %>"></script>
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment