new feature : preArgs option to prepend constant values in widgets' osc messages

This commit is contained in:
jean-emmanuel 2016-03-22 16:52:34 +01:00
parent f04cd39587
commit 44da95dcec
21 changed files with 387 additions and 125 deletions

View file

@ -9,17 +9,25 @@ module.exports = {
var data = data || event
// fetch ids corresponding to the osc path
var path = data.path
var ids = WIDGETS_ID_BY_PATH[path]
var path = data.path,
pathref = path,
args = data.args
for (i in ids) {
var id = ids[i]
// update
if (WIDGETS[id]) {
for (j in WIDGETS[id]){
WIDGETS[id][j].setValue(data.args,false,true)
if (typeof data.args == 'object') {
for (var i=data.args.length-1;i>=0;i--) {
var ref = path+'|--|--|'+data.args.slice(0,i).join('|--|--|')
if (WIDGETS_BY_PATH[ref]) {
pathref = ref
args = data.args.slice(i,data.args.length)
args = args.length==1?args[0]:args
continue
}
}
} else {
args = data.args
}
for (i in WIDGETS_BY_PATH[pathref]) {
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,false,true)
}

View file

@ -55,4 +55,14 @@ module.exports = function() {
delete WIDGETS_LINKED[i]
}
}
for (i in WIDGETS_BY_PATH) {
for (var j=WIDGETS_BY_PATH[i].length-1;j>=0;j--) {
if (!$b.find(WIDGETS_BY_PATH[i][j]).length) {
WIDGETS_BY_PATH[i].splice(j,1)
}
}
if (!WIDGETS_BY_PATH[i].length) {
delete WIDGETS_BY_PATH[i]
}
}
}

View file

@ -19,7 +19,7 @@ module.exports.tabs = function(data,parent,main,parentLabel){
// Reset Globals
WIDGETS = {}
WIDGETS_LINKED = {}
WIDGETS_ID_BY_PATH = {}
WIDGETS_BY_PATH = {}
SESSION = data
TABS['#container'] = {
tab:$('#container')
@ -120,6 +120,10 @@ module.exports.widgets = function(data,parent) {
delete widgetData.left
}
if (widgetData.preArgs!=undefined) {
widgetData.preArgs = Array.isArray(widgetData.preArgs)?widgetData.preArgs:[widgetData.preArgs]
}
var width = parseFloat(widgetData.width)==widgetData.width?parseFloat(widgetData.width)+'rem' : widgetData.width,
height = parseFloat(widgetData.height)==widgetData.height?parseFloat(widgetData.height)+'rem' : widgetData.height,
left = parseFloat(widgetData.left)==widgetData.left?parseFloat(widgetData.left)+'rem' : widgetData.left,
@ -160,8 +164,11 @@ module.exports.widgets = function(data,parent) {
}
// store path vs widget id for faster cross-app sync
if (WIDGETS_ID_BY_PATH[widgetData.path]==undefined) WIDGETS_ID_BY_PATH[widgetData.path] = []
WIDGETS_ID_BY_PATH[widgetData.path].push(widgetData.id)
if (widgetData.path)  {
var pathref = widgetData.preArgs&&widgetData.preArgs.length?widgetData.path+'|--|--|'+widgetData.preArgs.join('|--|--|'):widgetData.path
if (WIDGETS_BY_PATH[pathref]==undefined) WIDGETS_BY_PATH[pathref] = []
WIDGETS_BY_PATH[pathref].push(widgetInner)
}
parent[0].appendChild(widgetContainer[0])
}

View file

@ -32,6 +32,7 @@ module.exports.options = {
precision:2,
meter:false,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -56,7 +57,9 @@ module.exports.create = function(widgetData,container) {
dimension = widgetData.horizontal?'width':'height',
axe = dimension=='height'?'X':'Y',
absolute = widgetData.absolute,
logScale = widgetData.logScale
logScale = widgetData.logScale,
roundFactor = Math.pow(10,widgetData.precision)
if (widgetData.horizontal) container.addClass('horizontal')
@ -73,7 +76,8 @@ module.exports.create = function(widgetData,container) {
horizontal:widgetData.horizontal,
range:widgetData.range,
logScale:widgetData.logScale,
path:widgetData.path + '/meter'
path:widgetData.path + '/meter',
preArgs:widgetData.preArgs
}
var element = parsewidgets([data],fader)
element[0].classList.add('not-editable')
@ -196,7 +200,7 @@ module.exports.create = function(widgetData,container) {
}
widget.setValue = function(v,send,sync) {
var h,
v=clip(v,[rangeVals[0],rangeVals.slice(-1)[0]])
v=clip(Math.round(v*roundFactor)/roundFactor,[rangeVals[0],rangeVals.slice(-1)[0]])
for (var i=0;i<rangeVals.length-1;i++) {
if (v <= rangeVals[i+1] && v >= rangeVals[i]) {
h = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i],rangeKeys[i+1]],widgetData.precision,logScale,true)
@ -216,11 +220,13 @@ module.exports.create = function(widgetData,container) {
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
sendOsc({
target:widgetData.target,
path:widgetData.path,
precision:widgetData.precision,
args:v
args:args
})
}

View file

@ -31,6 +31,7 @@ module.exports.options = {
logScale:false,
precision:2,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -59,7 +60,8 @@ module.exports.create = function(widgetData,container) {
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
absolute = widgetData.absolute,
pan = widgetData.pan,
logScale = widgetData.logScale
logScale = widgetData.logScale,
roundFactor = Math.pow(10,widgetData.precision)
var pipmin = Math.abs(range.min)>=1000?range.min/1000+'k':range.min,
@ -180,15 +182,17 @@ module.exports.create = function(widgetData,container) {
input.val(v+unit)
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
sendOsc({
target:widgetData.target,
path:widgetData.path,
precision:widgetData.precision,
args:v
args:args
})
}
widget.setValue = function(v,send,sync) {
var r = mapToScale(v,[range.min,range.max],[0,270],widgetData.precision,logScale,true)
var r = mapToScale(Math.round(v*roundFactor)/roundFactor,[range.min,range.max],[0,270],widgetData.precision,logScale,true)
knob.rotation = r
widget.updateUi(r)

View file

@ -19,6 +19,7 @@ module.exports.options = {
range:{min:0,max:1},
logScale:false,
preArgs:[],
path:'auto'
}
module.exports.create = function(widgetData,container) {
@ -38,6 +39,6 @@ module.exports.create = function(widgetData,container) {
}
widget.setValue(range.min)
return widget
}

View file

@ -23,7 +23,8 @@ module.exports.options = {
range:{min:0,max:1},
logScale:false,
path:'auto'
path:'auto',
preArgs:[]
}
module.exports.create = function(widgetData,container) {

View file

@ -24,6 +24,7 @@ module.exports.options = {
logScale:false,
precision:2,
path:'auto',
preArgs:[],
target:[]
}
@ -50,6 +51,7 @@ module.exports.create = function(widgetData,container) {
logScale:widgetData.logScale,
precision:widgetData.precision,
path:widgetData.path + '/' + i,
preArgs:widgetData.preArgs,
target:widgetData.target
}
var element = parsewidgets([data],widget)

View file

@ -22,6 +22,7 @@ module.exports.options = {
off:0,
precision:2,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -45,6 +46,7 @@ module.exports.create = function(widgetData,container) {
off:widgetData.off,
precision:widgetData.precision,
path:widgetData.path + '/' + i,
preArgs:widgetData.preArgs,
target:widgetData.target
}
var element = parsewidgets([data],widget)

View file

@ -22,6 +22,7 @@ module.exports.options = {
off:0,
precision:2,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -45,6 +46,7 @@ module.exports.create = function(widgetData,container) {
off:widgetData.off,
precision:widgetData.precision,
path:widgetData.path + '/' + i,
preArgs:widgetData.preArgs,
target:widgetData.target
}
var element = parsewidgets([data],widget)

View file

@ -25,7 +25,8 @@ module.exports.options = {
separator3:'osc',
path:'auto'
path:'auto',
preArgs:[],
}
module.exports.create = function(widgetData,container) {

View file

@ -21,6 +21,7 @@ module.exports.options = {
off:0,
precision:2,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -73,11 +74,12 @@ module.exports.create = function(widgetData,container) {
}
widget.sendValue = function(v) {
if (v===false) return
var args = widgetData.preArgs.concat(v)
sendOsc({
target:widgetData.target,
path:widgetData.path,
precision:widgetData.precision,
args:v
args:args
})
}
widget.setValue()

View file

@ -27,6 +27,7 @@ module.exports.options = {
precision:0,
path:'auto',
preArgs:[],
split:false,
target:[]
}
@ -210,31 +211,33 @@ module.exports.create = function(widgetData,container) {
if (send) widget.sendValue(v)
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
sendOsc({
target:split?false:widgetData.target,
path:widgetData.path,
args:v,
args:args,
precision:widgetData.precision,
})
if (split) {
sendOsc({
target:widgetData.target,
path:split.r,
args:v[0],
args:widgetData.preArgs.concat(v[0]),
precision:widgetData.precision,
sync:false
})
sendOsc({
target:widgetData.target,
path:split.g,
args:v[1],
args:widgetData.preArgs.concat(v[1]),
precision:widgetData.precision,
sync:false
})
sendOsc({
target:widgetData.target,
path:split.b,
args:v[2],
args:widgetData.preArgs.concat(v[2]),
precision:widgetData.precision,
sync:false
})

View file

@ -21,6 +21,7 @@ module.exports.options = {
values:{"Value 1":1,"Value 2":2},
precision:2,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -71,11 +72,13 @@ module.exports.create = function(widgetData,container) {
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
sendOsc({
target:widgetData.target,
path:widgetData.path,
precision:widgetData.precision,
args:v
args:args
})
}
return widget

View file

@ -21,6 +21,7 @@ module.exports.options = {
off:0,
precision:2,
path:'auto',
preArgs:[],
target:[]
}
module.exports.create = function(widgetData,container) {
@ -71,11 +72,13 @@ module.exports.create = function(widgetData,container) {
}
widget.sendValue = function(v) {
if (v===false) return
var args = widgetData.preArgs.concat(v)
sendOsc({
target:widgetData.target,
path:widgetData.path,
precision:widgetData.precision,
args:v
args:args
})
}
widget.setValue()

View file

@ -25,7 +25,8 @@ module.exports.options = {
separator3:'osc',
path:'auto'
path:'auto',
preArgs:[],
}
module.exports.create = function(widgetData,container) {

View file

@ -30,6 +30,7 @@ module.exports.options = {
logScaleY:false,
precision:2,
path:'auto',
preArgs:[],
split:false,
target:[]
}
@ -55,7 +56,8 @@ module.exports.create = function(widgetData,container) {
widgetData.split:{x:widgetData.path+'/x',y:widgetData.path+'/y'}
:false;
logScaleX = widgetData.logScaleX,
logScaleY = widgetData.logScaleY
logScaleY = widgetData.logScaleY,
roundFactor = Math.pow(10,widgetData.precision)
if (widgetData.height!='auto') widget.addClass('manual-height')
@ -131,7 +133,7 @@ module.exports.create = function(widgetData,container) {
if (!v || v.length!=2) return
for (i in [0,1]) {
v[i] = clip(v[i],[range[['x','y'][i]].min,range[['x','y'][i]].max])
v[i] = clip(Math.round(v[i]*roundFactor)/roundFactor,[range[['x','y'][i]].min,range[['x','y'][i]].max])
}
var w = mapToScale(v[0],[range.x.min,range.x.max],[0,100],widgetData.precision,logScaleX,true)
@ -148,24 +150,26 @@ module.exports.create = function(widgetData,container) {
if (send) widget.sendValue(v)
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
sendOsc({
target:split?false:widgetData.target,
path:widgetData.path,
args:v,
args:args,
precision:widgetData.precision,
})
if (split) {
sendOsc({
target:widgetData.target,
path:split.x,
args:v[0],
args:widgetData.preArgs.concat(v[0]),
precision:widgetData.precision,
sync:false
})
sendOsc({
target:widgetData.target,
path:split.y,
args:v[1],
args:widgetData.preArgs.concat(v[1]),
precision:widgetData.precision,
sync:false
})