matrix: deprecate non generic matrices and show warning when using them

This commit is contained in:
jean-emmanuel 2018-11-19 16:47:51 +01:00
parent bb532a62cd
commit 5015059fd3
8 changed files with 40 additions and 22 deletions

View file

@ -22,10 +22,11 @@ module.exports.widgets = {
// matrices
matrix: require('./matrices/matrix'),
keyboard: require('./matrices/keyboard'),
// deprecated / hidden
multitoggle: require('./matrices/multitoggle'),
multipush: require('./matrices/multipush'),
multifader: require('./matrices/multifader'),
keyboard: require('./matrices/keyboard'),
// plots
led: require('./plots/led'),
@ -65,7 +66,7 @@ module.exports.categories = {
'Sliders':['fader','knob', 'encoder', 'range'],
'Buttons':['toggle','push','switch', 'dropdown'],
'Pads':['xy','rgb','multixy'],
'Matrices':['matrix', 'multifader','multitoggle','multipush', 'keyboard'],
'Matrices':['matrix', 'keyboard'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'frame'],
'Containers':['panel','strip','modal', 'clone'],
'Switchers':['switcher','crossfader'],

View file

@ -1,6 +1,7 @@
var Container = require('../common/container'),
{enableTraversingGestures} = require('../../events/drag'),
html = require('nanohtml')
html = require('nanohtml'),
ipc = require('../../ipc')
module.exports = class _matrix_base extends Container {
@ -11,13 +12,11 @@ module.exports = class _matrix_base extends Container {
this.value = []
this.start = parseInt(this.getProp('start'))
this.on('change',(e)=>{
if (e.widget == this) return
if (e.widget === this) return
this.value[DOM.index(e.widget.container)] = e.widget.getValue()
this.value[e.widget._index] = e.widget.getValue()
this.changed(e.options)
})

View file

@ -46,17 +46,18 @@ module.exports = class Keyboard extends _matrix_base {
super(options)
this.keys = parseInt(this.getProp('keys'))
var start = parseInt(this.getProp('start')),
keys = parseInt(this.getProp('keys'))
var strData = JSON.stringify(options.props),
pattern = 'wbwbwwbwbwbw',
whiteKeys = 0, whiteKeys2 = 0, i
for (i = this.start; i < this.keys + this.start && i < 109; i++) {
for (i = start; i < keys + start && i < 109; i++) {
if (pattern[i % 12] == 'w') whiteKeys++
}
for (i = this.start; i < this.keys + this.start && i < 109; i++) {
for (i = start; i < keys + start && i < 109; i++) {
var data = JSON.parse(strData)
@ -82,7 +83,7 @@ module.exports = class Keyboard extends _matrix_base {
parentNode: this.widget,
parent: this
})
key.container.classList.add('not-editable')
if (pattern[i % 12] == 'w') {
@ -95,7 +96,7 @@ module.exports = class Keyboard extends _matrix_base {
key.container.style.left = `${100 / whiteKeys * (whiteKeys2 - 3/10)}%`
}
this.value[i-this.start] = this.getProp('off')
this.value[i - start] = this.getProp('off')
}

View file

@ -1,4 +1,6 @@
var _matrix_base = require('./_matrix_base'),
{enableTraversingGestures} = require('../../events/drag'),
html = require('nanohtml'),
parser = require('../../parser')
class Matrix extends _matrix_base {
@ -34,9 +36,11 @@ class Matrix extends _matrix_base {
if (this.getProp('borders') === false) this.widget.classList.add('noborders')
var start = parseInt(this.getProp('start'))
if (parser.widgets[this.getProp('widgetType')]) {
for (var i = this.start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + this.start; i++) {
for (var i = start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + start; i++) {
var props = this.resolveProp('props', undefined, false, false, false, {'$':i})
var data = {
@ -58,9 +62,10 @@ class Matrix extends _matrix_base {
parent: this
})
widget._index = i - start
widget.container.classList.add('not-editable')
this.value[i-this.start] = widget.getValue()
this.value[i - start] = widget.getValue()
}
@ -80,7 +85,6 @@ class Matrix extends _matrix_base {
case 'props':
for (let i = this.children.length - 1; i >= 0; i--) {
let data = this.resolveProp('props', undefined, false, false, false, {'$':i})

View file

@ -1,4 +1,5 @@
var _matrix_base = require('./_matrix_base'),
ipc = require('../../ipc'),
parser = require('../../parser')
module.exports = class Multifader extends _matrix_base {
@ -50,6 +51,8 @@ module.exports = class Multifader extends _matrix_base {
super(options)
ipc.send('errorLog', `[Warning]\n"${this.getProp('type')}" is deprecated and will be removed in the future, please use "matrix" instead.`)
this.strips = parseInt(this.getProp('strips'))
if (this.getProp('horizontal')) {
@ -61,8 +64,9 @@ module.exports = class Multifader extends _matrix_base {
}
var strData = JSON.stringify(options.props)
var start = parseInt(this.getProp('start'))
for (var i = this.start; i < this.strips + this.start; i++) {
for (var i = start; i < this.strips + start; i++) {
var data = JSON.parse(strData)
@ -90,7 +94,7 @@ module.exports = class Multifader extends _matrix_base {
})
fader.container.classList.add('not-editable')
this.value[i-this.start] = this.getProp('range').min
this.value[i-start] = this.getProp('range').min
}

View file

@ -1,4 +1,5 @@
var _matrix_base = require('./_matrix_base'),
ipc = require('../../ipc'),
parser = require('../../parser')
module.exports = class Multipush extends _matrix_base {
@ -47,13 +48,16 @@ module.exports = class Multipush extends _matrix_base {
super(options)
ipc.send('errorLog', `[Warning]\n"${this.getProp('type')}" is deprecated and will be removed in the future, please use "matrix" instead.`)
this.widget.style.setProperty('--columns', this.getProp('matrix')[0])
this.widget.style.setProperty('--rows', this.getProp('matrix')[1])
this.widget.style.setProperty('--spacing', this.getProp('spacing') + 'rem')
var strData = JSON.stringify(options.props)
var start = parseInt(this.getProp('start'))
for (var i = this.start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + this.start; i++) {
for (var i = start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + start; i++) {
var data = JSON.parse(strData)
@ -82,7 +86,7 @@ module.exports = class Multipush extends _matrix_base {
push.container.classList.add('not-editable')
this.value[i-this.start] = this.getProp('off')
this.value[i - start] = this.getProp('off')
}

View file

@ -1,4 +1,5 @@
var _matrix_base = require('./_matrix_base'),
ipc = require('../../ipc'),
parser = require('../../parser')
module.exports = class Multitoggle extends _matrix_base {
@ -47,13 +48,16 @@ module.exports = class Multitoggle extends _matrix_base {
super(options)
ipc.send('errorLog', `[Warning]\n"${this.getProp('type')}" is deprecated and will be removed in the future, please use "matrix" instead.`)
this.widget.style.setProperty('--columns', this.getProp('matrix')[0])
this.widget.style.setProperty('--rows', this.getProp('matrix')[1])
this.widget.style.setProperty('--spacing', this.getProp('spacing') + 'rem')
var strData = JSON.stringify(options.props)
var start = parseInt(this.getProp('start'))
for (var i = this.start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + this.start; i++) {
for (var i = start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + start; i++) {
var data = JSON.parse(strData)
@ -81,7 +85,7 @@ module.exports = class Multitoggle extends _matrix_base {
})
toggle.container.classList.add('not-editable')
this.value[i-this.start] = this.getProp('off')
this.value[i-start] = this.getProp('off')
}