widget props: don't coerce "target" and "preArgs" to array and accept single string values (#211)
This commit is contained in:
parent
4ff64ac46d
commit
04fafb15ee
7 changed files with 22 additions and 12 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## next
|
||||
|
||||
- widgets
|
||||
- `target` properties are no longer coerced to arrays and can be simple strings when there's only one value to set
|
||||
|
||||
## 0.29.2
|
||||
|
||||
- bug fixes
|
||||
|
|
|
|||
|
|
@ -183,7 +183,6 @@ module.exports = {
|
|||
if (settings.read('targets') && !shortdata.target) Array.prototype.push.apply(targets, settings.read('targets'))
|
||||
if (data.target) Array.prototype.push.apply(targets, data.target)
|
||||
|
||||
|
||||
for (var i in targets) {
|
||||
|
||||
if (targets[i] == 'self') {
|
||||
|
|
@ -228,8 +227,15 @@ module.exports = {
|
|||
widgetHashTable[clientId][data.hash] = {}
|
||||
}
|
||||
|
||||
for (var k in data.data) {
|
||||
widgetHashTable[clientId][data.hash][k] = data.data[k]
|
||||
var cache = widgetHashTable[clientId][data.hash],
|
||||
widgetData = data.data
|
||||
|
||||
for (var k in widgetData) {
|
||||
if ((k === 'target' || k === 'preArgs')) {
|
||||
cache[k] = Array.isArray(widgetData[k]) ? widgetData[k] : [widgetData[k]]
|
||||
} else {
|
||||
cache[k] = widgetData[k]
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
|||
|
|
@ -78,12 +78,13 @@ All widgets share a set of generic properties described below.
|
|||
- a specific data type can be specified by appending a valid osc type tag to the precision value, for example : `3d` will make the widget send double precision numbers rounded to three decimals
|
||||
|
||||
### `target`<i class="dynamic-prop-icon" title="dynamic"></i>
|
||||
- type: `array`
|
||||
- type: `array|string`
|
||||
- default: `[]`
|
||||
- usage:
|
||||
- this defines the targets of the widget's osc messages
|
||||
- each element of the `array` must be a string formatted as follows : `"ip:port"`
|
||||
- multiple targets can be specified : `["ip1:port1","ip2:port2"]`
|
||||
- a single target can be set : `ip:port`
|
||||
- if [`midi`](../extras/midi.md) is enabled, targets can be `"midi:device_name"`
|
||||
- special item `"self"` can be used to refer to the emitting client directly
|
||||
- if no target is set (empty array `[]`), messages can still be sent if the server has defaults targets (`-s / --send`)
|
||||
|
|
@ -103,11 +104,12 @@ All widgets share a set of generic properties described below.
|
|||
```
|
||||
|
||||
### `preArgs`<i class="dynamic-prop-icon" title="dynamic"></i>
|
||||
- type: `array`
|
||||
- type: `array|*`
|
||||
- default: `[]`
|
||||
- usage:
|
||||
- each element of the `array` defines a constant value that will be prepended to the osc message
|
||||
- values can be defined as objects if the osc data type needs to be specified (ie different from the default implied by the `precision` option)
|
||||
- a single non-array value can be set
|
||||
- example:
|
||||
```js
|
||||
preArgs: [
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
var preArgs = widget ? widget.getProp('preArgs') : preArgs,
|
||||
address = widget ? widget.getProp('address') : address
|
||||
|
||||
if (!Array.isArray(preArgs) && preArgs !== '') preArgs = [preArgs]
|
||||
|
||||
return preArgs && preArgs.length ?
|
||||
address + this.preArgsSeparator + preArgs.join(this.preArgsSeparator)
|
||||
: address
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ var Osc = class Osc extends EventEmitter {
|
|||
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 (!data.target || !widgetTarget || !(widgetTarget < data.target || widgetTarget > data.target || widgetTarget.length !== data.target.length)) {
|
||||
if (!data.target || !widgetTarget || String(widgetTarget) === String(data.target)) {
|
||||
// update matching widgets
|
||||
if (widgets[i] && widgets[i].setValue) widgets[i].setValue(restArgs,{send:false,sync:true,fromExternal:!data.target})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ module.exports = class OscReceiver {
|
|||
|
||||
if (typeof args !== 'object') args = [args]
|
||||
var preArgs = this.parent.getProp('preArgs') || []
|
||||
if (!isArray(preArgs) && preArgs !== '') preArgs = [preArgs]
|
||||
if (args.length >= preArgs.length) {
|
||||
for (var i in preArgs) {
|
||||
if (preArgs[i] !== args[i]) return
|
||||
|
|
|
|||
|
|
@ -54,11 +54,6 @@ class Widget extends EventEmitter {
|
|||
this.props.preArgs = [this.props.preArgs]
|
||||
}
|
||||
|
||||
// Turn preArgs into array
|
||||
if (this.props.target !== undefined && !Array.isArray(this.resolveProp('target', undefined, false))) {
|
||||
this.props.target = [this.props.target]
|
||||
}
|
||||
|
||||
// strip parent ? no position
|
||||
if (this.parent && this.parent.props && this.parent.props.type == 'strip') {
|
||||
delete this.props.top
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue