osc: use 'address' instead of 'path' everywhere to avoid confusion

This commit is contained in:
jean-emmanuel 2016-11-02 08:54:53 +01:00
parent b397115e54
commit 4552bd6657
29 changed files with 80 additions and 77 deletions

View file

@ -2,7 +2,7 @@
WIDGETS = {}
WIDGETS_LINKED = {}
WIDGETS_BY_PATH = {}
WIDGETS_BY_ADDRESS = {}
SESSION = []
STATE = []

View file

@ -8,17 +8,17 @@ module.exports = {
receiveOsc: function(event,data){
var data = data || event
// fetch ids corresponding to the osc path
var path = data.path,
pathref = path,
// fetch ids corresponding to the osc address
var address = data.address,
addressref = address,
args = data.args,
target = data.target
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
var ref = address+'||||'+data.args.slice(0,i).join('||||')
if (WIDGETS_BY_ADDRESS[ref]) {
addressref = ref
args = data.args.slice(i,data.args.length)
continue
}
@ -31,13 +31,13 @@ module.exports = {
if (args.length==0) args = null
else if (args.length==1) args = args[0]
for (i in WIDGETS_BY_PATH[pathref]) {
for (i in WIDGETS_BY_ADDRESS[addressref]) {
// if the message target is provided (when message comes from another client connected to the same server)
// then we only update the widgets that have the same target
// compare arrays using > and < operators (both false = equality)
if (!target || !(WIDGETS_BY_PATH[pathref][i].target < target || WIDGETS_BY_PATH[pathref][i].target > target)) {
if (!target || !(WIDGETS_BY_ADDRESS[addressref][i].target < target || WIDGETS_BY_ADDRESS[addressref][i].target > target)) {
// update matching widgets
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,{send:false,sync:true,fromExternal:!target})
if (WIDGETS_BY_ADDRESS[addressref][i]) WIDGETS_BY_ADDRESS[addressref][i].setValue(args,{send:false,sync:true,fromExternal:!target})
}
}

View file

@ -117,27 +117,27 @@ var incrementWidget = function(data){
var id = data.id,
label = data.label,
path = data.path
address = data.address
if (id && id==label) {
data.label = 'auto'
}
if (id && path == '/'+id) {
if (id && address == '/'+id) {
data.path = 'auto'
data.address = 'auto'
} else if (path){
var pathref
while (WIDGETS_BY_PATH[pathref]) {
path = path.replace(/([0-9]*)$/,function(m){
} else if (address){
var addressref
while (WIDGETS_BY_ADDRESS[addressref]) {
address = address.replace(/([0-9]*)$/,function(m){
var n = parseInt(m)+1
n = isNaN(n)?1:n
return n
})
pathref = data.preArgs&&data.preArgs.length?path+'||||'+data.preArgs.join('||||'):path
addressref = data.preArgs&&data.preArgs.length?address+'||||'+data.preArgs.join('||||'):address
}
WIDGETS_BY_PATH[pathref] = []
data.path = path
WIDGETS_BY_ADDRESS[addressref] = []
data.address = address
}

View file

@ -20,7 +20,7 @@ module.exports.tabs = function(data,parent,main,parentLabel){
// Reset Globals
WIDGETS = {}
WIDGETS_LINKED = {}
WIDGETS_BY_PATH = {}
WIDGETS_BY_ADDRESS = {}
SESSION = data
for (i in TABS) {
if (i!='#container') {
@ -101,7 +101,9 @@ module.exports.widgets = function(data,parent) {
widgetData.id = id
}
widgetData.path = widgetData.path=='auto'?'/' + widgetData.id:widgetData.path
if (widgetData.path) widgetData.address = widgetData.path
widgetData.address = widgetData.address=='auto'?'/' + widgetData.id:widgetData.address
widgetData.target = widgetData.target?(Array.isArray(widgetData.target)?widgetData.target:[widgetData.target]):false
for (i in widgetData) {
@ -170,11 +172,11 @@ module.exports.widgets = function(data,parent) {
WIDGETS_LINKED[widgetData.linkId].push(widgetInner)
}
// store widget by path and encode preArgs for perfect cross-app sync
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)
// store widget by address and encode preArgs for perfect cross-app sync
if (widgetData.address)  {
var addressref = widgetData.preArgs&&widgetData.preArgs.length?widgetData.address+'||||'+widgetData.preArgs.join('||||'):widgetData.address
if (WIDGETS_BY_ADDRESS[addressref]==undefined) WIDGETS_BY_ADDRESS[addressref] = []
WIDGETS_BY_ADDRESS[addressref].push(widgetInner)
}
parent[0].appendChild(widgetContainer[0])

View file

@ -11,7 +11,7 @@ _widget_base.prototype.sendValue = function() {
sendOsc({
target:this.widgetData.target,
path:this.widgetData.path,
address:this.widgetData.address,
precision:this.widgetData.precision,
args:args,
syncOnly:this.split?true:false
@ -22,7 +22,7 @@ _widget_base.prototype.sendValue = function() {
for (i in this.split) {
sendOsc({
target:this.widgetData.target,
path:this.split[i],
address:this.split[i],
precision:this.widgetData.precision,
args:this.widgetData.preArgs.concat(this.value[n]),
sync:false

View file

@ -34,7 +34,7 @@ module.exports.options = {
logScale:false,
precision:2,
meter:false,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -58,7 +58,7 @@ var Multifader = module.exports.Multifader = function(widgetData) {
data.type = 'fader'
data.id = widgetData.id + '/' + i
data.label = i
data.path = widgetData.path + '/' + i
data.address = widgetData.address + '/' + i
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`${widgetData.horizontal?'height':'width'}:${100/widgetData.strips}%`)

View file

@ -28,7 +28,7 @@ module.exports.options = {
off:0,
norelease:false,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -49,7 +49,7 @@ var Multipush = module.exports.Multipush = function(widgetData) {
data.type = 'push'
data.id = widgetData.id + '/' + i
data.label = i
data.path = widgetData.path + '/' + i
data.address = widgetData.address + '/' + i
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)

View file

@ -27,7 +27,7 @@ module.exports.options = {
on:1,
off:0,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -47,7 +47,7 @@ var Multitoggle = module.exports.Multitoggle = function(widgetData) {
data.type = 'toggle'
data.id = widgetData.id + '/' + i
data.label = i
data.path = widgetData.path + '/' + i
data.address = widgetData.address + '/' + i
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)

View file

@ -29,7 +29,7 @@ module.exports.options = {
logScaleX:false,
logScaleY:false,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
split:false,
target:[]
@ -48,8 +48,8 @@ var MultiXy = module.exports.MultiXy = function(widgetData) {
: (()=>{
var s={};
for (var i=0; i<this.widgetData.points * 2;i=i+2) {
s[i]=this.widgetData.path + '/' + i/2 + '/x'
s[i+1]=this.widgetData.path + '/' + i/2 + '/y'
s[i]=this.widgetData.address + '/' + i/2 + '/x'
s[i+1]=this.widgetData.address + '/' + i/2 + '/y'
};
return s
})()

View file

@ -24,7 +24,7 @@ module.exports.options = {
separator3:'osc',
precision:0,
path:'auto',
address:'auto',
preArgs:[],
split:false,
target:[]
@ -37,7 +37,7 @@ var Rgb = module.exports.Rgb = function(widgetData) {
this.split = this.widgetData.split?
typeof this.widgetData.split == 'object'?
this.widgetData.split
: {r: this.widgetData.path + '/r', g: this.widgetData.path + '/g', b: this.widgetData.path + '/b'}
: {r: this.widgetData.address + '/r', g: this.widgetData.address + '/g', b: this.widgetData.address + '/b'}
: false
this.widget.append(`

View file

@ -28,7 +28,7 @@ module.exports.options = {
logScaleX:false,
logScaleY:false,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
split:false,
target:[]
@ -41,7 +41,7 @@ var Xy = module.exports.Xy = function(widgetData) {
this.split = this.widgetData.split?
typeof this.widgetData.split == 'object'?
this.widgetData.split
: {x: this.widgetData.path + '/x', y: this.widgetData.path + '/y'}
: {x: this.widgetData.address + '/x', y: this.widgetData.address + '/y'}
: false
this.widget.append(`

View file

@ -26,7 +26,7 @@ module.exports.options = {
separator3:'osc',
path:'auto',
address:'auto',
preArgs:[],
}

View file

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

View file

@ -20,7 +20,7 @@ module.exports.options = {
range:{min:0,max:1},
logScale:false,
path:'auto',
address:'auto',
preArgs:[]
}

View file

@ -26,7 +26,7 @@ module.exports.options = {
separator3:'osc',
path:'auto',
address:'auto',
preArgs:[],
}

View file

@ -16,7 +16,7 @@ module.exports.options = {
separator2:'osc',
preArgs:[],
path:'auto',
address:'auto',
defaultText:''
}
module.exports.create = function(widgetData,container) {

View file

@ -25,7 +25,7 @@ module.exports.options = {
separator3:'osc',
path:'auto',
address:'auto',
preArgs:[],
}

View file

@ -21,7 +21,7 @@ module.exports.options = {
off:0,
norelease:false,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -105,7 +105,7 @@ module.exports.create = function(widgetData,container) {
sendOsc({
target:widgetData.target,
path:widgetData.path,
address:widgetData.address,
precision:widgetData.precision,
args:args,
syncOnly:norelease

View file

@ -33,7 +33,7 @@ module.exports.options = {
logScale:false,
precision:2,
meter:false,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -94,7 +94,7 @@ var Fader = module.exports.Fader = function(widgetData){
horizontal:widgetData.horizontal,
range:widgetData.range,
logScale:widgetData.logScale,
path:widgetData.path + '/meter',
address:widgetData.address + '/meter',
preArgs:widgetData.preArgs,
color:widgetData.color
}

View file

@ -31,7 +31,7 @@ module.exports.options = {
origin: 'auto',
logScale:false,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}

View file

@ -20,7 +20,7 @@ module.exports.options = {
values:{"Value 1":1,"Value 2":2},
precision:2,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -71,7 +71,7 @@ module.exports.create = function(widgetData,container) {
sendOsc({
target:widgetData.target,
path:widgetData.path,
address:widgetData.address,
precision:widgetData.precision,
args:args
})

View file

@ -20,7 +20,7 @@ module.exports.options = {
on:1,
off:0,
precision:2,
path:'auto',
address:'auto',
preArgs:[],
target:[]
}
@ -79,7 +79,7 @@ module.exports.create = function(widgetData,container) {
sendOsc({
target:widgetData.target,
path:widgetData.path,
address:widgetData.address,
precision:widgetData.precision,
args:args
})