fader/knob/xy/range/multixy: remove touchAddress property; expose touch state in script property (touchAddress usages will be converted automatically)

This commit is contained in:
bordun 2020-10-01 15:07:04 +02:00
parent 58d8ec2171
commit 6b6c420277
11 changed files with 70 additions and 69 deletions

View file

@ -14,7 +14,9 @@
- widgets
- expose widgets unique identifiers with property name "uuid"
- xy/multixy: add `ephemeral` property
- xy/multixy: add `ephemeral` property
- fader/knob/xy/range/multixy: remove `touchAddress` property
- fader/knob/xy/range/multixy: expose touch state in `script` property (`touchAddress` usages will be converted automatically)
## 1.3.0

View file

@ -16,6 +16,7 @@ Depending on what triggered the script's execution, a few variables are availabl
- `id` (`string`): id of the widget that's reponsible for the value update
- `value`: widget's value
- `touch`: see [Touch state](#touch-state)
**Event: keyboard** (script widget only)
@ -27,10 +28,31 @@ Depending on what triggered the script's execution, a few variables are availabl
- `alt` (`boolean`): `true` if alt key is pressed
- `meta` (`boolean`): `true` if meta key is pressed
## Touch state
When some widgets are touched or released, a special event can be catched to trigger custom actions.
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`)
- `[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)
} else {
// do something with the value ?
}
```
To avoid unwanted script executions, touch state events will only be catched if the script contains the word `touch`.
## Available variables
Besides the variables available in the [javascript property syntax ](./advanced-syntaxes.md#available-variables), the following variables and functions are also accessible in this context.
Besides the variables available in the [javascript property syntax ](./advanced-syntaxes.md#available-variables) and the ones listed above, the following variables and functions are accessible in this context.
----

View file

@ -211,6 +211,28 @@ var converters = [
}
}
},
{
version: '1.3.1',
widget: (data)=>{
switch (data.type) {
case 'fader':
case 'knob':
case 'xy':
case 'range':
case 'multixy':
if (data.touchAddress && String(data.touchAddress).length) {
let touchVal = data.type.match(/range|multixy/) ? 'touch[0], touch[1]' : '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}`
}
break
}
}
}
]

View file

@ -213,7 +213,11 @@ class Widget extends EventEmitter {
this.on('change', (e)=>{
if (e.widget === this && this.mounted && !e.options.fromEdit) this.script.setValue(this.value, {...e.options, id: e.options.id || e.id})
})
if (String(this.getProp('script')).includes('touch')) {
this.on('touch', (e)=>{
this.script.setValue(this.value, {id: this.getProp('id'), touch: e.touch, sync: false, send: true})
})
}
}
this.container = html`

View file

@ -1,18 +1,13 @@
module.exports = (self, options)=>{
var sendTouchState = self.getProp('touchAddress') && self.getProp('touchAddress').length
self.touched = 0
self.setValueTouchedQueue = undefined
self.on('draginit',(e)=>{
self.touched += 1
if (self.touched == 1 && sendTouchState)
self.sendValue({
address:self.getProp('touchAddress'),
v:1,
split:false
})
if (self.touched == 1) {
self.trigger('touch', {stopPropagation :0, touch: 1})
}
}, options)
self.on('dragend', (e)=>{
@ -24,13 +19,7 @@ module.exports = (self, options)=>{
self.setValueTouchedQueue = undefined
}
if (sendTouchState) {
self.sendValue({
address:self.getProp('touchAddress'),
v:0,
split:false
})
}
self.trigger('touch', {stopPropagation :true, touch: 0})
} else if (self.touched > 1){
self.touched -= 1
@ -38,12 +27,8 @@ module.exports = (self, options)=>{
}, options)
self.onRemove = ()=>{
if (sendTouchState && self.touched > 0) {
self.sendValue({
address:self.getProp('touchAddress'),
v:0,
split:false
})
if (self.touched > 0) {
self.trigger('touch', {stopPropagation :true, touch: 0})
}
self.__proto__.onRemove.call(self)
}

View file

@ -43,11 +43,7 @@ module.exports = class MultiXy extends Pad {
logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis. Set to `-1` for exponential scale.'},
sensitivity: {type: 'number', value: 1, help: 'Defines the pad\'s sensitivity when `snap` is `false` '},
}, [], {
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
})
}, [], {})
}
@ -120,12 +116,7 @@ module.exports = class MultiXy extends Pad {
e.stopPropagation = true
if (this.getProp('touchAddress')) {
this.sendValue({
address: this.getProp('touchAddress'),
v: [parseInt(id), 1],
})
}
this.trigger('touch', {stopPropagation: true, touch: [parseInt(id), 1]})
this.pads[id].trigger('draginit', e)
@ -151,12 +142,7 @@ module.exports = class MultiXy extends Pad {
this.pads[i].trigger('dragend', e)
if (this.getProp('touchAddress')) {
this.sendValue({
address: this.getProp('touchAddress'),
v: [parseInt(this.touchMap[e.pointerId]), 0],
})
}
this.trigger('touch', {stopPropagation: true, touch: [parseInt(this.touchMap[e.pointerId]), 0]})
delete this.touchMap[e.pointerId]

View file

@ -37,11 +37,7 @@ module.exports = class Xy extends Pad {
]},
sensitivity: {type: 'number', value: 1, help: 'Defines the pad\'s sensitivity when `snap` is `false` '},
}, [], {
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`)'},
})
}, [], {})
}

View file

@ -56,7 +56,8 @@ class Script extends Widget {
this.compile({
id: '',
value: 0
value: 0,
touch: undefined
})
} else if (this.getProp('event') === 'keyboard' && this.getProp('keyBinding')) {
@ -128,6 +129,7 @@ class Script extends Widget {
this.run({
value: v,
id: options.id,
touch: options.touch
})
scriptVm.setValueOptions(options)

View file

@ -49,11 +49,7 @@ class Fader extends Slider {
]},
origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the fader\'s gauge'},
}, [], {
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
}, Fader)
}, [], {}, Fader)
}

View file

@ -48,11 +48,7 @@ module.exports = class Knob extends Slider {
]},
origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the knob\'s gauge'},
}, [], {
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
}, Knob)
}, [], {}, Knob)
}

View file

@ -141,12 +141,7 @@ class Range extends Fader {
if (!i) return
if (this.getProp('touchAddress')) {
this.sendValue({
address: this.getProp('touchAddress'),
v: [parseInt(i), 1],
})
}
this.trigger('touch', {stopPropagation: true, touch: [parseInt(i), 1]})
if (e.shiftKey) {
this.faders[0].trigger('drag', e)
@ -167,12 +162,7 @@ class Range extends Fader {
this.faders[i].trigger('dragend', e)
if (this.getProp('touchAddress')) {
this.sendValue({
address: this.getProp('touchAddress'),
v: [parseInt(i), 0],
})
}
this.trigger('touch', {stopPropagation: true, touch: [parseInt(i), 0]})
delete this.touchMap[e.pointerId]