knob: act as a relative encoder when traversing gestures are enabled and snap is false (#498)

This commit is contained in:
jean-emmanuel 2019-03-22 14:33:53 +01:00
parent 3cfde808e5
commit 567f57f9e9
2 changed files with 34 additions and 10 deletions

View file

@ -6,6 +6,7 @@
- added context menu action to display midi device list without starting the server
- widgets
- switch: add `traversing` option (`true` by default)
- knob: act as a relative encoder when traversing gestures are enabled and `snap` is `false`
- custom module
- expose shorthand functions `send` and `receives`
- expose a client object instead of just an id in `app` event handlers to allow retrieving the client's ip address as well

View file

@ -76,28 +76,49 @@ module.exports = class Knob extends Slider {
this.lastOffsetX = e.offsetX
this.lastOffsetY = e.offsetY
if (!(e.traversing || this.getProp('snap')) || e.ctrlKey) return
// if (!(e.traversing || this.getProp('snap')) || e.ctrlKey) return
this.percent = this.angleToPercent(this.coordsToAngle(e.offsetX, e.offsetY))
if (this.getProp('snap')) {
this.percent = this.angleToPercent(this.coordsToAngle(e.offsetX, e.offsetY))
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
}
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
}
dragHandle(e) {
if (!(e.traversing || this.getProp('snap')) || e.ctrlKey) {
// vertical
this.percent = -100 * (e.movementY / e.inertia) / this.height + this.percent
} else {
//snap
var offsetX = this.lastOffsetX + e.movementX / e.inertia,
offsetY = this.lastOffsetY + e.movementY / e.inertia
if (e.traversing && !this.getProp('snap')) {
var diff = this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true) - this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY), true)
if (Math.abs(diff) < 50 && diff !== 0) this.percent += diff
} else {
// snap
this.percent = this.angleToPercent(this.coordsToAngle(offsetX, offsetY))
}
this.lastOffsetX = offsetX
this.lastOffsetY = offsetY
this.lastOffsetX = this.lastOffsetX + e.movementX / e.inertia
this.lastOffsetY = this.lastOffsetY + e.movementY / e.inertia
this.percent = this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY))
}
this.percent = this.percent,[0,100]
this.percent = clip(this.percent,[0,100])
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
@ -113,9 +134,11 @@ module.exports = class Knob extends Slider {
}
angleToPercent(angle) {
angleToPercent(angle, ignoreMaxAngle=false) {
return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100
return ignoreMaxAngle ?
clip(angle, [0, 360]) / 360 * 100 :
clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100
}