osc receivers: apply the same rule as widgets regarding midi messages (only receive if the message's origin matches one of the host widget's midi targets)

This commit is contained in:
jean-emmanuel 2022-01-22 13:09:45 +01:00
parent 26207f0e70
commit 52147ba0a6
4 changed files with 36 additions and 20 deletions

View file

@ -2,6 +2,9 @@
## 1.14.3
- bug fixes
- osc receivers (`OSC{}` syntax) now apply the same rule as widgets regarding midi messages (only receive if the message's origin matches one of the host widget's midi targets)
- widgets
- clone/fragment: remove scripting properties as theyr are supposed to bo overriden in `props`

View file

@ -46,6 +46,9 @@ The OSC listener syntax returns the value received on specified address (or the
Options can contain `@{}` blocks.
!!! note "Receiving MIDI"
Midi messages will be processed only if the receiver's widget includes the emitting MIDI device in its targets.
??? example "Array/Object default value"
```js
JS{

View file

@ -39,6 +39,30 @@ var Osc = class Osc extends EventEmitter {
}
match(widget, data) {
let widgetTarget = widget.getProp('target'),
match = true
if (data._rawTarget) {
// 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 exact same target
match = deepEqual(widgetTarget, data._rawTarget)
} else if (data.host === 'midi') {
// if the message comes from a midi port, only update widgets that send to that port
let widgetArrayTarget = Array.isArray(widgetTarget) ? widgetTarget : [widgetTarget],
strTarget = data.host + ':' + data.port
match = widgetArrayTarget.includes(strTarget) ||
(!widgetArrayTarget.includes(null) && this.serverTargets.includes(strTarget))
}
return match
}
receive(data){
if (typeof this.remoteControl.exists === 'function' && this.remoteControl.exists(data.address)) this.remoteControl.exec(data.address, data.args)
@ -47,30 +71,13 @@ var Osc = class Osc extends EventEmitter {
for (let i in widgets) {
let widgetTarget = widgets[i].getProp('target'),
match = true
if (data._rawTarget) {
// 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 exact same target
match = deepEqual(widgetTarget, data._rawTarget)
} else if (data.host === 'midi') {
// if the message comes from a midi port, only update widgets that send to that port
let widgetArrayTarget = Array.isArray(widgetTarget) ? widgetTarget : [widgetTarget],
strTarget = data.host + ':' + data.port
match = widgetArrayTarget.includes(strTarget) ||
(!widgetArrayTarget.includes(null) && this.serverTargets.includes(strTarget))
}
if (match) {
if (this.match(widgets[i], data)) {
widgets[i].setValue(restArgs,{send:false,sync:true,fromExternal:!data.target})
}
}
this.trigger(data.address, data.args)
this.trigger(data.address, data)
}

View file

@ -56,7 +56,9 @@ module.exports = class OscReceiver {
}
callback(args) {
callback(data) {
var {args} = data
if (!Array.isArray(args)) args = [args]
var preArgs = this.usePreArgs ? (this.parent.getProp('preArgs') || []) : []
@ -65,6 +67,7 @@ module.exports = class OscReceiver {
for (var i in preArgs) {
if (preArgs[i] !== args[i]) return
}
if (!osc.match(this.parent, data)) return
var value = args.slice(preArgs.length)
if (value.length < 2) value = value[0]
if (typeof value === 'string' && isJSONObject(value)) {