diff --git a/CHANGELOG.md b/CHANGELOG.md index 10a609cd..7d0e0928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Changelog -## next +## 0.42.0 +- widgets + - `OSC{}` syntax accepts an optional third argument (`false`) to bypass the host widget's `preArgs` - editor - sticky header to remind selected widget's id - sidepanel can now be resized by dragging its edge diff --git a/resources/docs/extras/advanced-property-syntax.md b/resources/docs/extras/advanced-property-syntax.md index eb82b85e..c276a8ef 100644 --- a/resources/docs/extras/advanced-property-syntax.md +++ b/resources/docs/extras/advanced-property-syntax.md @@ -54,7 +54,7 @@ The following syntax allows listening on an osc address to define a property, wi ``` OSC{/address, 1} ``` -Will return `1` at first and listen for osc messages on address `/address`. Each time a value is received, the property will be updated. +Will return `1` at first and listen for osc messages on address `/address [preArgs]`. Each time a value is received, the property will be updated. If the leading slash (`/`) is omitted, the address will be prefixed with the widget's `address` property: @@ -62,10 +62,15 @@ If the leading slash (`/`) is omitted, the address will be prefixed with the wid ``` OSC{color, "auto"} ``` -Will listen for osc messages on address `/widget_address/color`. - +Will listen for osc messages on address `/widget_address/color [preArgs]`. ---- +By default, osc listeners inherit the widget's `preArgs` and (these must be matched for the osc messages to be processed). This can be bypassed by appending a third argument to the constructor: + +``` +OSC{color, "auto", false} +``` + ## Formulas: `#{}` diff --git a/src/client/app/widgets/common/osc-receiver.js b/src/client/app/widgets/common/osc-receiver.js index 67dee302..ab4e7201 100644 --- a/src/client/app/widgets/common/osc-receiver.js +++ b/src/client/app/widgets/common/osc-receiver.js @@ -4,7 +4,7 @@ module.exports = class OscReceiver { constructor(options) { - var {address, value, parent, propName} = options + var {address, value, parent, propName, usePreArgs} = options try { this.value = JSON.parse(value) @@ -14,6 +14,7 @@ module.exports = class OscReceiver { this.parent = parent this.propNames = [propName] + this.usePreArgs = usePreArgs this.bindedCallback = this.callback.bind(this) this.prefix = '' this.setAddress(address) @@ -48,7 +49,7 @@ module.exports = class OscReceiver { callback(args) { if (typeof args !== 'object') args = [args] - var preArgs = this.parent.getProp('preArgs') || [] + var preArgs = this.usePreArgs ? (this.parent.getProp('preArgs') || []) : [] if (!Array.isArray(preArgs) && preArgs !== '') preArgs = [preArgs] if (args.length >= preArgs.length) { for (var i in preArgs) { diff --git a/src/client/app/widgets/common/widget.js b/src/client/app/widgets/common/widget.js index 74f2cc0d..bed08fae 100644 --- a/src/client/app/widgets/common/widget.js +++ b/src/client/app/widgets/common/widget.js @@ -534,7 +534,7 @@ class Widget extends EventEmitter { }) propValue = propValue.replace(/OSC\{([^}]+)\}/g, (m)=>{ - let [address, value] = m.substr(4, m.length - 5).split(',').map(x=>x.trim()), + let [address, value, usePreArgs] = m.substr(4, m.length - 5).split(',').map(x=>x.trim()), resolvedAddress = address.replace(/VAR_[0-9]+/g, (m)=>{ return typeof variables[m] === 'string' ? variables[m] : JSON.stringify(variables[m]) }) @@ -544,7 +544,8 @@ class Widget extends EventEmitter { address: resolvedAddress, value: value, parent: this, - propName: propName + propName: propName, + usePreArgs: usePreArgs === 'false' ? false : true }) if (oscReceiverState[address]) { this.oscReceivers[address].value = oscReceiverState[address] @@ -553,6 +554,7 @@ class Widget extends EventEmitter { } else { this.oscReceivers[address].setAddress(resolvedAddress) this.oscReceivers[address].addProp(propName) + this.oscReceivers[address].usePreArgs = usePreArgs === 'false' ? false : true } var r = this.oscReceivers[address].value