client:osc: take all args for widget address+preArgs matching

This commit is contained in:
jean-emmanuel 2017-12-19 18:41:04 +01:00
parent bd6c32cab7
commit 2e1f7b8627
3 changed files with 42 additions and 32 deletions

View file

@ -5,6 +5,7 @@
- bug fixes
- sessions opened from command line with relative paths are now added to the history with their absolute path
- sending an empty message to a `text` widget resets it to its initial value and without ignoring its `value` property
- sending no value to a widget with `preArgs` is now possible : all the arguments found in incomming osc messages are now taken into account to match the widgets in the session
- engine
- downgraded to the latest *stable* electron release
- main

View file

@ -208,6 +208,42 @@ var WidgetManager = class WidgetManager {
}
getWidgetByAddressAndArgs(address, args) {
var addressref = address,
restArgs = args
if (typeof args == 'object' && args != null) {
for (var i = args.length; i >= 0; i--) {
var ref = this.createAddressRef(null, args.slice(0,i), address)
if (this.getWidgetByAddress(ref).length) {
addressref = ref
restArgs = args.slice(i, args.length)
break
}
}
} else {
restArgs = args
}
if (restArgs == null || restArgs.length == 0) restArgs = null
else if (restArgs.length == 1) restArgs = restArgs[0]
var widgets = this.getWidgetByAddress(addressref)
return [
widgets,
restArgs
]
}
}
var widgetManager = new WidgetManager()

View file

@ -38,43 +38,16 @@ var Osc = class Osc {
if (this.remoteControl.exists(data.address)) this.remoteControl.exec(data.address, data.args)
// fetch ids corresponding to the osc address
var address = data.address,
addressref = address,
args = data.args,
target = data.target
var [widgets, restArgs] = widgetManager.getWidgetByAddressAndArgs(data.address, data.args)
if (typeof data.args == 'object' && data.args != null) {
for (var i=data.args.length-1;i>=0;i--) {
var ref = widgetManager.createAddressRef(null, data.args.slice(0,i), address)
if (widgetManager.getWidgetByAddress(ref).length) {
addressref = ref
args = data.args.slice(i,data.args.length)
break
}
}
} else {
args = data.args
}
if (args == null || args.length==0) args = null
else if (args.length==1) args = args[0]
let widget = widgetManager.getWidgetByAddress(addressref)
for (let i in widget) {
let widgetTarget = widget[i].getProp('target')
for (let i in widgets) {
let widgetTarget = widgets[i].getProp('target')
// 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 || !widgetTarget || !(widgetTarget < target || widgetTarget > target || widgetTarget.length !== target.length)) {
if (!data.target || !widgetTarget || !(widgetTarget < data.target || widgetTarget > data.target || widgetTarget.length !== data.target.length)) {
// update matching widgets
if (widget[i] && widget[i].setValue) widget[i].setValue(args,{send:false,sync:true,fromExternal:!target})
if (widgets[i] && widgets[i].setValue) widgets[i].setValue(restArgs,{send:false,sync:true,fromExternal:!data.target})
}
}