From 79e5ad5a323cab37f7df4daf703336ed4b220a49 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 30 May 2017 00:12:42 +0200 Subject: [PATCH] widgets: WIP: options inheritance feature --- src/browser/js/app/managers.js | 30 +++---- src/browser/js/app/parser.js | 82 +++++++++++-------- src/browser/js/app/widgets/buttons/push.js | 28 +++---- src/browser/js/app/widgets/buttons/switch.js | 14 ++-- src/browser/js/app/widgets/buttons/toggle.js | 14 ++-- .../js/app/widgets/common/_widgets_base.js | 28 ++++++- .../js/app/widgets/containers/panel.js | 29 +++---- .../js/app/widgets/containers/strip.js | 4 +- src/browser/js/app/widgets/maths/formula.js | 26 +++--- .../js/app/widgets/matrices/_matrices_base.js | 6 +- .../js/app/widgets/matrices/keyboard.js | 22 ++--- .../js/app/widgets/matrices/multifader.js | 22 ++--- .../js/app/widgets/matrices/multipush.js | 20 ++--- .../js/app/widgets/matrices/multitoggle.js | 20 ++--- src/browser/js/app/widgets/pads/_pads_base.js | 2 +- src/browser/js/app/widgets/pads/multixy.js | 38 ++++----- src/browser/js/app/widgets/pads/rgb.js | 18 ++-- src/browser/js/app/widgets/pads/xy.js | 32 ++++---- .../js/app/widgets/plots/_plots_base.js | 16 ++-- src/browser/js/app/widgets/plots/eq.js | 18 ++-- src/browser/js/app/widgets/plots/led.js | 10 +-- src/browser/js/app/widgets/plots/meter.js | 4 +- src/browser/js/app/widgets/plots/plot.js | 16 ++-- src/browser/js/app/widgets/plots/rgbled.js | 6 +- src/browser/js/app/widgets/plots/text.js | 18 ++-- .../js/app/widgets/plots/visualizer.js | 20 ++--- .../js/app/widgets/sliders/_sliders_base.js | 38 ++++----- src/browser/js/app/widgets/sliders/encoder.js | 48 +++++------ src/browser/js/app/widgets/sliders/fader.js | 54 ++++++------ src/browser/js/app/widgets/sliders/knob.js | 18 ++-- .../app/widgets/switchers/_switchers_base.js | 2 +- .../js/app/widgets/switchers/crossfader.js | 2 +- .../js/app/widgets/switchers/switcher.js | 10 ++- 33 files changed, 382 insertions(+), 333 deletions(-) diff --git a/src/browser/js/app/managers.js b/src/browser/js/app/managers.js index 141d46c4..f368418e 100644 --- a/src/browser/js/app/managers.js +++ b/src/browser/js/app/managers.js @@ -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() diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index 573bcd64..6527696e 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -154,33 +154,61 @@ module.exports.widgets = function(data,parent) { widgetData.precision = Math.min(20,Math.max(widgetData.precision,0)) } + // create container + var widgetContainer = $(` +
+
+
+ `) + + // 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 = $(` -
-
${label}
-
- `) - - // 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(``) } + // 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 diff --git a/src/browser/js/app/widgets/buttons/push.js b/src/browser/js/app/widgets/buttons/push.js index 43b4578e..410fc2a9 100644 --- a/src/browser/js/app/widgets/buttons/push.js +++ b/src/browser/js/app/widgets/buttons/push.js @@ -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}) } } diff --git a/src/browser/js/app/widgets/buttons/switch.js b/src/browser/js/app/widgets/buttons/switch.js index 84968ead..110d00ec 100644 --- a/src/browser/js/app/widgets/buttons/switch.js +++ b/src/browser/js/app/widgets/buttons/switch.js @@ -37,16 +37,18 @@ module.exports = class Switch extends _widgets_base { constructor(widgetData) { var widgetHtml = ` -
+
` 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]) - $(`
${iconify(parseFloat(k) != k ? k : widgetData.values[k])}
`).data({value:widgetData.values[k]}).appendTo(this.widget) + for (var k in this.getOption('values')) { + this.values.push(this.getOption('values')[k]) + $(`
${iconify(parseFloat(k) != k ? k : this.getOption("values")[k])}
`).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}) } }} diff --git a/src/browser/js/app/widgets/buttons/toggle.js b/src/browser/js/app/widgets/buttons/toggle.js index f9b77481..57077a7e 100644 --- a/src/browser/js/app/widgets/buttons/toggle.js +++ b/src/browser/js/app/widgets/buttons/toggle.js @@ -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}) } diff --git a/src/browser/js/app/widgets/common/_widgets_base.js b/src/browser/js/app/widgets/common/_widgets_base.js index 8deb90b1..4ac4e683 100644 --- a/src/browser/js/app/widgets/common/_widgets_base.js +++ b/src/browser/js/app/widgets/common/_widgets_base.js @@ -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 + + + } + } diff --git a/src/browser/js/app/widgets/containers/panel.js b/src/browser/js/app/widgets/containers/panel.js index bc364634..40f41697 100644 --- a/src/browser/js/app/widgets/containers/panel.js +++ b/src/browser/js/app/widgets/containers/panel.js @@ -39,37 +39,38 @@ module.exports = class Panel extends _widgets_base { var widgetHtml = ` -
+
` 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']) { diff --git a/src/browser/js/app/widgets/containers/strip.js b/src/browser/js/app/widgets/containers/strip.js index 16e06a47..5b00911b 100644 --- a/src/browser/js/app/widgets/containers/strip.js +++ b/src/browser/js/app/widgets/containers/strip.js @@ -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) } diff --git a/src/browser/js/app/widgets/maths/formula.js b/src/browser/js/app/widgets/maths/formula.js index b1292920..e628f88d 100644 --- a/src/browser/js/app/widgets/maths/formula.js +++ b/src/browser/js/app/widgets/maths/formula.js @@ -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'))) ) } diff --git a/src/browser/js/app/widgets/matrices/_matrices_base.js b/src/browser/js/app/widgets/matrices/_matrices_base.js index 346a4b9b..8073e13e 100644 --- a/src/browser/js/app/widgets/matrices/_matrices_base.js +++ b/src/browser/js/app/widgets/matrices/_matrices_base.js @@ -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}) }) diff --git a/src/browser/js/app/widgets/matrices/keyboard.js b/src/browser/js/app/widgets/matrices/keyboard.js index fb4798f5..6a8cd842 100644 --- a/src/browser/js/app/widgets/matrices/keyboard.js +++ b/src/browser/js/app/widgets/matrices/keyboard.js @@ -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{ var s={}, t for (var i=0; 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.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() diff --git a/src/browser/js/app/widgets/plots/_plots_base.js b/src/browser/js/app/widgets/plots/_plots_base.js index 5fc82d04..57a100ba 100644 --- a/src/browser/js/app/widgets/plots/_plots_base.js +++ b/src/browser/js/app/widgets/plots/_plots_base.js @@ -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), ] diff --git a/src/browser/js/app/widgets/plots/eq.js b/src/browser/js/app/widgets/plots/eq.js index 207adec3..a94cd7d7 100644 --- a/src/browser/js/app/widgets/plots/eq.js +++ b/src/browser/js/app/widgets/plots/eq.js @@ -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) { diff --git a/src/browser/js/app/widgets/plots/led.js b/src/browser/js/app/widgets/plots/led.js index 975f9d40..f8962e43 100644 --- a/src/browser/js/app/widgets/plots/led.js +++ b/src/browser/js/app/widgets/plots/led.js @@ -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)) } diff --git a/src/browser/js/app/widgets/plots/meter.js b/src/browser/js/app/widgets/plots/meter.js index 9f92b6bf..aafff454 100644 --- a/src/browser/js/app/widgets/plots/meter.js +++ b/src/browser/js/app/widgets/plots/meter.js @@ -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--) { diff --git a/src/browser/js/app/widgets/plots/plot.js b/src/browser/js/app/widgets/plots/plot.js index b294f1c7..f42dbba9 100644 --- a/src/browser/js/app/widgets/plots/plot.js +++ b/src/browser/js/app/widgets/plots/plot.js @@ -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) { diff --git a/src/browser/js/app/widgets/plots/rgbled.js b/src/browser/js/app/widgets/plots/rgbled.js index 85b754e5..e0b9862a 100644 --- a/src/browser/js/app/widgets/plots/rgbled.js +++ b/src/browser/js/app/widgets/plots/rgbled.js @@ -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()) diff --git a/src/browser/js/app/widgets/plots/text.js b/src/browser/js/app/widgets/plots/text.js index 18c2f663..eb08bd74 100644 --- a/src/browser/js/app/widgets/plots/text.js +++ b/src/browser/js/app/widgets/plots/text.js @@ -37,21 +37,23 @@ module.exports = class Text extends _widgets_base { constructor(widgetData) { var widgetHtml = ` -
+
` 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--) { diff --git a/src/browser/js/app/widgets/plots/visualizer.js b/src/browser/js/app/widgets/plots/visualizer.js index a97cb9ef..5ed44c54 100644 --- a/src/browser/js/app/widgets/plots/visualizer.js +++ b/src/browser/js/app/widgets/plots/visualizer.js @@ -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.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[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) } diff --git a/src/browser/js/app/widgets/sliders/encoder.js b/src/browser/js/app/widgets/sliders/encoder.js index beefc338..dcfb2b24 100644 --- a/src/browser/js/app/widgets/sliders/encoder.js +++ b/src/browser/js/app/widgets/sliders/encoder.js @@ -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 } diff --git a/src/browser/js/app/widgets/sliders/fader.js b/src/browser/js/app/widgets/sliders/fader.js index f80d6418..6324cce2 100644 --- a/src/browser/js/app/widgets/sliders/fader.js +++ b/src/browser/js/app/widgets/sliders/fader.js @@ -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 = `${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}` @@ -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 diff --git a/src/browser/js/app/widgets/sliders/knob.js b/src/browser/js/app/widgets/sliders/knob.js index 63583e2d..2966a536 100644 --- a/src/browser/js/app/widgets/sliders/knob.js +++ b/src/browser/js/app/widgets/sliders/knob.js @@ -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(`
${this.rangeLabels[0]}
${this.rangeLabels[this.rangeLabels.length-1]}
@@ -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 diff --git a/src/browser/js/app/widgets/switchers/_switchers_base.js b/src/browser/js/app/widgets/switchers/_switchers_base.js index 82fe36f2..6963db8f 100644 --- a/src/browser/js/app/widgets/switchers/_switchers_base.js +++ b/src/browser/js/app/widgets/switchers/_switchers_base.js @@ -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() } diff --git a/src/browser/js/app/widgets/switchers/crossfader.js b/src/browser/js/app/widgets/switchers/crossfader.js index c1919ec1..2faf96ad 100644 --- a/src/browser/js/app/widgets/switchers/crossfader.js +++ b/src/browser/js/app/widgets/switchers/crossfader.js @@ -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) diff --git a/src/browser/js/app/widgets/switchers/switcher.js b/src/browser/js/app/widgets/switchers/switcher.js index 8b53bc50..4257bd45 100644 --- a/src/browser/js/app/widgets/switchers/switcher.js +++ b/src/browser/js/app/widgets/switchers/switcher.js @@ -39,16 +39,18 @@ module.exports = class Switcher extends _switchers_base { constructor(widgetData) { var widgetHtml = ` -
+
` 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 = ()=>{}