Send relative or absolute values for instruments

The "abs" button in the mixer toggles between sending the X/Y
Position (scaled to +- PI) or the dx/dy components of the current
velocity vector (again scaled to +- PI)
parent 3e074633
......@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do
[app: :grains,
version: "0.0.96",
version: "0.0.97",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
......@@ -6,6 +6,7 @@ let MixerPanel = {
presence: {},
sliders: {},
buttons: {},
init(socket, domId, sliders, presence) {
if (!document.getElementById(domId)) {
......@@ -41,27 +42,30 @@ let MixerPanel = {
label: s,
onvaluechange: function() {
console.log(s, this.value);
that.presence.set_volume(s, this.value);
// that.send_value(s, this.value);
}
});
this.buttons[s] = new Interface.Button({
bounds: [(1/nrSliders) * idx, .6, 1 / nrSliders, .1],
label:'Abs',
onvaluechange: function() {
that.presence.set_absolute(s, this.value);
}
});
console.log(s);
a.add(this.sliders[s]);
a.add(this.buttons[s]);
});
a.background = 'black';
console.log("initialized slider");
},
send_value(slider, value) {
let payload = {slider: slider, value: value};
this.sliderChannel.push("slider", payload)
.receive("error", e => console.log(e));
}
},
};
......
......@@ -271,6 +271,7 @@ function Master(p, x, y, type) {
this.separation_f = 1;
this.alignment_f = 2;
this.volume = 1.0;
this.absolute = false;
}
......@@ -292,8 +293,16 @@ Master.prototype.run = function(boids) {
}
Master.prototype.send_osc = function() {
let v = [0,0];
if (this.absolute) {
v[0] = (this.position.x * PresenceSketch.scale_x) + 3.14;
v[1] = (this.position.y * PresenceSketch.scale_y) + 3.14;
} else {
v = this.velocity.array();
}
let v = this.velocity.array();
//let v = this.position.array();
var message = new OSC.Message('/webosc/gyro/' + this.type, v[0], v[1], this.agitation, this.volume );
......@@ -310,6 +319,10 @@ Master.prototype.set_volume = function(vol) {
this.volume = vol;
}
Master.prototype.set_absolute = function(flag) {
this.absolute = (flag === 1) ? true : false;
}
Boid.prototype.agitate = function(list) {
if (this.agitation >= this.activation) {
this.agitation -= this.recovery;
......@@ -399,6 +412,8 @@ let PresenceSketch = {
width: 960,
height: 750,
scale_x: 1,
scale_y: 1,
boids: {},
p5: null,
presences: {},
......@@ -416,6 +431,14 @@ let PresenceSketch = {
}
},
set_absolute(type, abs_flag) {
console.log("set_absolute", type, abs_flag);
let master = PresenceSketch.masters[type];
if (master) {
master.set_absolute(abs_flag);
}
},
set_velocity(name, dx, dy) {
let boid = PresenceSketch.boids[name];
if (boid) {
......@@ -558,6 +581,9 @@ let PresenceSketch = {
PresenceSketch.width = w;
PresenceSketch.height = h;
PresenceSketch.scale_x = -6.28 / w;
PresenceSketch.scale_y = -6.28 / h;
PresenceSketch.osc = new OSC();
PresenceSketch.osc.open(); // connect to ws://localhost:8080
console.log("OSC openend");
......
......@@ -25,12 +25,12 @@ export default class View extends MainView {
let visuals = socket.channel("visuals:data", {});
visuals.on("velocity", state => {
console.log("velocity: ", state);
// console.log("velocity: ", state);
PresenceSketch.set_velocity(state.user, state.dy, state.dx);
});
visuals.on("acceleration", state => {
console.log("acceleration: ", state);
// console.log("acceleration: ", state);
PresenceSketch.set_acceleration(state.user, state.force);
});
......@@ -52,7 +52,7 @@ export default class View extends MainView {
}
render(presences, diff) {
console.log("ConductorIndexView.render()")
console.log("ConductorIndexView.render()");
super.render(presences, diff);
if (diff) {
......
Markdown is supported
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