diff --git a/CHANGELOG.md b/CHANGELOG.md index 7068ed00..d3a2589d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.6.3 +- widgets + - keyboard: add `velocity` property (allows mapping the touch coordinates between `off` (top) and `on` (bottom)) + - midi - accept sending sysex strings without spaces between the bytes diff --git a/src/client/widgets/basics/button.js b/src/client/widgets/basics/button.js index 9af22b43..19b736c5 100644 --- a/src/client/widgets/basics/button.js +++ b/src/client/widgets/basics/button.js @@ -63,10 +63,10 @@ class Button extends Widget { if (this.getProp('doubleTap')) { - doubletab(this.widget, ()=>{ + doubletab(this.container, (e)=>{ this.active = true - this.setValue(this.getProp('on'), {sync: true, send: true}) + this.setValue(this.getProp('on'), {sync: true, send: true, y: e.offsetY}) if (tap) this.container.classList.add('active') @@ -74,17 +74,17 @@ class Button extends Widget { } else { - this.on('draginit',()=>{ + this.on('draginit',(e)=>{ if (this.active) return this.active = true - this.setValue(this.getProp('on'), {sync: true, send: true}) + this.setValue(this.getProp('on'), {sync: true, send: true, y: e.offsetY}) if (tap) this.container.classList.add('active') - }, {element: this.widget}) + }, {element: this.container}) } @@ -97,36 +97,36 @@ class Button extends Widget { if (!tap) this.setValue(this.getProp('off'), {sync: true, send: true}) if (tap) this.container.classList.remove('active') - }, {element: this.widget}) + }, {element: this.container}) } else { if (this.getProp('doubleTap')) { - doubletab(this.widget, ()=>{ + doubletab(this.container, (e)=>{ this.active = true - this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) + this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true, y: e.offsetY}) }) } else { - this.on('draginit',()=>{ + this.on('draginit',(e)=>{ if (this.active) return this.active = true - this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) + this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true, y: e.offsetY}) - }, {element: this.widget}) + }, {element: this.container}) this.on('dragend',()=>{ this.active = false - }, {element: this.widget}) + }, {element: this.container}) } diff --git a/src/client/widgets/containers/keyboard.js b/src/client/widgets/containers/keyboard.js index b80fa8b1..00616517 100644 --- a/src/client/widgets/containers/keyboard.js +++ b/src/client/widgets/containers/keyboard.js @@ -1,6 +1,7 @@ var Panel = require('./panel'), Widget = require('../common/widget'), - parser = require('../../parser') + parser = require('../../parser'), + {mapToScale} = require('../utils') class Keyboard extends Panel { @@ -28,11 +29,12 @@ class Keyboard extends Panel { traversing: {type: 'boolean', value: true, help: 'Set to `false` to disable traversing gestures'}, on: {type: '*', value: 1, help: [ 'Set to `null` to send send no argument in the osc message', - 'Can be an `object` if the type needs to be specified (see preArgs)' ]}, off: {type: '*', value: 0, help: [ 'Set to `null` to send send no argument in the osc message', - 'Can be an `object` if the type needs to be specified (see preArgs)' + ]}, + velocity: {type: 'boolean', value: false, help: [ + 'Set to `true` to map the touch coordinates between `off` (top) and `on` (bottom). Requires `on` and `off` to be numbers', ]}, mode: {type: 'string', value: 'push', choices: ['push', 'toggle', 'tap'], help: [ 'Interraction mode:', @@ -51,6 +53,12 @@ class Keyboard extends Panel { this.childrenType = undefined this.value = [] + this.keyHeight = 100 + + this.on('resize', (e)=>{ + this.keyHeight = e.height + }, {element: this.widget}) + this.on('change',(e)=>{ @@ -58,12 +66,25 @@ class Keyboard extends Panel { if (widget === this) return - this.value[widget._index] = widget.getValue() + + var value + if (widget.getValue()) { + if (this.getProp('velocity')) { + var height = widget._black ? this.keyHeight * 0.65 : this.keyHeight + value = mapToScale(e.options.y, [0, height * 0.9], [this.getProp('off'), this.getProp('on')], this.decimals) + } else { + value = this.getProp('on') + } + } else { + value = this.getProp('off') + } + + this.value[widget._index] = value if (e.options.send) { var start = parseInt(this.getProp('start')) this.sendValue({ - v: [e.widget._index + start, widget.getValue() ? this.getProp('on') : this.getProp('off')] + v: [e.widget._index + start, value] }) } @@ -120,6 +141,7 @@ class Keyboard extends Panel { } else { key.container.classList.add('black') key.container.style.setProperty('--rank', whiteKeys2) + key._black = true } this.value[i - start] = this.getProp('off') diff --git a/src/scss/widgets/basics.scss b/src/scss/widgets/basics.scss index 734e82ac..0b72d692 100644 --- a/src/scss/widgets/basics.scss +++ b/src/scss/widgets/basics.scss @@ -32,6 +32,7 @@ bottom:0; margin: var(--widget-spacing); padding: var(--widget-padding); + pointer-events: none; @include pseudo-stroke($z: -1);