⚠️ long commit:
widgets: modularize last remaining widgets (text & led)
global: new widget manager module to properly handle widgets registration, synchronization events, store purges, and bindings from the dom element to the abstract object
: remove old setValue / getValue bindings in each widget and use direct access to the abstract objects everywhere
This commit is contained in:
parent
d11b25df7b
commit
3c2d0c1382
35 changed files with 351 additions and 245 deletions
|
|
@ -1,8 +1,5 @@
|
|||
///////////////////////
|
||||
|
||||
WIDGETS = {}
|
||||
WIDGETS_LINKED = {}
|
||||
WIDGETS_BY_ADDRESS = {}
|
||||
SESSION = []
|
||||
STATE = []
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
var {WidgetManager} = require('./managers')
|
||||
|
||||
module.exports = {
|
||||
|
||||
stateQuickSave: function(preset){
|
||||
|
|
@ -24,13 +26,13 @@ module.exports = {
|
|||
|
||||
stateGet: function (){
|
||||
var data = []
|
||||
for (i in WIDGETS) {
|
||||
var widget = WIDGETS[i]
|
||||
for (var j=widget.length-1;j>=0;j--) {
|
||||
if (widget[j].setValue && widget[j].getValue) {
|
||||
var v = widget[j].getValue()
|
||||
if (v!=undefined) data.push([i,v])
|
||||
break
|
||||
for (i in WidgetManager.widgets) {
|
||||
var widget = WidgetManager.widgets[i]
|
||||
if (widget.setValue && widget.getValue) {
|
||||
var v = widget.getValue()
|
||||
if (v!=undefined) {
|
||||
data.push([widget.widgetData.id,v])
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,11 +62,12 @@ module.exports = {
|
|||
stateSet: function(preset,send){
|
||||
|
||||
for (i in preset) {
|
||||
var data = preset[i]
|
||||
if (WIDGETS[data[0]]!=undefined) {
|
||||
for (var i=WIDGETS[data[0]].length-1;i>=0;i--) {
|
||||
if (WIDGETS[data[0]][i].setValue) {
|
||||
WIDGETS[data[0]][i].setValue(data[1],{send:send,sync:true})
|
||||
var data = preset[i],
|
||||
widgets = WidgetManager.getWidgetById(data[0])
|
||||
if (widgets.length) {
|
||||
for (var i=widgets.length-1;i>=0;i--) {
|
||||
if (widgets[i].setValue) {
|
||||
widgets[i].setValue(data[1],{send:send,sync:true})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ var init = require('./init'),
|
|||
actions = require('./actions'),
|
||||
utils = require('./utils'),
|
||||
icon = utils.icon,
|
||||
remoteExec = require('./remote-exec')
|
||||
remoteExec = require('./remote-exec'),
|
||||
{WidgetManager} = require('./managers')
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ module.exports = {
|
|||
if (typeof data.args == 'object') {
|
||||
for (var i=data.args.length-1;i>=0;i--) {
|
||||
var ref = address+'||||'+data.args.slice(0,i).join('||||')
|
||||
if (WIDGETS_BY_ADDRESS[ref]) {
|
||||
if (WidgetManager.getWidgetByAddress(ref).length) {
|
||||
addressref = ref
|
||||
args = data.args.slice(i,data.args.length)
|
||||
continue
|
||||
|
|
@ -34,13 +35,16 @@ module.exports = {
|
|||
if (args.length==0) args = null
|
||||
else if (args.length==1) args = args[0]
|
||||
|
||||
for (i in WIDGETS_BY_ADDRESS[addressref]) {
|
||||
|
||||
let widget = WidgetManager.getWidgetByAddress(addressref)
|
||||
|
||||
for (i in widget) {
|
||||
// if the message target is provided (when message comes from another client connected to the same server)
|
||||
// then we only update the widgets that have the same target
|
||||
// compare arrays using > and < operators (both false = equality)
|
||||
if (!target || !(WIDGETS_BY_ADDRESS[addressref][i].target < target || WIDGETS_BY_ADDRESS[addressref][i].target > target)) {
|
||||
if (!target || !(widget[i].widgetData.target < target || widget[i].widgetData.target > target)) {
|
||||
// update matching widgets
|
||||
if (WIDGETS_BY_ADDRESS[addressref][i]) WIDGETS_BY_ADDRESS[addressref][i].setValue(args,{send:false,sync:true,fromExternal:!target})
|
||||
if (widget[i]) widget[i].setValue(args,{send:false,sync:true,fromExternal:!target})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
var widgets = require('../widgets'),
|
||||
widgetOptions = widgets.widgetOptions,
|
||||
sync = widgets.sync,
|
||||
parser = require('../parser')
|
||||
parsewidgets = parser.widgets,
|
||||
parsetabs = parser.tabs,
|
||||
|
|
@ -10,7 +9,8 @@ var widgets = require('../widgets'),
|
|||
editObject = function(a,b){require('./edit-objects').editObject(a,b,true)},
|
||||
editSession = function(a,b){require('./edit-objects').editSession(a,b,true)},
|
||||
purgeStores = require('./purge'),
|
||||
{iconify} = require('../utils')
|
||||
{iconify} = require('../utils'),
|
||||
{WidgetManager} = require('../managers')
|
||||
|
||||
|
||||
var getObjectData = function(obj){
|
||||
|
|
@ -101,7 +101,6 @@ var updateDom = function(container,data, remote) {
|
|||
|
||||
// restore state
|
||||
actions.stateSet(state,false)
|
||||
sync()
|
||||
ui.scrolls()
|
||||
$('#sidepanel').scrollTop(scroll)
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ var incrementWidget = function(data){
|
|||
|
||||
} else if (address){
|
||||
var addressref
|
||||
while (WIDGETS_BY_ADDRESS[addressref]) {
|
||||
while (WidgetManager.getWidgetByAddress(addressref)) {
|
||||
address = address.replace(/([0-9]*)$/,function(m){
|
||||
var n = parseInt(m)+1
|
||||
n = isNaN(n)?1:n
|
||||
|
|
@ -139,20 +138,20 @@ var incrementWidget = function(data){
|
|||
})
|
||||
addressref = data.preArgs&&data.preArgs.length?address+'||||'+data.preArgs.join('||||'):address
|
||||
}
|
||||
WIDGETS_BY_ADDRESS[addressref] = []
|
||||
|
||||
data.address = address
|
||||
|
||||
}
|
||||
|
||||
if (id) {
|
||||
while (WIDGETS[id]) {
|
||||
while (WidgetManager.getWidgetById(id)) {
|
||||
id = id.replace(/([0-9]*)$/,function(m){
|
||||
var n = parseInt(m)+1
|
||||
n = isNaN(n)?1:n
|
||||
return n
|
||||
})
|
||||
}
|
||||
WIDGETS[id] = []
|
||||
|
||||
data.id = id
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
var {WidgetManager} = require('../managers')
|
||||
|
||||
module.exports = function(purgetabs) {
|
||||
|
||||
// prune tabs store
|
||||
|
|
@ -37,34 +39,9 @@ module.exports = function(purgetabs) {
|
|||
// prune widget stores
|
||||
// if widgets cannot be found in buffered tabs, it must be unreferenced
|
||||
var $b = $(bufferedTabs)
|
||||
for (i in WIDGETS) {
|
||||
for (var j=WIDGETS[i].length-1;j>=0;j--) {
|
||||
if (!$b.find(WIDGETS[i][j]).length) {
|
||||
WIDGETS[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS[i].length) {
|
||||
delete WIDGETS[i]
|
||||
}
|
||||
}
|
||||
for (i in WIDGETS_LINKED) {
|
||||
for (var j=WIDGETS_LINKED[i].length-1;j>=0;j--) {
|
||||
if (!$b.find(WIDGETS_LINKED[i][j]).length) {
|
||||
WIDGETS_LINKED[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS_LINKED[i].length) {
|
||||
delete WIDGETS_LINKED[i]
|
||||
}
|
||||
}
|
||||
for (i in WIDGETS_BY_ADDRESS) {
|
||||
for (var j=WIDGETS_BY_ADDRESS[i].length-1;j>=0;j--) {
|
||||
if (!$b.find(WIDGETS_BY_ADDRESS[i][j]).length) {
|
||||
WIDGETS_BY_ADDRESS[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS_BY_ADDRESS[i].length) {
|
||||
delete WIDGETS_BY_ADDRESS[i]
|
||||
for (hash in WidgetManager.widgets) {
|
||||
if (!$b.find(WidgetManager.widgets[hash].widget).length) {
|
||||
WidgetManager.removeWidget(hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ module.exports = function(session,callback) {
|
|||
ui.init()
|
||||
editorDisable()
|
||||
editorInit()
|
||||
sync()
|
||||
// sync()
|
||||
|
||||
|
||||
setTimeout(function(){
|
||||
|
|
|
|||
135
src/browser/js/app/managers.js
Normal file
135
src/browser/js/app/managers.js
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
var WidgetManager = function(){
|
||||
|
||||
this.widgets = []
|
||||
this.addressRoute = {}
|
||||
this.idRoute = {}
|
||||
this.linkIdRoute = {}
|
||||
|
||||
$(document).ready(()=>{
|
||||
$('body').off('sync.global').on('sync.global',(e)=>{
|
||||
|
||||
var {id, widget, linkId, fromExternal, options} = e,
|
||||
widgetsById = this.getWidgetById(id),
|
||||
widgetsByLinkId = this.getWidgetByLinkId(linkId)
|
||||
|
||||
// Widget that share the same id will update each other
|
||||
// without sending any extra osc message
|
||||
if (widgetsById.length>1) {
|
||||
var v = widget.abstract.getValue()
|
||||
for (i in widgetsById) {
|
||||
if (!widgetsById[i].widget.is(widget) && widgetsById[i].setValue) {
|
||||
widgetsById[i].setValue(v,{send:false,sync:false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// widgets that share the same linkId will update each other.
|
||||
// Updated widgets will send osc messages normally
|
||||
if (widgetsByLinkId.length>1) {
|
||||
var v = widget.abstract.getValue()
|
||||
for (i in widgetsByLinkId) {
|
||||
if (!widgetsByLinkId[i].widget.is(widget) && widgetsByLinkId[i].setValue) {
|
||||
widgetsByLinkId[i].setValue(v,{send:options.send,sync:false})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
WidgetManager.prototype.createHash = function(widget) {
|
||||
|
||||
return String(Math.random()).split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.createAddressRef = function(widget) {
|
||||
|
||||
return widget.widgetData.preArgs && widget.widgetData.preArgs.length ?
|
||||
widget.widgetData.address + '||||' + widget.widgetData.preArgs.join('||||')
|
||||
: widget.widgetData.address
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.addWidget = function(widget) {
|
||||
|
||||
var h1 = this.createHash(),
|
||||
h2 = this.createHash(),
|
||||
hash = [h1,h2].join('/')
|
||||
address = this.createAddressRef(widget),
|
||||
id = widget.widgetData.id,
|
||||
linkId = widget.widgetData.linkId
|
||||
|
||||
|
||||
this.widgets[hash] = widget
|
||||
|
||||
if (!this.idRoute[id]) this.idRoute[id] = {}
|
||||
this.idRoute[id][h2] = h1
|
||||
|
||||
if (address) {
|
||||
if (!this.addressRoute[address]) this.addressRoute[address] = {}
|
||||
this.addressRoute[address][h2] = h1
|
||||
}
|
||||
|
||||
if (linkId) {
|
||||
if (!this.linkIdRoute[linkId]) this.linkIdRoute[linkId] = {}
|
||||
this.linkIdRoute[linkId][h2] = h1
|
||||
}
|
||||
|
||||
widget.widget.abstract = widget
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.removeWidget = function(hash) {
|
||||
|
||||
var widget = this.widgets[hash],
|
||||
h2 = hash.split('/')[1]
|
||||
address = this.createAddressRef(widget),
|
||||
linkId = widget.widgetData.linkId,
|
||||
id = widget.widgetData.id
|
||||
|
||||
delete this.widgets[hash]
|
||||
delete this.idRoute[id][h2]
|
||||
delete this.linkIdRoute[linkId][h2]
|
||||
delete this.addressRoute[address][h2]
|
||||
}
|
||||
|
||||
WidgetManager.prototype.getWidgetBy = function(key, dict) {
|
||||
|
||||
var w = [],
|
||||
h1
|
||||
|
||||
for (h2 in dict[key]) {
|
||||
h1 = dict[key][h2]
|
||||
w.push(this.widgets[[h1,h2].join('/')])
|
||||
}
|
||||
|
||||
return w
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.getWidgetById = function(id) {
|
||||
|
||||
return this.getWidgetBy(id, this.idRoute)
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.getWidgetByLinkId = function(linkId) {
|
||||
|
||||
return this.getWidgetBy(linkId, this.linkIdRoute)
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.getWidgetByAddress = function(address) {
|
||||
|
||||
return this.getWidgetBy(address, this.addressRoute)
|
||||
|
||||
}
|
||||
|
||||
|
||||
var m = new WidgetManager()
|
||||
|
||||
module.exports.WidgetManager = m
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
Session File Parser
|
||||
*/
|
||||
|
||||
var {WidgetManager} = require('./managers')
|
||||
|
||||
var widgets = require('./widgets'),
|
||||
widgetOptions = widgets.widgetOptions,
|
||||
createWidget = widgets.createWidget,
|
||||
|
|
@ -22,9 +24,6 @@ module.exports.tabs = function(data,parent,main,parentLabel){
|
|||
|
||||
if (main) {
|
||||
// Reset Globals
|
||||
WIDGETS = {}
|
||||
WIDGETS_LINKED = {}
|
||||
WIDGETS_BY_ADDRESS = {}
|
||||
SESSION = data
|
||||
for (i in TABS) {
|
||||
if (i!='#container') {
|
||||
|
|
@ -104,7 +103,7 @@ module.exports.widgets = function(data,parent) {
|
|||
// Genrate widget's id, based on its type
|
||||
if (widgetData.id=='auto') {
|
||||
var id
|
||||
while (!id || WIDGETS[id]) {
|
||||
while (!id || WidgetManager.getWidgetById(id).length) {
|
||||
id=widgetData.type+'_'+getIterator(widgetData.type,'widget')
|
||||
}
|
||||
widgetData.id = id
|
||||
|
|
@ -179,27 +178,9 @@ module.exports.widgets = function(data,parent) {
|
|||
// create widget
|
||||
var widgetInner = createWidget[widgetData.type](widgetData,widgetContainer)
|
||||
|
||||
// store widgets target
|
||||
widgetInner.target = widgetData.target
|
||||
widgetContainer[0].appendChild(widgetInner.widget[0])
|
||||
|
||||
widgetContainer[0].appendChild(widgetInner[0])
|
||||
|
||||
// store widget reference for cross widget sync
|
||||
if (WIDGETS[widgetData.id]==undefined) WIDGETS[widgetData.id] = []
|
||||
WIDGETS[widgetData.id].push(widgetInner)
|
||||
|
||||
// store widget with linkId for widgte linking
|
||||
if (widgetData.linkId && widgetData.linkId.length) {
|
||||
if (WIDGETS_LINKED[widgetData.linkId]==undefined) WIDGETS_LINKED[widgetData.linkId] = []
|
||||
WIDGETS_LINKED[widgetData.linkId].push(widgetInner)
|
||||
}
|
||||
|
||||
// store widget by address and encode preArgs for perfect cross-app sync
|
||||
if (widgetData.address) {
|
||||
var addressref = widgetData.preArgs&&widgetData.preArgs.length?widgetData.address+'||||'+widgetData.preArgs.join('||||'):widgetData.address
|
||||
if (WIDGETS_BY_ADDRESS[addressref]==undefined) WIDGETS_BY_ADDRESS[addressref] = []
|
||||
WIDGETS_BY_ADDRESS[addressref].push(widgetInner)
|
||||
}
|
||||
WidgetManager.addWidget(widgetInner)
|
||||
|
||||
// set widget's initial state
|
||||
if (widgetData.value !== '' && widgetInner.setValue) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
var {getObjectData, updateDom} = require('./editor/data-workers')
|
||||
var {getObjectData, updateDom} = require('./editor/data-workers'),
|
||||
{WidgetManager} = require('./managers')
|
||||
|
||||
var callbacks = {
|
||||
edit: function(args) {
|
||||
var [id, json] = args,
|
||||
newdata = JSON.parse(json),
|
||||
containers = WIDGETS[id]
|
||||
containers = WidgetManager.getWidgetById(id)
|
||||
|
||||
if (!WIDGETS[id]) return
|
||||
for (var i=WIDGETS[id].length-1;i>=0;i--) {
|
||||
var container = WIDGETS[id][i].parent(),
|
||||
if (!containers.length) return
|
||||
for (var i=containers.length-1;i>=0;i--) {
|
||||
var container = containers[i].parent(),
|
||||
data = getObjectData(container)
|
||||
|
||||
$.extend(true,data,newdata)
|
||||
|
|
|
|||
|
|
@ -57,29 +57,3 @@ module.exports.createWidget = function(){
|
|||
}
|
||||
return r
|
||||
}()
|
||||
|
||||
module.exports.sync = function() {
|
||||
$('body').off('sync.global').on('sync.global',function(e){
|
||||
var {id, widget, linkId, fromExternal, options} = e
|
||||
// Widget that share the same id will update each other
|
||||
// without sending any extra osc message
|
||||
if (WIDGETS[id] && WIDGETS[id].length>1) {
|
||||
var v = widget.getValue()
|
||||
for (i in WIDGETS[id]) {
|
||||
if (!WIDGETS[id][i].is(widget) && WIDGETS[id][i].setValue) {
|
||||
WIDGETS[id][i].setValue(v,{send:false,sync:false})
|
||||
}
|
||||
}
|
||||
}
|
||||
// widgets that share the same linkId will update each other.
|
||||
// Updated widgets will send osc messages normally
|
||||
if (WIDGETS_LINKED[linkId] && WIDGETS_LINKED[linkId].length>1) {
|
||||
var v = widget.getValue()
|
||||
for (i in WIDGETS_LINKED[linkId]) {
|
||||
if (!WIDGETS_LINKED[linkId][i].is(widget) && WIDGETS_LINKED[linkId][i].setValue) {
|
||||
WIDGETS_LINKED[linkId][i].setValue(v,{send:options.send,sync:false})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,14 +47,6 @@ var Push = module.exports.Push = function(widgetData,container) {
|
|||
this.fakeclick()
|
||||
})
|
||||
|
||||
this.widget.getValue = ()=>{
|
||||
return this[this.lastChanged] ?
|
||||
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
|
||||
:
|
||||
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
|
||||
}
|
||||
|
||||
this.widget.setValue = this.setValue.bind(this)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -62,6 +54,15 @@ Push.prototype = Object.create(_widgets_base.prototype)
|
|||
|
||||
Push.prototype.constructor = Push
|
||||
|
||||
Push.prototype.getValue = function(){
|
||||
|
||||
return this[this.lastChanged] ?
|
||||
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
|
||||
:
|
||||
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
|
||||
|
||||
}
|
||||
|
||||
Push.prototype.fakeclick = function(){
|
||||
if (!this.active) this.setValuePrivate(this.widgetData.on,{send:true,sync:true})
|
||||
$document.on('dragend.push',()=>{
|
||||
|
|
@ -113,5 +114,5 @@ Push.prototype.setValue = function(v,options={}) {
|
|||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var push = new Push(widgetData, container)
|
||||
return push.widget
|
||||
return push
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,12 +65,6 @@ var Switch = module.exports.Switch = function(widgetData,container) {
|
|||
})
|
||||
|
||||
|
||||
|
||||
this.widget.getValue = ()=>{
|
||||
return this.value
|
||||
}
|
||||
this.widget.setValue = this.setValue.bind(this)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -93,5 +87,5 @@ Switch.prototype.setValue = function(v,options={}) {
|
|||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var _switch = new Switch(widgetData, container)
|
||||
return _switch.widget
|
||||
return _switch
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,14 +46,7 @@ var Toggle = module.exports.Toggle = function(widgetData,container) {
|
|||
})
|
||||
|
||||
|
||||
this.widget.getValue = ()=>{
|
||||
return this.widget.state ?
|
||||
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
|
||||
:
|
||||
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
|
||||
}
|
||||
this.value = this.widget.getValue()
|
||||
this.widget.setValue = this.setValue.bind(this)
|
||||
this.value = this.getValue()
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -62,9 +55,18 @@ Toggle.prototype = Object.create(_widgets_base.prototype)
|
|||
|
||||
Toggle.prototype.constructor = Toggle
|
||||
|
||||
Toggle.prototype.getValue = function(){
|
||||
|
||||
return this.widget.state ?
|
||||
this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on
|
||||
:
|
||||
this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off
|
||||
|
||||
}
|
||||
|
||||
Toggle.prototype.fakeclick = function(){
|
||||
var newVal = this.widget.state?this.widgetData.off:this.widgetData.on
|
||||
this.widget.setValue(newVal,{sync:true,send:true})
|
||||
this.setValue(newVal,{sync:true,send:true})
|
||||
$document.on('dragend.toggle',()=>{
|
||||
$document.off('dragend.toggle')
|
||||
this.widget.on('draginit.toggle',()=>{
|
||||
|
|
@ -95,5 +97,5 @@ Toggle.prototype.setValue = function(v,options={}){
|
|||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var toggle = new Toggle(widgetData, container)
|
||||
return toggle.widget
|
||||
return toggle
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,3 +33,27 @@ _widget_base.prototype.sendValue = function() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
_widget_base.prototype.getValue = function() {
|
||||
|
||||
if (typeof this.value == 'object') {
|
||||
|
||||
return (()=>{
|
||||
|
||||
var a = []
|
||||
|
||||
for (i in this.value) {
|
||||
a.push(this.value[i])
|
||||
}
|
||||
|
||||
return a
|
||||
|
||||
})()
|
||||
|
||||
} else {
|
||||
|
||||
return this.value
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,10 +42,6 @@ var Modal = module.exports.Modal = function(widgetData, container) {
|
|||
this.setValue(!this.value)
|
||||
})
|
||||
|
||||
this.widget.setValue = this.setValue.bind(this)
|
||||
this.widget.getValue = ()=>{
|
||||
return this.value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -69,5 +65,5 @@ Modal.prototype.setValue = function(v) {
|
|||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var modal = new Modal(widgetData, container)
|
||||
return modal.widget
|
||||
return modal
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,5 @@ Panel.prototype.constructor = Panel
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var panel = new Panel(widgetData)
|
||||
return panel.widget
|
||||
return panel
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,5 +47,5 @@ Strip.prototype.constructor = Strip
|
|||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var strip = new Strip(widgetData, container)
|
||||
return strip.widget
|
||||
return strip
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,10 @@ var _matrices_base = module.exports = function(widgetData){
|
|||
`)
|
||||
this.value = []
|
||||
|
||||
this.widget.getValue = function(){
|
||||
return this.value
|
||||
}.bind(this)
|
||||
|
||||
this.widget.on('sync',function(e){
|
||||
if (e.id==this.widgetData.id) return
|
||||
this.value[e.widget.parent().index()] = e.widget.getValue()
|
||||
this.value[e.widget.parent().index()] = e.widget.abstract.getValue()
|
||||
this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget})
|
||||
}.bind(this))
|
||||
|
||||
|
|
|
|||
|
|
@ -91,5 +91,5 @@ Keyboard.prototype.constructor = Keyboard
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var keyboard = new Keyboard(widgetData)
|
||||
return keyboard.widget
|
||||
return keyboard
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,5 +83,5 @@ Multifader.prototype.constructor = Multifader
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var multifader = new Multifader(widgetData)
|
||||
return multifader.widget
|
||||
return multifader
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,5 +73,5 @@ Multipush.prototype.constructor = Multipush
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var multipush = new Multipush(widgetData)
|
||||
return multipush.widget
|
||||
return multipush
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,5 +70,5 @@ Multitoggle.prototype.constructor = Multitoggle
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var multitoggle = new Multitoggle(widgetData)
|
||||
return multitoggle.widget
|
||||
return multitoggle
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,23 +104,13 @@ var MultiXy = module.exports.MultiXy = function(widgetData) {
|
|||
|
||||
this.wrapper.on('sync',(e)=>{
|
||||
e.stopPropagation()
|
||||
this.setValue(this.widget.getValue(), e.options)
|
||||
this.setValue(this.getValue(), e.options)
|
||||
})
|
||||
|
||||
this.widget.getValue = () => {
|
||||
var v = []
|
||||
for (var i=0;i<this.pads.length * 2;i=i+2) {
|
||||
[v[i],v[i+1]] = this.pads[i/2].widget.getValue()
|
||||
}
|
||||
return v
|
||||
}
|
||||
this.widget.setValue = (v, options) => {
|
||||
this.setValue(v, options)
|
||||
}
|
||||
|
||||
var v = []
|
||||
for (var i=0;i<this.widgetData.points * 2;i=i+2) {
|
||||
[v[i],v[i+1]] = this.pads[i/2].widget.getValue()
|
||||
[v[i],v[i+1]] = this.pads[i/2].getValue()
|
||||
}
|
||||
this.setValue(v)
|
||||
|
||||
|
|
@ -180,6 +170,15 @@ MultiXy.prototype.draw = function(){
|
|||
}
|
||||
}
|
||||
|
||||
MultiXy.prototype.getValue = function(){
|
||||
|
||||
var v = []
|
||||
for (var i=0;i<this.pads.length * 2;i=i+2) {
|
||||
[v[i],v[i+1]] = this.pads[i/2].getValue()
|
||||
}
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
MultiXy.prototype.setValue = function(v, options={}){
|
||||
if (!v || v.length!=this.widgetData.points * 2) return
|
||||
|
|
@ -194,7 +193,7 @@ MultiXy.prototype.setValue = function(v, options={}){
|
|||
this.draw()
|
||||
|
||||
for (var i=0;i<this.widgetData.points * 2;i=i+2) {
|
||||
[this.value[i],this.value[i+1]] = this.pads[i/2].widget.getValue()
|
||||
[this.value[i],this.value[i+1]] = this.pads[i/2].getValue()
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -208,5 +207,5 @@ MultiXy.prototype.setValue = function(v, options={}){
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var xy = new MultiXy(widgetData)
|
||||
return xy.widget
|
||||
return xy
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,13 +131,6 @@ var Rgb = module.exports.Rgb = function(widgetData) {
|
|||
},this)
|
||||
|
||||
|
||||
this.widget.getValue = () => {
|
||||
return [this.value[0], this.value[1], this.value[2]]
|
||||
}
|
||||
this.widget.setValue = (v, options) => {
|
||||
this.setValue(v, options)
|
||||
}
|
||||
|
||||
this.setValue([0,0,0])
|
||||
}
|
||||
|
||||
|
|
@ -244,5 +237,5 @@ Rgb.prototype.draw = function(){
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var rgb = new Rgb(widgetData)
|
||||
return rgb.widget
|
||||
return rgb
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,14 +130,6 @@ var Xy = module.exports.Xy = function(widgetData) {
|
|||
})
|
||||
|
||||
|
||||
this.widget.getValue = () => {
|
||||
return [this.value[0], this.value[1]]
|
||||
}
|
||||
this.widget.setValue = (v, options) => {
|
||||
this.setValue(v, options)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -155,6 +147,7 @@ Xy.prototype.dragHandle = function(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Xy.prototype.setValue = function(v, options={}){
|
||||
|
||||
if (!v || v.length!=2) return
|
||||
|
|
@ -210,5 +203,5 @@ Xy.prototype.draw = function(){
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var xy = new Xy(widgetData)
|
||||
return xy.widget
|
||||
return xy
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var {mapToScale} = require('../utils'),
|
||||
_canvas_base = require('../common/_canvas_base')
|
||||
_canvas_base = require('../common/_canvas_base'),
|
||||
{WidgetManager} = require('../../managers')
|
||||
|
||||
var _plots_base = module.exports = function(){
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ _plots_base.prototype.syncHandleProxy = function() {
|
|||
}
|
||||
|
||||
_plots_base.prototype.syncHandle = function(e) {
|
||||
if (this.linkedWidgets.indexOf(e.id)==-1 || !WIDGETS[e.id]) return
|
||||
if (this.linkedWidgets.indexOf(e.id)==-1 || !WidgetManager.getWidgetById(e.id).length) return
|
||||
this.updateData()
|
||||
requestAnimationFrame(this.draw.bind(this))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
var {mapToScale, clip} = require('../utils'),
|
||||
_biquad_response = require('./_biquad_response'),
|
||||
_plots_base = require('./_plots_base')
|
||||
_plots_base = require('./_plots_base'),
|
||||
{WidgetManager} = require('../../managers')
|
||||
|
||||
module.exports.options = {
|
||||
type:'eq',
|
||||
|
|
@ -69,10 +70,11 @@ Eq.prototype.updateData = function(){
|
|||
filters[i] = {}
|
||||
|
||||
for (j in filter) {
|
||||
let widget = WidgetManager.getWidgetById(filter[j])
|
||||
|
||||
if (typeof filter[j]=='string' && WIDGETS[filter[j]]) {
|
||||
if (typeof filter[j]=='string' && widget.length) {
|
||||
|
||||
filters[i][j] = WIDGETS[filter[j]][WIDGETS[filter[j]].length-1].getValue()
|
||||
filters[i][j] = widget[widget.length-1].getValue()
|
||||
|
||||
} else {
|
||||
|
||||
|
|
@ -109,5 +111,5 @@ Eq.prototype.updateData = function(){
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var eq = new Eq(widgetData)
|
||||
return eq.widget
|
||||
return eq
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
var {mapToScale} = require('../utils')
|
||||
var {mapToScale} = require('../utils'),
|
||||
_widgets_base = require('../common/_widgets_base')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'led',
|
||||
|
|
@ -22,21 +24,36 @@ module.exports.options = {
|
|||
preArgs:[],
|
||||
address:'auto'
|
||||
}
|
||||
module.exports.create = function(widgetData,container) {
|
||||
var widget = $(`
|
||||
|
||||
var Led = module.exports.Led = function(widgetData,container) {
|
||||
|
||||
_widgets_base.apply(this,arguments)
|
||||
|
||||
this.widget = $(`
|
||||
<div class="led">
|
||||
<div><span></span></div>
|
||||
</div>
|
||||
`),
|
||||
led = widget.find('span'),
|
||||
range = widgetData.range
|
||||
this.led = this.widget.find('span')
|
||||
|
||||
widget.setValue = function(v){
|
||||
if (typeof v != 'number') return
|
||||
led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],false,widgetData.logScale,true))
|
||||
}
|
||||
|
||||
widget.setValue(range.min)
|
||||
this.setValue(this.widgetData.range.min)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
||||
Led.prototype = Object.create(_widgets_base.prototype)
|
||||
|
||||
Led.prototype.constructor = Led
|
||||
|
||||
Led.prototype.setValue = function(v){
|
||||
|
||||
if (typeof v != 'number') return
|
||||
this.led.css('opacity',mapToScale(v,[this.widgetData.range.min,this.widgetData.range.max],[0,1],false,this.widgetData.logScale,true))
|
||||
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var led = new Led(widgetData, container)
|
||||
return led
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ var Meter = module.exports.Meter = function(widgetData, container){
|
|||
Fader.apply(this, arguments)
|
||||
|
||||
this.input.hide()
|
||||
this.widget.getValue = false
|
||||
|
||||
this.widget.addClass('meter')
|
||||
}
|
||||
|
|
@ -46,10 +45,10 @@ Meter.prototype = Object.create(Fader.prototype)
|
|||
|
||||
Meter.prototype.constructor = Meter
|
||||
|
||||
Meter.prototype.sendValue = false
|
||||
Meter.prototype.sendValue = ()=>{}
|
||||
|
||||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
var meter = new Meter(widgetData, container)
|
||||
return meter.widget
|
||||
return meter
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var {mapToScale} = require('../utils'),
|
||||
_plots_base = require('./_plots_base')
|
||||
_plots_base = require('./_plots_base'),
|
||||
{WidgetManager} = require('../../managers')
|
||||
|
||||
module.exports.options = {
|
||||
type:'plot',
|
||||
|
|
@ -52,20 +53,23 @@ var Plot = module.exports.Plot = function(widgetData) {
|
|||
|
||||
this.updateData = function(){
|
||||
var data = [],
|
||||
points = widgetData.points
|
||||
points = widgetData.points,
|
||||
widget = WidgetManager.getWidgetById(points)
|
||||
|
||||
if (typeof points=='string' && WIDGETS[points]) {
|
||||
if (typeof points=='string' && widget.length) {
|
||||
|
||||
data = WIDGETS[points][WIDGETS[points].length-1].getValue()
|
||||
data = widget[widget.length-1].getValue()
|
||||
|
||||
} else if (typeof points=='object') {
|
||||
|
||||
for (i in points) {
|
||||
|
||||
data[i] = []
|
||||
|
||||
for (k in [0,1]) {
|
||||
if (typeof points[i][k] == 'string' && WIDGETS[points[i][k]]) {
|
||||
data[i][k] = WIDGETS[points[i][k]][WIDGETS[points[i][k]].length-1].getValue()
|
||||
let widget = WidgetManager.getWidgetById(points[i][k])
|
||||
if (typeof points[i][k] == 'string' && widget.length) {
|
||||
data[i][k] = widget[widget.length-1].getValue()
|
||||
} else {
|
||||
data[i][k] = points[i][k]
|
||||
}
|
||||
|
|
@ -85,5 +89,5 @@ Plot.prototype.constructor = Plot
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var plot = new Plot(widgetData)
|
||||
return plot.widget
|
||||
return plot
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
var {iconify} = require('../../utils')
|
||||
var {iconify} = require('../../utils'),
|
||||
_widgets_base = require('../common/_widgets_base')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'text',
|
||||
|
|
@ -21,31 +23,44 @@ module.exports.options = {
|
|||
preArgs:[],
|
||||
address:'auto',
|
||||
}
|
||||
module.exports.create = function(widgetData,container) {
|
||||
var widget = $(`
|
||||
|
||||
var Text = module.exports.Text = function(widgetData,container) {
|
||||
|
||||
_widgets_base.apply(this,arguments)
|
||||
|
||||
|
||||
this.widget = $(`
|
||||
<div class="text">
|
||||
</div>
|
||||
`),
|
||||
label = widgetData.label===false?
|
||||
widgetData.id:
|
||||
widgetData.label=='auto'?
|
||||
`)
|
||||
|
||||
this.defaultValue = widgetData.label===false?
|
||||
widgetData.id:
|
||||
widgetData.label,
|
||||
text = label
|
||||
widgetData.label=='auto'?
|
||||
widgetData.id:
|
||||
widgetData.label
|
||||
|
||||
this.value = this.defaultValue
|
||||
|
||||
|
||||
if (widgetData.vertical) widget.addClass('vertical')
|
||||
if (this.widgetData.vertical) this.widget.addClass('vertical')
|
||||
|
||||
widget.setValue = function(v){
|
||||
text = typeof v=='object' && !v.length?label:v
|
||||
widget.html(iconify(text))
|
||||
}
|
||||
this.setValue(this.value)
|
||||
|
||||
widget.getValue = function(){
|
||||
return text
|
||||
}
|
||||
|
||||
widget.setValue(label)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
Text.prototype = Object.create(_widgets_base.prototype)
|
||||
|
||||
Text.prototype.constructor = Text
|
||||
|
||||
Text.prototype.setValue = function(v){
|
||||
|
||||
this.value = typeof v=='object' && !v.length ? this.defaultValue : v
|
||||
this.widget.html(iconify(this.value))
|
||||
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData, container) {
|
||||
var text = new Text(widgetData, container)
|
||||
return text
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
var {mapToScale, clip} = require('../utils'),
|
||||
_plots_base = require('./_plots_base')
|
||||
_plots_base = require('./_plots_base'),
|
||||
{WidgetManager} = require('../../managers')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'visualizer',
|
||||
|
|
@ -50,7 +52,7 @@ Visualizer.prototype = Object.create(_plots_base.prototype)
|
|||
Visualizer.prototype.constructor = Visualizer
|
||||
|
||||
Visualizer.prototype.syncHandle = function(e) {
|
||||
if (this.widgetData.widgetId!=e.id || !WIDGETS[e.id]) return
|
||||
if (this.widgetData.widgetId!=e.id || !WidgetManager.getWidgetById(e.id).length) return
|
||||
this.startLoop()
|
||||
}
|
||||
|
||||
|
|
@ -101,10 +103,11 @@ Visualizer.prototype.draw_data = function(){
|
|||
|
||||
|
||||
Visualizer.prototype.updateData = function(){
|
||||
var id = this.widgetData.widgetId
|
||||
var id = this.widgetData.widgetId,
|
||||
widget = WidgetManager.getWidgetById(id)
|
||||
|
||||
if (typeof id == 'string' && WIDGETS[id]) {
|
||||
var v = WIDGETS[id][WIDGETS[id].length-1].getValue()
|
||||
if (typeof id == 'string' && widget.length) {
|
||||
var v = widget[widget.length-1].getValue()
|
||||
this.data.push(v)
|
||||
this.value = v
|
||||
} else {
|
||||
|
|
@ -123,5 +126,5 @@ Visualizer.prototype.setValue = function(v) {
|
|||
|
||||
module.exports.create = function(widgetData,container) {
|
||||
var visualizer = new Visualizer(widgetData)
|
||||
return visualizer.widget
|
||||
return visualizer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,14 +66,9 @@ var _sliders_base = module.exports = function(){
|
|||
}
|
||||
|
||||
this.input.change(function(){
|
||||
this.widget.setValue(parseFloat(this.input.val()),{sync:true,send:true})
|
||||
this.setValue(parseFloat(this.input.val()),{sync:true,send:true})
|
||||
}.bind(this))
|
||||
|
||||
this.widget.getValue = function(){
|
||||
return this.value
|
||||
}.bind(this)
|
||||
|
||||
this.widget.setValue = this.setValue.bind(this)
|
||||
|
||||
this.setValue(this.originValue)
|
||||
|
||||
|
|
|
|||
|
|
@ -296,5 +296,5 @@ Fader.prototype.draw = function(){
|
|||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
var fader = new Fader(widgetData, container)
|
||||
return fader.widget
|
||||
return fader
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,5 +243,5 @@ Knob.prototype.draw = function(){
|
|||
|
||||
module.exports.create = function(widgetData) {
|
||||
var knob = new Knob(widgetData)
|
||||
return knob.widget
|
||||
return knob
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue