From 11fc7d2b5692e4d7d555c796f4e4c9f58f7105df Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 14 Feb 2024 19:53:01 +0100 Subject: [PATCH] multixy: add axisLock; bypass axisLock with Shift --- CHANGELOG.md | 2 +- src/client/widgets/pads/multixy.js | 6 ++++++ src/client/widgets/pads/xy.js | 7 +++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3c4494..cf9b2517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - widgets - dropdown: allow resubmitting the same value - plot: missing `logScaleX` and `logScaleY` properties - - xy: add `axisLock` property; allow locking one the axis by holding `Shift` while dragging + - xy/multixy: add `axisLock` property; allow locking one the axis by holding `Shift` while dragging if `axisLock` is not set, bypasses it otherwise. ## 1.25.7 diff --git a/src/client/widgets/pads/multixy.js b/src/client/widgets/pads/multixy.js index bc6944e8..88fb1569 100644 --- a/src/client/widgets/pads/multixy.js +++ b/src/client/widgets/pads/multixy.js @@ -40,6 +40,10 @@ module.exports = class MultiXy extends Pad { rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'}, logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis. Set to `-1` for exponential scale.'}, logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis. Set to `-1` for exponential scale.'}, + axisLock: {type: 'string', value: '', choices: ['', 'x', 'y'], help: [ + 'Restrict movements to one of the axes only.', + 'When left to the default value, holding `Shift` while dragging will lock the pad according the first movement.' + ]}, doubleTap: {type: 'boolean|string', value: false, help: [ 'Set to `true` to make the fader reset to its default value when receiving a double tap.', 'Can also be an osc address, which case the widget will just send an osc message: `/ `' @@ -77,6 +81,7 @@ module.exports = class MultiXy extends Pad { decimals:this.getProp('decimals'), logScaleX:this.getProp('logScaleX'), logScaleY:this.getProp('logScaleY'), + axisLock:this.getProp('axisLock'), pointSize: this.getProp('pointSize'), pips: this.getProp('pips') && i == this.npoints-1, sensitivity: this.getProp('sensitivity'), @@ -336,6 +341,7 @@ module.exports = class MultiXy extends Pad { } return case 'spring': + case 'axisLock': for (let w of this.pads) { w.cachedProps[propName] = this.getProp(propName) w.onPropChanged(propName, options) diff --git a/src/client/widgets/pads/xy.js b/src/client/widgets/pads/xy.js index a68dce22..f2e4a1aa 100644 --- a/src/client/widgets/pads/xy.js +++ b/src/client/widgets/pads/xy.js @@ -33,7 +33,7 @@ module.exports = class Xy extends Pad { logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis. Set to `-1` for exponential scale.'}, logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis. Set to `-1` for exponential scale.'}, axisLock: {type: 'string', value: '', choices: ['', 'x', 'y'], help: [ - 'Restrict movements to one of the axes only.', + 'Restrict movements to one of the axes only unless `Shift` is held.', 'When left to the default value, holding `Shift` while dragging will lock the pad according the first movement.' ]}, doubleTap: {type: 'boolean|string', value: false, help: [ @@ -98,6 +98,7 @@ module.exports = class Xy extends Pad { this.active = true this.autoAxisLock = '' var axis = this.getProp('axisLock') + if (axis !== '' && e.shiftKey) axis = '' if (axis !== 'y') this.faders.x.trigger('draginit', {...e, stopPropagation: true}) if (axis !== 'x') this.faders.y.trigger('draginit', {...e, stopPropagation: true}) this.dragHandle() @@ -105,7 +106,8 @@ module.exports = class Xy extends Pad { this.on('drag',(e)=>{ var axis = this.getProp('axisLock') - if (e.shiftKey && axis === '') { + if (axis !== '' && e.shiftKey) axis = '' + else if (e.shiftKey && axis === '') { if (this.autoAxisLock === '') { if (Math.abs(e.movementX) > Math.abs(e.movementY)) { this.autoAxisLock = 'x' @@ -123,6 +125,7 @@ module.exports = class Xy extends Pad { this.on('dragend', (e)=>{ this.active = false var axis = this.getProp('axisLock') + if (axis !== '' && e.shiftKey) axis = '' if (axis !== 'y') this.faders.x.trigger('dragend', {...e, stopPropagation: true}) if (axis !== 'x') this.faders.y.trigger('dragend', {...e, stopPropagation: true}) if (this.getProp('spring')) {