- new visualizer widget

- removed setValue/getValue method where useless
- don't store/recall widget's that don't have these methods
- purge global WIDGETS list after editing
This commit is contained in:
jean-emmanuel 2016-03-14 18:26:19 +01:00
parent fc86609875
commit b5d4606019
14 changed files with 206 additions and 29 deletions

File diff suppressed because one or more lines are too long

View file

@ -29,8 +29,13 @@ module.exports = {
stateGet: function (){
var data = []
$.each(WIDGETS,function(i,widget) {
var v = widget[widget.length-1].getValue()
if (v!=undefined) data.push(i+' '+v)
for (var j=widget.length-1;j>=0;j--) {
if (widget[j].getValue) {
var v = widget[j].getValue()
if (v!=undefined) data.push(i+' '+v)
break
}
}
})
return data.join('\n')
},
@ -66,7 +71,12 @@ module.exports = {
setTimeout(function(){
if (WIDGETS[data[0]]!=undefined) {
WIDGETS[data[0]][WIDGETS[data[0]].length-1].setValue(data[1].split(','),send,true)
for (var i=WIDGETS[data[0]].length-1;i>=0;i--) {
if (WIDGETS[data[0]][i].setValue) {
WIDGETS[data[0]][i].setValue(data[1].split(','),send,true)
break
}
}
}
},i)
})

View file

@ -76,6 +76,13 @@ var updateDom = function(container,data) {
// restore state
for (i in WIDGETS) {
for (j in WIDGETS[i]) {
if (!document.contains(WIDGETS[i][j][0])) {
WIDGETS[i].splice(j,1)
}
}
}
actions.stateSet(state,false)
sync()
@ -83,6 +90,7 @@ var updateDom = function(container,data) {
ui.scrolls()
$('#sidepanel').scrollTop(scroll)
// return updated node
return newContainer

View file

@ -2,6 +2,7 @@ var strip = require('./widgets/strip'),
panel = require('./widgets/panel'),
led = require('./widgets/led'),
plot = require('./widgets/plot'),
visualizer = require('./widgets/visualizer'),
fader = require('./widgets/fader'),
knob = require('./widgets/knob'),
xy = require('./widgets/xy'),
@ -18,6 +19,7 @@ module.exports.widgetOptions = {
panel: panel.options,
led: led.options,
plot: plot.options,
visualizer: visualizer.options,
fader: fader.options,
knob: knob.options,
xy: xy.options,
@ -35,6 +37,7 @@ module.exports.createWidget = {
panel: panel.create,
led: led.create,
plot: plot.create,
visualizer: visualizer.create,
fader: fader.create,
knob: knob.create,
xy: xy.create,
@ -52,7 +55,7 @@ module.exports.categories = {
'Buttons':['toggle','push','switch'],
'Pads':['xy','rgb'],
'Matrix':['multifader','multitoggle','multipush'],
'Plots':['plot','led'],
'Plots':['plot','visualizer','led'],
'Containers':['panel','strip']
}

View file

@ -32,8 +32,9 @@ module.exports.create = function(widgetData,container) {
if (widgetData.color!='auto') led.css('background-color',widgetData.color)
widget.setValue = function(v){
led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],widgetData.precision,widgetData.logScale))
widget.setValue = function(v,send,sync){
led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],widgetData.precision,widgetData.logScale,true))
if (sync) widget.trigger('sync',[widgetData.id,widget])
}
widget.getValue = function(){return}
return widget

View file

@ -59,9 +59,5 @@ module.exports.create = function(widgetData,container) {
widget.delegateDrag()
widget.getValue = function() {}
widget.setValue = function() {}
return widget
}

View file

@ -52,9 +52,5 @@ module.exports.create = function(widgetData,container) {
widget.delegateDrag()
widget.getValue = function() {}
widget.setValue = function() {}
return widget
}

View file

@ -52,9 +52,5 @@ module.exports.create = function(widgetData,container) {
widget.delegateDrag()
widget.getValue = function() {}
widget.setValue = function() {}
return widget
}

View file

@ -35,7 +35,5 @@ module.exports.create = function(widgetData,container) {
} else {
parsewidgets(widgetData.widgets,widget)
}
widget.getValue = function(){return}
widget.setValue = function(){return}
return widget
}

View file

@ -183,7 +183,5 @@ module.exports.create = function(widgetData,container) {
widget.data = data
}
widget.getValue = function(){return}
widget.setValue = function(){return}
return widget
}

View file

@ -30,8 +30,8 @@ module.exports.create = function(widgetData,container) {
} else {
container.addClass('vertical')
}
parsewidgets(widgetData.widgets,widget)
widget.getValue = function(){return}
widget.setValue = function(){return}
return widget
}

View file

@ -0,0 +1,152 @@
var utils = require('./utils'),
mapToScale = utils.mapToScale
module.exports.options = {
type:'visualizer',
id:'auto',
separator1:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
css:'',
separator2:'plot',
curve:'',
duration:1,
range: {min:0,max:1},
logScale: false,
}
module.exports.create = function(widgetData,container) {
var widget = $(`
<div class="plot">
<canvas></canvas>
</div>
`),
canvas = widget.find('canvas'),
ctx = canvas[0].getContext('2d')
widget.height = undefined
widget.width = undefined
widget.visible = false
widget.lineColor = String(getComputedStyle(document.documentElement).getPropertyValue("--color-accent")).trim()
widget.textColor = String(getComputedStyle(document.documentElement).getPropertyValue("--color-text-fade")).trim()
widget.pips = {
min: Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min,
max: Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max
}
widget.length = 60*widgetData.duration
widget.data = new Array(widget.length)
canvas.resize(function(){
var width = canvas.width(),
height = canvas.height()
if (height==100 && width==100) return
if (!self.visible) {
widget.visible = true
canvas.addClass('visible')
}
widget.height=height
widget.width=width
canvas[0].setAttribute('width',width)
canvas[0].setAttribute('height',height)
requestAnimationFrame(widget.draw)
})
$('body').on('sync',function(e,id,w){
if (widgetData.curve!=id || !document.contains(widget[0])) return
if (widget.cancel) clearTimeout(widget.cancel)
widget.cancel = setTimeout(function(){
clearInterval(widget.loop)
widget.loop = false
},1000*widgetData.duration)
if (widget.loop) return
widget.loop = widget.createLoop()
})
widget.cancel = false
widget.loop = false
widget.createLoop = function(){
return setInterval(function(){
widget.fetchValue()
widget.draw()
},1000*widgetData.duration/widget.length)
}
widget.draw = function(){
ctx.clearRect(0,0,widget.width,widget.height)
ctx.beginPath()
var first = true
var point = []
for (var i=widget.length-1;i>=0;i=i-1) {
var newpoint = [
mapToScale(i,[0,widget.length-1],[15,widget.width-15],1),
mapToScale(widget.data[i],[widgetData.range.min,widgetData.range.max],[widget.height-15,15],1,widgetData.logScale,true),
]
if (first) {
ctx.moveTo(newpoint[0],newpoint[1])
first = false
} else {
if (widgetData.logScale) {
ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
} else {
ctx.lineTo(newpoint[0],newpoint[1])
}
}
point = newpoint
}
ctx.lineWidth = 1.5
ctx.strokeStyle= widget.lineColor
ctx.stroke()
ctx.font = '10px sans-serif'
ctx.fillStyle = widget.textColor
ctx.save()
ctx.translate(0, widget.height)
ctx.rotate(-Math.PI/2)
ctx.textBaseline = "top"
ctx.textAlign = 'left'
ctx.fillText(widget.pips.min,12,2)
ctx.textAlign = 'right'
ctx.fillText(widget.pips.max,widget.height-10,2)
ctx.rotate(Math.PI/2)
ctx.restore()
}
widget.fetchValue = function(){
var id = widgetData.curve
if (!typeof id == 'string' || !WIDGETS[id] || !WIDGETS[id].length ) return
widget.data.push(WIDGETS[id][WIDGETS[id].length-1].getValue())
widget.data.splice(0,1)
}
return widget
}

View file

@ -516,11 +516,13 @@ a {
list-style:none;
display: flex;
padding:7rem 6rem;
overflow: hidden;
li.on + li {border-image:none;border-left:1rem solid transparent;}
li {
display:block;
max-width:250rem;
min-width:0;
flex: 1;
border-width:0 0 0 1rem;
@ -1825,7 +1827,7 @@ a {
}
}
.plot-container {
.plot-container, .visualizer-container {
min-height: 200rem;
min-width: 200rem;
.plot {

View file

@ -94,8 +94,8 @@
"type": "plot",
"id": "plot_1",
"label": "plot_1",
"left": "auto",
"top": "auto",
"left": 406,
"top": 215,
"width": "auto",
"height": "auto",
"css": "",
@ -127,7 +127,24 @@
},
"logScaleX": false,
"logScaleY": false
},
{
"type": "visualizer",
"left": 406,
"top": 7,
"width": "auto",
"height": "auto",
"css": "",
"id": "visualizer_(fader_1)",
"curve": "fader_1",
"duration": 1,
"range": {
"min": 0,
"max": 1
},
"logScale": false,
"label": "visualizer (fader1)"
}
]
}
]
]