script: pass options to set() to send/sync only when it should, bypass send() when options.send is false

This commit is contained in:
jean-emmanuel 2018-08-06 10:01:25 +02:00
parent 5ad8537ab7
commit 95cfe442a2
2 changed files with 11 additions and 8 deletions

View file

@ -89,7 +89,7 @@
- usage: this property is evaluated each time the widgets receives a non-falsy value. [Formulas](../extras/advanced-property-syntax/#formulas) are given extras variables in this context:
- `value`: the value received by the widget
- `send`: `function` for sending osc messages
- `set`: `function` for setting a widget's value (triggers osc sendings)
- `set`: `function` for setting a widget's value
#### `send(target, address, arg1, arg2, ...)`
- `target` (`string` or `array` or `false`): one or several osc targets. Default targets (`--send` and the script's `target` property) are ignored unless `target` is `false`
@ -99,4 +99,3 @@
#### `set(id, value, send)`
- `id` (`string`): a widget's id
- `value`: the widget's new value
- `send` (`boolean`): `true` by default, set to `false` to prevent osc sendings

View file

@ -50,16 +50,13 @@ class Script extends Widget {
}
static scriptSet(id, value, send = true) {
static scriptSet(id, value, options) {
var widgets = widgetManager.getWidgetById(id)
for (var i = widgets.length - 1; i >= 0; i--) {
return widgets[i].setValue(value, {
sync: true,
send: send
})
return widgets[i].setValue(value, options)
}
@ -82,7 +79,14 @@ class Script extends Widget {
setValue(v, options={} ) {
if (v) this.resolveProp('script', undefined, false, false, false, {value: v, send: this.scriptSend.bind(this), set: Script.scriptSet, log: console.log})
var context = {
value: v,
send: options.send ? this.scriptSend.bind(this) : ()=>{},
set: (id, value)=>{Script.scriptSet(id, value, options)},
log: console.log
}
if (v) this.resolveProp('script', undefined, false, false, false, context)
// if (options.send) this.sendValue()
if (options.sync) this.changed(options)