From 52147ba0a6c7610c21222e54276c8bb1fe2e3cf2 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 22 Jan 2022 13:09:45 +0100 Subject: [PATCH] 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) --- CHANGELOG.md | 3 ++ .../docs/docs/widgets/advanced-syntaxes.md | 3 ++ src/client/osc.js | 45 +++++++++++-------- src/client/widgets/common/osc-receiver.js | 5 ++- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 868c9b75..d8c848d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/resources/docs/docs/widgets/advanced-syntaxes.md b/resources/docs/docs/widgets/advanced-syntaxes.md index 288e86fa..ea1a28b7 100644 --- a/resources/docs/docs/widgets/advanced-syntaxes.md +++ b/resources/docs/docs/widgets/advanced-syntaxes.md @@ -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{ diff --git a/src/client/osc.js b/src/client/osc.js index 947f6b0e..f2519f3d 100644 --- a/src/client/osc.js +++ b/src/client/osc.js @@ -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) } diff --git a/src/client/widgets/common/osc-receiver.js b/src/client/widgets/common/osc-receiver.js index bb234503..09121fbf 100644 --- a/src/client/widgets/common/osc-receiver.js +++ b/src/client/widgets/common/osc-receiver.js @@ -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)) {