widgets: WIP: options inheritance feature

This commit is contained in:
jean-emmanuel 2017-05-30 00:12:42 +02:00
parent 3d77de67cd
commit 79e5ad5a32
33 changed files with 382 additions and 333 deletions

View file

@ -46,11 +46,11 @@ var WidgetManager = function(){
ipc.send('addWidget', {
hash:hash,
data:{
precision: this.widgets[hash].widgetData.precision,
preArgs: this.widgets[hash].widgetData.preArgs,
precision: this.widgets[hash].getOption('precision'),
preArgs: this.widgets[hash].getOption('preArgs'),
split: this.widgets[hash].split,
target: this.widgets[hash].widgetData.target,
address: this.widgets[hash].widgetData.address,
target: this.widgets[hash].getOption('target'),
address: this.widgets[hash].getOption('address'),
}
})
}
@ -62,9 +62,9 @@ var WidgetManager = function(){
WidgetManager.prototype.createAddressRef = function(widget) {
return widget.widgetData.preArgs && widget.widgetData.preArgs.length ?
widget.widgetData.address + this.preArgsSeparator + widget.widgetData.preArgs.join(this.preArgsSeparator)
: widget.widgetData.address
return widget.getOption('preArgs') && widget.getOption('preArgs').length ?
widget.getOption('address') + this.preArgsSeparator + widget.getOption('preArgs').join(this.preArgsSeparator)
: widget.getOption('address')
}
@ -72,8 +72,8 @@ WidgetManager.prototype.addWidget = function(widget) {
var hash = widget.hash,
address = this.createAddressRef(widget),
id = widget.widgetData.id,
linkId = widget.widgetData.linkId
id = widget.getOption('id'),
linkId = widget.getOption('linkId')
this.widgets[hash] = widget
@ -97,11 +97,11 @@ WidgetManager.prototype.addWidget = function(widget) {
ipc.send('addWidget', {
hash:hash,
data:{
precision: widget.widgetData.precision,
preArgs: widget.widgetData.preArgs,
precision: widget.getOption('precision'),
preArgs: widget.getOption('preArgs'),
split: widget.split,
target: widget.widgetData.target,
address: widget.widgetData.address,
target: widget.getOption('target'),
address: widget.getOption('address'),
}
})
@ -111,8 +111,8 @@ WidgetManager.prototype.removeWidget = function(hash) {
var widget = this.widgets[hash],
address = this.createAddressRef(widget),
linkId = widget.widgetData.linkId,
id = widget.widgetData.id
linkId = widget.getOption('linkId'),
id = widget.getOption('id')
if (this.widgets[hash]) {
if (this.widgets[hash].onRemove) this.widgets[hash].onRemove()

View file

@ -154,33 +154,61 @@ module.exports.widgets = function(data,parent) {
widgetData.precision = Math.min(20,Math.max(widgetData.precision,0))
}
// create container
var widgetContainer = $(`
<div class="widget ${widgetData.type}-container">
<div class="label"><span></span></div>
</div>
`)
// create widget
var widgetInner = createWidget[widgetData.type](widgetData,widgetContainer)
widgetContainer[0].appendChild(widgetInner.widget[0])
widgetManager.addWidget(widgetInner)
// dimensions / coordinates can't be < 0
for (let t in {width:'',height:'',top:'',left:''}) {
widgetData[t] = `${widgetData[t]}`.indexOf('-')!=-1?0:widgetData[t]
}
// convert dimensions / coordinates to rem
var width = parseFloat(widgetData.width)==widgetData.width?parseFloat(widgetData.width)+'rem' : widgetData.width,
height = parseFloat(widgetData.height)==widgetData.height?parseFloat(widgetData.height)+'rem' : widgetData.height,
left = parseFloat(widgetData.left)==widgetData.left?parseFloat(widgetData.left)+'rem' : widgetData.left,
top = parseFloat(widgetData.top)==widgetData.top?parseFloat(widgetData.top)+'rem' : widgetData.top
var width = parseFloat(widgetInner.getOption('width'))==widgetInner.getOption('width')?parseFloat(widgetInner.getOption('width'))+'rem' : widgetInner.getOption('width'),
height = parseFloat(widgetInner.getOption('height'))==widgetInner.getOption('height')?parseFloat(widgetInner.getOption('height'))+'rem' : widgetInner.getOption('height'),
left = parseFloat(widgetInner.getOption('left'))==widgetInner.getOption('left')?parseFloat(widgetInner.getOption('left'))+'rem' : widgetInner.getOption('left'),
top = parseFloat(widgetInner.getOption('top'))==widgetInner.getOption('top')?parseFloat(widgetInner.getOption('top'))+'rem' : widgetInner.getOption('top')
var geometry = {}
for (var d of ['width', 'height', 'left', 'top']){
if (widgetData[d])
geometry[d] = `${widgetData[d]}`.indexOf('-') != -1 ? 0 :
parseFloat(widgetData[d]) == widgetData[d] ?
parseFloat(widgetData[d])+'rem' : widgetData[d]
}
// dimensions / coordinates css
var styleW = widgetData.width&&widgetData.width!='auto'?`width:${width};min-width:auto;`:'',
styleH = widgetData.height&&widgetData.height!='auto'?`height:${height};min-height:auto;`:'',
styleL = widgetData.left&&widgetData.left!='auto'||widgetData.left==0?`left:${left};`:'',
styleT = widgetData.top&&widgetData.top!='auto'||widgetData.top==0?`top:${top};`:''
var styleW = widgetInner.getOption('width') && widgetInner.getOption('width') != 'auto' ? `width: ${geometry.width}; min-width:auto;` : '',
styleH = widgetInner.getOption('height') && widgetInner.getOption('height') != 'auto' ? `height: ${geometry.height}; min-height:auto;` : '',
styleL = widgetInner.getOption('left') && widgetInner.getOption('left') != 'auto'|| widgetInner.getOption('left') == 0 ?`left: ${geometry.left};` : '',
styleT = widgetInner.getOption('top') && widgetInner.getOption('top') != 'auto'|| widgetInner.getOption('top') == 0 ? `top: ${geometry.top};` : ''
// Generate label, iconify if starting with "icon:"
var label = widgetData.label == 'auto'?
widgetData.id:
iconify(widgetData.label)
if (styleL.length || styleT.length) widgetContainer.addClass('absolute-position')
// Hide label if false
if (widgetInner.getOption('label')===false) {
widgetContainer.addClass('nolabel')
} else {
// Generate label, iconify if starting with "icon:"
var label = widgetInner.getOption('label') == 'auto'?
widgetInner.getOption('id'):
iconify(widgetInner.getOption('label'))
widgetContainer.find('> .label span').html(label)
}
// parse scoped css
var css = ';' + widgetData.css,
var css = ';' + widgetInner.getOption('css'),
scopedCss = ''
css = css.replace(/[;\}\s]*([^;\{]*\{[^\}]*\})/g, (m)=>{
@ -193,25 +221,8 @@ module.exports.widgets = function(data,parent) {
return ''
})
// create container
var widgetContainer = $(`
<div class="widget ${widgetData.type}-container ${styleL.length || styleT.length?'absolute-position':''}" style="${styleW + styleH + styleL + styleT + css}">
<div class="label"><span>${label}</span></div>
</div>
`)
// Set custom css color variable
if (widgetData.color && widgetData.color!='auto') widgetContainer[0].style.setProperty('--color-custom',widgetData.color)
// Hide label if false
if (widgetData.label===false) widgetContainer.addClass('nolabel')
// create widget
var widgetInner = createWidget[widgetData.type](widgetData,widgetContainer)
widgetContainer[0].appendChild(widgetInner.widget[0])
widgetManager.addWidget(widgetInner)
// apply styles
widgetContainer[0].setAttribute('style', styleW + styleH + styleL + styleT + css)
// apply scoped css
if (scopedCss.length) {
@ -220,9 +231,12 @@ module.exports.widgets = function(data,parent) {
widgetContainer.prepend(`<style>${scopedCss}</style>`)
}
// Set custom css color variable
if (widgetInner.getOption('color') && widgetInner.getOption('color')!='auto') widgetContainer[0].style.setProperty('--color-custom',widgetInner.getOption('color'))
// set widget's initial state
if (widgetData.value !== '' && widgetInner.setValue) {
widgetInner.setValue(widgetData.value)
if (widgetInner.getOption('value') !== '' && widgetInner.setValue) {
widgetInner.setValue(widgetInner.getOption('value'))
}
// Append the widget to its parent

View file

@ -51,24 +51,24 @@ module.exports = class Push extends _widgets_base {
this.fakeclick()
})
this.value = widgetData.off
this.value = this.getOption('off')
}
updateValue(){
this.value = this[this.lastChanged] ?
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
this.getOption('on') != null && this.getOption('on').value !== undefined ? this.getOption('on').value : this.getOption('on')
:
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
this.getOption('off') != null && this.getOption('off').value !== undefined ? this.getOption('off').value : this.getOption('off')
}
fakeclick(){
if (!this.active) this.setValuePrivate(this.widgetData.on,{send:true,sync:true})
if (!this.active) this.setValuePrivate(this.getOption('on'),{send:true,sync:true})
this.widget.on('dragend.push',()=>{
this.setValuePrivate(this.widgetData.off,{send:true,sync:true})
this.setValuePrivate(this.getOption('off'),{send:true,sync:true})
this.widget.off('dragend.push')
this.widget.on('draginit.push',()=>{
this.widget.off('draginit.push')
@ -81,20 +81,20 @@ module.exports = class Push extends _widgets_base {
setValuePrivate(v,options={}) {
if (typeof v == 'object' && v !== null) v = v.value
if (v===this.widgetData.on || (this.widgetData.on != null && v === this.widgetData.on.value && v !== undefined)) {
if (v===this.getOption('on') || (this.getOption('on') != null && v === this.getOption('on').value && v !== undefined)) {
this.widget.addClass('active')
this.active = 1
this.lastChanged = 'active'
this.updateValue()
if (options.send) this.sendValue(v)
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 === this.widgetData.off.value && v !== undefined)) {
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
} else if (v===this.getOption('off') || (this.getOption('off') != null && v === this.getOption('off').value && v !== undefined)) {
this.widget.removeClass('active')
this.active = 0
this.lastChanged = 'active'
this.updateValue()
if (options.send) this.sendValue(v, this.widgetData.norelease)
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, this.getOption('norelease'))
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
}
}
@ -106,18 +106,18 @@ module.exports = class Push extends _widgets_base {
return
}
if (typeof v == 'object' && v !== null) v = v.value
if (v===this.widgetData.on || (this.widgetData.on != null && v === this.widgetData.on.value && v !== undefined)) {
if (v===this.getOption('on') || (this.getOption('on') != null && v === this.getOption('on').value && v !== 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 === this.widgetData.off.value && v !== undefined)) {
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'),options:options})
} else if (v===this.getOption('off') || (this.getOption('off') != null && v === this.getOption('off').value && v !== 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})
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'),options:options})
}
}

View file

@ -37,16 +37,18 @@ module.exports = class Switch extends _widgets_base {
constructor(widgetData) {
var widgetHtml = `
<div class="switch ${widgetData.horizontal?'horizontal':''}"></div>
<div class="switch"></div>
`
super(...arguments, widgetHtml)
if (this.getOption('horizontal')) this.widget.addClass('horizontal')
this.values = []
for (var k in widgetData.values) {
this.values.push(widgetData.values[k])
$(`<div class="value">${iconify(parseFloat(k) != k ? k : widgetData.values[k])}</div>`).data({value:widgetData.values[k]}).appendTo(this.widget)
for (var k in this.getOption('values')) {
this.values.push(this.getOption('values')[k])
$(`<div class="value">${iconify(parseFloat(k) != k ? k : this.getOption("values")[k])}</div>`).data({value:this.getOption('values')[k]}).appendTo(this.widget)
}
this.value = undefined
@ -76,11 +78,11 @@ module.exports = class Switch extends _widgets_base {
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})
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options})
} else {
this.widget.find('.on').removeClass('on')
this.value = undefined
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options})
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options})
}
}}

View file

@ -50,13 +50,13 @@ module.exports = class Toggle extends _widgets_base {
})
this.value = widgetData.off
this.value = this.getOption('off')
}
fakeclick() {
var newVal = this.widget.state?this.widgetData.off:this.widgetData.on
var newVal = this.widget.state?this.getOption('off'):this.getOption('on')
this.setValue(newVal,{sync:true,send:true})
this.widget.on('dragend.toggle',()=>{
this.widget.off('dragend.toggle')
@ -71,19 +71,19 @@ module.exports = class Toggle extends _widgets_base {
setValue(v,options={}) {
if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) {
if (v===this.getOption('on') || (this.getOption('on') != null && v.value === this.getOption('on').value && v.value !== undefined)) {
this.widget.addClass('on')
this.widget.state = 1
this.value = this.widgetData.on
this.value = this.getOption('on')
if (options.send) this.sendValue()
} else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) {
} else if (v===this.getOption('off') || (this.getOption('off') != null && v.value === this.getOption('off').value && v.value !== undefined)) {
this.widget.removeClass('on')
this.widget.state = 0
this.value = this.widgetData.off
this.value = this.getOption('off')
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})
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options})
}

View file

@ -1,5 +1,6 @@
var osc = require('../../osc'),
shortid = require('shortid')
shortid = require('shortid'),
{widgetManager} = require('../../managers')
module.exports = class _widgets_base {
@ -67,4 +68,29 @@ module.exports = class _widgets_base {
}
getOption(key) {
var opt = this.widgetData[key]
if (typeof opt == 'string' && opt.indexOf('@{') != -1) {
opt = opt.replace(/@\{([^\}]+)\}/g, (m)=>{
let id = m.substr(2, m.length - 3).split('.'),
k = id.pop()
id = id.join('.')
var widgets = widgetManager.getWidgetById(id)
for (var i in widgets) {
if (widgets[i].widgetData.hasOwnProperty(k)) {
return widgets[i].widgetData[k]
}
}
})
}
return opt
}
}

View file

@ -39,37 +39,38 @@ module.exports = class Panel extends _widgets_base {
var widgetHtml = `
<div class="panel
${!widgetData.scroll?'noscroll':''}
${widgetData.tabs.length?'has-tabs':''}
">
<div class="panel">
</div>
`
super(...arguments, widgetHtml)
var parsers = require('../../parser'),
if (!this.getOption('scroll')) this.widget.addClass('noscroll')
if (this.getOption('tabs').length) this.widget.addClass('has-tabs')
var parsers = require('../../parser'),
parsewidgets = parsers.widgets,
parsetabs = parsers.tabs
if (widgetData.tabs.length) {
parsetabs(widgetData.tabs,this.widget)
if (this.getOption('tabs').length) {
parsetabs(this.getOption('tabs'),this.widget)
} else {
parsewidgets(widgetData.widgets,this.widget)
parsewidgets(this.getOption('widgets'),this.widget)
}
this.children = this.widget.find('> .widget')
if (widgetData.layout != '') {
if (this.getOption('layout') != '') {
try {
var layout = widgetData.layout.replace(/\$([0-9])+/g, (m)=>{
return this.children[m.replace('$','')].abstract.widgetData.id
var layout = this.getOption('layout').replace(/\$([0-9])+/g, (m)=>{
return this.children[m.replace('$','')].abstract.this.getOption('id')
})
this.layout = new autolayout.View({
constraints: autolayout.VisualFormat.parse(layout.split('\\n').join('\n').split(' ').join(''), {extended: true}),
spacing: widgetData.spacing
spacing: this.getOption('spacing')
});
this.widget.on('resize',(e, w, h)=>{
@ -82,14 +83,14 @@ module.exports = class Panel extends _widgets_base {
})
} catch(err) {
throw `Visual Format Language error in ${widgetData.id}.layout: ${err.message} (line ${err.line})`
throw `Visual Format Language error in ${this.getOption('id')}.layout: ${err.message} (line ${err.line})`
}
}
}
applyLayout(){
this.widget.find('> .widget').each((i,widget)=>{
var id = widget.abstract.widgetData.id
var id = widget.abstract.this.getOption('id')
if (!this.layout.subViews[id]) return
var $widget = $(widget).addClass('absolute-position').css({'min-height':'auto','min-width':'auto'})
for (var prop of ['height', 'width', 'top', 'left']) {

View file

@ -36,13 +36,13 @@ module.exports = class Strip extends _widgets_base {
var parsewidgets = require('../../parser').widgets
if (widgetData.horizontal) {
if (this.getOption('horizontal')) {
container.addClass('horizontal')
} else {
container.addClass('vertical')
}
parsewidgets(widgetData.widgets,this.widget)
parsewidgets(this.getOption('widgets'),this.widget)
}

View file

@ -48,31 +48,31 @@ module.exports = class Formula extends _widgets_base {
super(...arguments, widgetHtml)
widgetData.formula = String(widgetData.formula)
widgetData.condition = String(widgetData.condition)
this.formula = String(this.getOption('formula'))
this.condition = String(this.getOption('condition'))
this.split = typeof widgetData.split == 'object' && widgetData.split.length ? widgetData.split : false
this.split = typeof this.getOption('split') == 'object' && this.getOption('split').length ? this.getOption('split') : false
this.input = this.widget.find('.input').fakeInput({align:'center', disabled:true})
this.linkedWidgets = []
if (widgetData.formula.length) {
if (this.formula.length) {
if (widgetData.formula.match(/\$\{([^\}]*)\}/g) != null) this.linkedWidgets = this.linkedWidgets.concat(widgetData.formula.match(/\$\{([^\}]*)\}/g).map((a)=>{return a.substr(2, a.length - 3)}))
if (this.formula.match(/\$\{([^\}]*)\}/g) != null) this.linkedWidgets = this.linkedWidgets.concat(this.formula.match(/\$\{([^\}]*)\}/g).map((a)=>{return a.substr(2, a.length - 3)}))
}
if (widgetData.condition.length) {
if (this.condition.length) {
if (widgetData.condition.match(/\$\{([^\}]*)\}/g) != null) this.linkedWidgets = this.linkedWidgets.concat(widgetData.condition.match(/\$\{([^\}]*)\}/g).map((a)=>{return a.substr(2, a.length - 3)}))
if (this.condition.match(/\$\{([^\}]*)\}/g) != null) this.linkedWidgets = this.linkedWidgets.concat(this.condition.match(/\$\{([^\}]*)\}/g).map((a)=>{return a.substr(2, a.length - 3)}))
}
this.formula = math.compile(widgetData.formula.replace(/\$\{([^\}]*)\}/g, '_$1'))
this.formula = math.compile(this.formula.replace(/\$\{([^\}]*)\}/g, '_$1'))
this.condition = math.compile(widgetData.condition.replace(/\$\{([^\}]*)\}/g, '_$1'))
this.condition = math.compile(this.condition.replace(/\$\{([^\}]*)\}/g, '_$1'))
this.conditionState = true
@ -107,7 +107,7 @@ module.exports = class Formula extends _widgets_base {
}
}
if (this.widgetData.condition.length) {
if (this.getOption('condition').length) {
try {
@ -131,7 +131,7 @@ module.exports = class Formula extends _widgets_base {
this.showValue()
if (e.options.sync && this.conditionState) this.widget.trigger({type: 'sync',id: this.widgetData.id,widget: this.widget, linkId: this.widgetData.linkId, options: e.options})
if (e.options.sync && this.conditionState) this.widget.trigger({type: 'sync',id: this.getOption('id'),widget: this.widget, linkId: this.getOption('linkId'), options: e.options})
if (e.options.send && this.conditionState) this.sendValue()
} catch(err) {
@ -163,8 +163,8 @@ module.exports = class Formula extends _widgets_base {
showValue() {
this.input.val(
(this.widgetData.condition.length && !this.conditionState ? '* ' : '') +
JSON.stringify(Formula.deepCopyWithPrecision(this.value, this.widgetData.precision))
(this.getOption('condition').length && !this.conditionState ? '* ' : '') +
JSON.stringify(Formula.deepCopyWithPrecision(this.value, this.getOption('precision')))
)
}

View file

@ -13,13 +13,13 @@ module.exports = class _matrices_base extends _widgets_base {
this.value = []
widgetData.start = parseInt(widgetData.start)
this.start = parseInt(this.getOption('start'))
this.widget.on('sync',(e)=>{
if (e.id==widgetData.id) return
if (e.id==this.getOption('id')) return
this.value[e.widget.parent().index()] = e.widget.abstract.getValue()
this.widget.trigger({type:'sync',id:widgetData.id,widget:this.widget,options:e.options})
this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget,options:e.options})
})

View file

@ -44,26 +44,26 @@ module.exports = class Keyboard extends _matrices_base {
super(...arguments)
widgetData.keys = parseInt(widgetData.keys)
this.keys = parseInt(this.getOption('keys'))
var strData = JSON.stringify(widgetData),
pattern = 'wbwbwwbwbwbw',
wCount = 0
pattern = 'wbwbwwbwbwbw',
wCount = 0
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.keys+widgetData.start&&i<108;i++) {
for (var i = this.start; i < this.keys + this.start && i < 108; i++) {
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'push'
data.id = widgetData.id + '/' + i
data.id = this.getOption('id') + '/' + i
data.label = false
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [].concat(widgetData.preArgs, i)
data.address = this.getOption('split') ? this.getOption('address') + '/' + i : this.getOption('address')
data.preArgs = this.getOption('split') ? this.getOption('preArgs') : [].concat(this.getOption('preArgs'), i)
data.css = ''
var element = parsewidgets([data],this.widget)
@ -77,7 +77,7 @@ module.exports = class Keyboard extends _matrices_base {
}
this.value[i-widgetData.start] = widgetData.off
this.value[i-this.start] = this.getOption('off')
}
@ -90,7 +90,7 @@ module.exports = class Keyboard extends _matrices_base {
})
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (this.getOption('traversing')) this.widget.enableTraversingGestures()
}

View file

@ -53,9 +53,9 @@ module.exports = class Multifader extends _matrices_base {
super(...arguments)
widgetData.strips = parseInt(widgetData.strips)
this.strips = parseInt(this.getOption('strips'))
if (widgetData.horizontal) {
if (this.getOption('horizontal')) {
this.widget.addClass('horizontal')
}
@ -64,30 +64,30 @@ module.exports = class Multifader extends _matrices_base {
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start; i<widgetData.strips+widgetData.start;i++) {
for (var i = this.start; i < this.strips + this.start; i++) {
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'fader'
data.id = widgetData.id + '/' + i
data.id = this.getOption('id') + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [].concat(widgetData.preArgs, i)
data.color = typeof widgetData.color == 'object' ? '' + widgetData.color[i % widgetData.color.length] : widgetData.color
data.address = this.getOption('split') ? this.getOption('address') + '/' + i : this.getOption('address')
data.preArgs = this.getOption('split') ? this.getOption('preArgs') : [].concat(this.getOption('preArgs'), i)
data.color = typeof this.getOption('color') == 'object' ? '' + this.getOption('color')[i % this.getOption('color').length] : this.getOption('color')
data.css = ''
var element = parsewidgets([data],this.widget)
element[0].style.setProperty(widgetData.horizontal?'height':'width', 100/widgetData.strips + '%')
element[0].style.setProperty(this.getOption('horizontal')?'height':'width', 100/this.strips + '%')
element[0].classList.add('not-editable')
if (widgetData.traversing) element.find('canvas').off('drag')
if (this.getOption('traversing')) element.find('canvas').off('drag')
this.value[i-widgetData.start] = widgetData.range.min
this.value[i-this.start] = this.getOption('range').min
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (this.getOption('traversing')) this.widget.enableTraversingGestures()
}

View file

@ -48,31 +48,31 @@ module.exports = class Multipush extends _matrices_base {
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
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 = this.start; i < this.getOption('matrix')[0] * this.getOption('matrix')[1] + this.start; i++) {
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'push'
data.id = widgetData.id + '/' + i
data.id = this.getOption('id') + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [].concat(widgetData.preArgs, i)
data.color = typeof widgetData.color == 'object' ? '' + widgetData.color[i % widgetData.color.length] : widgetData.color
data.address = this.getOption('split') ? this.getOption('address') + '/' + i : this.getOption('address')
data.preArgs = this.getOption('split') ? this.getOption('preArgs') : [].concat(this.getOption('preArgs'), i)
data.color = typeof this.getOption('color') == 'object' ? '' + this.getOption('color')[i % this.getOption('color').length] : this.getOption('color')
data.css = ''
var element = parsewidgets([data],this.widget)
element[0].style.setProperty('width', 100/widgetData.matrix[0] + '%')
element[0].style.setProperty('width', 100/this.getOption('matrix')[0] + '%')
element[0].classList.add('not-editable')
this.value[i-widgetData.start] = widgetData.off
this.value[i-this.start] = this.getOption('off')
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (this.getOption('traversing')) this.widget.enableTraversingGestures()
}

View file

@ -47,31 +47,31 @@ module.exports = class Multitoggle extends _matrices_base {
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
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 = this.start; i < this.getOption('matrix')[0] * this.getOption('matrix')[1] + this.start; i++) {
var data = JSON.parse(strData)
data.top = data.left = data.height = data.width = 'auto'
data.type = 'toggle'
data.id = widgetData.id + '/' + i
data.id = this.getOption('id') + '/' + i
data.label = i
data.address = widgetData.split ? widgetData.address + '/' + i : widgetData.address
data.preArgs = widgetData.split ? widgetData.preArgs : [].concat(widgetData.preArgs, i)
data.color = typeof widgetData.color == 'object' ? '' + widgetData.color[i % widgetData.color.length] : widgetData.color
data.address = this.getOption('split') ? this.getOption('address') + '/' + i : this.getOption('address')
data.preArgs = this.getOption('split') ? this.getOption('preArgs') : [].concat(this.getOption('preArgs'), i)
data.color = typeof this.getOption('color') == 'object' ? '' + this.getOption('color')[i % this.getOption('color').length] : this.getOption('color')
data.css = ''
var element = parsewidgets([data],this.widget)
element[0].style.setProperty('width', 100/widgetData.matrix[0] + '%')
element[0].style.setProperty('width', 100/this.getOption('matrix')[0] + '%')
element[0].classList.add('not-editable')
this.value[i-widgetData.start] = widgetData.off
this.value[i-this.start] = this.getOption('off')
}
if (widgetData.traversing) this.widget.enableTraversingGestures()
if (this.getOption('traversing')) this.widget.enableTraversingGestures()
}

View file

@ -17,7 +17,7 @@ module.exports = class _pads_base extends _canvas_base {
this.wrapper = this.widget.find('.wrapper')
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length)
if (this.getOption('touchAddress') && this.getOption('touchAddress').length)
osctouchstate(this, this.wrapper)
}

View file

@ -49,21 +49,21 @@ module.exports = class MultiXy extends _pads_base {
super(...arguments)
this.npoints = typeof widgetData.points == 'object' ? widgetData.points.length : widgetData.points
this.labels = typeof widgetData.points == 'object'
this.pointSize = parseInt(widgetData.pointSize)
this.npoints = typeof this.getOption('points') == 'object' ? this.getOption('points').length : this.getOption('points')
this.labels = typeof this.getOption('points') == 'object'
this.pointSize = parseInt(this.getOption('pointSize'))
this.widget[0].style.setProperty("--point-size",this.pointSize + 'rem')
this.split = widgetData.split?
typeof widgetData.split == 'object' && widgetData.split.length == 2 * this.npoints ?
widgetData.split
this.split = this.getOption('split')?
typeof this.getOption('split') == 'object' && this.getOption('split').length == 2 * this.npoints ?
this.getOption('split')
: (()=>{
var s={},
t
for (var i=0; i<this.npoints * 2;i=i+2) {
t = this.labels ? widgetData.points[i/2] : i/2
s[i]=widgetData.address + '/' + t + '/x'
s[i+1]=widgetData.address + '/' + t + '/y'
t = this.labels ? this.getOption('points')[i/2] : i/2
s[i]=this.getOption('address') + '/' + t + '/x'
s[i+1]=this.getOption('address') + '/' + t + '/y'
};
return s
})()
@ -77,14 +77,14 @@ module.exports = class MultiXy extends _pads_base {
for (var i=this.npoints-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
snap:this.getOption('snap'),
spring:this.getOption('spring'),
value:this.getOption('value').length == this.getOption('points') * 2 ? [this.getOption('value')[i*2], this.getOption('value')[i*2 + 1]] : '',
rangeX:this.getOption('rangeX'),
rangeY:this.getOption('rangeY'),
precision:this.getOption('precision'),
logScaleX:this.getOption('logScaleX'),
logScaleY:this.getOption('logScaleY')
}, false)
this.pads[i].sendValue = ()=>{}
this.pads[i].draw = ()=>{}
@ -185,7 +185,7 @@ module.exports = class MultiXy extends _pads_base {
for (var i=0;i<this.npoints;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,
t = this.labels ? this.widgetData.points[i] : i
t = this.labels ? this.getOption('points')[i] : i
this.ctx.strokeStyle = this.colors.custom
this.ctx.fillStyle = this.colors.custom
@ -243,7 +243,7 @@ module.exports = class MultiXy extends _pads_base {
}
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})
if (options.sync) this.widget.trigger({type:'sync', id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
}

View file

@ -42,10 +42,10 @@ module.exports = class Rgb extends _pads_base {
super(...arguments)
this.split = widgetData.split?
typeof widgetData.split == 'object' && widgetData.split.length == 3 ?
widgetData.split
: [widgetData.address + '/r', widgetData.address + '/g', widgetData.address + '/b']
this.split = this.getOption('split')?
typeof this.getOption('split') == 'object' && this.getOption('split').length == 3 ?
this.getOption('split')
: [this.getOption('address') + '/r', this.getOption('address') + '/g', this.getOption('address') + '/b']
: false
this.widget.append(`
@ -70,7 +70,7 @@ module.exports = class Rgb extends _pads_base {
compact:false,
noPip:true,
horizontal:true,
snap:widgetData.snap,
snap:this.getOption('snap'),
range:{min:0,max:360},
precision:2
}, false),
@ -78,7 +78,7 @@ module.exports = class Rgb extends _pads_base {
id:'s',
compact:true,
horizontal:true,
snap:widgetData.snap,
snap:this.getOption('snap'),
range:{min:0,max:100},
precision:2
@ -87,7 +87,7 @@ module.exports = class Rgb extends _pads_base {
id:'b',
compact:true,
horizontal:false,
snap:widgetData.snap,
snap:this.getOption('snap'),
range:{min:0,max:100},
precision:2
}, true)
@ -180,7 +180,7 @@ module.exports = class Rgb extends _pads_base {
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})
if (options.sync) this.widget.trigger({type:'sync', id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
this.update({dragged:options.dragged, nohue:options.nohue || (v[0]==v[1]&&v[1]==v[2])})
@ -196,7 +196,7 @@ module.exports = class Rgb extends _pads_base {
}
for (let i in this.inputs) [
this.inputs[i].val(this.value[i].toFixed(this.widgetData.precision))
this.inputs[i].val(this.value[i].toFixed(this.getOption('precision')))
]
this.draw()

View file

@ -47,10 +47,10 @@ module.exports = class Xy extends _pads_base {
super(...arguments)
this.split = widgetData.split?
typeof widgetData.split == 'object' && widgetData.split.length == 2 ?
widgetData.split
: [widgetData.address + '/x', widgetData.address + '/y']
this.split = this.getOption('split')?
typeof this.getOption('split') == 'object' && this.getOption('split').length == 2 ?
this.getOption('split')
: [this.getOption('address') + '/x', this.getOption('address') + '/y']
: false
this.widget.append(`
@ -71,12 +71,12 @@ module.exports = class Xy extends _pads_base {
horizontal:true,
height:'100%',
width:'100%',
value:widgetData.value.length==2?widgetData.value[0]:'',
snap:widgetData.snap,
range:widgetData.rangeX,
value:this.getOption('value').length==2?this.getOption('value')[0]:'',
snap:this.getOption('snap'),
range:this.getOption('rangeX'),
origin:'auto',
precision:widgetData.precision,
logScale:widgetData.logScaleX
precision:this.getOption('precision'),
logScale:this.getOption('logScaleX')
}, true),
y: new Fader({
id:1,
@ -84,12 +84,12 @@ module.exports = class Xy extends _pads_base {
horizontal:false,
height:'100%',
width:'100%',
value:widgetData.value.length==2?widgetData.value[1]:'',
snap:widgetData.snap,
range:widgetData.rangeY,
value:this.getOption('value').length==2?this.getOption('value')[1]:'',
snap:this.getOption('snap'),
range:this.getOption('rangeY'),
origin:'auto',
precision:widgetData.precision,
logScale:widgetData.logScaleY
precision:this.getOption('precision'),
logScale:this.getOption('logScaleY')
}, true)
}
@ -119,7 +119,7 @@ module.exports = class Xy extends _pads_base {
this.dragHandle()
})
if (widgetData.spring) {
if (this.getOption('spring')) {
this.wrapper.on('dragend', ()=>{
this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true,fromLocal:true})
})
@ -164,7 +164,7 @@ module.exports = class Xy extends _pads_base {
]
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})
if (options.sync) this.widget.trigger({type:'sync', id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
this.draw()

View file

@ -16,8 +16,8 @@ module.exports = class _plots_base extends _canvas_base {
this.data = []
this.linkedWidgets = []
this.rangeX = widgetData.rangeX || {min:0,max:1}
this.rangeY = widgetData.rangeY || {min:0,max:1}
this.rangeX = this.getOption('rangeX') || {min:0,max:1}
this.rangeY = this.getOption('rangeY') || {min:0,max:1}
this.pips = {
x : {
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
@ -75,9 +75,9 @@ module.exports = class _plots_base extends _canvas_base {
if (this.widgetData.origin !== false) {
if (this.getOption('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)
var origin = mapToScale(this.getOption('origin') || this.rangeY.min,[this.rangeY.min,this.rangeY.max],[this.height,0],0,this.getOption('logScaleY'),true)
this.ctx.globalAlpha = 0.1
this.ctx.fillStyle = this.colors.custom
@ -132,13 +132,13 @@ module.exports = class _plots_base extends _canvas_base {
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(this.data[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.getOption('logScaleX'),true),
mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.getOption('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),
mapToScale(i,[0,this.data.length-1],[0,this.width],0,this.getOption('logScaleX'),true),
mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.getOption('logScaleY'),true),
]

View file

@ -46,13 +46,13 @@ module.exports = class Eq extends _plots_base {
this.pips.x.min = '20'
this.pips.x.max = '22k'
widgetData.resolution = clip(widgetData.resolution,[64,1024])
this.resolution = clip(this.getOption('resolution'),[64,1024])
for (let i in widgetData.filters) {
for (let i in this.getOption('filters')) {
for (let 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/))) {
this.linkedWidgets.push(widgetData.filters[i][j])
for (let j in this.getOption('filters')[i]) {
if (typeof this.getOption('filters')[i][j]=='string' && !(j=='type' && this.getOption('filters')[i][j].match(/peak|notch|highpass|highshelf|lowpass|lowshelf/))) {
this.linkedWidgets.push(this.getOption('filters')[i][j])
}
}
@ -66,8 +66,8 @@ module.exports = class Eq extends _plots_base {
eqResponse = []
for (let i in this.widgetData.filters) {
var filter = this.widgetData.filters[i]
for (let i in this.getOption('filters')) {
var filter = this.getOption('filters')[i]
filters[i] = {}
@ -95,9 +95,9 @@ module.exports = class Eq extends _plots_base {
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)
filterResponse = _biquad_response({type:"peak",freq:1,gain:0,q:1},!this.getOption('logScaleX'), this.resolution)
} else {
filterResponse = _biquad_response(filters[i],!this.widgetData.logScaleX,this.widgetData.resolution)
filterResponse = _biquad_response(filters[i],!this.getOption('logScaleX'), this.resolution)
}
for (var k in filterResponse) {

View file

@ -23,7 +23,7 @@ module.exports = class Led extends _widgets_base {
_plot:'plot',
widgetId:'',
_osc:'osc',
range:{min:0,max:1},
@ -48,9 +48,9 @@ module.exports = class Led extends _widgets_base {
this.led = this.widget.find('span')
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
if (this.getOption('widgetId').length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
this.setValue(widgetData.range.min)
this.setValue(this.getOption('range').min)
}
@ -62,7 +62,7 @@ module.exports = class Led extends _widgets_base {
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
if (this.getOption('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
var widget = widgetManager.getWidgetById(e.id),
value
for (var i=widget.length-1; i>=0; i--) {
@ -76,7 +76,7 @@ module.exports = class Led extends _widgets_base {
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))
this.led.css('opacity',mapToScale(v,[this.getOption('range').min,this.getOption('range').max],[0,1],false,this.getOption('logScale'),true))
}

View file

@ -52,7 +52,7 @@ module.exports = class Meter extends Fader {
this.canvas.off('draginit drag')
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
if (this.getOption('widgetId').length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
}
@ -65,7 +65,7 @@ module.exports = class Meter extends Fader {
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
if (this.getOption('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
var widget = widgetManager.getWidgetById(e.id),
value
for (var i=widget.length-1; i>=0; i--) {

View file

@ -42,16 +42,16 @@ module.exports = class Plot extends _plots_base {
super(...arguments)
if (typeof widgetData.points=='string') {
if (typeof this.getOption('points')=='string') {
this.linkedWidgets.push(widgetData.points)
this.linkedWidgets.push(this.getOption('points'))
} else if (typeof widgetData.points=='object') {
} else if (typeof this.getOption('points')=='object') {
for (let i in widgetData.points) {
for (let j in widgetData.points[i]) {
if (typeof widgetData.points[i][j] == 'string') {
this.linkedWidgets.push(widgetData.points[i][j])
for (let i in this.getOption('points')) {
for (let j in this.getOption('points')[i]) {
if (typeof this.getOption('points')[i][j] == 'string') {
this.linkedWidgets.push(this.getOption('points')[i][j])
}
}
}
@ -62,7 +62,7 @@ module.exports = class Plot extends _plots_base {
updateData() {
var data = [],
points = this.widgetData.points,
points = this.getOption('points'),
widget = widgetManager.getWidgetById(points)
if (typeof points=='string' && widget.length) {

View file

@ -46,7 +46,7 @@ module.exports = class Led extends _widgets_base {
this.led = this.widget.find('span')
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
if (this.getOption('widgetId').length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
this.setValue([0,0,0])
@ -60,9 +60,11 @@ module.exports = class Led extends _widgets_base {
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
if (this.getOption('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
var widget = widgetManager.getWidgetById(e.id),
value
for (var i=widget.length-1; i>=0; i--) {
if (widget[i].getValue) {
this.setValue(widget[i].getValue())

View file

@ -37,21 +37,23 @@ module.exports = class Text extends _widgets_base {
constructor(widgetData) {
var widgetHtml = `
<div class="text ${widgetData.vertical?'vertical':''}">
<div class="text">
</div>
`
super(...arguments, widgetHtml)
this.defaultValue = widgetData.label===false?
widgetData.id:
widgetData.label=='auto'?
widgetData.id:
widgetData.label
if (this.getOption('vertical')) this.widget.addClass('vertical')
this.defaultValue = this.getOption('label')===false?
this.getOption('id'):
this.getOption('label')=='auto'?
this.getOption('id'):
this.getOption('label')
this.value = this.defaultValue
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
if (this.getOption('widgetId').length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
this.setValue(this.value)
@ -65,7 +67,7 @@ module.exports = class Text extends _widgets_base {
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
if (this.getOption('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
var widget = widgetManager.getWidgetById(e.id),
value
for (var i=widget.length-1; i>=0; i--) {

View file

@ -41,12 +41,12 @@ module.exports = class Visualizer extends _plots_base {
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.y.min = Math.abs(this.getOption('range').min) >= 1000? this.getOption('range').min/1000+'k' : this.getOption('range').min
this.pips.y.max = Math.abs(this.getOption('range').max) >= 1000? this.getOption('range').max/1000+'k' : this.getOption('range').max
this.pips.x = false
this.length = Math.round(clip(60*widgetData.duration,[8,4096]))
this.length = Math.round(clip(60 * this.getOption('duration'), [8, 4096]))
this.data = new Array(this.length)
this.value = widgetData.range.min
this.value = this.getOption('range').min
this.cancel = false
this.loop = false
@ -54,7 +54,7 @@ module.exports = class Visualizer extends _plots_base {
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
if (this.getOption('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
this.startLoop()
}
@ -67,7 +67,7 @@ module.exports = class Visualizer extends _plots_base {
clearInterval(this.loop)
this.loop = false
this.cancel = false
},1000*this.widgetData.duration)
},1000*this.getOption('duration'))
if (this.loop) return
@ -76,7 +76,7 @@ module.exports = class Visualizer extends _plots_base {
this.updateData()
this.draw()
},1000*this.widgetData.duration/this.length)
},1000*this.getOption('duration') / this.length)
}
@ -89,13 +89,13 @@ module.exports = class Visualizer extends _plots_base {
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),
mapToScale(this.data[i],[this.getOption('range').min,this.getOption('range').max],[this.height-PXSCALE,PXSCALE],1,this.getOption('logScale'),true),
]
if (first) {
this.ctx.moveTo(newpoint[0],newpoint[1])
first = false
} else {
if (this.widgetData.logScale) {
if (this.getOption('logScale')) {
this.ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
} else {
this.ctx.lineTo(newpoint[0],newpoint[1])
@ -110,7 +110,7 @@ module.exports = class Visualizer extends _plots_base {
updateData() {
var id = this.widgetData.widgetId,
var id = this.getOption('widgetId'),
widget = widgetManager.getWidgetById(id)
if (typeof id == 'string' && widget.length) {

View file

@ -22,20 +22,20 @@ module.exports = class _sliders_base extends _canvas_base {
this.value = undefined
this.percent = 0
this.unit = widgetData.unit ? ' ' + widgetData.unit : ''
this.unit = this.getOption('unit') ? ' ' + this.getOption('unit') : ''
this.rangeKeys = []
this.rangeVals = []
this.rangeLabels = []
for (var k in widgetData.range) {
for (var k in this.getOption('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 = typeof this.getOption('range')[k] == 'object'?
this.getOption('range')[k][Object.keys(this.getOption('range')[k])[0]]:
this.getOption('range')[k],
label = typeof this.getOption('range')[k] == 'object'?
Object.keys(this.getOption('range')[k])[0]:
val
this.rangeKeys.push(key)
@ -45,10 +45,10 @@ module.exports = class _sliders_base extends _canvas_base {
this.rangeValsMax = Math.max(...this.rangeVals),
this.rangeValsMin = Math.min(...this.rangeVals)
this.originValue = widgetData.origin=='auto'?
this.originValue = this.getOption('origin')=='auto'?
this.rangeValsMin:
clip(widgetData.origin,[this.rangeValsMin,this.rangeValsMax])
this.springValue = widgetData.value != '' ? widgetData.value :  this.originValue
clip(this.getOption('origin'), [this.rangeValsMin,this.rangeValsMax])
this.springValue = this.getOption('value') != '' ? this.getOption('value') :  this.originValue
this.widget.on('fake-right-click',function(e){
if (!EDITING) {
@ -58,9 +58,9 @@ module.exports = class _sliders_base extends _canvas_base {
}
}.bind(this))
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length)
if (this.getOption('touchAddress') && this.getOption('touchAddress').length)
osctouchstate(this, this.canvas)
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
this.canvas.on('drag',this.dragHandleProxy.bind(this))
@ -110,7 +110,7 @@ module.exports = class _sliders_base extends _canvas_base {
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.getOption('precision') + 1)) * direction, [0,100])
this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true})
@ -126,7 +126,7 @@ module.exports = class _sliders_base extends _canvas_base {
dragendHandle(e, data, traversing) {
if (this.widgetData.spring)
if (this.getOption('spring'))
this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
}
@ -150,7 +150,7 @@ module.exports = class _sliders_base extends _canvas_base {
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)
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.getOption('logScale'))
}
}
@ -160,7 +160,7 @@ module.exports = class _sliders_base extends _canvas_base {
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)
return mapToScale(value,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.getOption('logScale'),true)
}
}
@ -172,7 +172,7 @@ module.exports = class _sliders_base extends _canvas_base {
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
if ((options.dragged || options.fromLocal) && this.value.toFixed(this.getOption('precision')) == value.toFixed(this.getOption('precision'))) options.send = false
this.value = value
@ -182,14 +182,14 @@ module.exports = class _sliders_base extends _canvas_base {
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.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
if (options.send) this.sendValue(v)
}
showValue() {
this.input.val(this.value.toFixed(this.widgetData.precision) + this.unit)
this.input.val(this.value.toFixed(this.getOption('precision')) + this.unit)
}

View file

@ -12,7 +12,7 @@ var EncoderKnob = class extends Knob {
this.lastOffsetX = data.offsetX
this.lastOffsetY = data.offsetY
if (!(traversing || this.widgetData.snap)) return
if (!(traversing || this.getOption('snap'))) return
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
@ -25,7 +25,7 @@ var DisplayKnob = class extends Knob {
draw(){
super.draw()
if (this.widgetData.compact) {
if (this.getOption('compact')) {
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.raised
this.ctx.strokeStyle = this.colors.raised
@ -89,7 +89,7 @@ module.exports = class Encoder extends _widgets_base {
`)
this.wrapper = this.widget.find('.wrapper')
this.ticks = Math.abs(parseInt(widgetData.ticks))
this.ticks = Math.abs(parseInt(this.getOption('ticks')))
this.knob = new EncoderKnob({
label:false,
@ -105,7 +105,7 @@ module.exports = class Encoder extends _widgets_base {
label:false,
angle:360,
range:{min:0,max:this.ticks},
compact:widgetData.compact,
compact:this.getOption('compact'),
origin:this.ticks/2,
noPip:true,
}, true)
@ -126,14 +126,14 @@ module.exports = class Encoder extends _widgets_base {
var direction
if (value < this.previousValue)
direction = widgetData.back
direction = this.getOption('back')
if (value > this.previousValue)
direction = widgetData.forth
direction = this.getOption('forth')
if ((this.ticks * .75 < value && value < this.ticks) && (0 < this.previousValue && this.previousValue < this.ticks / 4))
direction = widgetData.back
direction = this.getOption('back')
if ((0 < value && value < this.ticks / 4) && (this.ticks * .75 < this.previousValue && this.previousValue < this.ticks))
direction = widgetData.forth
direction = this.getOption('forth')
if (direction && (Math.round(value) != Math.round(this.previousValue))) this.setValue(direction, {sync:true, send:true, dragged: e.options.dragged, draginit: e.options.draginit})
@ -142,24 +142,24 @@ module.exports = class Encoder extends _widgets_base {
})
this.wrapper.on('draginit', (e)=>{
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length
if (this.getOption('touchAddress') && this.getOption('touchAddress').length
&& e.target == this.wrapper[0])
this.sendValue({
address:this.widgetData.touchAddress,
address:this.getOption('touchAddress'),
v:1
})
})
this.wrapper.on('dragend', (e)=>{
if (widgetData.release !== '' && this.value !== widgetData.release) {
if (this.getOption('release') !== '' && this.value !== this.getOption('release')) {
this.knob.setValue(this.ticks/2)
this.display.setValue(this.ticks/2)
this.setValue(widgetData.release, {sync:true, send:true, dragged:false})
this.setValue(this.getOption('release'), {sync:true, send:true, dragged:false})
}
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length
if (this.getOption('touchAddress') && this.getOption('touchAddress').length
&& e.target == this.wrapper[0])
this.sendValue({
address:this.widgetData.touchAddress,
address:this.getOption('touchAddress'),
v:0
})
})
@ -168,24 +168,24 @@ module.exports = class Encoder extends _widgets_base {
setValue(v,options={}) {
if (this.widgetData.snap || (!this.widgetData.snap && !options.draginit)) {
if (this.getOption('snap') || (!this.getOption('snap') && !options.draginit)) {
var match = true
if (v === this.widgetData.back) {
this.value = this.widgetData.back
} else if (v === this.widgetData.forth) {
this.value = this.widgetData.forth
} else if (v === this.widgetData.release && this.widgetData.release !== '') {
this.value = this.widgetData.release
if (v === this.getOption('back')) {
this.value = this.getOption('back')
} else if (v === this.getOption('forth')) {
this.value = this.getOption('forth')
} else if (v === this.getOption('release') && this.getOption('release') !== '') {
this.value = this.getOption('release')
} else {
match = false
}
}
if (options.sync && match) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
if (options.send && match && !(!this.widgetData.snap && options.draginit)) this.sendValue()
if (options.sync && match) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
if (options.send && match && !(!this.getOption('snap') && options.draginit)) this.sendValue()
if (options.dragged || options.draginit) this.updateDisplay(options.draginit)
@ -193,7 +193,7 @@ module.exports = class Encoder extends _widgets_base {
updateDisplay(init){
if (this.widgetData.snap) {
if (this.getOption('snap')) {
this.display.setValue(this.knob.value)
return
}

View file

@ -56,27 +56,27 @@ module.exports = class Fader extends _sliders_base {
this.margin = 15
if (widgetData.horizontal) {
if (this.getOption('horizontal')) {
this.widget.add(widgetContainer).addClass('horizontal')
if (widgetData.width == 'auto' && widgetData.left != 'auto') {
if (this.getOption('width') == 'auto' && this.getOption('left') != 'auto') {
this.container.css({'width':'auto', 'right':'0'})
}
} else {
if (widgetData.height == 'auto' && widgetData.top != 'auto') {
if (this.getOption('height') == 'auto' && this.getOption('top') != 'auto') {
this.container.css({'height':'auto', 'bottom':'0'})
}
}
if (widgetData.compact) {
if (this.getOption('compact')) {
this.widget.addClass('compact')
this.margin = 0
}
if (widgetData.alignRight && !widgetData.horizontal) {
if (this.getOption('alignRight') && !this.getOption('horizontal')) {
this.widget.addClass('align-right')
}
if (!widgetData.noPip&&!widgetData.compact) {
if (!this.getOption('noPip') && !this.getOption('compact')) {
this.widget.addClass('has-pips')
@ -90,7 +90,7 @@ module.exports = class Fader extends _sliders_base {
for (var i=0;i<=100;i++) {
if (pipTexts[i]==undefined) continue
var pos = widgetData.horizontal?'left':'bottom';
var pos = this.getOption('horizontal')?'left':'bottom';
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
@ -103,18 +103,18 @@ module.exports = class Fader extends _sliders_base {
}
if (widgetData.meter) {
if (this.getOption('meter')) {
var parsewidgets = require('../../parser').widgets
var data = {
type:'meter',
id: widgetData.id + '/meter',
id: this.getOption('id') + '/meter',
label:false,
horizontal:widgetData.horizontal,
range:widgetData.range,
logScale:widgetData.logScale,
address:widgetData.meterAddress || widgetData.address + '/meter',
preArgs:widgetData.preArgs,
color:widgetData.color
horizontal:this.getOption('horizontal'),
range:this.getOption('range'),
logScale:this.getOption('logScale'),
address:this.getOption('meterAddress') || this.getOption('address') + '/meter',
preArgs:this.getOption('preArgs'),
color:this.getOption('color')
}
var element = parsewidgets([data],this.widget.find('.wrapper'))
element[0].classList.add('not-editable')
@ -129,9 +129,9 @@ module.exports = class Fader extends _sliders_base {
this.percent = clip(this.percent,[0,100])
if (!(traversing || this.widgetData.snap)) return
if (!(traversing || this.getOption('snap'))) return
this.percent = this.widgetData.horizontal?
this.percent = this.getOption('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
@ -145,7 +145,7 @@ module.exports = class Fader extends _sliders_base {
super.dragHandle(...arguments)
this.percent = this.widgetData.horizontal?
this.percent = this.getOption('horizontal')?
this.percent + ( data.speedX/(this.width - this.margin * PXSCALE * 2)) * 100:
this.percent + (-data.speedY/(this.height - this.margin * PXSCALE * 2)) * 100
@ -155,7 +155,7 @@ module.exports = class Fader extends _sliders_base {
percentToCoord(percent) {
if (this.widgetData.horizontal) {
if (this.getOption('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)
@ -166,8 +166,8 @@ module.exports = class Fader extends _sliders_base {
resizeHandle(){
super.resizeHandle(...arguments)
if (this.widgetData.compact) {
if (this.widgetData.horizontal) {
if (this.getOption('compact')) {
if (this.getOption('horizontal')) {
this.canvas[0].setAttribute('height', 1)
} else {
this.canvas[0].setAttribute('width', 1)
@ -183,14 +183,14 @@ module.exports = class Fader extends _sliders_base {
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)
m = Math.round(this.getOption('horizontal') ? this.height / 2 : this.width / 2)
this.clear()
if (this.widgetData.horizontal) {
if (this.widgetData.compact) {
if (this.getOption('horizontal')) {
if (this.getOption('compact')) {
if (!this.widgetData.noPip) {
if (!this.getOption('noPip')) {
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 1
@ -256,9 +256,9 @@ module.exports = class Fader extends _sliders_base {
} else {
if (this.widgetData.compact) {
if (this.getOption('compact')) {
if (!this.widgetData.noPip) {
if (!this.getOption('noPip')) {
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = 0.75

View file

@ -52,12 +52,12 @@ module.exports = class Knob extends _sliders_base {
this.margin = 5
if (widgetData.compact) {
if (this.getOption('compact')) {
this.widget.addClass('compact')
this.margin = 0
}
if (!widgetData.noPip) {
if (!this.getOption('noPip')) {
this.wrapper.append(`
<div class="pips">
<div>${this.rangeLabels[0]}</div><div>${this.rangeLabels[this.rangeLabels.length-1]}</div>
@ -69,7 +69,7 @@ module.exports = class Knob extends _sliders_base {
this.lastOffsetY = 0
this.minDimension = 0
this.maxAngle = widgetData.angle
this.maxAngle = this.getOption('angle')
// calculate lost height factor
var a = this.maxAngle <= 180 ?
@ -85,7 +85,7 @@ module.exports = class Knob extends _sliders_base {
this.lastOffsetX = data.offsetX
this.lastOffsetY = data.offsetY
if (!(traversing || this.widgetData.snap)) return
if (!(traversing || this.getOption('snap'))) return
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
@ -95,7 +95,7 @@ module.exports = class Knob extends _sliders_base {
dragHandle(e, data, traversing) {
if (!(traversing || this.widgetData.snap)) {
if (!(traversing || this.getOption('snap'))) {
this.percent = -100*data.speedY/this.height + this.percent
@ -144,10 +144,10 @@ module.exports = class Knob extends _sliders_base {
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.widgetData.label === false ? 0 : this.gaugeWidth / 4) + 'px'
if (this.getOption('compact')) {
this.canvas[0].style.top = this.input[0].style.marginTop = (this.minDimension) * this.lostHeightFactor - (this.getOption('label') === false ? 0 : this.gaugeWidth / 4) + 'px'
} else {
this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - (this.widgetData.label === false ? 0 : this.margin * PXSCALE / 2), this.input.outerHeight() * .5) + 'px'
this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - (this.getOption('label') === false ? 0 : this.margin * PXSCALE / 2), this.input.outerHeight() * .5) + 'px'
}
}
@ -161,7 +161,7 @@ module.exports = class Knob extends _sliders_base {
this.ctx.clearRect(0,0,this.width,this.height)
if (this.widgetData.compact) {
if (this.getOption('compact')) {
this.ctx.lineWidth = this.gaugeWidth
this.ctx.globalAlpha = 0.3

View file

@ -104,7 +104,7 @@ module.exports = class _switchers_base extends _widgets_base {
}
}
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
if (options.sync) this.widget.trigger({type:'sync',id:this.getOption('id'),widget:this.widget, linkId:this.getOption('linkId'), options:options})
if (options.send) this.sendValue()
}

View file

@ -22,7 +22,7 @@ module.exports = class Crossfader extends Switcher {
var o = Fader.options()
o.horizontal = widgetData.horizontal
o.horizontal = this.getOption('horizontal')
o.range = {min:{'A':0}, '50%':{" ":0.5},max:{'B':1}}
this.fader = new Fader(o, 0)

View file

@ -39,16 +39,18 @@ module.exports = class Switcher extends _switchers_base {
constructor(widgetData) {
var widgetHtml = `
<div class="switcher switch-container ${widgetData.horizontal ? 'horizontal' : ''}"></div>
<div class="switcher switch-container"></div>
`
super(...arguments, widgetHtml)
if (this.getOption('horizontal')) this.widget.addClass('horizontal')
this.switch = new Switch({
label:false,
values:widgetData.values,
value: widgetData.value,
horizontal:widgetData.horizontal
values:this.getOption('values'),
value: this.getOption('value'),
horizontal:this.getOption('horizontal')
},0)
this.switch.sendValue = ()=>{}