`)
})
@@ -167,7 +186,7 @@ class Panel extends Container() {
this.value = v
this.tabs[v].show()
- DOM.each(this.navigation, 'li', (el)=>{el.classList.remove('on')})[v].classList.add('on')
+ DOM.each(this.navigation, 'div', (el)=>{el.classList.remove('on')})[v].classList.add('on')
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
@@ -192,9 +211,18 @@ class Panel extends Container() {
switch (propName) {
- case 'color':
+ case 'traversing':
+ this.setTraversing()
+ return
+
+ case 'colorWidget':
+ case 'colorFill':
+ case 'colorStroke':
+ case 'alphaStroke':
+ case 'alphaFillOff':
+ case 'alphaFillOn':
for (var w of this.children) {
- if (w) w.onPropChanged('color')
+ if (w) w.onPropChanged(propName)
}
return
@@ -202,6 +230,30 @@ class Panel extends Container() {
}
+ setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) {
+
+ super.setContainerStyles(styles)
+
+ if (styles.includes('color') && this.getProp('scroll')) {
+
+ setScrollbarColor(this.container)
+
+ }
+
+ }
+
+ setTraversing(update) {
+
+ var traversing = this.getProp('traversing')
+
+ disableTraversingGestures(this.widget)
+
+ if (traversing) {
+ enableTraversingGestures(this.widget, {smart: typeof traversing === 'string' && traversing.match(/smart|auto/)})
+ }
+
+ }
+
onRemove() {
this.off('resize')
@@ -211,7 +263,8 @@ class Panel extends Container() {
}
Panel.dynamicProps = Panel.prototype.constructor.dynamicProps.concat(
- 'variables'
+ 'variables',
+ 'traversing'
)
module.exports = Panel
diff --git a/src/client/app/widgets/containers/root.js b/src/client/app/widgets/containers/root.js
index df63ccfc..fb7e8f97 100644
--- a/src/client/app/widgets/containers/root.js
+++ b/src/client/app/widgets/containers/root.js
@@ -1,11 +1,11 @@
var Panel = require('./panel'),
Widget = require('../common/widget'),
+ StaticProperties = require('../mixins/static_properties'),
{icon} = require('../../ui/utils'),
- {enableTraversingGestures, disableTraversingGestures} = require('../../events/drag'),
html = require('nanohtml'),
raw = require('nanohtml/raw')
-class Root extends Panel {
+class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'root'}) {
static description() {
@@ -15,17 +15,22 @@ class Root extends Panel {
static defaults() {
- return Widget.defaults({}, ['label', '_geometry', 'left', 'top', 'width', 'height'], {
+ return Widget.defaults({
+
+
+ _panel:'panel',
+
+ traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
+ variables: {type: '*', value: '', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
+
+ }, ['label', '_geometry', 'left', 'top', 'width', 'height', 'scroll'], {
_children:'children',
- traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
- variables: {type: '*', value: {}, help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
- tabs: {type: 'array', value: [{}], help: 'Each element of the array must be a tab object'},
- id: {type: 'string', value: 'root', help: 'Widgets sharing the same id will act as clones and update each other\'s value(s) without sending extra osc messages' },
+ tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'},
value: {type: 'integer', value: '', help: [
- 'Defines currently opened tab in the widget',
+ 'Defines currently widgeted tab in the widget',
'A tab can be opened only by setting its parent\'s value'
]},
@@ -36,22 +41,15 @@ class Root extends Panel {
constructor(options) {
options.root = true
- options.props.id = 'root'
- options.props.scroll = true
- options.props.label = false
super(options)
this.widget.classList.add('root')
- this.disabledProps.push('id')
-
DOM.each(this.widget, '> .navigation', (el)=>{
el.classList.add('main')
})
- if (this.getProp('traversing')) this.setTraversing()
-
}
createNavigation() {
@@ -59,43 +57,15 @@ class Root extends Panel {
super.createNavigation()
this.navigation.appendChild(html`
-
`)
}
- setTraversing(update) {
-
- var traversing = this.getProp('traversing')
-
- disableTraversingGestures(this.widget)
-
- if (traversing) {
- enableTraversingGestures(this.widget, {smart: typeof traversing === 'string' && traversing.match(/smart|auto/)})
- }
-
- }
-
- onPropChanged(propName, options, oldPropValue) {
-
- if (super.onPropChanged(...arguments)) return true
-
- switch (propName) {
-
- case 'traversing':
- this.setTraversing()
- return
-
- }
-
- }
}
-Root.dynamicProps = Root.prototype.constructor.dynamicProps.concat(
- 'traversing'
-)
module.exports = Root
diff --git a/src/client/app/widgets/containers/strip.js b/src/client/app/widgets/containers/strip.js
deleted file mode 100644
index 297c59f6..00000000
--- a/src/client/app/widgets/containers/strip.js
+++ /dev/null
@@ -1,66 +0,0 @@
-var Panel = require('./panel'),
- Widget = require('../common/widget')
-
-module.exports = class Strip extends Panel {
-
- static description() {
-
- return 'Widget container that display its children in a single column or row.'
-
- }
-
- static defaults() {
-
- return Widget.defaults({
-
- _strip: 'strip',
-
- scroll: {type: 'boolean', value: true, help: 'Set to `false` to disable scrollbars'},
- horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display widgets horizontally'},
- stretch: {type: 'boolean', value: false, help: 'Set to `true` to stretch widgets evenly'},
- border: {type: 'boolean', value: true, help: 'By default, widgets in panels/strip have their border disabled, except for panels and strips. Set to `false` to apply this rule to the panel too'},
- spacing: {type: 'integer|percentage', value: 0, help: 'Adds space between widgets. Percents are always relative to the strips width'}
-
- }, [], {
-
- _children:'children',
-
- variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
- widgets: {type: 'array', value: [], help: [
- 'Each element of the array must be a widget object',
- '- By default, children widgets that don\'t have an explicit `width`/`height` set will be shrinked to respect the sizes specified by others',
- '- Adding `flex:1;` to a children\'s `css` will give it the ability the fill the remaining space',
- '- Multiple children can have a `flex:x;` css property (`x` will ponderate their expansion)'
- ]}
-
- })
-
- }
-
- constructor(options) {
-
- var defaults = Panel.defaults()._props()
- for (var k in defaults) {
- if (!options.props.hasOwnProperty(k))
- options.props[k] = defaults[k]
- }
-
- super(options)
-
- this.disabledProps = []
-
- if (this.getProp('spacing')) {
- var spacing = this.getProp('spacing')
- if (!isNaN(spacing)) spacing += 'rem'
- this.widget.style.setProperty('--spacing', spacing)
- }
-
- this.container.classList.add(this.getProp('horizontal') ? 'horizontal' : 'vertical')
- if (this.getProp('stretch')) this.container.classList.add('stretch')
-
- }
-
- setValue(){}
- getValue(){}
-
-}
diff --git a/src/client/app/widgets/containers/tab.js b/src/client/app/widgets/containers/tab.js
index d6089805..eaf5b198 100644
--- a/src/client/app/widgets/containers/tab.js
+++ b/src/client/app/widgets/containers/tab.js
@@ -1,8 +1,9 @@
var Panel = require('./panel'),
Widget = require('../common/widget'),
+ StaticProperties = require('../mixins/static_properties'),
resize = require('../../events/resize')
-module.exports = class Tab extends Panel {
+module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) {
static description() {
@@ -16,18 +17,20 @@ module.exports = class Tab extends Panel {
_tab:'tab',
- detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'}
+ detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'},
+ layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal'], help:''},
+ traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
+ variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
- }, ['_geometry', 'left', 'top', 'width', 'height'], {
+ }, ['_geometry', 'left', 'top', 'width', 'height', 'scroll'], {
_children:'children',
- variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
- widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object. A tab cannot contain widgets and tabs simultaneously'},
- tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A tab cannot contain widgets and tabs simultaneously'},
+ widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object. A panel cannot contain widgets and tabs simultaneously.'},
+ tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'},
value: {type: 'integer', value: '', help: [
- 'Defines currently opened tab in the widget',
+ 'Defines currently widgeted tab in the widget',
'A tab can be opened only by setting its parent\'s value'
]},
@@ -37,12 +40,9 @@ module.exports = class Tab extends Panel {
constructor(options) {
- options.props.scroll = true
-
super(options)
this.container.classList.add('show')
- this.widget.classList.add('tab')
this.detached = false
@@ -69,8 +69,14 @@ module.exports = class Tab extends Panel {
switch (propName) {
+ case 'visible':
case 'label':
- case 'color':
+ case 'colorWidget':
+ case 'colorFill':
+ case 'colorStroke':
+ case 'alphaStroke':
+ case 'alphaFillOff':
+ case 'alphaFillOn':
if (this.parent.createNavigation) this.parent.createNavigation()
return
diff --git a/src/client/app/widgets/plots/frame.js b/src/client/app/widgets/frames/frame.js
similarity index 91%
rename from src/client/app/widgets/plots/frame.js
rename to src/client/app/widgets/frames/frame.js
index fcd6e4b5..6f67c92e 100644
--- a/src/client/app/widgets/plots/frame.js
+++ b/src/client/app/widgets/frames/frame.js
@@ -20,7 +20,7 @@ class Frame extends StaticProperties(Widget, {bypass: true}) {
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
- }, ['color', 'precision', 'bypass'], {
+ }, ['precision', 'bypass'], {
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
@@ -37,7 +37,11 @@ class Frame extends StaticProperties(Widget, {bypass: true}) {
constructor(options) {
- super({...options, html: html``})
+ super({...options, html: html`
+
+
+ `
+ })
if (!this.getProp('border')) this.container.classList.add('noborder')
diff --git a/src/client/app/widgets/plots/html.js b/src/client/app/widgets/frames/html.js
similarity index 91%
rename from src/client/app/widgets/plots/html.js
rename to src/client/app/widgets/frames/html.js
index fa2b18da..09949db7 100644
--- a/src/client/app/widgets/plots/html.js
+++ b/src/client/app/widgets/frames/html.js
@@ -31,16 +31,13 @@ class Html extends StaticProperties(Widget, {bypass: true}) {
]},
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
- }, ['color', 'precision', 'bypass'], {})
+ }, ['precision', 'bypass'], {})
}
constructor(options) {
- super({...options, html: html`
-
-
- `})
+ super({...options, html: html``})
if (!this.getProp('border')) this.container.classList.add('noborder')
diff --git a/src/client/app/widgets/plots/image.js b/src/client/app/widgets/frames/image.js
similarity index 93%
rename from src/client/app/widgets/plots/image.js
rename to src/client/app/widgets/frames/image.js
index 5cd61125..eeed4c72 100644
--- a/src/client/app/widgets/plots/image.js
+++ b/src/client/app/widgets/frames/image.js
@@ -27,7 +27,7 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
'When true, sending `reload` to the widget reloads its image without changing its value'
]}
- }, ['color', 'precision', 'bypass'], {
+ }, ['precision', 'bypass'], {
value: {type: 'string', value: '', help: [
'- File `url` or `path` (relative to the session file location by default, falling back to absolute path)',
@@ -40,7 +40,7 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
constructor(options) {
- super({...options, html: html``})
+ super({...options, html: html``})
if (!this.getProp('border')) this.container.classList.add('noborder')
@@ -93,7 +93,6 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
onRemove() {
- if (this.bindedOnStreamUpdate) ipc.off('video', this.bindedOnStreamUpdate)
super.onRemove()
}
diff --git a/src/client/app/widgets/plots/svg.js b/src/client/app/widgets/frames/svg.js
similarity index 95%
rename from src/client/app/widgets/plots/svg.js
rename to src/client/app/widgets/frames/svg.js
index 5ed6b395..3220e59b 100644
--- a/src/client/app/widgets/plots/svg.js
+++ b/src/client/app/widgets/frames/svg.js
@@ -26,16 +26,16 @@ class Svg extends StaticProperties(Widget, {bypass: true}) {
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
- }, ['color', 'precision', 'bypass'], {})
+ }, ['precision', 'bypass'], {})
}
constructor(options) {
super({...options, html: html`
-
+
-
+
`})
this.height = undefined
diff --git a/src/client/app/widgets/plots/_biquad_response.js b/src/client/app/widgets/graphs/eq.js
similarity index 56%
rename from src/client/app/widgets/plots/_biquad_response.js
rename to src/client/app/widgets/graphs/eq.js
index f3345a96..dd68e0ee 100644
--- a/src/client/app/widgets/plots/_biquad_response.js
+++ b/src/client/app/widgets/graphs/eq.js
@@ -1,10 +1,119 @@
+var {clip} = require('../utils'),
+ Plot = require('./plot')
+
+module.exports = class Eq extends Plot {
+
+ static description() {
+
+ return 'Draws frequency response between from from an array of filter objects.'
+
+ }
+
+ static defaults() {
+
+ return super.defaults({
+
+ _eq:'eq',
+
+ pips: {type: 'boolean', value: true, help: 'Set to false to hide the scale'},
+ resolution: {type: 'number', value: 128, help: 'Defines the number of points used to compute the frequency response'},
+ rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
+ origin: {type: 'number|boolean', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'},
+ logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
+ smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
+
+ }, ['precision', 'bypass'], {
+
+ value: {type: 'array', value: '', help: [
+ 'Each item must be an object with the following properties',
+ '- `type`: string ("highpass", "highshelf", "lowpass", "lowshelf", "peak" or "notch")',
+ '- `freq`: number (filter\'s resonant frequency)',
+ '- `q`: number (Q factor)',
+ '- `gain`: number',
+ '- `on`: boolean',
+
+ ]}
+
+ })
+
+ }
+
+ constructor(options) {
+
+ // backward compat
+ if (options.props.filters && options.props.filters.length) {
+ options.props.value = options.props.filters
+ delete options.props.filters
+ }
+
+ super(options)
+
+ this.rangeX = {min:20,max:22050}
+ this.pips.x.min = '20'
+ this.pips.x.max = '22k'
+
+ this.resolution = clip(this.getProp('resolution'),[64,1024])
+
+ }
+
+ setValue(v, options={}) {
+
+ if (typeof v == 'string') {
+ try {
+ v = JSON.parseFlex(v)
+ } catch(err) {}
+ }
+
+ if (Array.isArray(v)) {
+
+ var filters = v,
+ eqResponse = []
+
+ if (v.length === this.resolution) {
+
+ eqResponse = v
+
+ } else {
+
+ for (let i in filters) {
+
+ var filterResponse
+
+ if (!filters[i].type) filters[i].type = 'peak'
+
+ if (!filters[i].on) {
+ filterResponse = calcBiquad({type:'peak',freq:1,gain:0,q:1},!this.getProp('logScaleX'), this.resolution)
+ } else {
+ filterResponse = calcBiquad(filters[i],!this.getProp('logScaleX'), this.resolution)
+ }
+
+ for (var k in filterResponse) {
+ if (eqResponse[k]===undefined) {
+ eqResponse[k]=[0,0]
+ }
+
+ eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
+ }
+
+ }
+
+ }
+
+ if (eqResponse.length) super.setValue(eqResponse, options)
+
+ }
+
+ }
+
+}
+
//
// calcBiquad
//
// Dec 14, 2010 njr
// original @ Nigel Redmon
-module.exports = function(options,linear,resolution) {
+function calcBiquad(options,linear,resolution) {
var {type, freq, q, gain} = options,
Fs = 44100,
a0,a1,a2,b1,b2,norm,
diff --git a/src/client/app/widgets/graphs/plot.js b/src/client/app/widgets/graphs/plot.js
new file mode 100644
index 00000000..1c6fa184
--- /dev/null
+++ b/src/client/app/widgets/graphs/plot.js
@@ -0,0 +1,246 @@
+var {mapToScale} = require('../utils'),
+ Canvas = require('../common/canvas'),
+ html = require('nanohtml'),
+ StaticProperties = require('../mixins/static_properties')
+
+module.exports = class Plot extends StaticProperties(Canvas, {bypass: true}) {
+
+ static description() {
+
+ return 'XY coordinates plot.'
+
+ }
+
+ static defaults() {
+
+
+ return super.defaults({
+
+ _plot:'plot',
+
+ rangeX: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the x axis'},
+ rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
+ logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'},
+ logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
+ origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it.'},
+ dots: {type: 'boolean', value: true, help: ''},
+ bars: {type: 'boolean', value: false, help: 'Set to `true` to use draw bars instead (disables `logScaleX` and forces `x axis` even spacing)'},
+ smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
+ pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'},
+
+ }, ['precision', 'bypass'], {
+
+ value: {type: 'array|string', value: '', help: [
+ '- `Array` of `y` values',
+ '- `Array` of `[x, y]` `array` values',
+ '- `String` `array`',
+ '- `String` `object` to update specific coordinates only: `{0:1, 4:0}` will change the 1st and 5th points\' coordinates',
+ ]}
+
+ })
+
+ }
+
+ constructor(options) {
+
+ super({...options, html: html`
+
+
+
+ `})
+
+ this.value = []
+ this.rangeX = this.getProp('rangeX') || {min:0,max:1}
+ this.rangeY = this.getProp('rangeY') || {min:0,max:1}
+ this.logScaleX = this.getProp('logScaleX')
+ this.logScaleY = this.getProp('logScaleY')
+ this.pips = {
+ x : {
+ min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
+ max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max
+ },
+ y : {
+ min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min,
+ max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max
+ }
+ }
+ this.smooth = this.getProp('smooth') === true ? 0.25 : this.getProp('smooth') === false ? 0 : parseFloat(this.getProp('smooth')) || 0
+
+ }
+
+ draw() {
+
+ this.ctx.clearRect(0,0,this.width,this.height)
+
+ if (this.getProp('bars')) {
+ this.draw_bars()
+ } else {
+ var points = this.draw_line()
+ if (this.getProp('dots')) {
+ this.draw_dots(points)
+ }
+ }
+
+ if (this.getProp('pips')) this.draw_pips()
+
+ }
+
+ draw_pips() {
+
+ this.ctx.globalAlpha = 1
+ this.ctx.fillStyle = this.colors.textFade
+
+ var margin = this.cssVars.padding
+
+ if (margin < this.fontSize * 1.5) return
+
+
+ if (this.pips.x) {
+
+ this.ctx.textAlign = 'center'
+ this.ctx.fillText(this.pips.x.min, margin, this.height - margin / 2)
+ this.ctx.fillText(this.pips.x.max, this.width - margin, this.height - margin / 2)
+
+ }
+
+ if (this.pips.y) {
+
+ this.ctx.textAlign = 'right'
+ this.ctx.fillText(this.pips.y.min, margin / 2 + this.fontSize / 2, this.height - margin)
+ this.ctx.fillText(this.pips.y.max, margin / 2 + this.fontSize / 2, margin)
+
+ }
+
+ }
+
+ draw_line() {
+
+ var points = [],
+ padding = this.cssVars.padding + PXSCALE,
+ x, y
+
+ for (let i in this.value) {
+
+ if (this.value[i].length) {
+ points.push(mapToScale(this.value[i][0], [this.rangeX.min, this.rangeX.max], [padding, this.width - padding], 0, this.logScaleX, true))
+ points.push(mapToScale(this.value[i][1], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE, 2 * PXSCALE], 0, this.logScaleY, true))
+ } else {
+ let nx = mapToScale(i, [0, this.value.length - 1], [padding, this.width - padding], 0, this.logScaleX, true),
+ ny = mapToScale(this.value[i], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE - padding, 2 * PXSCALE + padding], 0, this. logScaleY, true)
+ if (x !== nx || y !== ny) {
+ points.push(nx)
+ points.push(ny)
+ x = nx
+ y = ny
+ }
+ }
+
+ }
+
+ if (points.length < 4) return points
+
+ this.ctx.beginPath()
+
+ if (this.getProp('smooth')) {
+ this.ctx.curve(points, this.smooth, Math.round(this.width/(points.length/2 - 1)))
+ } else {
+ this.ctx.moveTo(points[0], points[1])
+ let i
+ for (i = 2; i < points.length - 2; i += 2) {
+ this.ctx.lineTo(points[i], points[i + 1])
+ }
+ this.ctx.lineTo(points[i], points[i + 1])
+ }
+
+
+
+ this.ctx.globalAlpha = 1
+ this.ctx.lineWidth = 2 * PXSCALE
+ this.ctx.strokeStyle = this.cssVars.colorWidget
+ this.ctx.stroke()
+
+ if (this.getProp('origin') !== false) {
+
+ var origin = mapToScale(this.getProp('origin'), [this.rangeY.min, this.rangeY.max], [this.height - padding, padding], 0, this.getProp('logScaleY'), true)
+
+ this.ctx.globalAlpha = this.cssVars.alphaFillOn
+ this.ctx.fillStyle = this.cssVars.colorFill
+ this.ctx.lineTo(this.width - padding, origin)
+ this.ctx.lineTo(padding, origin)
+ this.ctx.closePath()
+ this.ctx.fill()
+
+ }
+
+ return points
+
+ }
+
+ draw_dots(points) {
+
+ this.ctx.globalAlpha = 1
+ this.ctx.fillStyle = this.cssVars.colorWidget
+ this.ctx.strokeStyle = this.cssVars.colorForeground
+ this.ctx.lineWidth = 2 * PXSCALE
+ for (var i = 0; i < points.length; i += 2) {
+ this.ctx.beginPath()
+ this.ctx.arc(points[i], points[i + 1], 3 * PXSCALE, 0, 2*Math.PI)
+ this.ctx.fill()
+ this.ctx.stroke()
+ }
+
+ }
+
+ draw_bars() {
+
+ var barWidth = Math.round(this.width / this.value.length),
+ offset = Math.round((this.width - barWidth * this.value.length) / 2)
+
+ var origin = mapToScale(this.getProp('origin') !== false ? this.getProp('origin') : this.rangeY.min, [this.rangeY.min,this.rangeY.max],[this.height,0],0,this.getProp('logScaleY'),true)
+
+ this.ctx.beginPath()
+
+ for (let i in this.value) {
+ var y = mapToScale(this.value[i].length ? this.value[i][1] : this.value[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true)
+ this.ctx.rect(offset + i * barWidth, Math.min(y, origin), barWidth - PXSCALE, Math.abs(Math.min(y - origin)))
+
+ }
+
+ this.ctx.globalAlpha = 0.4
+ this.ctx.fillStyle = this.colors.custom
+ this.ctx.fill()
+
+ }
+
+ setValue(v, options={}) {
+
+ if (typeof v == 'string') {
+ try {
+ v = JSON.parseFlex(v)
+ } catch(err) {}
+ }
+
+ if (typeof v == 'object' && v !== null) {
+
+ if (Array.isArray(v)) {
+
+ this.value = v
+
+ } else {
+
+ for (var i in v) {
+ if (!isNaN(i)) this.value[i] = v[i]
+ }
+
+ }
+
+ this.batchDraw()
+
+ if (options.sync) this.changed(options)
+
+ }
+
+
+ }
+
+}
diff --git a/src/client/app/widgets/plots/visualizer.js b/src/client/app/widgets/graphs/visualizer.js
similarity index 66%
rename from src/client/app/widgets/plots/visualizer.js
rename to src/client/app/widgets/graphs/visualizer.js
index b96eb461..056173db 100644
--- a/src/client/app/widgets/plots/visualizer.js
+++ b/src/client/app/widgets/graphs/visualizer.js
@@ -1,7 +1,10 @@
var {clip} = require('../utils'),
- _plots_base = require('./_plots_base')
+ Widget = require('../common/widget'),
+ Plot = require('./plot'),
+ StaticProperties = require('../mixins/static_properties')
-module.exports = class Visualizer extends _plots_base {
+
+module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: '', max: ''}, dots: false, smooth: false}) {
static description() {
@@ -11,15 +14,14 @@ module.exports = class Visualizer extends _plots_base {
static defaults() {
- return super.defaults({
+ return Widget.defaults({
_visualizer:'visualizer',
duration: {type: 'number', value: 1, help: 'Defines visualization duration in seconds'},
- range: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
+ rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'},
origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'},
- logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
- smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'},
+ logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'},
pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'},
}, ['precision', 'bypass'], {})
@@ -28,20 +30,9 @@ module.exports = class Visualizer extends _plots_base {
constructor(options) {
- // backward compat
- if (options.props.widgetId) {
- options.props.value = '@{' + options.props.widgetId + '}'
- delete options.props.widgetId
- }
-
super(options)
this.fps = CANVAS_FRAMERATE
- this.pips.y.min = Math.abs(this.getProp('range').min) >= 1000? this.getProp('range').min/1000+'k' : this.getProp('range').min
- this.pips.y.max = Math.abs(this.getProp('range').max) >= 1000? this.getProp('range').max/1000+'k' : this.getProp('range').max
- this.pips.x = false
- this.rangeY = this.getProp('range') || {min:0,max:1}
- this.logScaleY = this.getProp('logScale')
this.length = Math.round(clip(this.fps * this.getProp('duration'), [8, 4096]))
this.value = new Array(this.length).fill(this.rangeY.min)
this.cancel = false
diff --git a/src/client/app/widgets/index.js b/src/client/app/widgets/index.js
index 7e2c1298..98662671 100644
--- a/src/client/app/widgets/index.js
+++ b/src/client/app/widgets/index.js
@@ -11,15 +11,15 @@ module.exports.widgets = {
// buttons
toggle: require('./buttons/toggle'),
- push: require('./buttons/push'),
switch: require('./buttons/switch'),
- dropdown: require('./buttons/dropdown'),
- menu: require('./buttons/menu'),
+ dropdown: require('./buttons/dropdown'), // redo as menu derivate ?
+ menu: require('./buttons/menu'), // redo using canvas
// pads
xy: require('./pads/xy'),
rgb: require('./pads/rgb'),
multixy: require('./pads/multixy'),
+ canvas: require('./pads/canvas'), // implement...
// matrices
matrix: require('./matrices/matrix'),
@@ -27,21 +27,22 @@ module.exports.widgets = {
patchbay: require('./matrices/patchbay').PatchBay,
patchbaynode: require('./matrices/patchbay').PatchBayNode,
- // plots
- led: require('./plots/led'),
- rgbled: require('./plots/rgbled'),
- plot: require('./plots/plot'),
- eq: require('./plots/eq'),
- visualizer: require('./plots/visualizer'),
- meter: require('./plots/meter'),
- text: require('./plots/text'),
- image: require('./plots/image'),
- svg: require('./plots/svg'),
- html: require('./plots/html'),
- frame: require('./plots/frame'),
+ // indicators
+ led: require('./indicators/led'),
+ text: require('./indicators/text'),
+
+ // graphs
+ plot: require('./graphs/plot'),
+ eq: require('./graphs/eq'),
+ visualizer: require('./graphs/visualizer'),
+
+ // frames
+ image: require('./frames/image'),
+ svg: require('./frames/svg'),
+ html: require('./frames/html'),
+ frame: require('./frames/frame'),
// containers
- strip: require('./containers/strip'),
panel: require('./containers/panel'),
modal: require('./containers/modal'),
clone: require('./containers/clone'),
@@ -61,12 +62,20 @@ module.exports.widgets = {
}
module.exports.categories = {
- 'Sliders':['fader','knob', 'encoder', 'range'],
- 'Buttons':['toggle','push','switch', 'dropdown', 'menu'],
- 'Pads':['xy','rgb','multixy'],
+ 'Buttons':['toggle', 'switch', 'dropdown', 'menu'],
+ 'Containers':['panel', 'modal', 'clone'],
+ 'Frames':['frame', 'svg', 'html', 'image'],
+ 'Graphs':['plot','eq','visualizer'],
+ 'Indicator':['led', 'text'],
+ 'Inputs':['input', 'keys', 'script', 'gyroscope', 'file'],
'Matrices':['matrix', 'keyboard', 'patchbay'],
- 'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'html', 'frame'],
- 'Containers':['panel','strip','modal', 'clone'],
+ 'Pads':['xy','rgb','multixy', 'canvas'],
+ 'Sliders':['fader','knob', 'encoder', 'range'],
'Switchers':['state', 'switcher','crossfader'],
- 'Inputs':['input', 'keys', 'script', 'gyroscope', 'file']
}
+
+var defaults = {}
+for (var k in module.exports.widgets) {
+ defaults[k] = module.exports.widgets[k].defaults()
+}
+module.exports.defaults = defaults
diff --git a/src/client/app/widgets/indicators/led.js b/src/client/app/widgets/indicators/led.js
new file mode 100644
index 00000000..9918f62b
--- /dev/null
+++ b/src/client/app/widgets/indicators/led.js
@@ -0,0 +1,102 @@
+var {mapToScale, clip} = require('../utils'),
+ Widget = require('../common/widget'),
+ html = require('nanohtml'),
+ StaticProperties = require('../mixins/static_properties')
+
+module.exports = class Led extends StaticProperties(Widget, {bypass: true}) {
+
+ static description() {
+
+ return 'Intensity display.'
+
+ }
+
+ static defaults() {
+
+ return super.defaults({
+
+ _led:'led',
+
+ mode: {type: 'string', value: 'intensity', choices: ['intensity', 'color'], help: [
+ ''
+ ]},
+ range: {type: 'object', value: {min:0,max:1}, help: 'Value to led intensity mapping range'},
+ logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'},
+ borderRadius: {type: 'string', value: '', help: 'Css border-radius property.'},
+
+ }, ['precision', 'bypass'], {
+
+ value: {type: 'number|array|string', value: '', help: [
+ '- `Number`: if `mode` is set to `intensity`',
+ '- `Array`: `[r, g, b]` (`r`, `g` and `b` between `0` and `255`)',
+ '- `Array`: `[r, g, b, alpha]` (`alpha` between `0` and `255`)',
+ '- `String`: CSS color',
+ ]}
+
+ })
+
+ }
+
+ constructor(options) {
+
+ super({...options, html: html``})
+
+ this.setValueIntensity(this.getProp('mode') === 'intensity' ? this.getProp('range').min : 1)
+
+ var bR = this.getProp('borderRadius')
+ if (parseInt(bR) == bR) bR += 'rem'
+ this.container.style.setProperty('--border-radius', bR)
+
+ }
+
+ setValue(v, options={}) {
+
+
+ var ret = this.getProp('mode') === 'intensity' ? this.setValueIntensity(v) : this.setValueColor(v)
+
+
+ if (options.sync && ret !== false) this.changed(options)
+
+ }
+
+ setValueIntensity(v) {
+
+ if (typeof v != 'number') return false
+
+ this.value = v
+ this.container.style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
+
+
+ }
+
+ setValueColor(v) {
+
+ var c = ''
+
+ if (Array.isArray(v) && v.length >= 3) {
+
+ for (let i in [0,1,2]) {
+ v[i] = parseInt(clip(v[i],[0,255]))
+ }
+
+ v[3] = clip(v[3] != undefined ? v[3] : 1,[0,1])
+
+ c = `rgba(${v[0]}, ${v[1]}, ${v[2]}, ${v[3]})`
+
+ } else if (typeof v == 'string') {
+
+ c = v
+
+ } else {
+
+ return false
+
+ }
+
+ this.value = v
+
+ this.container .style.setProperty('--color-led', c)
+
+ }
+
+}
diff --git a/src/client/app/widgets/plots/text.js b/src/client/app/widgets/indicators/text.js
similarity index 63%
rename from src/client/app/widgets/plots/text.js
rename to src/client/app/widgets/indicators/text.js
index f6aa4fc0..031662c4 100644
--- a/src/client/app/widgets/plots/text.js
+++ b/src/client/app/widgets/indicators/text.js
@@ -22,7 +22,7 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) {
'Set to `true` to wrap long lines automatically.',
'This will not break overflowing words by default, word-breaking can be enabled by adding `word-break: break-all;` to the `css` property',
]},
- align: {type: 'string', value: '', help: 'Set to `left` or `right` to change text alignment (otherwise center)'},
+ align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Css text-align property.'},
}, ['precision', 'bypass'], {})
@@ -30,17 +30,15 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) {
constructor(options) {
- // backward compat
- if (options.props.widgetId) {
- options.props.value = '@{' + options.props.widgetId + '}'
- delete options.props.widgetId
- }
- super({...options, html: html``})
+ super({...options, html: html``})
+
+ this.text = this.widget.appendChild(html``)
+
+ if (this.getProp('vertical')) this.text.classList.add('vertical')
+ if (this.getProp('align') === 'left') this.text.classList.add('left')
+ if (this.getProp('align') === 'right') this.text.classList.add('right')
+ if (this.getProp('wrap')) this.text.classList.add('wrap')
- if (this.getProp('vertical')) this.widget.classList.add('vertical')
- if (this.getProp('align') === 'left') this.widget.classList.add('left')
- if (this.getProp('align') === 'right') this.widget.classList.add('right')
- if (this.getProp('wrap')) this.widget.classList.add('wrap')
this.defaultValue = this.getProp('default') || ( this.getProp('label')===false ?
this.getProp('id'):
@@ -61,9 +59,9 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) {
var s = String(this.value)
if (s.indexOf('^') > -1) {
- this.widget.innerHTML = iconify(s.replace(//g, '>').replace(/\n/g,' '))
+ this.text.innerHTML = iconify(s.replace(//g, '>').replace(/\n/g,' '))
} else {
- this.widget.textContent = s.replace(/\n/g,'\r\n')
+ this.text.textContent = s.replace(/\n/g,'\r\n')
}
if (options.sync) this.changed(options)
diff --git a/src/client/app/widgets/inputs/file.js b/src/client/app/widgets/inputs/file.js
index 39938da1..fe4673a9 100644
--- a/src/client/app/widgets/inputs/file.js
+++ b/src/client/app/widgets/inputs/file.js
@@ -3,7 +3,7 @@ var Widget = require('../common/widget'),
raw = require('nanohtml/raw'),
{remoteBrowse, icon} = require('../../ui/utils')
-module.exports = class Input extends Widget {
+module.exports = class File extends Widget {
static description() {
diff --git a/src/client/app/widgets/inputs/input.js b/src/client/app/widgets/inputs/input.js
index 9dea5330..6d452e67 100644
--- a/src/client/app/widgets/inputs/input.js
+++ b/src/client/app/widgets/inputs/input.js
@@ -16,8 +16,7 @@ module.exports = class Input extends Canvas {
_input:'input',
- vertical: {type: 'boolean', value: false, help: 'Set to `true` to display the text vertically'},
- align: {type: 'string', value: '', help: 'Set to `left` or `right` to change text alignment (otherwise center)'},
+ align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Set to `left` or `right` to change text alignment (otherwise center)'},
unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'},
editable: {type: 'boolean', value: true, help: 'Set to `false` to make the input non-editable'},
asYouType: {type: 'boolean', value: false, help: 'Set to `true` to make the input send its value at each keystroke'}
@@ -29,9 +28,9 @@ module.exports = class Input extends Canvas {
constructor(options) {
super({...options, html: html`
-