osc-listeners: accepts an optional third argument (false) to bypass the host widget's preArgs

This commit is contained in:
jean-emmanuel 2019-03-18 09:25:57 +01:00
parent 8910a797fd
commit fbc6aca6a2
4 changed files with 18 additions and 8 deletions

View file

@ -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

View file

@ -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: `#{}`

View file

@ -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) {

View file

@ -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