touch state: fix conversion for multitouch widgets

This commit is contained in:
bordun 2020-10-02 10:42:40 +02:00
parent 2f3de5a898
commit e1b81951ac
2 changed files with 7 additions and 7 deletions

View file

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

View file

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