widgets: add linkId option where missing, ⚠️ remove plot/input widgetId option

This commit is contained in:
jean-emmanuel 2018-02-13 09:45:10 +01:00
parent 85d255d5a4
commit 6840dc00d0
22 changed files with 54 additions and 246 deletions

View file

@ -2,6 +2,8 @@
## 0.24.0
/!\ BREAKING CHANGES /!\
- bug fixes
- regression preventing dropdown to display no option selected
- crossfaders display issue on iOS
@ -21,7 +23,10 @@
- property maths: added support for math expressions everywhere via `#{}`
- input: add glass effect when `editable` is `false`
- `linkId` can now be set as an array of linkIds
- plot: added `dots` options
- plot: added `dots` options; **removed** `points` options (use `value` and property inheritance instead)
- eq: **removed** `filters` options (use `value` and property inheritance instead)
- plot/meter/led/rgbled/text: **removed** `widgetId` option
- input: **removed** `widgetId` option
## 0.23.1

View file

@ -23,7 +23,7 @@ class Ipc extends EventEmitter {
var client = new Client(socket, id)
this.clients[id] = client
this.emit('connection', client)
client.on('close', ()=>{

View file

@ -10,11 +10,6 @@
}
```
### `widgetId`
- type: `object`
- default: `empty`
- usage: a widget's `id` whose value will be linked to the input
### `editable`
- type: `boolean`
- default: `true`

View file

@ -10,11 +10,6 @@ Plots are tools that display other widgets' state or incomming osc messages. The
}
```
### `widgetId`
- type: `string`
- default: `empty`
- usage: a widget's `id` whose value will be mapped to the led's color opacity
### `range`
- type: `object`
- default: `{"min":0,"max":1}`
@ -52,11 +47,10 @@ The plot receives an array of coordinates and draws them on a chart. Coordinates
}
```
### `points`
### `value`
- type: `array|string`
- default: `[]`
- default: `['']`
- usage:
- as a `string`: a widget's `id` whose values will be used
- as an `array`: where items can be
- `number`
- `string` (widget's `id`)
@ -107,7 +101,7 @@ The Eq receives an array of filter objects and draws their frequency response be
}
```
### `filters`
### `value`
- type: `array`
- default: `[]`
- usage:
@ -161,11 +155,6 @@ The visualizer displays the evolution in time of a received value (through osc)
}
```
### `widgetId`
- type: `string`
- default: `empty`
- usage: a widget's `id` whose value will be displayed (thus bypassing the incoming osc)
### `duration`
- type: `number`
- default: `1`
@ -202,11 +191,6 @@ Text displays incoming values (via osc) as text. Sending a message with no argum
}
```
### `widgetId`
- type: `string`
- default: `empty`
- usage: a widget's `id` whose value will be displayed
### `vertical`
- type: `boolean`
- default: `false`
@ -223,10 +207,6 @@ Meter displays incoming numerical values (via osc) as a gauge level
}
```
### `widgetId`
- type: `object`
- default: `empty`
- usage: a widget's `id` whose value will be displayed
### `horizontal`
- type: `boolean`

View file

@ -59,11 +59,6 @@ var Parser = class Parser {
// Generate default address
props.address = props.address == 'auto' ? '/' + props.id : props.address
// Delete unrecognized options
for (let i in props) {
if (defaults[i]===undefined && i!='type') {delete props[i]}
}
// create container
var widgetContainer = DOM.create(`
<div class="widget ${props.type}-container">

View file

@ -59,7 +59,7 @@ module.exports = {
open() {
if (this.state) return
this.state = 1
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
document.body.appendChild(this.html)

View file

@ -10,6 +10,7 @@ module.exports = class Modal extends Panel {
return {
type:'modal',
id:'auto',
linkId:'',
_geometry:'geometry',

View file

@ -13,6 +13,7 @@ class Panel extends Widget {
return {
type:'panel',
id:'auto',
linkId:'',
_geometry:'geometry',

View file

@ -12,6 +12,7 @@ module.exports = class Root extends Panel {
return {
type:'root',
linkId:'',
_style:'style',

View file

@ -7,6 +7,7 @@ module.exports = class Strip extends Panel {
return {
type:'strip',
id:'auto',
linkId:'',
_style:'style',

View file

@ -11,6 +11,7 @@ module.exports = class Tab extends Panel {
return {
type:'tab',
id:'auto',
linkId:'',
_style:'style',

View file

@ -29,7 +29,6 @@ module.exports = class Input extends Canvas {
vertical:false,
unit: '',
widgetId:'',
editable:true,
value:'',
@ -76,12 +75,6 @@ module.exports = class Input extends Canvas {
this.widget.classList.add('not-editable')
}
if (this.getProp('widgetId').length) {
widgetManager.on(`change.${this.hash}`, this.syncHandle.bind(this))
}
}
focus() {
@ -114,14 +107,6 @@ module.exports = class Input extends Canvas {
}
syncHandle(e) {
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length || !e.widget) return
this.setValue(e.widget.getValue(), {...e.options, internal:true})
}
resizeHandle(event){
super.resizeHandle(event)
@ -149,19 +134,6 @@ module.exports = class Input extends Canvas {
this.value = v
}
if (!options.internal && this.getProp('widgetId').length) {
var widget = widgetManager.getWidgetById(this.getProp('widgetId'))
for (var i=widget.length-1; i>=0; i--) {
if (widget[i].setValue) {
widget[i].setValue(this.value, options)
this.setValue(widget[i].getValue(), {...options, internal:true, sentOnce:options.send})
return
}
}
}
if (options.sentOnce) options.send = false
this.stringValue = this.getStringValue()
this.batchDraw()

View file

@ -11,6 +11,7 @@ module.exports = class Keys extends Widget {
return {
type:'led',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -88,7 +89,6 @@ module.exports = class Keys extends Widget {
var widget = this.getLinkedWidget()
if (widget) {
var v = this.keydownMath.eval({
value: widget.getValue(),
key: e.key,

View file

@ -16,7 +16,6 @@ module.exports = class _plots_base extends Canvas {
super({...options, html: html})
this.data = []
this.linkedWidgets = []
this.rangeX = this.getProp('rangeX') || {min:0,max:1}
this.rangeY = this.getProp('rangeY') || {min:0,max:1}
this.logScaleX = this.getProp('logScaleX')
@ -33,24 +32,6 @@ module.exports = class _plots_base extends Canvas {
}
this.smooth = this.getProp('smooth') === true ? 0.25 : this.getProp('smooth') === false ? 0 : parseFloat(this.getProp('smooth')) || 0
widgetManager.on(`change.${this.hash}`, this.syncHandleProxy.bind(this), this)
}
syncHandleProxy() {
this.syncHandle(...arguments)
}
syncHandle(e) {
if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return
this.updateData()
this.batchDraw()
}
resizeHandle() {

View file

@ -10,6 +10,7 @@ module.exports = class Eq extends _plots_base {
return {
type:'eq',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -27,12 +28,12 @@ module.exports = class Eq extends _plots_base {
_eq:'eq',
pips:true,
filters:[],
resolution:128,
rangeY: {min:-20,max:20},
origin: 'auto',
logScaleX: false,
smooth: false,
value: '',
_osc:'osc',
@ -45,6 +46,9 @@ module.exports = class Eq extends _plots_base {
constructor(options) {
// backward compat
if (options.props.filters && options.props.filters.length) options.props.value = options.props.filters
super(options)
this.rangeX = {min:20,max:22050}
@ -53,45 +57,12 @@ module.exports = class Eq extends _plots_base {
this.resolution = clip(this.getProp('resolution'),[64,1024])
for (let i in this.getProp('filters')) {
for (let j in this.getProp('filters')[i]) {
if (typeof this.getProp('filters')[i][j]=='string' && !(j=='type' && this.getProp('filters')[i][j].match(/peak|notch|highpass|highshelf|lowpass|lowshelf/))) {
this.linkedWidgets.push(this.getProp('filters')[i][j])
}
}
}
}
updateData() {
setValue(v, options={}) {
var filters = [],
eqResponse = []
for (let i in this.getProp('filters')) {
var filter = this.getProp('filters')[i]
filters[i] = {}
for (let j in filter) {
let widget = widgetManager.getWidgetById(filter[j])
if (typeof filter[j]=='string' && widget.length) {
filters[i][j] = widget[widget.length-1].getValue()
} else {
filters[i][j] = filter[j]
}
}
}
var filters = v,
eqResponse = []
for (let i in filters) {
@ -115,7 +86,7 @@ module.exports = class Eq extends _plots_base {
}
if (eqResponse.length) this.data = eqResponse
if (eqResponse.length) super.setValue(eqResponse, options)
}

View file

@ -8,6 +8,7 @@ module.exports = class Led extends Widget {
return {
type:'image',
id:'auto',
linkId:'',
_geometry:'geometry',

View file

@ -9,6 +9,7 @@ module.exports = class Led extends Widget {
return {
type:'led',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -25,7 +26,6 @@ module.exports = class Led extends Widget {
_led:'led',
widgetId:'',
range:{min:0,max:1},
logScale:false,
value:'',
@ -41,6 +41,9 @@ module.exports = class Led extends Widget {
constructor(options) {
// backward compat
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
var html = `
<div class="led">
</div>
@ -48,28 +51,14 @@ module.exports = class Led extends Widget {
super({...options, html: html})
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`, this.syncHandle.bind(this))
this.setValue(this.getProp('range').min)
}
syncHandle(e) {
if (this.getProp('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(), {sync: e.options.sync})
return
}
}
}
setValue(v, options={}) {
if (typeof v != 'number') return
this.value = v
this.widget.style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))

View file

@ -9,6 +9,7 @@ module.exports = class Meter extends Fader {
return {
type:'fader',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -26,7 +27,6 @@ module.exports = class Meter extends Fader {
_meter:'meter',
widgetId:'',
range:{min:0,max:1},
logScale:false,
origin:'auto',
@ -47,6 +47,9 @@ module.exports = class Meter extends Fader {
constructor(options) {
// backward compat
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
options.props.compact = true
options.props.input = false
@ -56,23 +59,6 @@ module.exports = class Meter extends Fader {
this.off(/drag(.*)?/)
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
}
syncHandle(e) {
if (this.getProp('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(), {sync: e.options.sync})
return
}
}
}
sendValue() {

View file

@ -9,6 +9,7 @@ module.exports = class Plot extends _plots_base {
return {
type:'plot',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -25,7 +26,6 @@ module.exports = class Plot extends _plots_base {
_plot:'plot',
points:[],
rangeX: {min:0,max:1},
rangeY: {min:0,max:1},
origin: 'auto',
@ -35,6 +35,7 @@ module.exports = class Plot extends _plots_base {
logScaleY: false,
smooth: false,
pips:true,
value: '',
_osc:'osc',
@ -47,56 +48,11 @@ module.exports = class Plot extends _plots_base {
constructor(options) {
// backward compat
if (options.props.points && options.props.points.length) options.props.value = options.props.points
super(options)
if (typeof this.getProp('points')=='string') {
this.linkedWidgets.push(this.getProp('points'))
} else if (typeof this.getProp('points')=='object') {
for (let i in this.getProp('points')) {
for (let j in this.getProp('points')[i]) {
if (typeof this.getProp('points')[i][j] == 'string') {
this.linkedWidgets.push(this.getProp('points')[i][j])
}
}
}
}
}
updateData() {
var data = [],
points = this.getProp('points'),
widget = widgetManager.getWidgetById(points)
if (typeof points=='string' && widget.length) {
data = widget[widget.length-1].getValue()
} else if (typeof points=='object') {
for (let i in points) {
data[i] = []
for (var k in [0,1]) {
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]
}
}
}
}
if (data.length) this.data = data
}
}

View file

@ -10,6 +10,7 @@ module.exports = class Rbgled extends Widget {
return {
type:'rgbled',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -25,7 +26,6 @@ module.exports = class Rbgled extends Widget {
_rgbled:'rgbled',
widgetId:'',
value:'',
_osc:'osc',
@ -39,6 +39,10 @@ module.exports = class Rbgled extends Widget {
constructor(options) {
// backward compat
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
var html = `
<div class="led">
</div>
@ -46,27 +50,11 @@ module.exports = class Rbgled extends Widget {
super({...options, html: html})
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
this.setValue([0,0,0,0])
}
syncHandle(e) {
if (this.getProp('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(), {sync: e.options.sync})
return
}
}
}
setValue(v, options={}) {
var c = ''

View file

@ -9,6 +9,7 @@ module.exports = class Text extends Widget {
return {
type:'text',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -25,7 +26,6 @@ module.exports = class Text extends Widget {
_text: 'text',
widgetId:'',
vertical:false,
value:'',
@ -39,6 +39,9 @@ module.exports = class Text extends Widget {
constructor(options) {
// backward compat
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
super({...options, html: '<div class="text"></div>'})
if (this.getProp('vertical')) this.widget.classList.add('vertical')
@ -51,25 +54,10 @@ module.exports = class Text extends Widget {
this.value = this.defaultValue
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
this.setValue(this.value)
}
syncHandle(e) {
if (this.getProp('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(true), {sync: e.options.sync})
return
}
}
}
setValue(v, options={}) {

View file

@ -9,6 +9,7 @@ module.exports = class Visualizer extends _plots_base {
return {
type:'visualizer',
id:'auto',
linkId:'',
_geometry:'geometry',
@ -25,7 +26,6 @@ module.exports = class Visualizer extends _plots_base {
_visualizer:'visualizer',
widgetId:'',
duration:1,
range: {min:0,max:1},
origin: 'auto',
@ -44,6 +44,9 @@ module.exports = class Visualizer extends _plots_base {
constructor(options) {
// backward compat
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
super(options)
this.fps = 30
@ -64,13 +67,6 @@ module.exports = class Visualizer extends _plots_base {
}
syncHandle(e) {
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length || !e.widget) return
this.setValue(e.widget.getValue(), {sync: e.options.sync})
}
startLoop() {
this.clock = new Date().getTime()