From 7cc67e6b59489af55d17ea6fc4f2383d1bf7fb66 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 4 Oct 2022 12:15:42 +0200 Subject: [PATCH] button: add decoupled mode script: add external option for set() --- CHANGELOG.md | 5 ++++- resources/docs/docs/widgets/scripting.md | 1 + src/client/widgets/basics/button.js | 17 +++++++++++++++-- src/client/widgets/scripts/script-vm.js | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aed20617..9336005e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,15 @@ ## 1.17.1 +- widgets + - button: add `decoupled` property (restrict visual feedback to values received from osc/midi messages) + - scripting - add `updateCanvas()` function (forces a canvas widget to redraw) - remote control - `/NOTIFY`: if multiple arguments are provided, interpret the first one as the icon's name for the client notification - + - midi - on Mac, name virtual ports after the device name to avoid confusion diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 99ae03eb..dbb7f5bb 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -137,6 +137,7 @@ Returns the value of the first matching widget. If the returned value is an obje - `sync: false`: prevents widgets from triggering synchronization and scripts - `script: false`: prevents scripts but not synchronization - `send: false`: prevents widgets from sending osc messages + - `external: true`: simulates a value coming from an osc/midi message Sets the value of the first matching widget. If `ìd` contains wildcards, affects all matching widgets **except** the emitting widget. diff --git a/src/client/widgets/basics/button.js b/src/client/widgets/basics/button.js index 1850b343..e4eabf76 100644 --- a/src/client/widgets/basics/button.js +++ b/src/client/widgets/basics/button.js @@ -39,9 +39,14 @@ class Button extends Widget { 'Interraction mode:', '- `toggle` (classic on/off switch)', '- `push` (press & release)', - '- `momentary` (no release, no value sent)', + '- `momentary` (no release, no value sent with the address)', '- `tap` (no release, sends `on` as value)' ]}, + decoupled: {type: 'boolean', value: false, help: [ + 'If `true`, the button\'s visual state will not change unless it receives a value that matches `on` or `off` coming from an osc/midi message.', + 'From a script property this kind of message can be simulated with:', + `set('widget_id', value, {external: true})` + ]}, doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the button require a double tap to be pushed instead of a single tap'}, } @@ -197,9 +202,15 @@ class Button extends Widget { if (newstate !== undefined) { this.state = newstate - if (mode === 'toggle' || mode === 'push') { + if (this.getProp('decoupled')) { + if (options.fromExternal) { + this.container.classList.toggle('on', this.state) + } + } + else if (mode === 'toggle' || mode === 'push') { this.container.classList.toggle('on', this.state) } + if (mode !== 'momentary') { this.value = this.getProp(this.state ? 'on' : 'off') } @@ -220,6 +231,8 @@ class Button extends Widget { if (mode === 'tap') this.setValue(this.getProp('off'), {sync: false, send: false, tapRelease: true}) // pulse + if (this.getProp('decoupled') && options.fromExternal) return + clearTimeout(this.pulse) this.container.classList.remove('pulse') setTimeout(()=>{ diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index b0508bf0..71d6ee81 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -77,6 +77,7 @@ class ScriptVm extends Vm { if (extraOptions.send === false) options.send = false if (extraOptions.sync === false) options.sync = false if (extraOptions.script === false) options.script = false + if (extraOptions.external === true) options.fromExternal = true var widgets if (id.includes('*')) {