interface.server
Version:
Design interactive interfaces using various devices and OSC/0MQ/WebSockets
65 lines (55 loc) • 2.97 kB
JavaScript
var app = {
name:'test',
destinations: [
{ type:'ZeroMQ', ip:'127.0.0.1', port:10080 },
{ type:'WebSocket', ip:'127.0.0.1', port:9081 },
{ type:'OSC', ip:'127.0.0.1', port:8082 },
],
inputs: {
pitch: { min: 200, max: 300, destinations: -1, expression: function( v ) { return v * 4 } },
mute: { min: 0, max: 1, destinations: [1,2] },
volume: { min: 2, max: 10, destinations: 2 },
orientation: { destinations: 2 },
},
mappings: [
// set system state, no output
{ input: { io:'USB 2-Axis 8-Button Gamepad', name:'Button1' }, expression: function(v) { mode = v } },
// output value with no transform
{ input: { io:'USB 2-Axis 8-Button Gamepad', name:'Button1' },
output:{ io:'test', name:'blah' },
transform: false,
expression: function( v ) { return mode * .33 }
},
// quaternion, no transformation
{ input: { io:'PhaseSpace', name:'Orientation' }, transform:false, output:{ io:'text', name:'orientation'} },
// regular output with affine transform and expression
{ input: { io:'USB 2-Axis 8-Button Gamepad', name:'Button2' }
output:{ io:'test', name:'blah2' },
expression: function(v) { var out = (previous + v) / 2 ; previous = v; return out; }
}
]
}
var mode = 0, previous = 0
By default, everything uses a float type. Create a type table that matches inputs of one type to outputs of another type. If no type is declared for input or output than all raw values are transmitted. For a four-dimensional to a 2-dimensional, only use the first two dimensions. Going the other way, use a modulo.
*DONE* The transform flag is true by default, but if false, affine transforms are disabled on mappings.
*DONE* If a mapping only has an input and expression, values generated by the input are fed to the expression. This can be used to change app state and upvalues.
testApp = [
"var blah = 0, app = {",
" name:'test',",
" destinations: [",
" { type:'ZeroMQ', ip:'127.0.0.1', port:10080 },",
" { type:'WebSocket', ip:'127.0.0.1', port:9081 },",
" { type:'OSC', ip:'127.0.0.1', port:8082 }",
" ],",
" inputs: {",
" blah: { min: 200, max: 300, destinations: -1 },",
" blah2: { min: 0, max: 1, destinations: [1,2] },",
" blah3: { min: 2, max: 10, destinations: 2 },",
" },",
" mappings: [",
" { input: { io:'USB 2-Axis 8-Button Gamepad', name:'Button1' }, transform:false, output:{ io:'test', name:'blah' }, expression: function( v ) { return v * .33 } },",
" { input: { io:'USB 2-Axis 8-Button Gamepad', name:'Button2' }, expression: function(v) { blah = v } },",
" { input: { io:'USB 2-Axis 8-Button Gamepad', name:'Button3' }, output:{ io:'test', name:'blah3' }, expression: function(v) { return v * blah } },",
" ]",
"}"
].join('\n')