From 4c83badea273cee21cdc9f1a73d6e51fdc7fc400 Mon Sep 17 00:00:00 2001 From: bordun Date: Fri, 2 Oct 2020 10:42:40 +0200 Subject: [PATCH] touch state: fix conversion for multitouch widgets --- resources/docs/docs/widgets/scripting.md | 10 +++++----- src/client/managers/session/session.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 34958b8a..a48f0d9f 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -34,15 +34,15 @@ When some widgets are touched or released, a special event can be catched to tri If the variable `touch` is not `undefined`, this means it holds the widget's cuurent touch state: -- `0/1` if the widget is single touch (`fader`, `knob` and `xy`) +- `0/1` for the widget's touch state (`fader`, `knob` and `xy`, `range` and `multixy`) - `[i, 0/1]` if the widget is multi touch (`range` and `multixy`). In this case `i` is the touched handle's index, starting with `0`. -Example script: - ```js if (touch !== undefined) { - // send touch state - send('/touch_address', touch) + // send multi touch state + if (touch.length) send('/touch_address', touch[0], touch[1]) + // send global touch state + else send('/touch_address', touch) } else { // do something with the value ? } diff --git a/src/client/managers/session/session.js b/src/client/managers/session/session.js index d96f1f19..afc5a453 100644 --- a/src/client/managers/session/session.js +++ b/src/client/managers/session/session.js @@ -225,9 +225,9 @@ var converters = [ case 'range': case 'multixy': if (data.touchAddress && String(data.touchAddress).length) { - let touchVal = data.type.match(/range|multixy/) ? 'touch[0], touch[1]' : 'touch', + let sendScript = data.type.match(/range|multixy/) ? 'if (touch.length) send(address, touch[0], touch[1])\n else send(address, touch)' : 'send(address, touch)', originalScript = data.script ? ` else {\n // original script\n ${data.script}\n // -----------\n}` : '' - data.script = `\nif (touch !== undefined) {\n // generated automatically\n // from touchAddress\n send("${data.touchAddress}", ${touchVal})\n}${originalScript}` + data.script = `\nif (touch !== undefined) {\n // generated automatically\n // from touchAddress\n var address = "${data.touchAddress}"\n ${sendScript}\n}${originalScript}` } break