:warning long commit:

rewrite all widget classes using ES6 class expressions, much cleaner
this sets firefox version requirement to 46 because of a bug in v45 with spread arguments
This commit is contained in:
jean-emmanuel 2016-12-17 15:26:58 +01:00
parent 42f4afca7e
commit 9d4ebb1d1e
33 changed files with 2331 additions and 2318 deletions

View file

@ -35,7 +35,7 @@ var editObject = function(container, data, refresh){
for (i in params) {
if (i.indexOf('separator')!=-1) {
if (i.indexOf('_')==0) {
$(`<div class="separator"><span>${params[i]}</span></div>`).appendTo(form)
continue
} else if (data[i]===undefined) {

View file

@ -81,6 +81,7 @@ WidgetManager.prototype.addWidget = function(widget) {
}
widget.widget.abstract = widget
if (widget.container) widget.container[0].abstract = widget
}

View file

@ -103,7 +103,7 @@ module.exports.widgets = function(data,parent) {
// Set widget's undefined options to default
for (i in tmpWidgetOptions[widgetData.type]) {
if (i.indexOf('separator')==-1 && widgetData[i]===undefined) widgetData[i] = tmpWidgetOptions[widgetData.type][i]
if (i.indexOf('_')!=0 && widgetData[i]===undefined) widgetData[i] = tmpWidgetOptions[widgetData.type][i]
}
// Genrate widget's id, based on its type

View file

@ -45,7 +45,7 @@ module.exports.categories = {
module.exports.widgetOptions = function(){
var r = {}
for (i in widgets) {
r[i] = widgets[i].options
r[i] = widgets[i].options()
}
return r
}()
@ -53,7 +53,11 @@ module.exports.widgetOptions = function(){
module.exports.createWidget = function(){
var r = {}
for (i in widgets) {
r[i] = widgets[i].create
let x = i,
f = function(){
return new widgets[x](...arguments)
}
r[i] = f
}
return r
}()

View file

@ -2,131 +2,133 @@ var _widgets_base = require('../common/_widgets_base'),
$document = $(document),
osc = require('../../osc')
module.exports.options = {
type:'push',
id:'auto',
linkId:'',
module.exports = class Push extends _widgets_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
return {
type:'push',
id:'auto',
linkId:'',
separator2:'osc',
separator1:'style',
on:1,
off:0,
norelease:false,
precision:2,
address:'auto',
preArgs:[],
target:[]
}
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
var Push = module.exports.Push = function(widgetData,container) {
separator2:'osc',
_widgets_base.apply(this, arguments)
on:1,
off:0,
norelease:false,
precision:2,
address:'auto',
preArgs:[],
target:[]
}
}
this.widget = $(`
<div class="light">
</div>\
`)
constructor(widgetData) {
this.state = 0
this.active = 0
this.lastChanged = 'state'
var widgetHtml = `
<div class="light"></div>
`
this.widget.on('drag',function(e){e.stopPropagation()})
this.widget.on('draginit.push',()=>{
this.widget.off('draginit.push')
this.fakeclick()
})
super(...arguments, widgetHtml)
}
this.state = 0
this.active = 0
this.lastChanged = 'state'
Push.prototype = Object.create(_widgets_base.prototype)
Push.prototype.constructor = Push
Push.prototype.getValue = function(){
return this[this.lastChanged] ?
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
:
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
}
Push.prototype.fakeclick = function(){
if (!this.active) this.setValuePrivate(this.widgetData.on,{send:true,sync:true})
$document.on('dragend.push',()=>{
this.setValuePrivate(this.widgetData.off,{send:true,sync:true})
$document.off('dragend.push')
this.widget.on('drag',function(e){e.stopPropagation()})
this.widget.on('draginit.push',()=>{
this.widget.off('draginit.push')
this.fakeclick()
})
})
}
Push.prototype.setValuePrivate = function(v,options={}) {
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
this.widget.addClass('active')
this.active = 1
if (options.send) this.sendValue(v)
this.lastChanged = 'active'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
this.widget.removeClass('active')
this.active = 0
if (options.send) this.sendValue(v, this.widgetData.norelease)
this.lastChanged = 'active'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
}
}
Push.prototype.setValue = function(v,options={}) {
if (!options.fromExternal) {
if (options.send || options.sync) this.setValuePrivate(v,options)
return
getValue(){
return this[this.lastChanged] ?
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
:
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
}
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
this.widget.addClass('on')
this.state = 1
if (options.send) this.sendValue(v)
this.lastChanged = 'state'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options})
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
this.widget.removeClass('on')
this.state = 0
if (options.send) this.sendValue(v)
this.lastChanged = 'state'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options})
fakeclick(){
if (!this.active) this.setValuePrivate(this.widgetData.on,{send:true,sync:true})
$document.on('dragend.push',()=>{
this.setValuePrivate(this.widgetData.off,{send:true,sync:true})
$document.off('dragend.push')
this.widget.on('draginit.push',()=>{
this.widget.off('draginit.push')
this.fakeclick()
})
})
}
}
Push.prototype.sendValue = function(v, norelease) {
setValuePrivate(v,options={}) {
var args = this.widgetData.preArgs.concat(v)
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
this.widget.addClass('active')
this.active = 1
if (options.send) this.sendValue(v)
this.lastChanged = 'active'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
this.widget.removeClass('active')
this.active = 0
if (options.send) this.sendValue(v, this.widgetData.norelease)
this.lastChanged = 'active'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
}
osc.send({
target: this.widgetData.target,
address: this.widgetData.address,
precision: this.widgetData.precision,
args:args,
syncOnly:norelease
})
}
setValue(v,options={}) {
if (!options.fromExternal) {
if (options.send || options.sync) this.setValuePrivate(v,options)
return
}
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
this.widget.addClass('on')
this.state = 1
if (options.send) this.sendValue(v)
this.lastChanged = 'state'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options})
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
this.widget.removeClass('on')
this.state = 0
if (options.send) this.sendValue(v)
this.lastChanged = 'state'
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options})
}
}
sendValue(v, norelease) {
var args = this.widgetData.preArgs.concat(v)
osc.send({
target: this.widgetData.target,
address: this.widgetData.address,
precision: this.widgetData.precision,
args:args,
syncOnly:norelease
})
}
}
module.exports.create = function(widgetData, container) {
var push = new Push(widgetData, container)
return push
}

View file

@ -1,50 +1,51 @@
var _widgets_base = require('../common/_widgets_base'),
$document = $(document)
module.exports.options = {
type:'switch',
id:'auto',
linkId:'',
module.exports = class Switch extends _widgets_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
horizontal:false,
color:'auto',
css:'',
return {
type:'switch',
id:'auto',
linkId:'',
separator2:'osc',
_style:'style',
values:{"Value 1":1,"Value 2":2},
value:'',
precision:2,
address:'auto',
preArgs:[],
target:[]
}
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
horizontal:false,
color:'auto',
css:'',
var Switch = module.exports.Switch = function(widgetData,container) {
_osc:'osc',
_widgets_base.apply(this, arguments)
this.widget = $(`
<div class="switch">
</div>
`)
if (this.widgetData.horizontal) {
this.widget.addClass('horizontal')
values:{"Value 1":1,"Value 2":2},
value:'',
precision:2,
address:'auto',
preArgs:[],
target:[]
}
}
constructor(widgetData) {
var widgetHtml = `
<div class="switch ${widgetData.horizontal?'horizontal':''}"></div>
`
super(...arguments, widgetHtml)
this.values = []
for (k in this.widgetData.values) {
this.values.push(this.widgetData.values[k])
$('<div class="value">'+k+'</div>').data({value:this.widgetData.values[k]}).appendTo(this.widget)
for (var k in widgetData.values) {
this.values.push(widgetData.values[k])
$('<div class="value">'+k+'</div>').data({value:widgetData.values[k]}).appendTo(this.widget)
}
this.value = undefined
@ -64,28 +65,17 @@ var Switch = module.exports.Switch = function(widgetData,container) {
if (value!=this.value || this.value===undefined) this.setValue(value,{sync:true,send:true})
})
}
Switch.prototype = Object.create(_widgets_base.prototype)
Switch.prototype.constructor = Switch
Switch.prototype.setValue = function(v,options={}) {
var i = this.values.indexOf(v)
if (i!=-1) {
this.value = this.values[i]
this.widget.find('.on').removeClass('on')
this.widget.find('.value').eq(i).addClass('on')
if (options.send) this.sendValue(this.value)
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options})
}
}
setValue(v,options={}) {
module.exports.create = function(widgetData, container) {
var _switch = new Switch(widgetData, container)
return _switch
}
var i = this.values.indexOf(v)
if (i!=-1) {
this.value = this.values[i]
this.widget.find('.on').removeClass('on')
this.widget.find('.value').eq(i).addClass('on')
if (options.send) this.sendValue(this.value)
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options})
}
}}

View file

@ -1,101 +1,100 @@
var _widgets_base = require('../common/_widgets_base'),
$document = $(document)
module.exports.options = {
type:'toggle',
id:'auto',
linkId:'',
module.exports = class Toggle extends _widgets_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
return {
type:'toggle',
id:'auto',
linkId:'',
separator2:'osc',
_style:'style',
on:1,
off:0,
value:'',
precision:2,
address:'auto',
preArgs:[],
target:[]
}
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
var Toggle = module.exports.Toggle = function(widgetData,container) {
_osc:'osc',
_widgets_base.apply(this, arguments)
on:1,
off:0,
value:'',
precision:2,
address:'auto',
preArgs:[],
target:[]
}
this.widget = $(`
<div class="light">
</div>\
`)
}
this.widget.value = this.widget.find('span')
this.widget.state = 0
constructor() {
this.widget.on('drag',(e)=>{e.stopPropagation()})
this.widget.on('draginit.toggle',()=>{
this.widget.off('draginit.toggle')
this.fakeclick()
})
var widgetHtml = `
<div class="light"></div>
`
super(...arguments, widgetHtml)
this.value = this.getValue()
this.widget.value = this.widget.find('span')
this.widget.state = 0
}
Toggle.prototype = Object.create(_widgets_base.prototype)
Toggle.prototype.constructor = Toggle
Toggle.prototype.getValue = function(){
return this.widget.state ?
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
:
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
}
Toggle.prototype.fakeclick = function(){
var newVal = this.widget.state?this.widgetData.off:this.widgetData.on
this.setValue(newVal,{sync:true,send:true})
$document.on('dragend.toggle',()=>{
$document.off('dragend.toggle')
this.widget.on('drag',(e)=>{e.stopPropagation()})
this.widget.on('draginit.toggle',()=>{
this.widget.off('draginit.toggle')
this.fakeclick()
})
})
}
Toggle.prototype.setValue = function(v,options={}){
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
this.widget.addClass('on')
this.widget.state = 1
this.value = this.widgetData.on
if (options.send) this.sendValue(this.widgetData.on)
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
this.widget.removeClass('on')
this.widget.state = 0
this.value = this.widgetData.off
if (options.send) this.sendValue(this.widgetData.off)
this.value = this.getValue()
}
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options})
getValue() {
return this.widget.state ?
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
:
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
}
fakeclick() {
var newVal = this.widget.state?this.widgetData.off:this.widgetData.on
this.setValue(newVal,{sync:true,send:true})
$document.on('dragend.toggle',()=>{
$document.off('dragend.toggle')
this.widget.on('draginit.toggle',()=>{
this.widget.off('draginit.toggle')
this.fakeclick()
})
})
}
setValue(v,options={}) {
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
this.widget.addClass('on')
this.widget.state = 1
this.value = this.widgetData.on
if (options.send) this.sendValue(this.widgetData.on)
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
this.widget.removeClass('on')
this.widget.state = 0
this.value = this.widgetData.off
if (options.send) this.sendValue(this.widgetData.off)
}
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options})
}
}
module.exports.create = function(widgetData, container) {
var toggle = new Toggle(widgetData, container)
return toggle
}

View file

@ -1,70 +1,71 @@
var _widgets_base = require('./_widgets_base')
var _canvas_base = module.exports = function() {
module.exports = class _canvas_base extends _widgets_base {
_widgets_base.apply(this,arguments)
constructor() {
this.canvas = this.widget.find('canvas')
this.ctx = this.canvas[0].getContext('2d')
super(...arguments)
this.height = undefined
this.width = undefined
this.canvas = this.widget.find('canvas')
this.ctx = this.canvas[0].getContext('2d')
this.visible = false
this.height = undefined
this.width = undefined
this.colors = {}
this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
this.visible = false
this.colors = {}
this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
this.canvas.on('resize',this.resizeHandleProxy.bind(this))
this.canvas.on('resize',this.resizeHandleProxy.bind(this))
this.ctx.arc = (x, y, r, s, e, c)=>{
this.ctx.arc = (x, y, r, s, e, c)=>{
CanvasRenderingContext2D.prototype.arc.call(this.ctx, x, y, Math.max(0,r), s, e, c)
CanvasRenderingContext2D.prototype.arc.call(this.ctx, x, y, Math.max(0,r), s, e, c)
}
}
}
_canvas_base.prototype = Object.create(_widgets_base.prototype)
_canvas_base.prototype.constructor = _canvas_base
_canvas_base.prototype.resizeHandleProxy = function() {
this.resizeHandle.apply(this,arguments)
}
_canvas_base.prototype.resizeHandle = function(e, width, height, checkColors){
var width = width,
height = height
if (width && height) {
this.height=height
this.width=width
this.canvas[0].setAttribute('width',width)
this.canvas[0].setAttribute('height',height)
resizeHandleProxy() {
this.resizeHandle(...arguments)
}
if (!this.visible || checkColors) {
this.visible = true
var style = getComputedStyle(this.widget[0])
this.colors.custom = style.getPropertyValue('--color-custom')
this.colors.text = style.getPropertyValue('--color-text')
this.colors.raised = style.getPropertyValue('--color-raised')
this.colors.bg = style.getPropertyValue('--color-bg')
this.colors.fg = style.getPropertyValue('--color-fg')
this.colors.faded = style.getPropertyValue('--color-faded')
resizeHandle(e, width, height, checkColors){
var width = width,
height = height
if (width && height) {
this.height=height
this.width=width
this.canvas[0].setAttribute('width',width)
this.canvas[0].setAttribute('height',height)
}
if (!this.visible || checkColors) {
this.visible = true
var style = getComputedStyle(this.widget[0])
this.colors.custom = style.getPropertyValue('--color-custom')
this.colors.text = style.getPropertyValue('--color-text')
this.colors.raised = style.getPropertyValue('--color-raised')
this.colors.bg = style.getPropertyValue('--color-bg')
this.colors.fg = style.getPropertyValue('--color-fg')
this.colors.faded = style.getPropertyValue('--color-faded')
}
requestAnimationFrame(this.draw.bind(this))
}
requestAnimationFrame(this.draw.bind(this))
draw(){
throw 'Calling unimplemented draw() method'
}
}
_canvas_base.prototype.draw = function(){
//
}

View file

@ -1,58 +1,72 @@
var osc = require('../../osc')
var _widget_base = module.exports = function(widgetData) {
this.widgetData = widgetData
}
module.exports = class {
_widget_base.prototype.sendValue = function() {
static options() {
var args = this.widgetData.preArgs.concat(this.value)
throw 'Calling unimplemented static options() method'
osc.send({
target:this.widgetData.target,
address:this.widgetData.address,
precision:this.widgetData.precision,
args:args,
syncOnly:this.split?true:false
})
if (this.split) {
var n = 0
for (i in this.split) {
osc.send({
target:this.widgetData.target,
address:this.split[i],
precision:this.widgetData.precision,
args:this.widgetData.preArgs.concat(this.value[n]),
sync:false
})
n++
}
}
}
constructor(widgetData, widgetContainer, widgetHtml) {
_widget_base.prototype.getValue = function() {
this.container = widgetContainer
this.widget = $(widgetHtml)
this.widgetData = widgetData
if (typeof this.value == 'object') {
}
return (()=>{
sendValue() {
var a = []
var args = this.widgetData.preArgs.concat(this.value)
for (i in this.value) {
a.push(this.value[i])
osc.send({
target:this.widgetData.target,
address:this.widgetData.address,
precision:this.widgetData.precision,
args:args,
syncOnly:this.split?true:false
})
if (this.split) {
var n = 0
for (i in this.split) {
osc.send({
target:this.widgetData.target,
address:this.split[i],
precision:this.widgetData.precision,
args:this.widgetData.preArgs.concat(this.value[n]),
sync:false
})
n++
}
}
return a
}
})()
getValue() {
} else {
if (typeof this.value == 'object') {
return this.value
return (()=>{
var a = []
for (i in this.value) {
a.push(this.value[i])
}
return a
})()
} else {
return this.value
}
}

View file

@ -1,69 +1,65 @@
var {Panel} = require('./panel')
module.exports.options = {
type:'modal',
id:'auto',
separator1:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator2:'osc',
address:'auto',
separator3:'chilren',
widgets:[],
tabs:[]
}
var Modal = module.exports.Modal = function(widgetData, container) {
Panel.apply(this,arguments)
this.widget.removeClass('noscroll')
this.container = container
container.append('<div class="light"></div>')
this.light = container.find('.light').first()
this.modal = this.widget.detach()
this.value = false
this.light.on('fake-click',()=>{
this.setValue(!this.value)
})
var Panel = require('./panel'),
_widgets_base = require('../common/_widgets_base')
}
module.exports = class Modal extends Panel {
Modal.prototype = Object.create(Panel.prototype)
static options() {
Modal.prototype.constructor = Modal
return {
type:'modal',
id:'auto',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
_osc:'osc',
address:'auto',
_chidlren:'chilren',
widgets:[],
tabs:[]
}
}
constructor(widgetData, container) {
super(...arguments)
this.widget.removeClass('noscroll')
this.container = container
container.append('<div class="light"></div>')
this.light = container.find('.light').first()
this.modal = this.widget.detach()
this.value = false
this.light.on('fake-click',()=>{
this.setValue(!this.value)
})
}
setValue(v) {
this.value = v ? true : false
this.container.toggleClass('on', this.value)
this.widget.toggleClass('on', this.value)
this.light.toggleClass('on', this.value)
Modal.prototype.setValue = function(v) {
if (v) {
this.container.addClass('on')
this.widget.addClass('on')
this.light.addClass('on')
this.value = true
} else {
this.container.removeClass('on')
this.widget.removeClass('on')
this.light.removeClass('on')
this.value = false
}
}
module.exports.create = function(widgetData, container) {
var modal = new Modal(widgetData, container)
return modal
}

View file

@ -1,56 +1,55 @@
var _widgets_base = require('../common/_widgets_base')
module.exports.options = {
type:'panel',
id:'auto',
module.exports = class Panel extends _widgets_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
scroll:true,
color:'auto',
css:'',
return {
type:'panel',
id:'auto',
separator2:'chilren',
_style:'style',
widgets:[],
tabs:[]
}
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
scroll:true,
color:'auto',
css:'',
var Panel = module.exports.Panel = function(widgetData) {
_children:'chilren',
_widgets_base.apply(this,arguments)
widgets:[],
tabs:[]
}
var parsers = require('../../parser'),
parsewidgets = parsers.widgets,
parsetabs = parsers.tabs
}
constructor(widgetData) {
this.widget = $(`
<div class="panel">
</div>
`)
var widgetHtml = `
<div class="panel
${!widgetData.scroll?'noscroll':''}
${widgetData.tabs.length?'has-tabs':''}
">
</div>
`
if (!widgetData.scroll) this.widget.addClass('noscroll')
super(...arguments, widgetHtml)
if (widgetData.tabs.length) {
parsetabs(widgetData.tabs,this.widget)
this.widget.addClass('has-tabs')
} else {
parsewidgets(widgetData.widgets,this.widget)
}
var parsers = require('../../parser'),
parsewidgets = parsers.widgets,
parsetabs = parsers.tabs
if (widgetData.tabs.length) {
parsetabs(widgetData.tabs,this.widget)
} else {
parsewidgets(widgetData.widgets,this.widget)
}
}
}
Panel.prototype = Object.create(_widgets_base.prototype)
Panel.prototype.constructor = Panel
module.exports.create = function(widgetData) {
var panel = new Panel(widgetData)
return panel
}

View file

@ -1,51 +1,50 @@
var _widgets_base = require('../common/_widgets_base')
module.exports.options = {
type:'strip',
id:'auto',
module.exports = class Strip extends _widgets_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
horizontal:false,
color:'auto',
css:'',
return {
type:'strip',
id:'auto',
separator2:'children',
_style:'style',
widgets:[]
}
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
horizontal:false,
color:'auto',
css:'',
var Strip = module.exports.Strip = function(widgetData, container) {
_children:'children',
_widgets_base.apply(this,arguments)
widgets:[]
}
var parsewidgets = require('../../parser').widgets
this.widget = $(`
<div class="strip">
</div>
`)
if (widgetData.horizontal) {
container.addClass('horizontal')
} else {
container.addClass('vertical')
}
parsewidgets(widgetData.widgets,this.widget)
constructor(widgetData, container) {
var widgetHtml = `
<div class="strip"></div>
`
super(...arguments, widgetHtml)
var parsewidgets = require('../../parser').widgets
if (widgetData.horizontal) {
container.addClass('horizontal')
} else {
container.addClass('vertical')
}
parsewidgets(widgetData.widgets,this.widget)
}
}
Strip.prototype = Object.create(_widgets_base.prototype)
Strip.prototype.constructor = Strip
module.exports.create = function(widgetData, container) {
var strip = new Strip(widgetData, container)
return strip
}

View file

@ -1,33 +1,33 @@
var _widgets_base = require('../common/_widgets_base')
var _matrices_base = module.exports = function(widgetData){
module.exports = class _matrices_base extends _widgets_base {
_widgets_base.apply(this,arguments)
constructor(widgetData) {
this.widget = $(`
<div class="matrix">
</div>\
`)
var widgetHtml = `
<div class="matrix"></div>
`
this.value = []
super(...arguments, widgetHtml)
widgetData.start = parseInt(widgetData.start)
this.widget.on('sync',function(e){
if (e.id==this.widgetData.id) return
this.value[e.widget.parent().index()] = e.widget.abstract.getValue()
this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget})
}.bind(this))
this.value = []
widgetData.start = parseInt(widgetData.start)
this.widget.on('sync',(e)=>{
if (e.id==widgetData.id) return
this.value[e.widget.parent().index()] = e.widget.abstract.getValue()
this.widget.trigger({type:'sync',id:widgetData.id,widget:this.widget})
})
}
getValue() {
return this.value
}
}
_matrices_base.prototype = Object.create(_widgets_base.prototype)
_matrices_base.prototype.constructor = _matrices_base
_matrices_base.prototype.getValue = function(){
return this.value
}

View file

@ -1,99 +1,96 @@
var _matrices_base = require('./_matrices_base')
module.exports.options = {
type:'keyboard',
id:'auto',
module.exports = class Keyboard extends _matrices_base {
separator0: 'Matrix',
static options() {
keys: 24,
start:60,
return {
type:'keyboard',
id:'auto',
separator1:'style',
_matrix: 'Matrix',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
keys: 24,
start:60,
separator2:'behaviour',
_style:'style',
traversing:true,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
on:1,
off:0,
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
traversing:true,
_osc:'osc',
var Keyboard = module.exports.Keyboard = function(widgetData) {
on:1,
off:0,
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
_matrices_base.apply(this,arguments)
}
widgetData.keys = parseInt(widgetData.keys)
constructor(widgetData) {
var strData = JSON.stringify(widgetData),
super(...arguments)
widgetData.keys = parseInt(widgetData.keys)
var strData = JSON.stringify(widgetData),
pattern = 'wbwbwwbwbwbw',
wCount = 0
var parsers = require('../../parser'),
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.keys+widgetData.start&&i<108;i++) {
for (var i=widgetData.start;i<widgetData.keys+widgetData.start&&i<108;i++) {
var data = JSON.parse(strData)
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'push'
data.id = widgetData.id + '/' + i
data.label = false
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'push'
data.id = widgetData.id + '/' + i
data.label = false
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
var element = parsewidgets([data],this.widget)
element[0].classList.add('not-editable')
var element = parsewidgets([data],this.widget)
element[0].classList.add('not-editable')
if (pattern[i % 12] == 'w') {
element.addClass('white')
wCount++
} else {
element.addClass('black').data('wCount',wCount)
if (pattern[i % 12] == 'w') {
element.addClass('white')
wCount++
} else {
element.addClass('black').data('wCount',wCount)
}
this.value[i-widgetData.start] = widgetData.off
}
this.value[i-widgetData.start] = widgetData.off
this.widget.find('.widget.white').css('width',`${100/wCount}%`)
this.widget.find('.widget.black').each(function(){
$(this).css({
'width':`${100/wCount * 6/10}%`,
'left':`${100/wCount * ($(this).data('wCount') - 3/10)}%`
})
}
this.widget.find('.widget.white').css('width',`${100/wCount}%`)
this.widget.find('.widget.black').each(function(){
$(this).css({
'width':`${100/wCount * 6/10}%`,
'left':`${100/wCount * ($(this).data('wCount') - 3/10)}%`
})
})
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (widgetData.traversing) this.widget.enableTraversingGestures()
}
}
Keyboard.prototype = Object.create(_matrices_base.prototype)
Keyboard.prototype.constructor = Keyboard
module.exports.create = function(widgetData) {
var keyboard = new Keyboard(widgetData)
return keyboard
}

View file

@ -1,93 +1,91 @@
var _matrices_base = require('./_matrices_base')
module.exports.options = {
type:'multifader',
id:'auto',
module.exports = class Multifader extends _matrices_base {
separator0:'Matrix',
static options() {
strips:2,
start:0,
return {
type:'multifader',
id:'auto',
separator1:'style',
_matrix:'Matrix',
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
alignRight:false,
horizontal:false,
noPip:true,
compact:false,
color:'auto',
css:'',
strips:2,
start:0,
separator2:'behaviour',
_style:'style',
traversing:true,
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
alignRight:false,
horizontal:false,
noPip:true,
compact:false,
color:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
range:{min:0,max:1},
value:'',
origin: 'auto',
logScale:false,
precision:2,
meter:false,
address:'auto',
preArgs:[],
split:false,
target:[]
}
traversing:true,
_osc:'osc',
var Multifader = module.exports.Multifader = function(widgetData) {
range:{min:0,max:1},
value:'',
origin: 'auto',
logScale:false,
precision:2,
meter:false,
address:'auto',
preArgs:[],
split:false,
target:[]
}
_matrices_base.apply(this,arguments)
widgetData.strips = parseInt(widgetData.strips)
if (widgetData.horizontal) {
this.widget.addClass('horizontal')
}
var strData = JSON.stringify(widgetData)
constructor(widgetData) {
var parsers = require('../../parser'),
super(...arguments)
widgetData.strips = parseInt(widgetData.strips)
if (widgetData.horizontal) {
this.widget.addClass('horizontal')
}
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start; i<widgetData.strips+widgetData.start;i++) {
for (var i=widgetData.start; i<widgetData.strips+widgetData.start;i++) {
var data = JSON.parse(strData)
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'fader'
data.id = widgetData.id + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'fader'
data.id = widgetData.id + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`${widgetData.horizontal?'height':'width'}:${100/widgetData.strips}%`)
element[0].classList.add('not-editable')
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`${widgetData.horizontal?'height':'width'}:${100/widgetData.strips}%`)
element[0].classList.add('not-editable')
if (widgetData.traversing) element.find('.fader-wrapper').off('drag')
if (widgetData.traversing) element.find('.fader-wrapper').off('drag')
this.value[i-widgetData.start] = widgetData.range.min
this.value[i-widgetData.start] = widgetData.range.min
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
}
Multifader.prototype = Object.create(_matrices_base.prototype)
Multifader.prototype.constructor = Multifader
module.exports.create = function(widgetData) {
var multifader = new Multifader(widgetData)
return multifader
}

View file

@ -1,81 +1,77 @@
var _matrices_base = require('./_matrices_base')
module.exports.options = {
type:'multipush',
id:'auto',
module.exports = class Multipush extends _matrices_base {
separator0: 'Matrix',
static options() {
matrix: [2,2],
start:0,
return {
type:'multipush',
id:'auto',
separator1:'style',
_matrix: 'Matrix',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
matrix: [2,2],
start:0,
separator2:'behaviour',
style:'style',
traversing:true,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
on:1,
off:0,
value:'',
norelease:false,
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
traversing:true,
_osc:'osc',
var Multipush = module.exports.Multipush = function(widgetData) {
on:1,
off:0,
value:'',
norelease:false,
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
_matrices_base.apply(this,arguments)
}
constructor(widgetData) {
var strData = JSON.stringify(widgetData)
super(...arguments)
var parsers = require('../../parser'),
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.matrix[0]*widgetData.matrix[1]+widgetData.start;i++) {
for (var i=widgetData.start;i<widgetData.matrix[0]*widgetData.matrix[1]+widgetData.start;i++) {
var data = JSON.parse(strData)
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'push'
data.id = widgetData.id + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'push'
data.id = widgetData.id + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)
element[0].classList.add('not-editable')
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)
element[0].classList.add('not-editable')
this.value[i-widgetData.start] = widgetData.off
this.value[i-widgetData.start] = widgetData.off
}
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (widgetData.traversing) this.widget.enableTraversingGestures()
}
}
Multipush.prototype = Object.create(_matrices_base.prototype)
Multipush.prototype.constructor = Multipush
module.exports.create = function(widgetData) {
var multipush = new Multipush(widgetData)
return multipush
}

View file

@ -1,78 +1,76 @@
var _matrices_base = require('./_matrices_base')
module.exports.options = {
type:'multitoggle',
id:'auto',
module.exports = class Multitoggle extends _matrices_base {
separator0: 'Matrix',
static options() {
matrix: [2,2],
start:0,
return {
type:'multitoggle',
id:'auto',
separator1:'style',
_matrix: 'Matrix',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
matrix: [2,2],
start:0,
separator2:'behaviour',
_style:'style',
traversing:true,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
on:1,
off:0,
value:'',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
traversing:true,
var Multitoggle = module.exports.Multitoggle = function(widgetData) {
_osc:'osc',
_matrices_base.apply(this,arguments)
on:1,
off:0,
value:'',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
}
var strData = JSON.stringify(widgetData)
constructor(widgetData) {
var parsers = require('../../parser'),
super(...arguments)
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.matrix[0]*widgetData.matrix[1]+widgetData.start;i++) {
for (var i=widgetData.start;i<widgetData.matrix[0]*widgetData.matrix[1]+widgetData.start;i++) {
var data = JSON.parse(strData)
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'toggle'
data.id = widgetData.id + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'toggle'
data.id = widgetData.id + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [i].concat(widgetData.preArgs)
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)
element[0].classList.add('not-editable')
var element = parsewidgets([data],this.widget)
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)
element[0].classList.add('not-editable')
this.value[i-widgetData.start] = widgetData.off
this.value[i-widgetData.start] = widgetData.off
}
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (widgetData.traversing) this.widget.enableTraversingGestures()
}
}
Multitoggle.prototype = Object.create(_matrices_base.prototype)
Multitoggle.prototype.constructor = Multitoggle
module.exports.create = function(widgetData) {
var multitoggle = new Multitoggle(widgetData)
return multitoggle
}

View file

@ -1,14 +1,16 @@
var {Fader} = require('../sliders/fader')
var Fader = require('../sliders/fader')
var _fake_fader = module.exports = function(widgetData, cancelDraw){
module.exports = class _fake_fader extends Fader {
if (cancelDraw) this.noDraw = true
constructor(widgetData, cancelDraw) {
super(widgetData, false)
if (cancelDraw) this.noDraw = true
}
sendValue() {
// disabled
}
Fader.apply(this, arguments)
}
_fake_fader.prototype = Object.create(Fader.prototype)
_fake_fader.prototype.constructor = _fake_fader
_fake_fader.prototype.sendValue = function(){}

View file

@ -1,27 +1,21 @@
var Fader = require('../sliders/fader')
var _canvas_base = require('../common/_canvas_base')
var _pads_base = module.exports = function(){
module.exports = class _pads_base extends _canvas_base {
this.widget = $(`
<div class="pad">
<div class="wrapper">
<canvas></canvas>
constructor() {
var widgetHtml = `
<div class="pad">
<div class="wrapper">
<canvas></canvas>
</div>
</div>
</div>
`)
this.wrapper = this.widget.find('.wrapper')
_canvas_base.apply(this, arguments)
`
}
_pads_base.prototype = Object.create(_canvas_base.prototype)
_pads_base.prototype.constructor = _pads_base
_pads_base.prototype.setValue = function(v,options={}) {
if (typeof v != 'number') return
super(...arguments, widgetHtml)
this.wrapper = this.widget.find('.wrapper')
}
}

View file

@ -1,211 +1,210 @@
var _pads_base = require('./_pads_base'),
{Xy} = require('./xy'),
Xy = require('./xy'),
{clip} = require('../utils')
module.exports.options = {
type:'xy',
id:'auto',
linkId:'',
module.exports = class MultiXy extends _pads_base {
separator1:'multi xy',
static options() {
points: 2,
pointSize: 20,
snap:false,
spring:false,
return {
type:'xy',
id:'auto',
linkId:'',
separator2:'style',
_mutlixy:'multi xy',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
points: 2,
pointSize: 20,
snap:false,
spring:false,
separator3:'osc',
_style:'style',
rangeX:{min:0,max:1},
rangeY:{min:0,max:1},
logScaleX:false,
logScaleY:false,
value:'',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
var MultiXy = module.exports.MultiXy = function(widgetData) {
_osc:'osc',
_pads_base.apply(this,arguments)
this.pointSize = parseInt(this.widgetData.pointSize)
this.widget[0].style.setProperty("--point-size",this.pointSize + 'rem')
this.split = this.widgetData.split?
typeof this.widgetData.split == 'object'?
this.widgetData.split
: (()=>{
var s={};
for (var i=0; i<this.widgetData.points * 2;i=i+2) {
s[i]=this.widgetData.address + '/' + i/2 + '/x'
s[i+1]=this.widgetData.address + '/' + i/2 + '/y'
};
return s
})()
: false
this.handles = []
this.pads = []
for (var i=this.widgetData.points-1;i>=0;i--) {
this.pads[i] = new Xy({
snap:widgetData.snap,
spring:widgetData.spring,
value:widgetData.value.length == widgetData.points * 2 ? [widgetData.value[i*2], widgetData.value[i*2 + 1]] : '',
rangeX:widgetData.rangeX,
rangeY:widgetData.rangeY,
precision:widgetData.precision,
logScaleX:widgetData.logScaleX,
logScaleY:widgetData.logScaleY
})
this.pads[i].sendValue = ()=>{}
this.pads[i].draw = ()=>{}
this.wrapper.append(this.pads[i].widget)
this.handles[i] = $(`<div class="handle">${i}</div>`)
this.wrapper.append(this.handles[i])
let pad = this.pads[i]
pad.wrapper.on('draginit',(e)=>{
pad.widget.addClass('active')
})
pad.wrapper.on('dragend',(e)=>{
pad.widget.removeClass('active')
})
}
this.wrapper.addClass('snap')
this.value = []
this.handles.forEach((handle, i)=>{
handle.on('draginit drag dragend',(e, data, traversing)=>{
if (this.widgetData.snap && e.type == 'draginit') {
e.type = 'drag'
this.pads[i].widget.addClass('active')
}
this.pads[i].wrapper.trigger(e.type, [data, traversing])
})
})
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
this.setValue(this.getValue(), e.options)
})
var v = []
for (var i=0;i<this.widgetData.points * 2;i=i+2) {
[v[i],v[i+1]] = this.pads[i/2].getValue()
}
this.setValue(v)
}
MultiXy.prototype = Object.create(_pads_base.prototype)
MultiXy.prototype.constructor = MultiXy
MultiXy.prototype.resizeHandle = function(){
_pads_base.prototype.resizeHandle.apply(this, arguments)
this.updateHandlesPosition()
}
MultiXy.prototype.updateHandlesPosition = function(){
for (var i=0;i<this.widgetData.points;i++) {
this.handles[i][0].setAttribute('style',`
transform:translate3d(${clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE}px,
${- clip(this.pads[i].faders.y.percent,[0,100]) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) - (this.pointSize + 1) * PXSCALE}px,
0);
`)
}
}
MultiXy.prototype.draw = function(){
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.textAlign = 'center'
this.ctx.textBaseline = 'middle'
for (var i=0;i<this.widgetData.points;i++) {
var x = clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE,
y = (100 - clip(this.pads[i].faders.y.percent,[0,100])) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE
this.ctx.globalAlpha = 0.3
this.ctx.strokeStyle = this.colors.custom
this.ctx.fillStyle = this.colors.custom
this.ctx.lineWidth = PXSCALE * 2
this.ctx.beginPath()
this.ctx.arc(x, y, this.pointSize * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.arc(x, y, (this.pointSize-1) * PXSCALE, Math.PI * 2, false)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.text
this.ctx.strokeStyle = this.colors.text
this.ctx.lineWidth = PXSCALE
this.ctx.font = PXSCALE * 11 + 'px Droid Sans'
this.ctx.fillText(i,x,y)
this.ctx.strokeText(i,x,y)
}
}
MultiXy.prototype.getValue = function(){
var v = []
for (var i=0;i<this.pads.length * 2;i=i+2) {
[v[i],v[i+1]] = this.pads[i/2].getValue()
}
return v
}
MultiXy.prototype.setValue = function(v, options={}){
if (!v || v.length!=this.widgetData.points * 2) return
for (var i=0;i<this.widgetData.points;i++) {
if (!options.dragged) {
this.pads[i].setValue([v[i*2],v[i*2+1]])
rangeX:{min:0,max:1},
rangeY:{min:0,max:1},
logScaleX:false,
logScaleY:false,
value:'',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
}
this.updateHandlesPosition()
this.draw()
constructor(widgetData) {
super(...arguments)
this.pointSize = parseInt(widgetData.pointSize)
this.widget[0].style.setProperty("--point-size",this.pointSize + 'rem')
this.split = widgetData.split?
typeof widgetData.split == 'object'?
widgetData.split
: (()=>{
var s={};
for (var i=0; i<widgetData.points * 2;i=i+2) {
s[i]=widgetData.address + '/' + i/2 + '/x'
s[i+1]=widgetData.address + '/' + i/2 + '/y'
};
return s
})()
: false
this.handles = []
this.pads = []
for (var i=widgetData.points-1;i>=0;i--) {
this.pads[i] = new Xy({
snap:widgetData.snap,
spring:widgetData.spring,
value:widgetData.value.length == widgetData.points * 2 ? [widgetData.value[i*2], widgetData.value[i*2 + 1]] : '',
rangeX:widgetData.rangeX,
rangeY:widgetData.rangeY,
precision:widgetData.precision,
logScaleX:widgetData.logScaleX,
logScaleY:widgetData.logScaleY
}, false)
this.pads[i].sendValue = ()=>{}
this.pads[i].draw = ()=>{}
this.wrapper.append(this.pads[i].widget)
this.handles[i] = $(`<div class="handle">${i}</div>`)
this.wrapper.append(this.handles[i])
let pad = this.pads[i]
pad.wrapper.on('draginit',(e)=>{
pad.widget.addClass('active')
})
pad.wrapper.on('dragend',(e)=>{
pad.widget.removeClass('active')
})
}
this.value = []
this.handles.forEach((handle, i)=>{
handle.on('draginit drag dragend',(e, data, traversing)=>{
if (widgetData.snap && e.type == 'draginit') {
e.type = 'drag'
this.pads[i].widget.addClass('active')
}
this.pads[i].wrapper.trigger(e.type, [data, traversing])
})
})
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
this.setValue(this.getValue(), e.options)
})
var v = []
for (var i=0;i<widgetData.points * 2;i=i+2) {
[v[i],v[i+1]] = this.pads[i/2].getValue()
}
this.setValue(v)
for (var i=0;i<this.widgetData.points * 2;i=i+2) {
[this.value[i],this.value[i+1]] = this.pads[i/2].getValue()
}
resizeHandle() {
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
super.resizeHandle(...arguments)
this.updateHandlesPosition()
}
updateHandlesPosition() {
for (var i=0;i<this.widgetData.points;i++) {
this.handles[i][0].setAttribute('style',`
transform:translate3d(${clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE}px,
${- clip(this.pads[i].faders.y.percent,[0,100]) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) - (this.pointSize + 1) * PXSCALE}px,
0);
`)
}
}
draw() {
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.textAlign = 'center'
this.ctx.textBaseline = 'middle'
for (var i=0;i<this.widgetData.points;i++) {
var x = clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE,
y = (100 - clip(this.pads[i].faders.y.percent,[0,100])) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE
this.ctx.globalAlpha = 0.3
this.ctx.strokeStyle = this.colors.custom
this.ctx.fillStyle = this.colors.custom
this.ctx.lineWidth = PXSCALE * 2
this.ctx.beginPath()
this.ctx.arc(x, y, this.pointSize * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.arc(x, y, (this.pointSize-1) * PXSCALE, Math.PI * 2, false)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.text
this.ctx.strokeStyle = this.colors.text
this.ctx.lineWidth = PXSCALE
this.ctx.font = PXSCALE * 11 + 'px Droid Sans'
this.ctx.fillText(i,x,y)
this.ctx.strokeText(i,x,y)
}
}
getValue() {
var v = []
for (var i=0;i<this.pads.length * 2;i=i+2) {
[v[i],v[i+1]] = this.pads[i/2].getValue()
}
return v
}
setValue(v, options={}) {
if (!v || v.length!=this.widgetData.points * 2) return
for (var i=0;i<this.widgetData.points;i++) {
if (!options.dragged) {
this.pads[i].setValue([v[i*2],v[i*2+1]])
}
}
this.updateHandlesPosition()
this.draw()
for (var i=0;i<this.widgetData.points * 2;i=i+2) {
[this.value[i],this.value[i+1]] = this.pads[i/2].getValue()
}
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
}
}
module.exports.create = function(widgetData) {
var xy = new MultiXy(widgetData)
return xy
}

View file

@ -3,239 +3,240 @@ var _pads_base = require('./_pads_base'),
{clip, hsbToRgb, rgbToHsb} = require('../utils')
module.exports.options = {
type:'rgb',
id:'auto',
linkId:'',
module.exports = class Rgb extends _pads_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
css:'',
return {
type:'rgb',
id:'auto',
linkId:'',
separator2:'behaviour',
_style:'style',
snap:false,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
value:'',
precision:0,
address:'auto',
preArgs:[],
split:false,
target:[]
}
snap:false,
var Rgb = module.exports.Rgb = function(widgetData) {
_osc:'osc',
_pads_base.apply(this,arguments)
value:'',
precision:0,
address:'auto',
preArgs:[],
split:false,
target:[]
}
this.split = this.widgetData.split?
typeof this.widgetData.split == 'object'?
this.widgetData.split
: {r: this.widgetData.address + '/r', g: this.widgetData.address + '/g', b: this.widgetData.address + '/b'}
: false
this.widget.append(`
<div class="hue-wrapper"></div>
<div class="labels row">
<span class="input">R</span>
<span class="input">G</span>
<span class="input">B</span>
</div>
<div class="row">
<div class="input r"></div>
<div class="input g"></div>
<div class="input b"></div>
</div>
`)
this.hueWrapper = this.widget.find('.hue-wrapper')
this.faders = {
h: new Fader({
id:'h',
compact:false,
noPip:true,
horizontal:true,
snap:widgetData.snap,
range:{min:0,max:360},
precision:2
}),
s: new Fader({
id:'s',
compact:true,
horizontal:true,
snap:widgetData.snap,
range:{min:0,max:100},
precision:2
},true),
b: new Fader({
id:'b',
compact:true,
horizontal:false,
snap:widgetData.snap,
range:{min:0,max:100},
precision:2
},true)
}
this.faders.h.margin = 0
constructor(widgetData) {
this.inputs = [
this.widget.find('.r').fakeInput({align:'center'}),
this.widget.find('.g').fakeInput({align:'center'}),
this.widget.find('.b').fakeInput({align:'center'})
]
super(...arguments)
this.value = []
this.hsb = {h:0,s:0,b:0}
this.split = widgetData.split?
typeof widgetData.split == 'object'?
widgetData.split
: {r: widgetData.address + '/r', g: widgetData.address + '/g', b: widgetData.address + '/b'}
: false
this.wrapper.append(this.faders.s.widget)
this.wrapper.append(this.faders.b.widget)
this.widget.append(`
<div class="hue-wrapper"></div>
<div class="labels row">
<span class="input">R</span>
<span class="input">G</span>
<span class="input">B</span>
</div>
<div class="row">
<div class="input r"></div>
<div class="input g"></div>
<div class="input b"></div>
</div>
`)
this.hueWrapper.append(this.faders.h.widget)
this.hueWrapper = this.widget.find('.hue-wrapper')
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
})
this.faders = {
h: new Fader({
id:'h',
compact:false,
noPip:true,
horizontal:true,
snap:widgetData.snap,
range:{min:0,max:360},
precision:2
}, false),
s: new Fader({
id:'s',
compact:true,
horizontal:true,
snap:widgetData.snap,
range:{min:0,max:100},
precision:2
this.faders.h.widget.on('sync',(e)=>{
e.stopPropagation()
this.dragHandle(true)
})
}, true),
b: new Fader({
id:'b',
compact:true,
horizontal:false,
snap:widgetData.snap,
range:{min:0,max:100},
precision:2
}, true)
}
this.wrapper.on('draginit',(e, data, traversing)=>{
this.faders.s.draginitHandleProxy(e, data, traversing)
this.faders.b.draginitHandleProxy(e, data, traversing)
this.dragHandle()
})
this.wrapper.on('drag',(e, data, traversing)=>{
this.faders.s.dragHandleProxy(e, data, traversing)
this.faders.b.dragHandleProxy(e, data, traversing)
this.dragHandle()
})
this.faders.h.margin = 0
this.inputs = [
this.widget.find('.r').fakeInput({align:'center'}),
this.widget.find('.g').fakeInput({align:'center'}),
this.widget.find('.b').fakeInput({align:'center'})
]
this.inputs.forEach(function(input,i){
input.change(()=>{
this.value[i] = parseFloat(clip(this.inputs[i].val(),[0,255]))
this.setValue(this.value,{send:true,sync:true})
this.value = []
this.hsb = {h:0,s:0,b:0}
this.wrapper.append(this.faders.s.widget)
this.wrapper.append(this.faders.b.widget)
this.hueWrapper.append(this.faders.h.widget)
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
})
this.faders.h.widget.on('sync',(e)=>{
e.stopPropagation()
this.dragHandle(true)
})
this.wrapper.on('draginit',(e, data, traversing)=>{
this.faders.s.draginitHandleProxy(e, data, traversing)
this.faders.b.draginitHandleProxy(e, data, traversing)
this.dragHandle()
})
this.wrapper.on('drag',(e, data, traversing)=>{
this.faders.s.dragHandleProxy(e, data, traversing)
this.faders.b.dragHandleProxy(e, data, traversing)
this.dragHandle()
})
},this)
this.setValue([0,0,0])
}
this.inputs.forEach(function(input,i){
input.change(()=>{
this.value[i] = parseFloat(clip(this.inputs[i].val(),[0,255]))
this.setValue(this.value,{send:true,sync:true})
})
},this)
Rgb.prototype = Object.create(_pads_base.prototype)
this.setValue([0,0,0])
Rgb.prototype.constructor = Rgb
}
Rgb.prototype.dragHandle = function(hue){
var h =this.faders.h.value,
dragHandle(hue) {
var h =this.faders.h.value,
s = this.faders.s.value,
b = this.faders.b.value
if (h != this.hsb.h ||s != this.hsb.s || b != this.hsb.b) {
if (h != this.hsb.h ||s != this.hsb.s || b != this.hsb.b) {
this.hsb.h = this.faders.h.value
this.hsb.s = this.faders.s.value
this.hsb.b = this.faders.b.value
this.hsb.h = this.faders.h.value
this.hsb.s = this.faders.s.value
this.hsb.b = this.faders.b.value
this.update({nohue:!hue})
this.update({nohue:!hue})
var rgb = hsbToRgb(this.hsb)
if (rgb.r != this.value[0] || rgb.g != this.value[1] || rgb.b != this.value[2]) {
this.setValue([rgb.r, rgb.g, rgb.b],{send:true,sync:true,dragged:true,nohue:!hue})
var rgb = hsbToRgb(this.hsb)
if (rgb.r != this.value[0] || rgb.g != this.value[1] || rgb.b != this.value[2]) {
this.setValue([rgb.r, rgb.g, rgb.b],{send:true,sync:true,dragged:true,nohue:!hue})
}
}
}
}
setValue(v, options={}) {
Rgb.prototype.setValue = function(v, options={}){
if (!v || v.length!=3) return
if (!v || v.length!=3) return
for (i in [0,1,2]) {
v[i] = clip(v[i],[0,255])
}
var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
if (!options.dragged) {
this.faders.s.setValue(hsb.s, {sync: false, send:false, dragged:false})
this.faders.b.setValue(hsb.b, {sync: false, send:false, dragged:false})
}
this.hsb = hsb
this.value = v
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
this.update({dragged:options.dragged, nohue:options.nohue || (v[0]==v[1]&&v[1]==v[2])})
for (i in [0,1,2]) {
v[i] = clip(v[i],[0,255])
}
var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
update(options={}) {
if (!options.nohue && !options.dragged) {
var hue = hsbToRgb({h:this.hsb.h,s:100,b:100})
this.hue = `rgb(${Math.round(hue.r)},${Math.round(hue.g)},${Math.round(hue.b)})`
this.wrapper[0].setAttribute('style',`background:${this.hue}`)
this.faders.h.setValue(this.hsb.h, {sync: false, send:false, dragged:false})
}
for (i in this.inputs) [
this.inputs[i].val(this.value[i].toFixed(this.widgetData.precision))
]
this.draw()
if (!options.dragged) {
this.faders.s.setValue(hsb.s, {sync: false, send:false, dragged:false})
this.faders.b.setValue(hsb.b, {sync: false, send:false, dragged:false})
}
this.hsb = hsb
this.value = v
draw() {
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
this.update({dragged:options.dragged, nohue:options.nohue || (v[0]==v[1]&&v[1]==v[2])})
}
Rgb.prototype.update = function(options={}) {
if (!options.nohue && !options.dragged) {
var hue = hsbToRgb({h:this.hsb.h,s:100,b:100})
this.hue = `rgb(${Math.round(hue.r)},${Math.round(hue.g)},${Math.round(hue.b)})`
this.wrapper[0].setAttribute('style',`background:${this.hue}`)
this.faders.h.setValue(this.hsb.h, {sync: false, send:false, dragged:false})
}
for (i in this.inputs) [
this.inputs[i].val(this.value[i].toFixed(this.widgetData.precision))
]
this.draw()
}
Rgb.prototype.draw = function(){
var x = clip(this.faders.s.percent / 100 * this.width,[0,this.width]),
var x = clip(this.faders.s.percent / 100 * this.width,[0,this.width]),
y = clip((1 - this.faders.b.percent / 100) * this.height,[0,this.height]),
color = this.hsb.b > 70 && this.hsb.s < 30 ? '#555' : 'white'
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.fillStyle = color
this.ctx.strokeStyle = color
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = color
this.ctx.strokeStyle = color
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 0.3
this.ctx.globalAlpha = 0.3
this.ctx.beginPath()
this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 0.1
this.ctx.globalAlpha = 0.1
this.ctx.beginPath()
this.ctx.moveTo(0,y)
this.ctx.lineTo(this.width,y)
this.ctx.moveTo(x,0)
this.ctx.lineTo(x,this.height)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.moveTo(0,y)
this.ctx.lineTo(this.width,y)
this.ctx.moveTo(x,0)
this.ctx.lineTo(x,this.height)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
}
this.ctx.beginPath()
this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
}
module.exports.create = function(widgetData) {
var rgb = new Rgb(widgetData)
return rgb
}

View file

@ -2,206 +2,204 @@ var _pads_base = require('./_pads_base'),
Fader = require('./_fake_fader'),
{clip} = require('../utils')
module.exports.options = {
type:'xy',
id:'auto',
linkId:'',
module.exports = class Xy extends _pads_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
return {
type:'xy',
id:'auto',
linkId:'',
separator2:'behaviour',
_style:'style',
snap:false,
spring:false,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
rangeX:{min:0,max:1},
rangeY:{min:0,max:1},
logScaleX:false,
logScaleY:false,
value:'',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
snap:false,
spring:false,
var Xy = module.exports.Xy = function(widgetData) {
_osc:'osc',
_pads_base.apply(this,arguments)
rangeX:{min:0,max:1},
rangeY:{min:0,max:1},
logScaleX:false,
logScaleY:false,
value:'',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[]
}
this.split = this.widgetData.split?
typeof this.widgetData.split == 'object'?
this.widgetData.split
: {x: this.widgetData.address + '/x', y: this.widgetData.address + '/y'}
: false
this.widget.append(`
<div class="labels row">
<span class="input">X</span>
<span class="input">Y</span>
</div>
<div class="row">
<div class="input x"></div>
<div class="input y"></div>
</div>
`)
this.faders = {
x: new Fader({
id:0,
compact:true,
horizontal:true,
height:'100%',
width:'100%',
value:widgetData.value.length==2?widgetData.value[0]:'',
snap:widgetData.snap,
range:widgetData.rangeX,
origin:'auto',
precision:widgetData.precision,
logScale:widgetData.logScaleX
}, true),
y: new Fader({
id:1,
compact:true,
horizontal:false,
height:'100%',
width:'100%',
value:widgetData.value.length==2?widgetData.value[1]:'',
snap:widgetData.snap,
range:widgetData.rangeY,
origin:'auto',
precision:widgetData.precision,
logScale:widgetData.logScaleY
}, true)
}
this.inputs = [
this.widget.find('.x').replaceWith(this.faders.x.input),
this.widget.find('.y').replaceWith(this.faders.y.input)
]
constructor(widgetData) {
this.value = [this.faders.x.value, this.faders.y.value]
super(...arguments)
this.wrapper.append(this.faders.x.widget)
this.wrapper.append(this.faders.y.widget)
this.split = widgetData.split?
typeof widgetData.split == 'object'?
widgetData.split
: {x: widgetData.address + '/x', y: widgetData.address + '/y'}
: false
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
})
this.widget.append(`
<div class="labels row">
<span class="input">X</span>
<span class="input">Y</span>
</div>
<div class="row">
<div class="input x"></div>
<div class="input y"></div>
</div>
`)
this.wrapper.on('draginit',(e, data, traversing)=>{
this.faders.x.draginitHandleProxy(e, data, traversing)
this.faders.y.draginitHandleProxy(e, data, traversing)
this.dragHandle()
})
this.wrapper.on('drag',(e, data, traversing)=>{
this.faders.x.dragHandleProxy(e, data, traversing)
this.faders.y.dragHandleProxy(e, data, traversing)
this.dragHandle()
})
this.faders = {
x: new Fader({
id:0,
compact:true,
horizontal:true,
height:'100%',
width:'100%',
value:widgetData.value.length==2?widgetData.value[0]:'',
snap:widgetData.snap,
range:widgetData.rangeX,
origin:'auto',
precision:widgetData.precision,
logScale:widgetData.logScaleX
}, true),
y: new Fader({
id:1,
compact:true,
horizontal:false,
height:'100%',
width:'100%',
value:widgetData.value.length==2?widgetData.value[1]:'',
snap:widgetData.snap,
range:widgetData.rangeY,
origin:'auto',
precision:widgetData.precision,
logScale:widgetData.logScaleY
if (this.widgetData.spring) {
this.wrapper.on('dragend', ()=>{
this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true,fromLocal:true})
}, true)
}
this.inputs = [
this.widget.find('.x').replaceWith(this.faders.x.input),
this.widget.find('.y').replaceWith(this.faders.y.input)
]
this.value = [this.faders.x.value, this.faders.y.value]
this.wrapper.append(this.faders.x.widget)
this.wrapper.append(this.faders.y.widget)
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
})
this.wrapper.on('draginit',(e, data, traversing)=>{
this.faders.x.draginitHandleProxy(e, data, traversing)
this.faders.y.draginitHandleProxy(e, data, traversing)
this.dragHandle()
})
this.wrapper.on('drag',(e, data, traversing)=>{
this.faders.x.dragHandleProxy(e, data, traversing)
this.faders.y.dragHandleProxy(e, data, traversing)
this.dragHandle()
})
if (widgetData.spring) {
this.wrapper.on('dragend', ()=>{
this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true,fromLocal:true})
})
}
this.faders.x.input.change(()=>{
var v = [this.faders.x.value, this.faders.y.value]
this.setValue(v,{send:true,sync:true})
})
this.faders.y.input.change(()=>{
var v = [this.faders.x.value, this.faders.y.value]
this.setValue(v,{send:true,sync:true})
})
}
dragHandle(){
var x = this.faders.x.value,
y = this.faders.y.value
if (x != this.value[0] || y != this.value[1]) {
this.setValue([x, y],{send:true,sync:true,dragged:true})
}
}
setValue(v, options={}) {
this.faders.x.input.change(()=>{
var v = [this.faders.x.value, this.faders.y.value]
this.setValue(v,{send:true,sync:true})
})
this.faders.y.input.change(()=>{
var v = [this.faders.x.value, this.faders.y.value]
this.setValue(v,{send:true,sync:true})
})
if (!v || v.length!=2) return
if (!options.dragged) {
this.faders.x.setValue(v[0], {sync: false, send:false, dragged:false})
this.faders.y.setValue(v[1], {sync: false, send:false, dragged:false})
}
}
this.value = [
this.faders.x.value,
this.faders.y.value
]
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
Xy.prototype = Object.create(_pads_base.prototype)
this.draw()
Xy.prototype.constructor = Xy
Xy.prototype.dragHandle = function(){
var x = this.faders.x.value,
y = this.faders.y.value
if (x != this.value[0] || y != this.value[1]) {
this.setValue([x, y],{send:true,sync:true,dragged:true})
}
}
Xy.prototype.setValue = function(v, options={}){
if (!v || v.length!=2) return
if (!options.dragged) {
this.faders.x.setValue(v[0], {sync: false, send:false, dragged:false})
this.faders.y.setValue(v[1], {sync: false, send:false, dragged:false})
}
this.value = [
this.faders.x.value,
this.faders.y.value
]
draw() {
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
this.draw()
}
Xy.prototype.draw = function(){
var x = clip(this.faders.x.percent / 100 * this.width,[0,this.width]),
var x = clip(this.faders.x.percent / 100 * this.width,[0,this.width]),
y = clip((1 - this.faders.y.percent / 100) * this.height,[0,this.height])
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.fillStyle = this.faders.x.colors.custom
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.faders.x.colors.custom
this.ctx.fillStyle = this.faders.x.colors.custom
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.faders.x.colors.custom
this.ctx.globalAlpha = 0.3
this.ctx.globalAlpha = 0.3
this.ctx.beginPath()
this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 0.1
this.ctx.globalAlpha = 0.1
this.ctx.beginPath()
this.ctx.moveTo(0,y)
this.ctx.lineTo(this.width,y)
this.ctx.moveTo(x,0)
this.ctx.lineTo(x,this.height)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.moveTo(0,y)
this.ctx.lineTo(this.width,y)
this.ctx.moveTo(x,0)
this.ctx.lineTo(x,this.height)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
}
this.ctx.beginPath()
this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
}
module.exports.create = function(widgetData) {
var xy = new Xy(widgetData)
return xy
}

View file

@ -2,151 +2,163 @@ var {mapToScale} = require('../utils'),
_canvas_base = require('../common/_canvas_base'),
{widgetManager} = require('../../managers')
var _plots_base = module.exports = function(){
module.exports = class _plots_base extends _canvas_base {
this.widget = $(`
<div class="plot">
<canvas></canvas>
</div>
`)
constructor(widgetData) {
_canvas_base.apply(this,arguments)
var widgetHtml = `
<div class="plot">
<canvas></canvas>
</div>
`
this.data = []
this.linkedWidgets = []
this.rangeX = this.widgetData.rangeX || {min:0,max:1}
this.rangeY = this.widgetData.rangeY || {min:0,max:1}
this.pips = {
x : {
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max
},
y : {
min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min,
max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max
super(...arguments, widgetHtml)
this.data = []
this.linkedWidgets = []
this.rangeX = widgetData.rangeX || {min:0,max:1}
this.rangeY = widgetData.rangeY || {min:0,max:1}
this.pips = {
x : {
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max
},
y : {
min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min,
max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max
}
}
}
$('body').on('sync',this.syncHandleProxy.bind(this))
}
_plots_base.prototype = Object.create(_canvas_base.prototype)
_plots_base.prototype.constructor = _plots_base
_plots_base.prototype.syncHandleProxy = function() {
this.syncHandle.apply(this,arguments)
}
_plots_base.prototype.syncHandle = function(e) {
if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return
this.updateData()
requestAnimationFrame(this.draw.bind(this))
}
_plots_base.prototype.resizeHandle = function(){
this.updateData()
_canvas_base.prototype.resizeHandle.apply(this, arguments)
}
_plots_base.prototype.draw = function() {
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.beginPath()
this.draw_data()
this.ctx.lineWidth = 1*PXSCALE
this.ctx.strokeStyle = this.colors.custom
this.ctx.stroke()
if (this.widgetData.origin !== false) {
var origin = mapToScale(this.widgetData.origin||this.rangeY.min,[this.rangeY.min,this.rangeY.max],[this.height,0],0,this.widgetData.logScaleY,true)
this.ctx.globalAlpha = 0.1
this.ctx.fillStyle = this.colors.custom
this.ctx.lineTo(this.width,origin)
this.ctx.lineTo(0,origin)
this.ctx.closePath()
this.ctx.fill()
this.ctx.globalAlpha = 1
$('body').on('sync',this.syncHandleProxy.bind(this))
}
syncHandleProxy() {
this.ctx.font = PXSCALE * 10 + 'px sans-serif'
this.ctx.fillStyle = this.colors.text
if (this.pips.x) {
this.ctx.textBaseline = "bottom"
this.ctx.textAlign = 'left'
this.ctx.fillText(this.pips.x.min,(this.pips.y?12:2)*PXSCALE,this.height)
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.x.max,this.width-2*PXSCALE,this.height)
this.syncHandle(...arguments)
}
if (this.pips.y) {
syncHandle(e) {
this.ctx.save()
this.ctx.translate(0, this.height)
this.ctx.rotate(-Math.PI/2)
this.ctx.textBaseline = "top"
this.ctx.textAlign = 'left'
this.ctx.fillText(this.pips.y.min,(this.pips.x?12:2)*PXSCALE,2*PXSCALE)
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.y.max,this.height-2*PXSCALE,2*PXSCALE)
this.ctx.rotate(Math.PI/2)
this.ctx.restore()
if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return
this.updateData()
this.draw()
}
}
resizeHandle() {
_plots_base.prototype.draw_data = function() {
var first = true
var point = []
for (i in this.data) {
this.updateData()
super.resizeHandle(...arguments)
if (this.data[i][1]>this.rangeY.max || this.data[i][1]<this.rangeY.min ||
this.data[i][0]>this.rangeX.max || this.data[i][0]<this.rangeX.min) continue
}
var newpoint = this.data[i].length?
[
mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.widgetData.logScaleX,true),
mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.widgetData.logScaleY,true),
]
:
[
mapToScale(i,[0,this.data.length-1],[0,this.width],0,this.widgetData.logScaleX,true),
mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.widgetData.logScaleY,true),
]
draw() {
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.beginPath()
this.draw_data()
this.ctx.lineWidth = 1*PXSCALE
this.ctx.strokeStyle = this.colors.custom
this.ctx.stroke()
if (first) {
this.ctx.moveTo(newpoint[0],newpoint[1])
this.ctx.lineTo(newpoint[0],newpoint[1])
first = false
} else {
// this.ctx.moveTo(point[0],point[1])
this.ctx.lineTo(newpoint[0],newpoint[1])
if (this.widgetData.origin !== false) {
var origin = mapToScale(this.widgetData.origin||this.rangeY.min,[this.rangeY.min,this.rangeY.max],[this.height,0],0,this.widgetData.logScaleY,true)
this.ctx.globalAlpha = 0.1
this.ctx.fillStyle = this.colors.custom
this.ctx.lineTo(this.width,origin)
this.ctx.lineTo(0,origin)
this.ctx.closePath()
this.ctx.fill()
this.ctx.globalAlpha = 1
}
point = newpoint
this.ctx.font = PXSCALE * 10 + 'px sans-serif'
this.ctx.fillStyle = this.colors.text
if (this.pips.x) {
this.ctx.textBaseline = "bottom"
this.ctx.textAlign = 'left'
this.ctx.fillText(this.pips.x.min,(this.pips.y?12:2)*PXSCALE,this.height)
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.x.max,this.width-2*PXSCALE,this.height)
}
if (this.pips.y) {
this.ctx.save()
this.ctx.translate(0, this.height)
this.ctx.rotate(-Math.PI/2)
this.ctx.textBaseline = "top"
this.ctx.textAlign = 'left'
this.ctx.fillText(this.pips.y.min,(this.pips.x?12:2)*PXSCALE,2*PXSCALE)
this.ctx.textAlign = 'right'
this.ctx.fillText(this.pips.y.max,this.height-2*PXSCALE,2*PXSCALE)
this.ctx.rotate(Math.PI/2)
this.ctx.restore()
}
}
}
_plots_base.prototype.setValue = function(v) {
this.data = v
requestAnimationFrame(this.draw.bind(this))
}
draw_data() {
var first = true
var point = []
for (i in this.data) {
if (this.data[i][1]>this.rangeY.max || this.data[i][1]<this.rangeY.min ||
this.data[i][0]>this.rangeX.max || this.data[i][0]<this.rangeX.min) continue
var newpoint = this.data[i].length?
[
mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.widgetData.logScaleX,true),
mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.widgetData.logScaleY,true),
]
:
[
mapToScale(i,[0,this.data.length-1],[0,this.width],0,this.widgetData.logScaleX,true),
mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.widgetData.logScaleY,true),
]
if (first) {
this.ctx.moveTo(newpoint[0],newpoint[1])
this.ctx.lineTo(newpoint[0],newpoint[1])
first = false
} else {
// this.ctx.moveTo(point[0],point[1])
this.ctx.lineTo(newpoint[0],newpoint[1])
}
point = newpoint
}
}
setValue(v) {
this.data = v
this.draw()
}
updateData() {
// update the coordinates to draw
}
_plots_base.prototype.updateData = function(){
// update the coordinates to draw
}

View file

@ -3,46 +3,52 @@ var {mapToScale, clip} = require('../utils'),
_plots_base = require('./_plots_base'),
{widgetManager} = require('../../managers')
module.exports.options = {
type:'eq',
id:'auto',
module.exports = class Eq extends _plots_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
return {
type:'eq',
id:'auto',
separator2:'plot',
_style:'style',
filters:[],
resolution:128,
rangeY: {min:-20,max:20},
origin: 'auto',
logScaleX: false,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator3:'osc',
_plot:'plot',
address:'auto',
preArgs:[],
filters:[],
resolution:128,
rangeY: {min:-20,max:20},
origin: 'auto',
logScaleX: false,
}
_osc:'osc',
var Eq = module.exports.Eq = function(widgetData) {
address:'auto',
preArgs:[],
_plots_base.call(this,widgetData)
}
this.rangeX = {min:20,max:22050}
this.pips.x.min = '20'
this.pips.x.max = '22k'
}
widgetData.resolution = clip(widgetData.resolution,[64,1024])
constructor(widgetData) {
for (i in widgetData.filters) {
super(...arguments)
this.rangeX = {min:20,max:22050}
this.pips.x.min = '20'
this.pips.x.max = '22k'
widgetData.resolution = clip(widgetData.resolution,[64,1024])
for (i in widgetData.filters) {
for (j in widgetData.filters[i]) {
if (typeof widgetData.filters[i][j]=='string' && !(j=='type' && widgetData.filters[i][j].match(/peak|notch|highpass|highshelf|lowpass|lowshelf/))) {
@ -50,66 +56,62 @@ var Eq = module.exports.Eq = function(widgetData) {
}
}
}
}
}
updateData() {
Eq.prototype = Object.create(_plots_base.prototype)
Eq.prototype.constructor = Eq
Eq.prototype.updateData = function(){
var filters = [],
var filters = [],
eqResponse = []
for (i in this.widgetData.filters) {
var filter = this.widgetData.filters[i]
for (i in this.widgetData.filters) {
var filter = this.widgetData.filters[i]
filters[i] = {}
filters[i] = {}
for (j in filter) {
let widget = widgetManager.getWidgetById(filter[j])
for (j in filter) {
let widget = widgetManager.getWidgetById(filter[j])
if (typeof filter[j]=='string' && widget.length) {
if (typeof filter[j]=='string' && widget.length) {
filters[i][j] = widget[widget.length-1].getValue()
filters[i][j] = widget[widget.length-1].getValue()
} else {
filters[i][j] = filter[j]
}
}
}
for (i in filters) {
var filterResponse
if (!filters[i].type) filters[i].type = "peak"
if (!filters[i].on) {
filterResponse = _biquad_response({type:"peak",freq:1,gain:0,q:1},!this.widgetData.logScaleX,this.widgetData.resolution)
} else {
filterResponse = _biquad_response(filters[i],!this.widgetData.logScaleX,this.widgetData.resolution)
}
filters[i][j] = filter[j]
for (var k in filterResponse) {
if (eqResponse[k]===undefined) {
eqResponse[k]=[0,0]
}
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
}
}
if (eqResponse.length) this.data = eqResponse
}
for (i in filters) {
var filterResponse
if (!filters[i].type) filters[i].type = "peak"
if (!filters[i].on) {
filterResponse = _biquad_response({type:"peak",freq:1,gain:0,q:1},!this.widgetData.logScaleX,this.widgetData.resolution)
} else {
filterResponse = _biquad_response(filters[i],!this.widgetData.logScaleX,this.widgetData.resolution)
}
for (k in filterResponse) {
if (eqResponse[k]===undefined) {
eqResponse[k]=[0,0]
}
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
}
}
if (eqResponse.length) this.data = eqResponse
}
module.exports.create = function(widgetData) {
var eq = new Eq(widgetData)
return eq
}

View file

@ -1,59 +1,57 @@
var {mapToScale} = require('../utils'),
_widgets_base = require('../common/_widgets_base')
module.exports = class Led extends _widgets_base {
module.exports.options = {
type:'led',
id:'auto',
static options() {
separator1:'style',
return {
type:'led',
id:'auto',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
_style:'style',
separator2:'osc',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
range:{min:0,max:1},
logScale:false,
value:'',
preArgs:[],
address:'auto'
}
_osc:'osc',
var Led = module.exports.Led = function(widgetData,container) {
range:{min:0,max:1},
logScale:false,
value:'',
preArgs:[],
address:'auto'
_widgets_base.apply(this,arguments)
}
this.widget = $(`
}
constructor(widgetData) {
var widgetHtml = `
<div class="led">
<div><span></span></div>
</div>
`),
this.led = this.widget.find('span')
`
super(...arguments, widgetHtml)
this.setValue(this.widgetData.range.min)
this.led = this.widget.find('span')
this.setValue(widgetData.range.min)
}
setValue(v) {
if (typeof v != 'number') return
this.led.css('opacity',mapToScale(v,[this.widgetData.range.min,this.widgetData.range.max],[0,1],false,this.widgetData.logScale,true))
}
}
Led.prototype = Object.create(_widgets_base.prototype)
Led.prototype.constructor = Led
Led.prototype.setValue = function(v){
if (typeof v != 'number') return
this.led.css('opacity',mapToScale(v,[this.widgetData.range.min,this.widgetData.range.max],[0,1],false,this.widgetData.logScale,true))
}
module.exports.create = function(widgetData, container) {
var led = new Led(widgetData, container)
return led
}

View file

@ -1,59 +1,54 @@
var {Fader} = require('../sliders/fader')
var Fader = require('../sliders/fader')
module.exports.options = {
type:'fader',
id:'auto',
module.exports = class Meter extends Fader {
separator1:'style',
static options() {
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
horizontal:false,
color:'auto',
css:'',
return {
type:'fader',
id:'auto',
separator3:'osc',
_style:'style',
range:{min:0,max:1},
logScale:false,
origin:'auto',
value:'',
address:'auto',
preArgs:[]
}
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
horizontal:false,
color:'auto',
css:'',
_osc:'osc',
var {Fader} = require('../sliders/fader')
range:{min:0,max:1},
logScale:false,
origin:'auto',
value:'',
address:'auto',
preArgs:[]
}
var Meter = module.exports.Meter = function(widgetData, container){
}
var data = widgetData
data.compact = true
constructor(widgetData) {
Fader.apply(this, arguments)
widgetData.compact = true
this.input.hide()
super(...arguments)
this.widget.addClass('meter')
this.input.hide()
this.widget.off('mousewheel')
this.canvas.off('draginit')
this.canvas.off('drag')
this.widget.addClass('meter')
.off('mousewheel')
this.canvas.off('draginit drag')
}
sendValue() {
// disabled
}
}
Meter.prototype = Object.create(Fader.prototype)
Meter.prototype.constructor = Meter
Meter.prototype.sendValue = ()=>{}
module.exports.create = function(widgetData,container) {
var meter = new Meter(widgetData, container)
return meter
}

View file

@ -2,58 +2,67 @@ var {mapToScale} = require('../utils'),
_plots_base = require('./_plots_base'),
{widgetManager} = require('../../managers')
module.exports.options = {
type:'plot',
id:'auto',
module.exports = class Plot extends _plots_base {
separator1:'style',
static options() {
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
return {
type:'plot',
id:'auto',
separator2:'plot',
_style:'style',
points:[],
rangeX: {min:0,max:1},
rangeY: {min:0,max:1},
origin: 'auto',
logScaleX: false,
logScaleY: false,
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator3:'osc',
_plot:'plot',
address:'auto',
preArgs:[],
points:[],
rangeX: {min:0,max:1},
rangeY: {min:0,max:1},
origin: 'auto',
logScaleX: false,
logScaleY: false,
}
_osc:'osc',
var Plot = module.exports.Plot = function(widgetData) {
address:'auto',
preArgs:[],
_plots_base.call(this,widgetData)
}
if (typeof widgetData.points=='string') {
}
this.linkedWidgets.push(widgetData.points)
constructor(widgetData) {
} else if (typeof widgetData.points=='object') {
super(...arguments)
for (i in widgetData.points) {
for (j in widgetData.points[i]) {
if (typeof widgetData.points[i][j] == 'string') {
this.linkedWidgets.push(widgetData.points[i][j])
if (typeof widgetData.points=='string') {
this.linkedWidgets.push(widgetData.points)
} else if (typeof widgetData.points=='object') {
for (i in widgetData.points) {
for (j in widgetData.points[i]) {
if (typeof widgetData.points[i][j] == 'string') {
this.linkedWidgets.push(widgetData.points[i][j])
}
}
}
}
}
this.updateData = function(){
updateData() {
var data = [],
points = widgetData.points,
points = this.widgetData.points,
widget = widgetManager.getWidgetById(points)
if (typeof points=='string' && widget.length) {
@ -66,7 +75,7 @@ var Plot = module.exports.Plot = function(widgetData) {
data[i] = []
for (k in [0,1]) {
for (var k in [0,1]) {
let widget = widgetManager.getWidgetById(points[i][k])
if (typeof points[i][k] == 'string' && widget.length) {
data[i][k] = widget[widget.length-1].getValue()
@ -80,14 +89,7 @@ var Plot = module.exports.Plot = function(widgetData) {
}
if (data.length) this.data = data
}
}
Plot.prototype = Object.create(_plots_base.prototype)
Plot.prototype.constructor = Plot
module.exports.create = function(widgetData) {
var plot = new Plot(widgetData)
return plot
}

View file

@ -1,66 +1,60 @@
var {iconify} = require('../../utils'),
_widgets_base = require('../common/_widgets_base')
module.exports = class Text extends _widgets_base {
module.exports.options = {
type:'text',
id:'auto',
static options() {
separator1:'style',
return {
type:'text',
id:'auto',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
vertical:false,
color:'auto',
css:'',
_style:'style',
separator2:'osc',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
vertical:false,
color:'auto',
css:'',
value:'',
preArgs:[],
address:'auto',
}
_osc:'osc',
var Text = module.exports.Text = function(widgetData,container) {
value:'',
preArgs:[],
address:'auto',
}
_widgets_base.apply(this,arguments)
}
constructor(widgetData) {
this.widget = $(`
<div class="text">
var widgetHtml = `
<div class="text ${widgetData.vertical?'vertical':''}">
</div>
`)
`
this.defaultValue = widgetData.label===false?
widgetData.id:
widgetData.label=='auto'?
super(...arguments, widgetHtml)
this.defaultValue = widgetData.label===false?
widgetData.id:
widgetData.label
widgetData.label=='auto'?
widgetData.id:
widgetData.label
this.value = this.defaultValue
this.value = this.defaultValue
this.setValue(this.value)
if (this.widgetData.vertical) this.widget.addClass('vertical')
}
this.setValue(this.value)
setValue(v) {
this.value = typeof v=='object' && !v.length ? this.defaultValue : v
this.widget.html(iconify(this.value))
}
}
Text.prototype = Object.create(_widgets_base.prototype)
Text.prototype.constructor = Text
Text.prototype.setValue = function(v){
this.value = typeof v=='object' && !v.length ? this.defaultValue : v
this.widget.html(iconify(this.value))
}
module.exports.create = function(widgetData, container) {
var text = new Text(widgetData, container)
return text
}

View file

@ -2,129 +2,134 @@ var {mapToScale, clip} = require('../utils'),
_plots_base = require('./_plots_base'),
{widgetManager} = require('../../managers')
module.exports = class Visualizer extends _plots_base {
module.exports.options = {
type:'visualizer',
id:'auto',
static options() {
separator1:'style',
return {
type:'visualizer',
id:'auto',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
_style:'style',
separator2:'plot',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
widgetId:'',
duration:1,
range: {min:0,max:1},
origin: 'auto',
logScale: false,
_plot:'plot',
separator3:'osc',
widgetId:'',
duration:1,
range: {min:0,max:1},
origin: 'auto',
logScale: false,
value:'',
address:'auto',
preArgs:[],
}
var Visualizer = module.exports.Visualizer = function(widgetData) {
_plots_base.call(this,widgetData)
this.pips.y.min = Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min
this.pips.y.max = Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max
this.pips.x = false
this.length = Math.round(clip(60*widgetData.duration,[8,4096]))
this.data = new Array(this.length)
this.value = widgetData.range.min
this.cancel = false
this.loop = false
}
Visualizer.prototype = Object.create(_plots_base.prototype)
Visualizer.prototype.constructor = Visualizer
Visualizer.prototype.syncHandle = function(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
this.startLoop()
}
Visualizer.prototype.startLoop = function(){
if (this.cancel) clearTimeout(this.cancel)
this.cancel = setTimeout(function(){
clearInterval(this.loop)
this.loop = false
this.cancel = false
},1000*this.widgetData.duration)
if (this.loop) return
this.loop = setInterval(function(){
this.updateData()
this.draw()
}.bind(this),1000*this.widgetData.duration/this.length)
}
Visualizer.prototype.draw_data = function(){
var first = true
var point = []
for (var i=0;i<this.length;i++) {
var newpoint = [
mapToScale(i,[0,this.length-1],[0,this.width],1),
mapToScale(this.data[i],[this.widgetData.range.min,this.widgetData.range.max],[this.height-PXSCALE,PXSCALE],1,this.widgetData.logScale,true),
]
if (first) {
this.ctx.moveTo(newpoint[0],newpoint[1])
first = false
} else {
if (this.widgetData.logScale) {
this.ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
} else {
this.ctx.lineTo(newpoint[0],newpoint[1])
}
_osc:'osc',
value:'',
address:'auto',
preArgs:[],
}
point = newpoint
}
}
constructor(widgetData) {
super(...arguments)
this.pips.y.min = Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min
this.pips.y.max = Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max
this.pips.x = false
this.length = Math.round(clip(60*widgetData.duration,[8,4096]))
this.data = new Array(this.length)
this.value = widgetData.range.min
this.cancel = false
this.loop = false
}
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
this.startLoop()
}
startLoop() {
if (this.cancel) clearTimeout(this.cancel)
this.cancel = setTimeout(function(){
clearInterval(this.loop)
this.loop = false
this.cancel = false
},1000*this.widgetData.duration)
if (this.loop) return
this.loop = setInterval(()=>{
this.updateData()
this.draw()
},1000*this.widgetData.duration/this.length)
}
Visualizer.prototype.updateData = function(){
var id = this.widgetData.widgetId,
draw_data() {
var first = true
var point = []
for (var i=0;i<this.length;i++) {
var newpoint = [
mapToScale(i,[0,this.length-1],[0,this.width],1),
mapToScale(this.data[i],[this.widgetData.range.min,this.widgetData.range.max],[this.height-PXSCALE,PXSCALE],1,this.widgetData.logScale,true),
]
if (first) {
this.ctx.moveTo(newpoint[0],newpoint[1])
first = false
} else {
if (this.widgetData.logScale) {
this.ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
} else {
this.ctx.lineTo(newpoint[0],newpoint[1])
}
}
point = newpoint
}
}
updateData() {
var id = this.widgetData.widgetId,
widget = widgetManager.getWidgetById(id)
if (typeof id == 'string' && widget.length) {
var v = widget[widget.length-1].getValue()
this.data.push(v)
this.value = v
} else {
this.data.push(this.value)
if (typeof id == 'string' && widget.length) {
var v = widget[widget.length-1].getValue()
this.data.push(v)
this.value = v
} else {
this.data.push(this.value)
}
this.data.splice(0,1)
}
this.data.splice(0,1)
setValue(v) {
this.value = v
this.startLoop()
}
}
Visualizer.prototype.setValue = function(v) {
this.value = v
this.startLoop()
}
module.exports.create = function(widgetData,container) {
var visualizer = new Visualizer(widgetData)
return visualizer
}

View file

@ -1,168 +1,185 @@
var {clip, mapToScale} = require('../utils')
var _canvas_base = require('../common/_canvas_base')
var {clip, mapToScale} = require('../utils'),
_canvas_base = require('../common/_canvas_base')
var _sliders_base = module.exports = function(){
module.exports = class _sliders_base extends _canvas_base {
this.widget = $(`
<div class="slider">
<div class="wrapper">
<canvas></canvas>
constructor(widgetData) {
var widgetHtml = `
<div class="slider">
<div class="wrapper">
<canvas></canvas>
</div>
<div class="input"></div>
</div>
<div class="input"></div>
</div>
`)
`
_canvas_base.apply(this, arguments)
super(...arguments, widgetHtml)
this.wrapper = this.widget.find('.wrapper')
this.input = this.widget.find('.input').fakeInput({align:'center'})
this.value = undefined
this.percent = 0
this.wrapper = this.widget.find('.wrapper')
this.input = this.widget.find('.input').fakeInput({align:'center'})
this.value = undefined
this.percent = 0
this.unit = this.widgetData.unit ? ' ' + this.widgetData.unit : ''
this.unit = widgetData.unit ? ' ' + widgetData.unit : ''
this.rangeKeys = []
this.rangeVals = []
this.rangeLabels = []
this.rangeKeys = []
this.rangeVals = []
this.rangeLabels = []
for (k in this.widgetData.range) {
var key = k=='min'?0:k=='max'?100:parseInt(k),
val = typeof this.widgetData.range[k] == 'object'?
this.widgetData.range[k][Object.keys(this.widgetData.range[k])[0]]:
this.widgetData.range[k],
label = typeof this.widgetData.range[k] == 'object'?
Object.keys(this.widgetData.range[k])[0]:
val
for (var 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
this.rangeKeys.push(key)
this.rangeVals.push(val)
this.rangeLabels.push(label)
}
this.rangeValsMax = Math.max.apply(Math, this.rangeVals),
this.rangeValsMin = Math.min.apply(Math, this.rangeVals)
this.originValue = this.widgetData.origin=='auto'?
this.rangeValsMin:
clip(this.widgetData.origin,[this.rangeValsMin,this.rangeValsMax])
this.springValue = this.widgetData.value != '' ? this.widgetData.value :  this.originValue
this.widget.on('fake-right-click',function(e){
if (!EDITING) {
e.stopPropagation()
e.preventDefault()
this.input.focus()
this.rangeKeys.push(key)
this.rangeVals.push(val)
this.rangeLabels.push(label)
}
}.bind(this))
this.rangeValsMax = Math.max(...this.rangeVals),
this.rangeValsMin = Math.min(...this.rangeVals)
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
this.canvas.on('drag',this.dragHandleProxy.bind(this))
this.originValue = widgetData.origin=='auto'?
this.rangeValsMin:
clip(widgetData.origin,[this.rangeValsMin,this.rangeValsMax])
this.springValue = widgetData.value != '' ? widgetData.value :  this.originValue
this.widget.on('fake-right-click',function(e){
if (!EDITING) {
e.stopPropagation()
e.preventDefault()
this.input.focus()
}
}.bind(this))
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
this.canvas.on('drag',this.dragHandleProxy.bind(this))
if (widgetData.spring) {
this.canvas.on('dragend', ()=>{
this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
})
}
this.input.change(()=>{
this.setValue(parseFloat(this.input.val()),{sync:true,send:true})
if (this.widgetData.spring) {
this.canvas.on('dragend', ()=>{
this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
})
this.setValue(this.originValue)
}
this.input.change(function(){
this.setValue(parseFloat(this.input.val()),{sync:true,send:true})
}.bind(this))
mousewheelHandleProxy() {
this.mousewheelHandle(...arguments)
}
draginitHandleProxy() {
this.draginitHandle(...arguments)
}
dragHandleProxy() {
this.dragHandle(...arguments)
}
this.setValue(this.originValue)
mousewheelHandle(e, data, traversing) {
}
if (e.originalEvent.wheelDeltaX) return
_sliders_base.prototype = Object.create(_canvas_base.prototype)
e.preventDefault()
e.stopPropagation()
_sliders_base.prototype.constructor = _sliders_base
_sliders_base.prototype.mousewheelHandleProxy = function() {
this.mousewheelHandle.apply(this,arguments)
}
_sliders_base.prototype.draginitHandleProxy = function() {
this.draginitHandle.apply(this,arguments)
}
_sliders_base.prototype.dragHandleProxy = function() {
this.dragHandle.apply(this,arguments)
}
_sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
if (e.originalEvent.wheelDeltaX) return
e.preventDefault()
e.stopPropagation()
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
increment = e.ctrlKey?0.25:1
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true})
this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true})
}
_sliders_base.prototype.draginitHandle = function(e, data, traversing) {
}
_sliders_base.prototype.dragHandle = function(e, data, traversing) {
}
_sliders_base.prototype.resizeHandle = function(e, width, height, checkColors) {
if (!this.visible || checkColors) {
var style = getComputedStyle(this.widget[0])
this.colors.track = style.getPropertyValue('--color-track')
this.colors.gauge = style.getPropertyValue('--color-gauge')
this.colors.knob = style.getPropertyValue('--color-knob')
}
_canvas_base.prototype.resizeHandle.apply(this, arguments)
}
draginitHandle(e, data, traversing) {
_sliders_base.prototype.percentToValue = function(percent) {
var h = clip(percent,[0,100])
for (var i=0;i<this.rangeKeys.length-1;i++) {
if (h <= this.rangeKeys[i+1] && h >= this.rangeKeys[i]) {
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.widgetData.logScale)
}
dragHandle(e, data, traversing) {
}
resizeHandle(e, width, height, checkColors) {
if (!this.visible || checkColors) {
var style = getComputedStyle(this.widget[0])
this.colors.track = style.getPropertyValue('--color-track')
this.colors.gauge = style.getPropertyValue('--color-gauge')
this.colors.knob = style.getPropertyValue('--color-knob')
}
super.resizeHandle(...arguments)
}
}
_sliders_base.prototype.valueToPercent = function(value) {
for (var i=0;i<this.rangeVals.length-1;i++) {
if (value <= this.rangeVals[i+1] && value >= this.rangeVals[i]) {
return mapToScale(value,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.widgetData.logScale,true)
percentToValue(percent) {
var h = clip(percent,[0,100])
for (var i=0;i<this.rangeKeys.length-1;i++) {
if (h <= this.rangeKeys[i+1] && h >= this.rangeKeys[i]) {
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.widgetData.logScale)
}
}
}
}
_sliders_base.prototype.setValue = function(v,options={}) {
if (typeof v != 'number') return
var value = clip(v,[this.rangeValsMin,this.rangeValsMax])
if ((options.dragged || options.fromLocal) && this.value.toFixed(this.widgetData.precision) == value.toFixed(this.widgetData.precision)) options.send = false
this.value = value
if (!options.dragged) this.percent = this.valueToPercent(this.value)
if (!this.noDraw) this.draw()
this.showValue()
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
if (options.send) this.sendValue(v)
}
_sliders_base.prototype.showValue = function() {
this.input.val(this.value.toFixed(this.widgetData.precision) + this.unit)
valueToPercent(value) {
for (var i=0;i<this.rangeVals.length-1;i++) {
if (value <= this.rangeVals[i+1] && value >= this.rangeVals[i]) {
return mapToScale(value,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.widgetData.logScale,true)
}
}
}
setValue(v,options={}) {
if (typeof v != 'number') return
var value = clip(v,[this.rangeValsMin,this.rangeValsMax])
if ((options.dragged || options.fromLocal) && this.value.toFixed(this.widgetData.precision) == value.toFixed(this.widgetData.precision)) options.send = false
this.value = value
if (!options.dragged) this.percent = this.valueToPercent(this.value)
if (!this.noDraw) this.draw()
this.showValue()
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
if (options.send) this.sendValue(v)
}
showValue() {
this.input.val(this.value.toFixed(this.widgetData.precision) + this.unit)
}
}

View file

@ -2,303 +2,302 @@ var {clip, mapToScale} = require('../utils'),
_sliders_base = require('./_sliders_base')
module.exports.options = {
type:'fader',
id:'auto',
linkId:'',
module.exports = class Fader extends _sliders_base {
separator1:'style',
static options() {
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
alignRight:false,
horizontal:false,
noPip:false,
compact:false,
color:'auto',
css:'',
return {
type:'fader',
id:'auto',
linkId:'',
separator2:'behaviour',
_style:'style',
snap:false,
spring:false,
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
alignRight:false,
horizontal:false,
noPip:false,
compact:false,
color:'auto',
css:'',
separator3:'osc',
_behaviour:'behaviour',
range:{min:0,max:1},
origin: 'auto',
value:'',
logScale:false,
precision:2,
meter:false,
address:'auto',
preArgs:[],
target:[]
}
snap:false,
spring:false,
var Fader = module.exports.Fader = function(widgetData, container){
_osc:'osc',
_sliders_base.apply(this,arguments)
this.widget.addClass('fader')
this.margin = 20
if (widgetData.horizontal) {
this.widget.add(container).addClass('horizontal')
if (widgetData.width == 'auto' && widgetData.left != 'auto') {
container.css({'width':'auto', 'right':'0'})
}
} else {
if (widgetData.height == 'auto' && widgetData.top != 'auto') {
container.css({'height':'auto', 'bottom':'0'})
}
}
if (widgetData.compact) {
this.widget.addClass('compact')
this.margin = 0
}
if (widgetData.alignRight && !widgetData.horizontal) {
this.widget.addClass('align-right')
}
if (!widgetData.noPip&&!widgetData.compact) {
this.widget.addClass('has-pips')
var pips = $('<div class="pips"></div>').appendTo(this.widget.find('.wrapper'))
var pipTexts = {}
for (k in this.rangeKeys) {
pipTexts[this.rangeKeys[k]]=this.rangeLabels[k]
range:{min:0,max:1},
origin: 'auto',
value:'',
logScale:false,
precision:2,
meter:false,
address:'auto',
preArgs:[],
target:[]
}
var pipsInner = ''
for (var i=0;i<=100;i++) {
if (pipTexts[i]==undefined) continue
}
var pos = widgetData.horizontal?'left':'bottom';
constructor(widgetData) {
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
super(...arguments)
var add = `
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
this.widget.addClass('fader')
this.margin = 20
if (widgetData.horizontal) {
this.widget.add(container).addClass('horizontal')
if (widgetData.width == 'auto' && widgetData.left != 'auto') {
this.container.css({'width':'auto', 'right':'0'})
}
} else {
if (widgetData.height == 'auto' && widgetData.top != 'auto') {
this.container.css({'height':'auto', 'bottom':'0'})
}
}
if (widgetData.compact) {
this.widget.addClass('compact')
this.margin = 0
}
if (widgetData.alignRight && !widgetData.horizontal) {
this.widget.addClass('align-right')
}
if (!widgetData.noPip&&!widgetData.compact) {
this.widget.addClass('has-pips')
var pips = $('<div class="pips"></div>').appendTo(this.widget.find('.wrapper'))
var pipTexts = {}
for (var k in this.rangeKeys) {
pipTexts[this.rangeKeys[k]]=this.rangeLabels[k]
}
var pipsInner = ''
for (var i=0;i<=100;i++) {
if (pipTexts[i]==undefined) continue
var pos = widgetData.horizontal?'left':'bottom';
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
var add = `
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
`
pipsInner = pipsInner + add
pipsInner = pipsInner + add
}
pips[0].innerHTML = pipsInner
}
pips[0].innerHTML = pipsInner
if (widgetData.meter) {
var parsewidgets = require('../../parser').widgets
var data = {
type:'meter',
id: widgetData.id + '/meter',
label:false,
horizontal:widgetData.horizontal,
range:widgetData.range,
logScale:widgetData.logScale,
address:widgetData.address + '/meter',
preArgs:widgetData.preArgs,
color:widgetData.color
}
var element = parsewidgets([data],this.widget.find('.wrapper'))
element[0].classList.add('not-editable')
this.widget[0].classList.add('has-meter')
}
}
draginitHandle(e, data, traversing) {
if (widgetData.meter) {
var parsewidgets = require('../../parser').widgets
var data = {
type:'meter',
id: widgetData.id + '/meter',
label:false,
horizontal:widgetData.horizontal,
range:widgetData.range,
logScale:widgetData.logScale,
address:widgetData.address + '/meter',
preArgs:widgetData.preArgs,
color:widgetData.color
}
var element = parsewidgets([data],this.widget.find('.wrapper'))
element[0].classList.add('not-editable')
this.widget[0].classList.add('has-meter')
}
this.percent = clip(this.percent,[0,100])
if (!(traversing || this.widgetData.snap)) return
}
Fader.prototype = Object.create(_sliders_base.prototype)
Fader.prototype.constructor = Fader
Fader.prototype.draginitHandle = function(e, data, traversing){
this.percent = clip(this.percent,[0,100])
if (!(traversing || this.widgetData.snap)) return
this.percent = this.widgetData.horizontal?
this.percent = this.widgetData.horizontal?
(data.offsetX - this.margin * PXSCALE) / (this.width - (this.margin * PXSCALE * 2)) * 100:
(this.height - data.offsetY - this.margin * PXSCALE) / (this.height - (this.margin * PXSCALE * 2)) * 100
// this.percent = clip(this.percent,[0,100])
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
}
}
Fader.prototype.dragHandle = function(e, data) {
dragHandle(e, data) {
this.percent = this.widgetData.horizontal?
this.percent = this.widgetData.horizontal?
this.percent + ( data.speedX/(this.width - this.margin * PXSCALE * 2)) * 100:
this.percent + (-data.speedY/(this.height - this.margin * PXSCALE * 2)) * 100
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
}
Fader.prototype.percentToCoord = function(percent) {
if (this.widgetData.horizontal) {
return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin)
} else {
return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
}
percentToCoord(percent) {
if (this.widgetData.horizontal) {
return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin)
} else {
return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
}
}
}
Fader.prototype.draw = function(){
draw() {
var d = Math.round(this.percentToCoord(this.percent)),
var d = Math.round(this.percentToCoord(this.percent)),
o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))),
m = Math.round(this.widgetData.horizontal ? this.height / 2 : this.width / 2)
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.clearRect(0,0,this.width,this.height)
if (this.widgetData.horizontal) {
if (this.widgetData.compact) {
if (this.widgetData.horizontal) {
if (this.widgetData.compact) {
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:this.width-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(d, m)
this.ctx.lineTo(o, m)
this.ctx.lineWidth = this.height + 1
this.ctx.stroke()
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:this.width-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(d, m)
this.ctx.lineTo(o, m)
this.ctx.lineWidth = this.height + 1
this.ctx.stroke()
if (!this.widgetData.noPip) {
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 1
if (!this.widgetData.noPip) {
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 1
var x,
var x,
min = Math.min(d,o),
max = Math.max(d,o)
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
x = Math.round(this.percentToCoord(this.rangeKeys[i])) + 0.5
this.ctx.strokeStyle = this.colors.bg
this.ctx.beginPath()
this.ctx.moveTo(x, 0)
this.ctx.lineTo(x, this.height)
this.ctx.stroke()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
x = Math.round(this.percentToCoord(this.rangeKeys[i])) + 0.5
this.ctx.strokeStyle = this.colors.bg
this.ctx.beginPath()
this.ctx.moveTo(x, 0)
this.ctx.lineTo(x, this.height)
this.ctx.stroke()
}
}
}
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(Math.min(d,this.width-PXSCALE), 0, PXSCALE, this.height)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(Math.min(d,this.width-PXSCALE), 0, PXSCALE, this.height)
this.ctx.fill()
} else {
} else {
this.ctx.lineWidth = Math.round(2 * PXSCALE)
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(this.margin * PXSCALE, m)
this.ctx.lineTo(this.width - this.margin * PXSCALE, m )
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(d + this.margin * PXSCALE, m)
this.ctx.lineTo(o + this.margin * PXSCALE, m)
this.ctx.stroke()
this.ctx.fillStyle = this.colors.knob
this.ctx.globalAlpha = 0.3
this.ctx.arc(d + this.margin * PXSCALE, m, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(d + this.margin * PXSCALE, m, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
}
} else {
if (this.widgetData.compact) {
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:this.height-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.lineWidth = this.width + 1
this.ctx.stroke()
if (!this.widgetData.noPip) {
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 0.75
var y,
min = Math.min(d,o),
max = Math.max(d,o)
this.ctx.lineWidth = Math.round(2 * PXSCALE)
this.ctx.beginPath()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
y = Math.round(this.percentToCoord(this.rangeKeys[i])) + 0.5
this.ctx.strokeStyle = this.colors.bg
this.ctx.moveTo(0, y)
this.ctx.lineTo(this.width, y)
}
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(this.margin * PXSCALE, m)
this.ctx.lineTo(this.width - this.margin * PXSCALE, m )
this.ctx.stroke()
}
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(0, Math.min(d, this.height - PXSCALE), this.width, PXSCALE)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(d + this.margin * PXSCALE, m)
this.ctx.lineTo(o + this.margin * PXSCALE, m)
this.ctx.stroke()
this.ctx.fillStyle = this.colors.knob
this.ctx.globalAlpha = 0.3
this.ctx.arc(d + this.margin * PXSCALE, m, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(d + this.margin * PXSCALE, m, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
}
} else {
this.ctx.lineWidth = Math.round(2 * PXSCALE)
if (this.widgetData.compact) {
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(m, this.margin * PXSCALE)
this.ctx.lineTo(m, this.height - this.margin * PXSCALE)
this.ctx.stroke()
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:this.height-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.lineWidth = this.width + 1
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.stroke()
if (!this.widgetData.noPip) {
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 0.75
var y,
min = Math.min(d,o),
max = Math.max(d,o)
this.ctx.beginPath()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
y = Math.round(this.percentToCoord(this.rangeKeys[i])) + 0.5
this.ctx.strokeStyle = this.colors.bg
this.ctx.moveTo(0, y)
this.ctx.lineTo(this.width, y)
}
this.ctx.stroke()
}
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(0, Math.min(d, this.height - PXSCALE), this.width, PXSCALE)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.globalAlpha = 0.3
this.ctx.arc(m, d, 10 * PXSCALE, Math.PI * 2,false)
this.ctx.fill()
this.ctx.globalAlpha = 1
} else {
this.ctx.beginPath()
this.ctx.arc(m, d, 4 * PXSCALE, Math.PI * 2,false)
this.ctx.fill()
this.ctx.lineWidth = Math.round(2 * PXSCALE)
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(m, this.margin * PXSCALE)
this.ctx.lineTo(m, this.height - this.margin * PXSCALE)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.globalAlpha = 0.3
this.ctx.arc(m, d, 10 * PXSCALE, Math.PI * 2,false)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(m, d, 4 * PXSCALE, Math.PI * 2,false)
this.ctx.fill()
}
}
}
}
module.exports.create = function(widgetData,container) {
var fader = new Fader(widgetData, container)
return fader
}

View file

@ -1,247 +1,248 @@
var {clip, mapToScale} = require('../utils'),
_sliders_base = require('./_sliders_base')
module.exports = class Knob extends _sliders_base {
module.exports.options = {
type:'knob',
id:'auto',
linkId:'',
static options() {
separator1:'style',
return {
type:'knob',
id:'auto',
linkId:'',
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
noPip:true,
compact:false,
angle:270,
css:'',
_style:'style',
separator2:'behaviour',
label:'auto',
unit:'',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
noPip:true,
compact:false,
angle:270,
css:'',
snap:false,
spring:false,
_behaviour:'behaviour',
separator3:'osc',
snap:false,
spring:false,
range:{min:0,max:1},
origin: 'auto',
value:'',
logScale:false,
precision:2,
address:'auto',
preArgs:[],
target:[]
}
_osc:'osc',
range:{min:0,max:1},
origin: 'auto',
value:'',
logScale:false,
precision:2,
address:'auto',
preArgs:[],
target:[]
}
var Knob = module.exports.Knob = function(widgetData) {
_sliders_base.apply(this,arguments)
this.widget.addClass('knob')
this.margin = 5
if (widgetData.compact) {
this.widget.addClass('compact')
this.margin = 0
}
if (!widgetData.noPip) {
this.wrapper.append(`
<div class="pips">
<div>${this.rangeLabels[0]}</div><div>${this.rangeLabels[this.rangeLabels.length-1]}</div>
</div>
`)
constructor(widgetData) {
super(...arguments)
this.widget.addClass('knob')
this.margin = 5
if (widgetData.compact) {
this.widget.addClass('compact')
this.margin = 0
}
if (!widgetData.noPip) {
this.wrapper.append(`
<div class="pips">
<div>${this.rangeLabels[0]}</div><div>${this.rangeLabels[this.rangeLabels.length-1]}</div>
</div>
`)
}
this.lastOffsetX = 0
this.lastOffsetY = 0
this.minDimension = 0
this.maxAngle = widgetData.angle
// calculate lost height factor
var a = this.maxAngle <= 180 ?
1 : 1 - Math.sin((this.maxAngle - 180) / 2 * Math.PI / 180)
this.lostHeightFactor = a / 4
}
this.lastOffsetX = 0
this.lastOffsetY = 0
this.minDimension = 0
draginitHandle(e, data, traversing) {
this.maxAngle = widgetData.angle
this.percent = clip(this.percent,[0,100])
// calculate lost height factor
var a = this.maxAngle <= 180 ?
1 : 1 - Math.sin((this.maxAngle - 180) / 2 * Math.PI / 180)
this.lostHeightFactor = a / 4
this.lastOffsetX = data.offsetX
this.lastOffsetY = data.offsetY
}
if (!(traversing || this.widgetData.snap)) return
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
Knob.prototype = Object.create(_sliders_base.prototype)
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
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), {send:true,sync:true,dragged:true})
}
Knob.prototype.dragHandle = function(e, data, traversing) {
if (!(traversing || this.widgetData.snap)) {
this.percent = -100*data.speedY/this.height + 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]
dragHandle(e, data, traversing) {
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
if (!(traversing || this.widgetData.snap)) {
}
this.percent = -100*data.speedY/this.height + this.percent
Knob.prototype.coordsToAngle = function(x,y) {
var xToCenter = x - this.width /2,
} 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), {send:true,sync:true,dragged:true})
}
coordsToAngle(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
}
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.apply(this, arguments)
this.minDimension = Math.min(this.width, this.height)
this.gaugeWidth = this.minDimension / 8
if (this.widgetData.compact) {
this.canvas[0].style.top = this.input[0].style.marginTop = (this.minDimension) * this.lostHeightFactor - this.gaugeWidth / 4 + 'px'
} else {
this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - this.margin * PXSCALE / 2, this.input.outerHeight() * .5) + 'px'
}
}
angleToPercent(angle) {
return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100
}
percentToAngle(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
}
resizeHandle() {
super.resizeHandle(...arguments)
this.minDimension = Math.min(this.width, this.height)
this.gaugeWidth = this.minDimension / 8
if (this.widgetData.compact) {
this.canvas[0].style.top = this.input[0].style.marginTop = (this.minDimension) * this.lostHeightFactor - this.gaugeWidth / 4 + 'px'
} else {
this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - this.margin * PXSCALE / 2, this.input.outerHeight() * .5) + 'px'
}
}
draw() {
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)
if (this.widgetData.compact) {
this.ctx.lineWidth = this.gaugeWidth * PXSCALE
this.ctx.globalAlpha = 0.3
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o-min:max-o)
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth/2 + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
Knob.prototype.draw = function(){
this.ctx.globalAlpha = 1
var o = this.percentToAngle(this.valueToPercent(this.originValue)),
d = this.percentToAngle(this.percent),
min = this.percentToAngle(0),
max = this.percentToAngle(100)
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth/2 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.clearRect(0,0,this.width,this.height)
this.ctx.beginPath()
if (this.widgetData.compact) {
this.ctx.strokeStyle = this.colors.knob
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.lineWidth = this.gaugeWidth * PXSCALE
this.ctx.globalAlpha = 0.3
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o-min:max-o)
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth/2 + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth/2 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.knob
this.ctx.lineWidth = 1 * PXSCALE
let r1 = this.minDimension / 2 - (this.gaugeWidth/2 + this.margin) * PXSCALE,
let r1 = this.minDimension / 2 - (this.gaugeWidth/2 + this.margin) * PXSCALE,
r2 = this.minDimension / 2 - (this.gaugeWidth * 1.5 + this.margin) * PXSCALE,
a = 2 * Math.PI - d
this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a))
this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a))
this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a))
this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a))
this.ctx.stroke()
this.ctx.stroke()
} else {
} else {
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.raised
this.ctx.arc(this.width / 2, this.height / 2, Math.max(this.minDimension / 2 - (30 + this.margin) * PXSCALE, 2 * PXSCALE), 0, Math.PI * 2)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.raised
this.ctx.arc(this.width / 2, this.height / 2, Math.max(this.minDimension / 2 - (30 + this.margin) * PXSCALE, 2 * PXSCALE), 0, Math.PI * 2)
this.ctx.fill()
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 - (10 + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
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 - (10 + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.save()
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.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.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.arc(this.width / 2 + this.minDimension / 2 - (10 + this.margin) * PXSCALE, this.height / 2, 4 * PXSCALE, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.fillStyle = this.colors.knob
this.ctx.arc(this.width / 2 + this.minDimension / 2 - (10 + this.margin) * 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 - (10 + this.margin) * PXSCALE, this.height / 2, 10 * 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 - (10 + this.margin) * PXSCALE, this.height / 2, 10 * PXSCALE, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.restore()
}
this.ctx.restore()
}
}
module.exports.create = function(widgetData) {
var knob = new Knob(widgetData)
return knob
}

View file

@ -33,7 +33,7 @@
if (!self.visible || checkColors) {
self.color = getComputedStyle(canvas[0]).getPropertyValue("--color-text")
self.fontSize = parseInt(getComputedStyle(canvas[0]).getPropertyValue("font-size"))
self.fontSize = parseFloat(getComputedStyle(canvas[0]).getPropertyValue("font-size"))
}
self.val(self.value)
@ -47,7 +47,7 @@
if (!self.height || !self.width || (self.height==100 && self.width==100)) return
ctx.clearRect(0,0,self.width,self.height)
ctx.font = PXSCALE * 2 * self.fontSize + 'px Droid Sans'
ctx.font = 2 * self.fontSize + 'px Droid Sans'
ctx.textBaseline = "middle"
ctx.fillStyle = self.color