widgets: continue sliders oop + canvas reimplementation, knobs almost ok, added origin and angle option
This commit is contained in:
parent
36d5944ce0
commit
4def266315
7 changed files with 664 additions and 358 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,7 @@
|
|||
var widgets = {
|
||||
// sliders
|
||||
fader: require('./widgets/sliders/fader'),
|
||||
knob: require('./widgets/knob'),
|
||||
knob: require('./widgets/sliders/knob'),
|
||||
|
||||
// buttons
|
||||
toggle: require('./widgets/toggle'),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ var _sliders_base = module.exports = function(){
|
|||
|
||||
_canvas_base.apply(this, arguments)
|
||||
|
||||
this.wrapper = this.widget.find('.wrapper')
|
||||
this.input = this.widget.find('.input').fakeInput({align:'center'})
|
||||
this.roundFactor = Math.pow(10,this.widgetData.precision)
|
||||
this.value = undefined
|
||||
|
|
|
|||
|
|
@ -1,6 +1,43 @@
|
|||
var {clip, mapToScale, sendOsc} = require('../utils'),
|
||||
_sliders_base = require('./_sliders_base')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'fader',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
separator1:'style',
|
||||
|
||||
label:'auto',
|
||||
unit:'',
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
alignRight:false,
|
||||
horizontal:false,
|
||||
noPip:false,
|
||||
compact:false,
|
||||
color:'auto',
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
||||
snap:false,
|
||||
|
||||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScale:false,
|
||||
precision:2,
|
||||
meter:false,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
|
||||
var Fader = function(widgetData){
|
||||
|
||||
_sliders_base.apply(this,arguments)
|
||||
|
|
@ -157,12 +194,12 @@ Fader.prototype.draw = function(){
|
|||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 10 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 10 * PXSCALE, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 4 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 4 * PXSCALE, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +221,7 @@ Fader.prototype.draw = function(){
|
|||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.rect(0, Math.min(d,this.height-PXSCALE), this.width, PXSCALE)
|
||||
this.ctx.rect(0, Math.min(d, this.height - PXSCALE), this.width, PXSCALE)
|
||||
this.ctx.fill()
|
||||
|
||||
|
||||
|
|
@ -207,54 +244,17 @@ Fader.prototype.draw = function(){
|
|||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.arc(this.width / 2, d, 10 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(this.width / 2, d, 10 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(this.width / 2, d, 4 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(this.width / 2, d, 4 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'fader',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
separator1:'style',
|
||||
|
||||
label:'auto',
|
||||
unit:'',
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
alignRight:false,
|
||||
horizontal:false,
|
||||
noPip:false,
|
||||
compact:false,
|
||||
color:'auto',
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
||||
snap:false,
|
||||
|
||||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScale:false,
|
||||
precision:2,
|
||||
meter:false,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
var fader = new Fader(widgetData, container)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
var utils = require('./utils'),
|
||||
clip = utils.clip,
|
||||
mapToScale = utils.mapToScale,
|
||||
sendOsc = utils.sendOsc
|
||||
var {clip, mapToScale, sendOsc} = require('../utils'),
|
||||
_sliders_base = require('./_sliders_base')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'knob',
|
||||
|
|
@ -19,6 +18,7 @@ module.exports.options = {
|
|||
color:'auto',
|
||||
noPip:false,
|
||||
compact:false,
|
||||
angle:270,
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
|
@ -28,13 +28,153 @@ module.exports.options = {
|
|||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScale:false,
|
||||
precision:2,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
|
||||
|
||||
Knob = function(widgetData) {
|
||||
|
||||
_sliders_base.apply(this,arguments)
|
||||
|
||||
this.widget.addClass('knob')
|
||||
|
||||
this.lastOffsetX = 0
|
||||
this.lastOffsetY = 0
|
||||
this.minDimension = 0
|
||||
|
||||
this.maxAngle = widgetData.angle
|
||||
|
||||
// calculate lost height factor
|
||||
var a = Math.sin((360 - this.maxAngle)),
|
||||
h = a < 0 ? 1 - a : a
|
||||
|
||||
this.lostHeightFactor = h / 4
|
||||
|
||||
}
|
||||
|
||||
|
||||
Knob.prototype = Object.create(_sliders_base.prototype)
|
||||
|
||||
Knob.prototype.constructor = Knob
|
||||
|
||||
Knob.prototype.draginitHandle = function(e, data, traversing){
|
||||
|
||||
this.percent = clip(this.percent,[0,100])
|
||||
|
||||
this.lastOffsetX = data.offsetX
|
||||
this.lastOffsetY = data.offsetY
|
||||
|
||||
if (!(traversing || this.widgetData.snap)) return
|
||||
|
||||
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true, true)
|
||||
|
||||
}
|
||||
|
||||
Knob.prototype.dragHandle = function(e, data, traversing) {
|
||||
|
||||
|
||||
if (!(traversing || this.widgetData.snap)) {
|
||||
|
||||
this.percent = -data.speedY + this.percent
|
||||
|
||||
} else {
|
||||
|
||||
this.lastOffsetX = this.lastOffsetX + data.speedX
|
||||
this.lastOffsetY = this.lastOffsetY + data.speedY
|
||||
this.percent = this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY))
|
||||
}
|
||||
|
||||
this.percent = this.percent,[0,100]
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true, true)
|
||||
|
||||
}
|
||||
|
||||
Knob.prototype.coordsToAngle = function(x,y) {
|
||||
var xToCenter = x - this.width /2,
|
||||
yToCenter = y - this.height / 2,
|
||||
angle = Math.atan2(-yToCenter, -xToCenter) * 180 / Math.PI + 90
|
||||
|
||||
return angle<0?360+angle:angle
|
||||
}
|
||||
|
||||
Knob.prototype.angleToPercent = function(angle) {
|
||||
return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100
|
||||
}
|
||||
|
||||
Knob.prototype.percentToAngle = function(percent) {
|
||||
var percent = clip(percent, [0, 100])
|
||||
return 2 * Math.PI * percent / 100 * (this.maxAngle / 360) // angle relative to maxAngle
|
||||
+ Math.PI / 2 // quarter circle offset
|
||||
+ Math.PI * (1 - this.maxAngle / 360) // centering offset depending on maxAngle
|
||||
}
|
||||
|
||||
Knob.prototype.resizeHandle = function() {
|
||||
_sliders_base.prototype.resizeHandle.call(this)
|
||||
this.minDimension = Math.min(this.width, this.height)
|
||||
this.canvas[0].style.top = (this.minDimension / 2 - 15) * this.lostHeightFactor + 'px'
|
||||
}
|
||||
|
||||
|
||||
Knob.prototype.draw = function(){
|
||||
|
||||
var o = this.percentToAngle(this.valueToPercent(this.originValue)),
|
||||
d = this.percentToAngle(this.percent),
|
||||
min = this.percentToAngle(0),
|
||||
max = this.percentToAngle(100)
|
||||
|
||||
this.ctx.clearRect(0,0,this.width,this.height)
|
||||
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.track
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - 15 * PXSCALE, min, max)
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.custom
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - 15 * PXSCALE, Math.min(o,d), Math.max(o,d))
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
this.ctx.save()
|
||||
|
||||
this.ctx.translate(this.width / 2, this.height / 2)
|
||||
this.ctx.rotate(d)
|
||||
this.ctx.translate(-this.width / 2, -this.height / 2)
|
||||
|
||||
this.ctx.beginPath()
|
||||
|
||||
this.ctx.fillStyle = this.colors.gauge
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - 15 * PXSCALE, this.height / 2, 4 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - 15 * PXSCALE, this.height / 2, 10 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.restore()
|
||||
}
|
||||
|
||||
|
||||
module.exports.create = function(widgetData) {
|
||||
var knob = new Knob(widgetData)
|
||||
return knob.widget
|
||||
}
|
||||
|
||||
|
||||
|
||||
var oldstuf = function(widgetData,container) {
|
||||
var widget = $(`
|
||||
<div class="knob-wrapper-outer">
|
||||
<div class="knob-wrapper">
|
||||
|
|
@ -1610,7 +1610,7 @@ module.exports = {
|
|||
var widgets = {
|
||||
// sliders
|
||||
fader: require('./widgets/sliders/fader'),
|
||||
knob: require('./widgets/knob'),
|
||||
knob: require('./widgets/sliders/knob'),
|
||||
|
||||
// buttons
|
||||
toggle: require('./widgets/toggle'),
|
||||
|
|
@ -1689,7 +1689,7 @@ module.exports.sync = function() {
|
|||
})
|
||||
}
|
||||
|
||||
},{"./widgets/knob":17,"./widgets/multifader":18,"./widgets/multipush":19,"./widgets/multitoggle":20,"./widgets/panel":21,"./widgets/plots/eq":24,"./widgets/plots/led":25,"./widgets/plots/meter":26,"./widgets/plots/plot":27,"./widgets/plots/text":28,"./widgets/plots/visualizer":29,"./widgets/push":30,"./widgets/rgb":31,"./widgets/sliders/fader":33,"./widgets/strip":34,"./widgets/switch":35,"./widgets/toggle":36,"./widgets/xy":38}],15:[function(require,module,exports){
|
||||
},{"./widgets/multifader":17,"./widgets/multipush":18,"./widgets/multitoggle":19,"./widgets/panel":20,"./widgets/plots/eq":23,"./widgets/plots/led":24,"./widgets/plots/meter":25,"./widgets/plots/plot":26,"./widgets/plots/text":27,"./widgets/plots/visualizer":28,"./widgets/push":29,"./widgets/rgb":30,"./widgets/sliders/fader":32,"./widgets/sliders/knob":33,"./widgets/strip":34,"./widgets/switch":35,"./widgets/toggle":36,"./widgets/xy":38}],15:[function(require,module,exports){
|
||||
var _widgets_base = require('./_widgets_base')
|
||||
|
||||
var _canvas_base = module.exports = function() {
|
||||
|
|
@ -1760,284 +1760,6 @@ var _widget_base = module.exports = function(widgetData) {
|
|||
}
|
||||
|
||||
},{}],17:[function(require,module,exports){
|
||||
var utils = require('./utils'),
|
||||
clip = utils.clip,
|
||||
mapToScale = utils.mapToScale,
|
||||
sendOsc = utils.sendOsc
|
||||
|
||||
module.exports.options = {
|
||||
type:'knob',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
separator1:'style',
|
||||
|
||||
label:'auto',
|
||||
unit:'',
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
color:'auto',
|
||||
noPip:false,
|
||||
compact:false,
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
||||
snap:false,
|
||||
|
||||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
logScale:false,
|
||||
precision:2,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
module.exports.create = function(widgetData,container) {
|
||||
var widget = $(`
|
||||
<div class="knob-wrapper-outer">
|
||||
<div class="knob-wrapper">
|
||||
<div class="knob-mask">
|
||||
<div class="knob"><span></span></div>
|
||||
<div class="handle"></div>
|
||||
</div>
|
||||
<div class="pips">
|
||||
<div class="pip min"></div>
|
||||
<div class="pip max"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input"></div>
|
||||
</div>
|
||||
`),
|
||||
wrapper = widget.find('.knob-wrapper'),
|
||||
mask = widget.find('.knob-mask'),
|
||||
knob = widget.find('.knob'),
|
||||
handle = widget.find('.handle'),
|
||||
input = widget.find('.input').fakeInput({align:'center'}),
|
||||
range = widgetData.range,
|
||||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||||
snap = widgetData.snap,
|
||||
logScale = widgetData.logScale,
|
||||
roundFactor = Math.pow(10,widgetData.precision)
|
||||
|
||||
if (widgetData.noPip) wrapper.addClass('no-pip')
|
||||
if (widgetData.compact) container.addClass('compact')
|
||||
|
||||
|
||||
var rangeKeys = [],
|
||||
rangeVals = [],
|
||||
rangeLabels = []
|
||||
|
||||
for (k in widgetData.range) {
|
||||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||||
val = typeof widgetData.range[k] == 'object'?
|
||||
widgetData.range[k][Object.keys(widgetData.range[k])[0]]:
|
||||
widgetData.range[k],
|
||||
label = typeof widgetData.range[k] == 'object'?
|
||||
Object.keys(widgetData.range[k])[0]:
|
||||
val
|
||||
|
||||
rangeKeys.push(key)
|
||||
rangeVals.push(val)
|
||||
rangeLabels.push(label)
|
||||
}
|
||||
|
||||
var rangeValsMax = Math.max.apply(Math, rangeVals),
|
||||
rangeValsMin = Math.min.apply(Math, rangeVals)
|
||||
|
||||
|
||||
var pipmin = Math.abs(rangeLabels[0])>=1000?rangeLabels[0]/1000+'k':rangeLabels[0],
|
||||
pipmax = Math.abs(rangeLabels[rangeLabels.length-1])>=1000?rangeLabels[rangeLabels.length-1]/1000+'k':rangeLabels[rangeLabels.length-1]
|
||||
|
||||
|
||||
|
||||
widget.find('.pip.min').text(pipmin)
|
||||
widget.find('.pip.max').text(pipmax)
|
||||
|
||||
mask.size = 0
|
||||
widget.value = undefined
|
||||
|
||||
wrapper.resize(function(e,width,height){
|
||||
|
||||
var w = Math.floor(Math.min(height,width)*.58)
|
||||
|
||||
if (!w || mask.size==w) return
|
||||
mask.size=w
|
||||
mask[0].setAttribute('style',`height:${w}px;width:${w}px;padding-bottom:0`)
|
||||
wrapper.size = {width:wrapper[0].clientWidth,height:wrapper[0].clientHeight}
|
||||
})
|
||||
|
||||
wrapper.on('fake-right-click',function(e){
|
||||
if (!EDITING) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
input.focus()
|
||||
}
|
||||
})
|
||||
|
||||
wrapper.on('mousewheel',function(e){
|
||||
if (e.originalEvent.wheelDeltaX) return
|
||||
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var divider = e.ctrlKey?48:8
|
||||
knob.rotation = clip(knob.rotation+e.originalEvent.wheelDeltaY/divider,[0,270])
|
||||
|
||||
widget.updateUi(knob.rotation)
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
knob.rotation = 0
|
||||
|
||||
var offR = 0,
|
||||
offX = 0,
|
||||
offY = 0
|
||||
wrapper.on('draginit',function(e,data,traversing){
|
||||
|
||||
if (snap || traversing) {
|
||||
|
||||
var w = wrapper.size.width,
|
||||
h = wrapper.size.height,
|
||||
x = data.offsetX-w/2,
|
||||
y = data.offsetY-h/2,
|
||||
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
|
||||
r = angle<-90?angle+360:angle
|
||||
r = (angle>=-90 && angle<-45)?270:r
|
||||
r = clip(r,[0,270])
|
||||
|
||||
offX = x
|
||||
offY = y
|
||||
|
||||
widget.updateUi(r)
|
||||
|
||||
knob.rotation = r
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
offR = knob.rotation
|
||||
})
|
||||
|
||||
wrapper.on('drag',function(e,data){
|
||||
|
||||
var r = clip(-data.deltaY*2+offR,[0,270])
|
||||
|
||||
if (snap || data.ctrlKey || data.shiftKey) {
|
||||
var w = data.target.clientWidth,
|
||||
h = data.target.clientHeight,
|
||||
x = data.deltaX + offX,
|
||||
y = data.deltaY + offY,
|
||||
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
|
||||
r = angle<-90?angle+360:angle
|
||||
r = (angle>=-90 && angle<-45)?270:r
|
||||
r = clip(r,[0,270])
|
||||
}
|
||||
|
||||
widget.updateUi(r)
|
||||
|
||||
knob.rotation = r
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
})
|
||||
|
||||
widget.updateUi = function(r) {
|
||||
knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
|
||||
handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
|
||||
|
||||
if (r>180) {knob.addClass('d3')}
|
||||
else if (r>90) {knob.removeClass('d3').addClass('d2')}
|
||||
else {knob.removeClass('d3 d2')}
|
||||
}
|
||||
|
||||
widget.getValue = function() {
|
||||
var h = knob.rotation
|
||||
for (var i=0;i<rangeKeys.length-1;i++) {
|
||||
if (h <= rangeKeys[i+1]*2.7 && h >= rangeKeys[i]*2.7) {
|
||||
return mapToScale(h,[rangeKeys[i]*2.7,rangeKeys[i+1]*2.7],[rangeVals[i],rangeVals[i+1]],widgetData.precision,logScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
widget.showValue = function(v) {
|
||||
input.val(v+unit)
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
var args = widgetData.preArgs.concat(v)
|
||||
|
||||
sendOsc({
|
||||
target:widgetData.target,
|
||||
path:widgetData.path,
|
||||
precision:widgetData.precision,
|
||||
args:args
|
||||
})
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
var v = clip(Math.round(v*roundFactor)/roundFactor,[rangeValsMin,rangeValsMax]),
|
||||
r
|
||||
|
||||
for (var i=0;i<rangeVals.length-1;i++) {
|
||||
if (v <= rangeVals[i+1] && v >= rangeVals[i]) {
|
||||
r = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i]*2.7,rangeKeys[i+1]*2.7],false,logScale,true)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
knob.rotation = r
|
||||
|
||||
widget.updateUi(r)
|
||||
|
||||
var v = widget.getValue()
|
||||
widget.value = v
|
||||
|
||||
widget.showValue(v)
|
||||
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
input.change(function(){
|
||||
widget.setValue(parseFloat(input.val()),true,true)
|
||||
})
|
||||
|
||||
widget.setValue(rangeVals[0])
|
||||
return widget
|
||||
}
|
||||
|
||||
},{"./utils":37}],18:[function(require,module,exports){
|
||||
module.exports.options = {
|
||||
type:'multifader',
|
||||
id:'auto',
|
||||
|
|
@ -2124,7 +1846,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"../parser":10}],19:[function(require,module,exports){
|
||||
},{"../parser":10}],18:[function(require,module,exports){
|
||||
module.exports.options = {
|
||||
type:'multipush',
|
||||
id:'auto',
|
||||
|
|
@ -2202,7 +1924,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"../parser":10}],20:[function(require,module,exports){
|
||||
},{"../parser":10}],19:[function(require,module,exports){
|
||||
module.exports.options = {
|
||||
type:'multitoggle',
|
||||
id:'auto',
|
||||
|
|
@ -2280,7 +2002,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"../parser":10}],21:[function(require,module,exports){
|
||||
},{"../parser":10}],20:[function(require,module,exports){
|
||||
module.exports.options = {
|
||||
type:'panel',
|
||||
id:'auto',
|
||||
|
|
@ -2323,7 +2045,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"../parser":10}],22:[function(require,module,exports){
|
||||
},{"../parser":10}],21:[function(require,module,exports){
|
||||
//
|
||||
// calcBiquad
|
||||
//
|
||||
|
|
@ -2462,7 +2184,7 @@ module.exports = function(options,linear,resolution) {
|
|||
return magPlot
|
||||
}
|
||||
|
||||
},{}],23:[function(require,module,exports){
|
||||
},{}],22:[function(require,module,exports){
|
||||
var {mapToScale} = require('../utils'),
|
||||
_canvas_base = require('../common/_canvas_base')
|
||||
|
||||
|
|
@ -2590,7 +2312,7 @@ _plots_base.prototype.updateData = function(){
|
|||
// update the coordinates to draw
|
||||
}
|
||||
|
||||
},{"../common/_canvas_base":15,"../utils":37}],24:[function(require,module,exports){
|
||||
},{"../common/_canvas_base":15,"../utils":37}],23:[function(require,module,exports){
|
||||
var {mapToScale, clip} = require('../utils'),
|
||||
_biquad_response = require('./_biquad_response'),
|
||||
_plots_base = require('./_plots_base')
|
||||
|
|
@ -2704,7 +2426,7 @@ module.exports.create = function(widgetData) {
|
|||
return eq.widget
|
||||
}
|
||||
|
||||
},{"../utils":37,"./_biquad_response":22,"./_plots_base":23}],25:[function(require,module,exports){
|
||||
},{"../utils":37,"./_biquad_response":21,"./_plots_base":22}],24:[function(require,module,exports){
|
||||
var {mapToScale} = require('../utils')
|
||||
|
||||
module.exports.options = {
|
||||
|
|
@ -2747,7 +2469,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"../utils":37}],26:[function(require,module,exports){
|
||||
},{"../utils":37}],25:[function(require,module,exports){
|
||||
var {mapToScale, clip} = require('../utils')
|
||||
|
||||
module.exports.options = {
|
||||
|
|
@ -2834,7 +2556,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"../utils":37}],27:[function(require,module,exports){
|
||||
},{"../utils":37}],26:[function(require,module,exports){
|
||||
var {mapToScale} = require('../utils'),
|
||||
_plots_base = require('./_plots_base')
|
||||
|
||||
|
|
@ -2924,7 +2646,7 @@ module.exports.create = function(widgetData) {
|
|||
return plot.widget
|
||||
}
|
||||
|
||||
},{"../utils":37,"./_plots_base":23}],28:[function(require,module,exports){
|
||||
},{"../utils":37,"./_plots_base":22}],27:[function(require,module,exports){
|
||||
module.exports.options = {
|
||||
type:'text',
|
||||
id:'auto',
|
||||
|
|
@ -2977,7 +2699,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{}],29:[function(require,module,exports){
|
||||
},{}],28:[function(require,module,exports){
|
||||
var {mapToScale, clip} = require('../utils'),
|
||||
_plots_base = require('./_plots_base')
|
||||
|
||||
|
|
@ -3105,7 +2827,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return visualizer.widget
|
||||
}
|
||||
|
||||
},{"../utils":37,"./_plots_base":23}],30:[function(require,module,exports){
|
||||
},{"../utils":37,"./_plots_base":22}],29:[function(require,module,exports){
|
||||
var sendOsc = require('./utils').sendOsc
|
||||
|
||||
module.exports.options = {
|
||||
|
|
@ -3214,7 +2936,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"./utils":37}],31:[function(require,module,exports){
|
||||
},{"./utils":37}],30:[function(require,module,exports){
|
||||
var utils = require('./utils'),
|
||||
clip = utils.clip,
|
||||
mapToScale = utils.mapToScale,
|
||||
|
|
@ -3508,7 +3230,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget
|
||||
}
|
||||
|
||||
},{"./utils":37}],32:[function(require,module,exports){
|
||||
},{"./utils":37}],31:[function(require,module,exports){
|
||||
var {clip, roundTo, mapToScale, sendOsc} = require('../utils')
|
||||
var _canvas_base = require('../common/_canvas_base')
|
||||
|
||||
|
|
@ -3525,6 +3247,7 @@ var _sliders_base = module.exports = function(){
|
|||
|
||||
_canvas_base.apply(this, arguments)
|
||||
|
||||
this.wrapper = this.widget.find('.wrapper')
|
||||
this.input = this.widget.find('.input').fakeInput({align:'center'})
|
||||
this.roundFactor = Math.pow(10,this.widgetData.precision)
|
||||
this.value = undefined
|
||||
|
|
@ -3683,10 +3406,47 @@ _sliders_base.prototype.showValue = function() {
|
|||
this.input.val(this.value + ' ' + this.widgetData.unit)
|
||||
}
|
||||
|
||||
},{"../common/_canvas_base":15,"../utils":37}],33:[function(require,module,exports){
|
||||
},{"../common/_canvas_base":15,"../utils":37}],32:[function(require,module,exports){
|
||||
var {clip, mapToScale, sendOsc} = require('../utils'),
|
||||
_sliders_base = require('./_sliders_base')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'fader',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
separator1:'style',
|
||||
|
||||
label:'auto',
|
||||
unit:'',
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
alignRight:false,
|
||||
horizontal:false,
|
||||
noPip:false,
|
||||
compact:false,
|
||||
color:'auto',
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
||||
snap:false,
|
||||
|
||||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScale:false,
|
||||
precision:2,
|
||||
meter:false,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
|
||||
var Fader = function(widgetData){
|
||||
|
||||
_sliders_base.apply(this,arguments)
|
||||
|
|
@ -3843,12 +3603,12 @@ Fader.prototype.draw = function(){
|
|||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 10 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 10 * PXSCALE, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 4 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 4 * PXSCALE, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
}
|
||||
|
||||
|
|
@ -3870,7 +3630,7 @@ Fader.prototype.draw = function(){
|
|||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.rect(0, Math.min(d,this.height-PXSCALE), this.width, PXSCALE)
|
||||
this.ctx.rect(0, Math.min(d, this.height - PXSCALE), this.width, PXSCALE)
|
||||
this.ctx.fill()
|
||||
|
||||
|
||||
|
|
@ -3893,20 +3653,30 @@ Fader.prototype.draw = function(){
|
|||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.arc(this.width / 2, d, 10 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(this.width / 2, d, 10 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(this.width / 2, d, 4 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.arc(this.width / 2, d, 4 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
var fader = new Fader(widgetData, container)
|
||||
return fader.widget
|
||||
}
|
||||
|
||||
},{"../../parser":10,"../utils":37,"./_sliders_base":31}],33:[function(require,module,exports){
|
||||
var {clip, mapToScale, sendOsc} = require('../utils'),
|
||||
_sliders_base = require('./_sliders_base')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'fader',
|
||||
type:'knob',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
|
|
@ -3918,11 +3688,10 @@ module.exports.options = {
|
|||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
alignRight:false,
|
||||
horizontal:false,
|
||||
color:'auto',
|
||||
noPip:false,
|
||||
compact:false,
|
||||
color:'auto',
|
||||
angle:270,
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
|
@ -3935,19 +3704,391 @@ module.exports.options = {
|
|||
origin: 'auto',
|
||||
logScale:false,
|
||||
precision:2,
|
||||
meter:false,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
var fader = new Fader(widgetData, container)
|
||||
return fader.widget
|
||||
|
||||
Knob = function(widgetData) {
|
||||
|
||||
_sliders_base.apply(this,arguments)
|
||||
|
||||
this.widget.addClass('knob')
|
||||
|
||||
this.lastOffsetX = 0
|
||||
this.lastOffsetY = 0
|
||||
this.minDimension = 0
|
||||
|
||||
this.maxAngle = widgetData.angle
|
||||
|
||||
// calculate lost height factor
|
||||
var a = Math.sin((360 - this.maxAngle)),
|
||||
h = a < 0 ? 1 - a : a
|
||||
|
||||
this.lostHeightFactor = h / 4
|
||||
|
||||
}
|
||||
|
||||
},{"../../parser":10,"../utils":37,"./_sliders_base":32}],34:[function(require,module,exports){
|
||||
|
||||
Knob.prototype = Object.create(_sliders_base.prototype)
|
||||
|
||||
Knob.prototype.constructor = Knob
|
||||
|
||||
Knob.prototype.draginitHandle = function(e, data, traversing){
|
||||
|
||||
this.percent = clip(this.percent,[0,100])
|
||||
|
||||
this.lastOffsetX = data.offsetX
|
||||
this.lastOffsetY = data.offsetY
|
||||
|
||||
if (!(traversing || this.widgetData.snap)) return
|
||||
|
||||
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true, true)
|
||||
|
||||
}
|
||||
|
||||
Knob.prototype.dragHandle = function(e, data, traversing) {
|
||||
|
||||
|
||||
if (!(traversing || this.widgetData.snap)) {
|
||||
|
||||
this.percent = -data.speedY + this.percent
|
||||
|
||||
} else {
|
||||
|
||||
this.lastOffsetX = this.lastOffsetX + data.speedX
|
||||
this.lastOffsetY = this.lastOffsetY + data.speedY
|
||||
this.percent = this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY))
|
||||
}
|
||||
|
||||
this.percent = this.percent,[0,100]
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true, true)
|
||||
|
||||
}
|
||||
|
||||
Knob.prototype.coordsToAngle = function(x,y) {
|
||||
var xToCenter = x - this.width /2,
|
||||
yToCenter = y - this.height / 2,
|
||||
angle = Math.atan2(-yToCenter, -xToCenter) * 180 / Math.PI + 90
|
||||
|
||||
return angle<0?360+angle:angle
|
||||
}
|
||||
|
||||
Knob.prototype.angleToPercent = function(angle) {
|
||||
return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100
|
||||
}
|
||||
|
||||
Knob.prototype.percentToAngle = function(percent) {
|
||||
var percent = clip(percent, [0, 100])
|
||||
return 2 * Math.PI * percent / 100 * (this.maxAngle / 360) // angle relative to maxAngle
|
||||
+ Math.PI / 2 // quarter circle offset
|
||||
+ Math.PI * (1 - this.maxAngle / 360) // centering offset depending on maxAngle
|
||||
}
|
||||
|
||||
Knob.prototype.resizeHandle = function() {
|
||||
_sliders_base.prototype.resizeHandle.call(this)
|
||||
this.minDimension = Math.min(this.width, this.height)
|
||||
this.canvas[0].style.top = (this.minDimension / 2 - 15) * this.lostHeightFactor + 'px'
|
||||
}
|
||||
|
||||
|
||||
Knob.prototype.draw = function(){
|
||||
|
||||
var o = this.percentToAngle(this.valueToPercent(this.originValue)),
|
||||
d = this.percentToAngle(this.percent),
|
||||
min = this.percentToAngle(0),
|
||||
max = this.percentToAngle(100)
|
||||
|
||||
this.ctx.clearRect(0,0,this.width,this.height)
|
||||
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.track
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - 15 * PXSCALE, min, max)
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.custom
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - 15 * PXSCALE, Math.min(o,d), Math.max(o,d))
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
this.ctx.save()
|
||||
|
||||
this.ctx.translate(this.width / 2, this.height / 2)
|
||||
this.ctx.rotate(d)
|
||||
this.ctx.translate(-this.width / 2, -this.height / 2)
|
||||
|
||||
this.ctx.beginPath()
|
||||
|
||||
this.ctx.fillStyle = this.colors.gauge
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - 15 * PXSCALE, this.height / 2, 4 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - 15 * PXSCALE, this.height / 2, 10 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.restore()
|
||||
}
|
||||
|
||||
|
||||
module.exports.create = function(widgetData) {
|
||||
var knob = new Knob(widgetData)
|
||||
return knob.widget
|
||||
}
|
||||
|
||||
|
||||
|
||||
var oldstuf = function(widgetData,container) {
|
||||
var widget = $(`
|
||||
<div class="knob-wrapper-outer">
|
||||
<div class="knob-wrapper">
|
||||
<div class="knob-mask">
|
||||
<div class="knob"><span></span></div>
|
||||
<div class="handle"></div>
|
||||
</div>
|
||||
<div class="pips">
|
||||
<div class="pip min"></div>
|
||||
<div class="pip max"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input"></div>
|
||||
</div>
|
||||
`),
|
||||
wrapper = widget.find('.knob-wrapper'),
|
||||
mask = widget.find('.knob-mask'),
|
||||
knob = widget.find('.knob'),
|
||||
handle = widget.find('.handle'),
|
||||
input = widget.find('.input').fakeInput({align:'center'}),
|
||||
range = widgetData.range,
|
||||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||||
snap = widgetData.snap,
|
||||
logScale = widgetData.logScale,
|
||||
roundFactor = Math.pow(10,widgetData.precision)
|
||||
|
||||
if (widgetData.noPip) wrapper.addClass('no-pip')
|
||||
if (widgetData.compact) container.addClass('compact')
|
||||
|
||||
|
||||
var rangeKeys = [],
|
||||
rangeVals = [],
|
||||
rangeLabels = []
|
||||
|
||||
for (k in widgetData.range) {
|
||||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||||
val = typeof widgetData.range[k] == 'object'?
|
||||
widgetData.range[k][Object.keys(widgetData.range[k])[0]]:
|
||||
widgetData.range[k],
|
||||
label = typeof widgetData.range[k] == 'object'?
|
||||
Object.keys(widgetData.range[k])[0]:
|
||||
val
|
||||
|
||||
rangeKeys.push(key)
|
||||
rangeVals.push(val)
|
||||
rangeLabels.push(label)
|
||||
}
|
||||
|
||||
var rangeValsMax = Math.max.apply(Math, rangeVals),
|
||||
rangeValsMin = Math.min.apply(Math, rangeVals)
|
||||
|
||||
|
||||
var pipmin = Math.abs(rangeLabels[0])>=1000?rangeLabels[0]/1000+'k':rangeLabels[0],
|
||||
pipmax = Math.abs(rangeLabels[rangeLabels.length-1])>=1000?rangeLabels[rangeLabels.length-1]/1000+'k':rangeLabels[rangeLabels.length-1]
|
||||
|
||||
|
||||
|
||||
widget.find('.pip.min').text(pipmin)
|
||||
widget.find('.pip.max').text(pipmax)
|
||||
|
||||
mask.size = 0
|
||||
widget.value = undefined
|
||||
|
||||
wrapper.resize(function(e,width,height){
|
||||
|
||||
var w = Math.floor(Math.min(height,width)*.58)
|
||||
|
||||
if (!w || mask.size==w) return
|
||||
mask.size=w
|
||||
mask[0].setAttribute('style',`height:${w}px;width:${w}px;padding-bottom:0`)
|
||||
wrapper.size = {width:wrapper[0].clientWidth,height:wrapper[0].clientHeight}
|
||||
})
|
||||
|
||||
wrapper.on('fake-right-click',function(e){
|
||||
if (!EDITING) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
input.focus()
|
||||
}
|
||||
})
|
||||
|
||||
wrapper.on('mousewheel',function(e){
|
||||
if (e.originalEvent.wheelDeltaX) return
|
||||
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var divider = e.ctrlKey?48:8
|
||||
knob.rotation = clip(knob.rotation+e.originalEvent.wheelDeltaY/divider,[0,270])
|
||||
|
||||
widget.updateUi(knob.rotation)
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
knob.rotation = 0
|
||||
|
||||
var offR = 0,
|
||||
offX = 0,
|
||||
offY = 0
|
||||
wrapper.on('draginit',function(e,data,traversing){
|
||||
|
||||
if (snap || traversing) {
|
||||
|
||||
var w = wrapper.size.width,
|
||||
h = wrapper.size.height,
|
||||
x = data.offsetX-w/2,
|
||||
y = data.offsetY-h/2,
|
||||
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
|
||||
r = angle<-90?angle+360:angle
|
||||
r = (angle>=-90 && angle<-45)?270:r
|
||||
r = clip(r,[0,270])
|
||||
|
||||
offX = x
|
||||
offY = y
|
||||
|
||||
widget.updateUi(r)
|
||||
|
||||
knob.rotation = r
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
offR = knob.rotation
|
||||
})
|
||||
|
||||
wrapper.on('drag',function(e,data){
|
||||
|
||||
var r = clip(-data.deltaY*2+offR,[0,270])
|
||||
|
||||
if (snap || data.ctrlKey || data.shiftKey) {
|
||||
var w = data.target.clientWidth,
|
||||
h = data.target.clientHeight,
|
||||
x = data.deltaX + offX,
|
||||
y = data.deltaY + offY,
|
||||
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
|
||||
r = angle<-90?angle+360:angle
|
||||
r = (angle>=-90 && angle<-45)?270:r
|
||||
r = clip(r,[0,270])
|
||||
}
|
||||
|
||||
widget.updateUi(r)
|
||||
|
||||
knob.rotation = r
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
})
|
||||
|
||||
widget.updateUi = function(r) {
|
||||
knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
|
||||
handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
|
||||
|
||||
if (r>180) {knob.addClass('d3')}
|
||||
else if (r>90) {knob.removeClass('d3').addClass('d2')}
|
||||
else {knob.removeClass('d3 d2')}
|
||||
}
|
||||
|
||||
widget.getValue = function() {
|
||||
var h = knob.rotation
|
||||
for (var i=0;i<rangeKeys.length-1;i++) {
|
||||
if (h <= rangeKeys[i+1]*2.7 && h >= rangeKeys[i]*2.7) {
|
||||
return mapToScale(h,[rangeKeys[i]*2.7,rangeKeys[i+1]*2.7],[rangeVals[i],rangeVals[i+1]],widgetData.precision,logScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
widget.showValue = function(v) {
|
||||
input.val(v+unit)
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
var args = widgetData.preArgs.concat(v)
|
||||
|
||||
sendOsc({
|
||||
target:widgetData.target,
|
||||
path:widgetData.path,
|
||||
precision:widgetData.precision,
|
||||
args:args
|
||||
})
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
var v = clip(Math.round(v*roundFactor)/roundFactor,[rangeValsMin,rangeValsMax]),
|
||||
r
|
||||
|
||||
for (var i=0;i<rangeVals.length-1;i++) {
|
||||
if (v <= rangeVals[i+1] && v >= rangeVals[i]) {
|
||||
r = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i]*2.7,rangeKeys[i+1]*2.7],false,logScale,true)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
knob.rotation = r
|
||||
|
||||
widget.updateUi(r)
|
||||
|
||||
var v = widget.getValue()
|
||||
widget.value = v
|
||||
|
||||
widget.showValue(v)
|
||||
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
input.change(function(){
|
||||
widget.setValue(parseFloat(input.val()),true,true)
|
||||
})
|
||||
|
||||
widget.setValue(rangeVals[0])
|
||||
return widget
|
||||
}
|
||||
|
||||
},{"../utils":37,"./_sliders_base":31}],34:[function(require,module,exports){
|
||||
|
||||
module.exports.options = {
|
||||
type:'strip',
|
||||
|
|
|
|||
|
|
@ -1,3 +1,27 @@
|
|||
.knob {
|
||||
height:100%;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
|
||||
.wrapper {
|
||||
overflow: hidden;
|
||||
flex:1;
|
||||
display: flex;
|
||||
max-height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
|
||||
canvas {
|
||||
flex:1;
|
||||
max-height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.knob-container {
|
||||
--color-pips: var(--color-text-fade);
|
||||
--color-gauge: var(--color-custom);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue