From 9eb5dd50606b7e725a070f400106df484b33a16b Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 29 Feb 2020 17:01:29 +0100 Subject: [PATCH] rename precision to decimals, add typeTags, continue refactoring --- app/client/index.html | 6 +- src/client/managers/widgets.js | 3 +- src/client/ui/ui-inspector-field.js | 4 +- src/client/ui/ui-inspector.js | 2 +- src/client/ui/ui-tree.js | 5 +- src/client/utils.js | 15 ++- src/client/widgets/buttons/toggle.js | 49 +++++--- src/client/widgets/common/canvas.js | 11 +- src/client/widgets/common/widget.js | 61 +++++---- src/client/widgets/containers/clone.js | 2 +- src/client/widgets/containers/matrix.js | 4 +- src/client/widgets/containers/modal.js | 1 + src/client/widgets/containers/panel.js | 3 + src/client/widgets/containers/tab.js | 2 +- src/client/widgets/frames/frame.js | 2 +- src/client/widgets/frames/html.js | 2 +- src/client/widgets/frames/image.js | 2 +- src/client/widgets/frames/svg.js | 2 +- src/client/widgets/graphs/eq.js | 2 +- src/client/widgets/graphs/plot.js | 4 +- src/client/widgets/graphs/visualizer.js | 2 +- src/client/widgets/indicators/led.js | 2 +- src/client/widgets/indicators/text.js | 2 +- src/client/widgets/inputs/gyroscope.js | 2 +- src/client/widgets/inputs/input.js | 2 +- src/client/widgets/matrices/keyboard.js | 2 +- src/client/widgets/pads/multixy.js | 2 +- src/client/widgets/pads/pad.js | 2 +- src/client/widgets/pads/rgb.js | 6 +- src/client/widgets/pads/xy.js | 4 +- src/client/widgets/sliders/encoder.js | 2 +- src/client/widgets/sliders/fader.js | 159 ++++++++++++++++++------ src/client/widgets/sliders/knob.js | 12 +- src/client/widgets/sliders/range.js | 20 ++- src/client/widgets/sliders/slider.js | 20 ++- src/client/widgets/utils.js | 6 +- src/scss/themes/default.scss | 4 +- src/scss/ui/button.scss | 2 +- src/scss/ui/filebrowser.scss | 23 ++-- src/scss/ui/inspector.scss | 24 ++-- src/scss/ui/loading.scss | 2 +- src/scss/ui/lobby.scss | 15 +-- src/scss/ui/modal.scss | 10 +- src/scss/ui/scrollbars.scss | 12 +- src/scss/ui/workspaces.scss | 8 +- src/scss/widgets.scss | 5 +- src/scss/widgets/buttons.scss | 16 +-- src/scss/widgets/containers.scss | 41 ++++-- src/scss/widgets/inputs.scss | 2 +- src/scss/widgets/plots.scss | 3 + src/scss/widgets/sliders.scss | 10 ++ src/server/callbacks.js | 2 +- src/server/osc/index.js | 70 ++++++----- src/server/utils.js | 6 +- 54 files changed, 426 insertions(+), 256 deletions(-) diff --git a/app/client/index.html b/app/client/index.html index e26e602c..c811c3ad 100644 --- a/app/client/index.html +++ b/app/client/index.html @@ -37,12 +37,8 @@ - + -
diff --git a/src/client/managers/widgets.js b/src/client/managers/widgets.js index e7f5c56c..aef9eb40 100644 --- a/src/client/managers/widgets.js +++ b/src/client/managers/widgets.js @@ -136,11 +136,10 @@ var WidgetManager = class WidgetManager extends EventEmitter { ipc.send('addWidget', { hash: widget.hash, data: updatedData || { - precision: widget.getProp('precision'), preArgs: widget.getProp('preArgs'), target: widget.getProp('target'), + typeTags: widget.getProp('typeTags'), address: widget.getProp('address'), - noSync: widget.getProp('noSync'), } }) diff --git a/src/client/ui/ui-inspector-field.js b/src/client/ui/ui-inspector-field.js index c4cf1893..4ada14fb 100644 --- a/src/client/ui/ui-inspector-field.js +++ b/src/client/ui/ui-inspector-field.js @@ -94,11 +94,11 @@ class UiInspectorField extends UiWidget { } else if (this.name.includes('color')) { let style = window.getComputedStyle(this.widget.container), - cssName = this.widget.constructor.cssVariables.find(x=>x.js === this.name).css, + colorData = this.widget.constructor.cssVariables.find(x=>x.js === this.name), val = '#000' try { - val = chroma(style.getPropertyValue('--' + this.name.replace(/([A-Z])/g, (a,s)=>'-' + s.toLowerCase())).trim()).hex('rgb') + val = chroma(style.getPropertyValue(colorData.css).trim()).hex('rgb') } catch(e) {console.log(e)} let picker = html`` diff --git a/src/client/ui/ui-inspector.js b/src/client/ui/ui-inspector.js index c2c2754d..59f3d12c 100644 --- a/src/client/ui/ui-inspector.js +++ b/src/client/ui/ui-inspector.js @@ -179,7 +179,7 @@ class UiInspector extends UiWidget { if (this.colorPicker.opened) { var picker = DOM.get(this.container, `osc-inspector-color[name="${this.colorPicker.name}"]`) - if (picker) { + if (picker && picker[0]) { this.colorPicker.setValue(picker[0].getAttribute('value')) } else { this.colorPicker.close() diff --git a/src/client/ui/ui-tree.js b/src/client/ui/ui-tree.js index a0a03dc6..0ecdb5d3 100644 --- a/src/client/ui/ui-tree.js +++ b/src/client/ui/ui-tree.js @@ -3,7 +3,7 @@ var UiWidget = require('./ui-widget'), doubleClick = require('../events/double-click'), Sortable = require('sortablejs'), morph = require('nanomorph'), - Panel, Matrix, widgetManager + Panel, Matrix, Keyboard, widgetManager class UiTree extends UiWidget { @@ -11,6 +11,7 @@ class UiTree extends UiWidget { Panel = require('../widgets/containers/panel') Matrix = require('../widgets/containers/matrix') + Keyboard = require('../widgets/matrices/keyboard') widgetManager = require('../managers/widgets') super(options) @@ -144,7 +145,7 @@ class UiTree extends UiWidget { data-id="${id}""> ${id}` - if (widget instanceof Panel && !(widget instanceof Matrix)) { + if (widget instanceof Panel && !(widget instanceof Matrix || widget instanceof Keyboard)) { node.insertBefore(html``, node.childNodes[0]) node.classList.add('container') if (this.expanded[id]) node.classList.add('expanded') diff --git a/src/client/utils.js b/src/client/utils.js index 7a873517..5a41596d 100644 --- a/src/client/utils.js +++ b/src/client/utils.js @@ -1,6 +1,6 @@ module.exports = { - deepCopy: function(obj, precision) { + deepCopy: function(obj, decimals) { var copy = obj @@ -11,10 +11,10 @@ module.exports = { if (typeof obj === 'object') { copy = Array.isArray(obj) ? [] : {} for (let key in obj) { - copy[key] = module.exports.deepCopy(obj[key], precision) + copy[key] = module.exports.deepCopy(obj[key], decimals) } } else if (typeof obj == 'number') { - return precision === undefined ? copy : parseFloat(copy.toFixed(precision)) + return decimals === undefined ? copy : parseFloat(copy.toFixed(decimals)) } return copy @@ -34,6 +34,15 @@ module.exports = { return a === b } + }, + + isJSON: function(str) { + // heuristic to avoid using JSON when unnecessary + // if the string doesn't starts with one of these chars + // it's going to fail + // ref in source: https://github.com/douglascrockford/JSON-js + return ' \n+-eE{([0123456789tfn"'.indexOf(str[0]) !== -1 + } } diff --git a/src/client/widgets/buttons/toggle.js b/src/client/widgets/buttons/toggle.js index 5a5857bf..c6324e25 100644 --- a/src/client/widgets/buttons/toggle.js +++ b/src/client/widgets/buttons/toggle.js @@ -1,6 +1,7 @@ var Widget = require('../common/widget'), doubletab = require('../mixins/double_tap'), - html = require('nanohtml') + html = require('nanohtml'), + {deepEqual, isJSON} = require('../../utils') class Toggle extends Widget { @@ -19,11 +20,9 @@ class Toggle extends Widget { on: {type: '*', value: 1, help: [ 'Set to `null` to send send no argument in the osc message', - 'Can be an `object` if the type needs to be specified (see preArgs)' ]}, off: {type: '*', value: 0, help: [ - 'Set to `null` to send send no argument in the osc message', - 'Can be an `object` if the type needs to be specified (see preArgs)' + 'Set to `null` to send send no argument in the osc message. Must be different from `on`.', ]}, mode: {type: 'string', value: 'toggle', choices: ['toggle', 'push', 'tap'], help: [ 'Interraction mode:', @@ -56,6 +55,7 @@ class Toggle extends Widget { doubletab(this.widget, ()=>{ + this.active = true this.setValue(this.getProp('on'), {sync: true, send: true}) }) @@ -75,6 +75,8 @@ class Toggle extends Widget { this.on('dragend',()=>{ + if (!this.active) return + this.active = false this.setValue(this.getProp('off'), {sync: true, send: !tap}) @@ -86,6 +88,8 @@ class Toggle extends Widget { doubletab(this.widget, ()=>{ + + this.active = true this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) }) @@ -118,27 +122,38 @@ class Toggle extends Widget { - setValue(v,options={}) { + setValue(v, options={}) { - if (typeof v == 'object' && v !== null) v = v.value + if (typeof v === 'string' && isJSON(v)) { + try { + v = JSON.parse(v ) + } catch (err) {} + } - if (v===this.getProp('on') || (this.getProp('on') != null && v === this.getProp('on').value && v !== undefined)) { + var newstate - this.container.classList.add('on') - this.state = 1 - this.value = this.getProp('on') - if (options.send) this.sendValue() + if (deepEqual(v, this.getProp('on'))) { - } else if (v===this.getProp('off') || (this.getProp('off') != null && v === this.getProp('off').value && v !== undefined)) { + newstate = 1 - this.container.classList.remove('on') - this.state = 0 - this.value = this.getProp('off') - if (options.send) this.sendValue() + } else if (deepEqual(v, this.getProp('off'))) { + + newstate = 0 } - if (options.sync) this.changed(options) + if (newstate !== undefined) { + + this.state = newstate + this.container.classList.toggle('on', this.state) + this.value = this.getProp(this.state ? 'on' : 'off') + + if (options.send) this.sendValue() + if (options.sync) this.changed(options) + + } + + } diff --git a/src/client/widgets/common/canvas.js b/src/client/widgets/common/canvas.js index 04325beb..522e9338 100644 --- a/src/client/widgets/common/canvas.js +++ b/src/client/widgets/common/canvas.js @@ -139,7 +139,6 @@ class Canvas extends Widget { switch (propName) { - case 'css': case 'colorText': case 'colorWidget': case 'colorFill': @@ -147,11 +146,13 @@ class Canvas extends Widget { case 'alphaStroke': case 'alphaFillOff': case 'alphaFillOn': + case 'colorPanel': setTimeout(()=>{ this.cacheCanvasStyle() this.batchDraw() },10) return + case 'css': case 'padding': resize.check(this.canvas, true) setTimeout(()=>{ @@ -174,12 +175,8 @@ class Canvas extends Widget { } Canvas.cssVariables = Canvas.prototype.constructor.cssVariables.concat( - {js: 'alphaPips', css: '--alpha-pips', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)} -) - -Canvas.dynamicProps = Canvas.prototype.constructor.dynamicProps.concat( - 'on', - 'off' + {js: 'alphaPips', css: '--alpha-pips', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)}, + {js: 'alphaPipsText', css: '--alpha-pips-text', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)} ) module.exports = Canvas diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index b9eef7a8..626713cd 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -7,18 +7,18 @@ var EventEmitter = require('../../events/event-emitter'), {iconify} = require('../../ui/utils'), resize = require('../../events/resize'), OscReceiver = require('./osc-receiver'), - {deepCopy, deepEqual} = require('../../utils'), + {deepCopy, deepEqual, isJSON} = require('../../utils'), html = require('nanohtml'), - // ipc = require('../../ipc'), updateWidget = ()=>{} var oscReceiverState = {} var OSCProps = [ - 'precision', + 'decimals', 'address', 'preArgs', + 'typeTags', 'target', 'bypass' ] @@ -96,18 +96,23 @@ class Widget extends EventEmitter { 'When prefixed with <<, the `linkId` will make the widget act as a slave (receiving but not sending)' ]}, + _osc: 'osc', - precision: {type: 'integer|string', value: 2, help: [ - 'Defines the number of decimals to display and to send.', - 'Set to `0` to send integers only.', - 'Data type can be specified by appending a valid osc type tag to the precision value, for example : `3d` will make the widget send double precision numbers rounded to three decimals' - ]}, address: {type: 'string', value: 'auto', help: 'OSC address for sending messages, it must start with a /'}, preArgs: {type: '*|array', value: '', help: [ 'A value or array of values that will be prepended to the OSC messages.', 'Values can be defined as objects if the osc type tag needs to be specified: `{type: "i", value: 1}`' ]}, + typeTags: {type: 'string', value: '', help: [ + 'Defines the osc argument types, one letter per argument (including preArgs)', + '- If empty, the types are infered automatically from the values (with numbers casted to floats by default)', + '- If there are more arguments than type letters, the last type is used for the extra arguments', + 'See http://opensoundcontrol.org/spec-1_0 for existing typetags' + ]}, + decimals: {type: 'integer', value: 2, help: [ + 'Defines the number of decimals to send.', + ]}, target: {type: 'string|array|null', value: '', help: [ 'This defines the targets of the widget\'s OSC messages', '- A `string` or `array` of strings formatted as follow: `ip:port` or `["ip:port"]`', @@ -179,9 +184,9 @@ class Widget extends EventEmitter { // this.mathjsDeprecationWarned = false - // cache precision - if (this.props.precision != undefined) { - this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0)) + // cache decimals + if (this.props.decimals !== undefined) { + this.decimals = Math.min(20, Math.max(this.getProp('decimals'), 0)) } @@ -260,8 +265,8 @@ class Widget extends EventEmitter { if (this.getProp('bypass') && !options.force) return var data = { - h:this.hash, - v:this.value + h: this.hash, + v: this.getValue(true) } if (overrides) { @@ -284,9 +289,9 @@ class Widget extends EventEmitter { setValue() {} - getValue(withPrecision) { + getValue(withdecimals) { - return deepCopy(this.value, withPrecision ? this.precision : undefined) + return deepCopy(this.value, withdecimals ? this.decimals : undefined) } @@ -644,11 +649,7 @@ class Widget extends EventEmitter { propValue = propValue.replace(new RegExp(k, 'g'), v) } - // heuristic to avoid using JSON when unnecessary - // if the string doesn't starts with one of these chars - // it's going to fail - // ref in source: https://github.com/douglascrockford/JSON-js - if (' \n+-eE{([0123456789tfn"'.indexOf(propValue[0]) !== -1) { + if (isJSON(propValue)) { try { propValue = JSON.parse(propValue) } catch (err) {} @@ -756,7 +757,8 @@ class Widget extends EventEmitter { case 'height': case 'width': this.setContainerStyles(['geometry']) - resize.check(this.container) + var container = this.parent !== widgetManager && this.parent.getProp('layout') !== 'default' ? this.parent.container : this.container + resize.check(container) return case 'visible': @@ -777,9 +779,10 @@ class Widget extends EventEmitter { case 'css': this.setContainerStyles(['css']) - var re = /width|height|display/ + var re = /width|height|display|margin|padding|flex/ if (re.test(oldPropValue) || re.test(this.getProp('css'))) { - resize.check(this.container) + var container = this.parent !== widgetManager && this.parent.getProp('layout') !== 'default' ? this.parent.container : this.container + resize.check(container) } return @@ -794,9 +797,13 @@ class Widget extends EventEmitter { this.setCssVariables() return - case 'precision': + case 'decimals': + this.decimals = Math.min(20, Math.max(this.getProp('decimals'), 0)) + return + case 'address': case 'preArgs': + case 'typeTags': case 'target': if (propName === 'address') { for (var k in this.oscReceivers) { @@ -806,7 +813,6 @@ class Widget extends EventEmitter { } } } - if (propName === 'precision') this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0)) var data = {}, oldData = { preArgs: propName == 'preArgs' ? oldPropValue : this.getProp('preArgs'), @@ -1015,11 +1021,11 @@ Widget.cssVariables = [ {js: 'colorFill', css: '--color-fill'}, {js: 'colorStroke', css: '--color-stroke'}, {js: 'colorText', css: '--color-text'}, + {js: 'colorPanel', css: '--color-background'}, {js: 'padding', css: '--widget-padding', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE}, {js: 'alphaFillOn', css: '--alpha-fill-on', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)}, {js: 'alphaFillOff', css: '--alpha-fill-off', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)}, {js: 'alphaStroke', css: '--alpha-stroke', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)}, - {js: 'colorForegroud', css: '--color-foreground'} ] Widget.dynamicProps = [ @@ -1045,9 +1051,10 @@ Widget.dynamicProps = [ 'value', - 'precision', + 'decimals', 'address', 'preArgs', + 'typeTags', 'target', 'bypass' ] diff --git a/src/client/widgets/containers/clone.js b/src/client/widgets/containers/clone.js index aeae23ac..e3f811fd 100644 --- a/src/client/widgets/containers/clone.js +++ b/src/client/widgets/containers/clone.js @@ -32,7 +32,7 @@ class Clone extends Container() { 'colorText', 'colorWidget', 'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn', 'padding', 'label', 'color', 'linkId', '_value', 'default', 'value', - '_osc', 'precision', 'address', 'preArgs', 'target', 'bypass' + '_osc', 'decimals', 'address', 'preArgs', 'typeTags', 'target', 'bypass' ]) } diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index 6dcb8e08..3f9f6655 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -113,7 +113,7 @@ class Matrix extends StaticProperties(Panel, {scroll: false}) { address: '@{parent.address}/' + i, preArgs: '@{parent.preArgs}', target: '@{parent.target}', - precision: '@{parent.precision}', + decimals: '@{parent.decimals}', bypass: '@{parent.bypass}', label: i, top: 'auto', @@ -176,7 +176,7 @@ class Matrix extends StaticProperties(Panel, {scroll: false}) { Matrix.overriddenDefaults = [ - 'type', 'id', 'address', 'preArgs', 'target', 'precision', 'bypass', + 'type', 'id', 'address', 'preArgs', 'target', 'decimals', 'bypass', 'label', 'top', 'left', 'height', 'width' ] diff --git a/src/client/widgets/containers/modal.js b/src/client/widgets/containers/modal.js index b189e392..5d153dcf 100644 --- a/src/client/widgets/containers/modal.js +++ b/src/client/widgets/containers/modal.js @@ -26,6 +26,7 @@ class Modal extends Panel { popupHeight: {type: 'number|percentage', value: '80%', help: 'Modal popup\'s size'}, popupLeft: {type: 'number|percentage', value: 'auto', help: 'Modal popup\'s position'}, popupTop: {type: 'number|percentage', value: 'auto', help: 'Modal popup\'s position'}, + colorPanel: {type: 'string', value: 'auto', help:''}, layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal', 'grid'], help:''}, gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'}, 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'}, diff --git a/src/client/widgets/containers/panel.js b/src/client/widgets/containers/panel.js index 36f71006..7437e23e 100644 --- a/src/client/widgets/containers/panel.js +++ b/src/client/widgets/containers/panel.js @@ -20,6 +20,7 @@ class Panel extends Container() { _panel:'panel', + colorPanel: {type: 'string', value: 'auto', help:''}, layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal', 'grid'], help:''}, gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'}, 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'}, @@ -214,6 +215,8 @@ class Panel extends Container() { case 'alphaStroke': case 'alphaFillOff': case 'alphaFillOn': + case 'colorPanel': + case 'padding': for (var w of this.children) { if (w) w.onPropChanged(propName) } diff --git a/src/client/widgets/containers/tab.js b/src/client/widgets/containers/tab.js index fa88ee90..fb9c1651 100644 --- a/src/client/widgets/containers/tab.js +++ b/src/client/widgets/containers/tab.js @@ -69,7 +69,7 @@ module.exports = class Tab extends Panel { isVisible() { - return !this.detached && super.isVisible() + return !this.detached && super.isVisible() } diff --git a/src/client/widgets/frames/frame.js b/src/client/widgets/frames/frame.js index aa16c146..1b4cc090 100644 --- a/src/client/widgets/frames/frame.js +++ b/src/client/widgets/frames/frame.js @@ -16,7 +16,7 @@ class Frame extends StaticProperties(Widget, {bypass: true}) { return super.defaults({ - }, ['precision', 'bypass'], { + }, ['decimals', 'bypass'], { label: {type: 'string|boolean', value: 'auto', help: [ 'Set to `false` to hide completely', diff --git a/src/client/widgets/frames/html.js b/src/client/widgets/frames/html.js index 743c83a7..9e600f0b 100644 --- a/src/client/widgets/frames/html.js +++ b/src/client/widgets/frames/html.js @@ -30,7 +30,7 @@ class Html extends StaticProperties(Widget, {bypass: true}) { '  table, thead, img, caption, tbody, tr, th, td, pre' ]}, - }, ['precision', 'bypass'], {}) + }, ['decimals', 'bypass'], {}) } diff --git a/src/client/widgets/frames/image.js b/src/client/widgets/frames/image.js index 55729261..31f0deee 100644 --- a/src/client/widgets/frames/image.js +++ b/src/client/widgets/frames/image.js @@ -26,7 +26,7 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) { 'When true, sending `reload` to the widget reloads its image without changing its value' ]} - }, ['precision', 'bypass'], { + }, ['decimals', 'bypass'], { value: {type: 'string', value: '', help: [ '- File `url` or `path` (relative to the session file location by default, falling back to absolute path)', diff --git a/src/client/widgets/frames/svg.js b/src/client/widgets/frames/svg.js index 50efb105..70f6250f 100644 --- a/src/client/widgets/frames/svg.js +++ b/src/client/widgets/frames/svg.js @@ -24,7 +24,7 @@ class Svg extends StaticProperties(Widget, {bypass: true}) { '- `` commands support a special percent notation (`%x` and `%y`)' ]}, - }, ['precision', 'bypass'], {}) + }, ['decimals', 'bypass'], {}) } diff --git a/src/client/widgets/graphs/eq.js b/src/client/widgets/graphs/eq.js index d8287811..2d797733 100644 --- a/src/client/widgets/graphs/eq.js +++ b/src/client/widgets/graphs/eq.js @@ -25,7 +25,7 @@ module.exports = class Eq extends StaticProperties(Plot, {rangeX: {min: 20, max: 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`)'}, - }, ['interaction', 'precision', 'bypass'], { + }, ['interaction', 'decimals', 'typeTags', 'bypass'], { value: {type: 'array', value: '', help: [ 'Each item must be an object with the following properties', diff --git a/src/client/widgets/graphs/plot.js b/src/client/widgets/graphs/plot.js index a0869a8d..8af6720d 100644 --- a/src/client/widgets/graphs/plot.js +++ b/src/client/widgets/graphs/plot.js @@ -28,7 +28,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte 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'}, - }, ['interaction', 'precision', 'bypass'], { + }, ['interaction', 'decimals', 'typeTags', 'bypass'], { value: {type: 'array|string', value: '', help: [ '- `Array` of `y` values', @@ -180,7 +180,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte this.ctx.globalAlpha = 1 this.ctx.fillStyle = this.cssVars.colorWidget - this.ctx.strokeStyle = this.cssVars.colorForeground + this.ctx.strokeStyle = this.cssVars.colorBackground this.ctx.lineWidth = 2 * PXSCALE for (var i = 0; i < points.length; i += 2) { this.ctx.beginPath() diff --git a/src/client/widgets/graphs/visualizer.js b/src/client/widgets/graphs/visualizer.js index 5e3f18bc..5e555739 100644 --- a/src/client/widgets/graphs/visualizer.js +++ b/src/client/widgets/graphs/visualizer.js @@ -25,7 +25,7 @@ module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: 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'}, - }, ['interaction', 'precision', 'bypass'], {}) + }, ['interaction', 'decimals', 'typeTags', 'bypass'], {}) } diff --git a/src/client/widgets/indicators/led.js b/src/client/widgets/indicators/led.js index 5c48dce3..f6e3ce12 100644 --- a/src/client/widgets/indicators/led.js +++ b/src/client/widgets/indicators/led.js @@ -24,7 +24,7 @@ module.exports = class Led extends StaticProperties(Widget, {bypass: true, inter 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.'}, - }, ['interaction', 'precision', 'bypass'], { + }, ['interaction', 'decimals', 'bypass'], { value: {type: 'number|array|string', value: '', help: [ '- `Number`: if `mode` is set to `intensity`', diff --git a/src/client/widgets/indicators/text.js b/src/client/widgets/indicators/text.js index 23be35b1..67f0a70e 100644 --- a/src/client/widgets/indicators/text.js +++ b/src/client/widgets/indicators/text.js @@ -24,7 +24,7 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true, inte ]}, align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Css text-align property.'}, - }, ['interaction', 'precision', 'bypass'], {}) + }, ['interaction', 'decimals', 'bypass'], {}) } diff --git a/src/client/widgets/inputs/gyroscope.js b/src/client/widgets/inputs/gyroscope.js index 3b074eba..ebd83765 100644 --- a/src/client/widgets/inputs/gyroscope.js +++ b/src/client/widgets/inputs/gyroscope.js @@ -62,7 +62,7 @@ class Gyroscope extends Widget { frequency: 1000 / clip(this.getProp('frequency'), [0.01, 60]), gravityNormalized: this.getProp('normalize'), orientationBase: this.getProp('compass') ? GyroNorm.WORLD : GyroNorm.GAME, - decimalCount: this.getProp('precision'), + decimalCount: this.getProp('decimals'), screenAdjusted: this.getProp('screenAdjusted'), logger: null diff --git a/src/client/widgets/inputs/input.js b/src/client/widgets/inputs/input.js index 0df11596..85e8f738 100644 --- a/src/client/widgets/inputs/input.js +++ b/src/client/widgets/inputs/input.js @@ -160,7 +160,7 @@ class Input extends Canvas { getStringValue() { if (this.value === undefined) return '' return typeof this.value != 'string' ? - JSON.stringify(deepCopy(this.value, this.precision)).replace(/,/g, ', ') : + JSON.stringify(deepCopy(this.value, this.decimals)).replace(/,/g, ', ') : this.value } diff --git a/src/client/widgets/matrices/keyboard.js b/src/client/widgets/matrices/keyboard.js index 5ab19845..b0c9147e 100644 --- a/src/client/widgets/matrices/keyboard.js +++ b/src/client/widgets/matrices/keyboard.js @@ -86,7 +86,7 @@ module.exports = class Keyboard extends Panel { data.css = '' data.target = '@{parent.target}' - data.precision = '@{parent.precision}' + data.decimals = '@{parent.decimals}' data.address = '@{parent.address}' data.preArgs = `JS{{ diff --git a/src/client/widgets/pads/multixy.js b/src/client/widgets/pads/multixy.js index 81605c2c..b778720c 100644 --- a/src/client/widgets/pads/multixy.js +++ b/src/client/widgets/pads/multixy.js @@ -68,7 +68,7 @@ module.exports = class MultiXy extends Pad { default:this.getProp('default').length === this.getProp('points') * 2 ? [this.getProp('default')[i*2], this.getProp('default')[i*2 + 1]] : '', rangeX:this.getProp('rangeX'), rangeY:this.getProp('rangeY'), - precision:this.getProp('precision'), + decimals:this.getProp('decimals'), logScaleX:this.getProp('logScaleX'), logScaleY:this.getProp('logScaleY'), pointSize: this.getProp('pointSize'), diff --git a/src/client/widgets/pads/pad.js b/src/client/widgets/pads/pad.js index 0cdfc75e..7bd3d9ec 100644 --- a/src/client/widgets/pads/pad.js +++ b/src/client/widgets/pads/pad.js @@ -28,6 +28,6 @@ class Pad extends Canvas { } -Pad.dynamicProps = Pad.prototype.constructor.dynamicProps.filter(n => n !== 'precision') +Pad.dynamicProps = Pad.prototype.constructor.dynamicProps.filter(n => n !== 'decimals') module.exports = Pad diff --git a/src/client/widgets/pads/rgb.js b/src/client/widgets/pads/rgb.js index 2f49d38e..c762bf5b 100644 --- a/src/client/widgets/pads/rgb.js +++ b/src/client/widgets/pads/rgb.js @@ -50,7 +50,7 @@ module.exports = class Rgb extends Widget { snap:this.getProp('snap'), rangeX:{min:0,max:100}, rangeY:{min:0,max:100}, - precision:2, + decimals:2, pointSize: 10, pips: false, }, parent: this}) @@ -71,7 +71,7 @@ module.exports = class Rgb extends Widget { horizontal:false, snap:this.getProp('snap'), range:{min:0,max:360}, - precision:2 + decimals:2 }, parent: this}) this.hue.container.classList.add('not-editable', 'hue') this.widget.appendChild(this.hue.container) @@ -91,7 +91,7 @@ module.exports = class Rgb extends Widget { range: this.getProp('rangeAlpha'), default: 255, input:false, - precision:2 + decimals:2 }, parent: this}) this.alpha.container.classList.add('not-editable', 'alpha') this.widget.appendChild(this.alpha.container) diff --git a/src/client/widgets/pads/xy.js b/src/client/widgets/pads/xy.js index 83263f74..a9a8d82f 100644 --- a/src/client/widgets/pads/xy.js +++ b/src/client/widgets/pads/xy.js @@ -57,7 +57,7 @@ module.exports = class Xy extends Pad { default:this.getProp('default').length === 2 ? this.getProp('default')[0] : '', snap:this.getProp('snap'), range:this.getProp('rangeX'), - precision:this.getProp('precision'), + decimals:this.getProp('decimals'), logScale:this.getProp('logScaleX'), sensitivity: this.getProp('sensitivity'), }, parent: this}), @@ -69,7 +69,7 @@ module.exports = class Xy extends Pad { default:this.getProp('default').length === 2 ? this.getProp('default')[1] : '', snap:this.getProp('snap'), range:this.getProp('rangeY'), - precision:this.getProp('precision'), + decimals:this.getProp('decimals'), logScale:this.getProp('logScaleY'), sensitivity: this.getProp('sensitivity'), }, parent: this}), diff --git a/src/client/widgets/sliders/encoder.js b/src/client/widgets/sliders/encoder.js index 5e984c0a..17a5758d 100644 --- a/src/client/widgets/sliders/encoder.js +++ b/src/client/widgets/sliders/encoder.js @@ -150,7 +150,7 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range var direction = e.wheelDelta / Math.abs(e.wheelDelta), increment = e.ctrlKey?0.25:1 - this.setPercent(this.percent + Math.max(increment, 10 / Math.pow(10, this.precision + 1)) * direction) + this.setPercent(this.percent + Math.max(increment, 10 / Math.pow(10, this.decimals + 1)) * direction) } diff --git a/src/client/widgets/sliders/fader.js b/src/client/widgets/sliders/fader.js index b58533cf..7fdd472a 100644 --- a/src/client/widgets/sliders/fader.js +++ b/src/client/widgets/sliders/fader.js @@ -20,7 +20,7 @@ module.exports = class Fader extends Slider { mode: {type: 'string', value: 'compact', choices: ['compact', 'classic', 'round'], help: 'Design style'}, horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display the fader horizontally'}, alignRight: {type: 'boolean', value: false, help: 'Set to `true` to invert the pip\'s and fader\'s position'}, - pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, + pips: {type: 'boolean', value: false, help: 'Set to `true` to show range breakpoints'}, dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'}, gradient: {type: 'array|object', value: [], help: [ 'When set, the meter\'s gauge will be filled with a linear color gradient', @@ -67,35 +67,6 @@ module.exports = class Fader extends Slider { this.container.classList.add('design-' + this.getProp('mode')) - if (false && this.getProp('pips')) { - - this.widget.classList.add('has-pips') - - - var pipTexts = {} - for (var k in this.rangeKeys) { - pipTexts[this.rangeKeys[k]]=this.rangeLabels[k] - } - - var pips = html`
` - for (var i=0;i<=100;i++) { - if (pipTexts[i]==undefined) continue - - var pos = this.getProp('horizontal')?'left':'bottom' - - pips.appendChild(html` -
- ${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]} -
- `) - - } - - this.widget.appendChild(pips) - - } - - } draginitHandle(e) { @@ -187,6 +158,15 @@ module.exports = class Fader extends Slider { } + + } + + cacheCanvasStyle(style) { + + super.cacheCanvasStyle(style) + + if (this.getProp('pips')) this.drawPips() + } @@ -202,11 +182,16 @@ module.exports = class Fader extends Slider { dashed = this.getProp('dashed'), compact = this.getProp('mode') === 'compact' - // sharp border trick - if (width % 2 && parseInt(m) === m) m -= 0.5 - this.clear() + if (this.getProp('pips') && !compact) m -= 10 * PXSCALE + + // sharp border trick + if (compact) { + if (width % 2 && parseInt(m) === m) m -= 0.5 + } else { + if (width % 2 && parseInt(m) !== m) m -= 0.5 + } this.ctx.strokeStyle = this.gaugeGradient || this.cssVars.colorFill @@ -277,7 +262,7 @@ module.exports = class Fader extends Slider { if (this.cssVars.alphaStroke) { this.ctx.globalAlpha = 1 - this.ctx.fillStyle = this.cssVars.colorForegroud + this.ctx.fillStyle = this.cssVars.colorPanel this.ctx.beginPath() this.ctx.rect(m - 6 * PXSCALE, d - 10 * PXSCALE, 12 * PXSCALE, 20 * PXSCALE) @@ -301,7 +286,6 @@ module.exports = class Fader extends Slider { this.ctx.rect(m - 3 * PXSCALE, d, 6 * PXSCALE, PXSCALE) this.ctx.fill() - this.clearRect = [m - 10 * PXSCALE, this.gaugePadding - 10 * PXSCALE, 20 * PXSCALE, height - 2 * this.gaugePadding + 20 * PXSCALE] } else { @@ -323,12 +307,115 @@ module.exports = class Fader extends Slider { this.ctx.fill() } - this.clearRect = [m - 10 * PXSCALE, this.gaugePadding - 10 * PXSCALE, 20 * PXSCALE, height - 2 * this.gaugePadding + 20 * PXSCALE] + this.clearRect = [m - 11 * PXSCALE, this.gaugePadding - 11 * PXSCALE, 22 * PXSCALE, height - 2 * this.gaugePadding + 22 * PXSCALE] } + if (this.getProp('pips')) { + this.ctx.globalAlpha = 1 + this.ctx.drawImage(this.pips, 0, 0); + if (!compact) this.clearRect = [this.clearRect, [m + 10 * PXSCALE, 0, 10 * PXSCALE + this.pipsTextSize, height]] + } + } + + drawPips() { + + this.pips = this.canvas.cloneNode() + this.pips.width = this.getProp('horizontal') ? this.height : this.width + this.pips.height = !this.getProp('horizontal') ? this.height : this.width + this.pipsTextSize = this.fontSize + + + var ctx = this.pips.getContext('2d',{ + desynchronized: true, + lowLatency: true, + alpha: true, + preserveDrawingBuffer: true + }) + + ctx.font = this.ctx.font + ctx.textBaseline = this.ctx.textBaseline + ctx.textAlign = this.ctx.textAlign + + var width = this.getProp('horizontal') ? this.height : this.width, + height = !this.getProp('horizontal') ? this.height : this.width, + m = this.getProp('horizontal') ? this.height / 2 : this.width / 2, + compact = this.getProp('mode') === 'compact' + + if (width % 2 && parseInt(m) !== m) m -= 0.5 + + if (!compact) m -= 10 * PXSCALE + + + ctx.lineWidth = PXSCALE + ctx.fillStyle = this.cssVars.colorWidget + ctx.strokeStyle = this.cssVars.colorWidget + + var i = 0 + + for (var pip of this.rangeKeys) { + + let d = Math.round(this.percentToCoord(pip)), + y = compact ? Math.min(d, height - this.gaugePadding - PXSCALE) : d, + pipWidth = 4 * PXSCALE + + y += 0.5 + + + ctx.globalAlpha = this.cssVars.alphaPips + + ctx.beginPath() + + if (compact) { + + + ctx.moveTo(width - pipWidth - PXSCALE, y) + ctx.lineTo(width - PXSCALE, y - pipWidth / 2) + ctx.lineTo(width - PXSCALE, y + pipWidth / 2) + ctx.closePath() + ctx.fill() + + } else { + + ctx.moveTo(m + 10 * PXSCALE, y) + ctx.lineTo(m + 10 * PXSCALE + pipWidth, y) + ctx.stroke() + + + + var textX = m + 10 * PXSCALE + pipWidth + 5 * PXSCALE, + textY = y + PXSCALE + + ctx.fillStyle = this.cssVars.colorText + ctx.globalAlpha = this.cssVars.alphaPipsText + + + if (this.getProp('horizontal')) { + + ctx.save() + ctx.translate(textX + 3 * PXSCALE, textY - 0.5 * PXSCALE) + ctx.rotate(Math.PI/2) + ctx.textAlign = "center" + ctx.fillText(this.rangeLabels[i], 0, 0) + ctx.restore() + + } else { + + this.pipsTextSize = Math.max(this.pipsTextSize , ctx.measureText(this.rangeLabels[i]).width) + ctx.fillText(this.rangeLabels[i], textX, textY) + + } + + + + } + + i++ + + } + } diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index 77b05575..fd027fc5 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -175,7 +175,7 @@ module.exports = class Knob extends Slider { dashed = this.getProp('dashed'), pips = this.getProp('pips'), minRadius = this.minDimension / 6, - maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 1.5 : PXSCALE), + maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 2 : PXSCALE), gaugeWidth = maxRadius - minRadius, gaugeRadius = maxRadius - gaugeWidth / 2 @@ -240,9 +240,9 @@ module.exports = class Knob extends Slider { this.ctx.lineWidth = 1.5 * PXSCALE this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.globalAlpha = this.cssVars.alphaPips - for (var pip of this.rangeKeys.concat(this.valueToPercent(this.originValue))) { + for (var pip of this.rangeKeys) { let r1 = maxRadius, r2 = r1 + 4 * PXSCALE, @@ -256,11 +256,11 @@ module.exports = class Knob extends Slider { } - var radius = maxRadius + this.fontSize * 1.5 + var radius = maxRadius + (this.fontSize + 2 * PXSCALE) this.ctx.fillStyle = this.cssVars.colorText - this.ctx.globalAlpha = this.cssVars.alphaPips + this.ctx.globalAlpha = this.cssVars.alphaPipsText for (var p in this.pipTexts) { - if (this.pipTexts[p] == undefined) continue + if (this.pipTexts[p] === undefined || (this.maxAngle === 360 && p === '100')) continue var angle = this.percentToAngle(p), size = this.ctx.measureText(this.pipTexts[p]), x = this.width / 2 + radius * Math.cos(angle) - size.width / 2, diff --git a/src/client/widgets/sliders/range.js b/src/client/widgets/sliders/range.js index 556167ff..dfa7d20b 100644 --- a/src/client/widgets/sliders/range.js +++ b/src/client/widgets/sliders/range.js @@ -3,11 +3,12 @@ var {clip} = require('../utils'), Fader = require('./fader'), Input = require('../inputs/input'), touchstate = require('../mixins/touch_state'), - html = require('nanohtml') + html = require('nanohtml'), + StaticProperties = require('../mixins/static_properties') var faderDefaults = Fader.defaults()._props() -class Range extends Fader { +class Range extends StaticProperties(Fader, {mode: 'compact'}) { static description() { @@ -15,6 +16,15 @@ class Range extends Fader { } + static defaults() { + + var defaults = super.defaults() + delete defaults.mode + + return defaults + + } + constructor(options) { options.multitouch = true @@ -33,7 +43,7 @@ class Range extends Fader { snap:this.getProp('snap'), spring:this.getProp('spring'), range:this.getProp('range'), - precision:this.getProp('precision'), + decimals:this.getProp('decimals'), logScale:this.getProp('logScale'), sensitivity:this.getProp('sensitivity'), }, parent: this}), @@ -46,7 +56,7 @@ class Range extends Fader { snap:this.getProp('snap'), spring:this.getProp('spring'), range:this.getProp('range'), - precision:this.getProp('precision'), + decimals:this.getProp('decimals'), logScale:this.getProp('logScale'), sensitivity:this.getProp('sensitivity'), }, parent: this}) @@ -274,7 +284,7 @@ class Range extends Fader { Range.dynamicProps = Range.prototype.constructor.dynamicProps - .filter(n => !['spring', 'precision'].includes(n)) + .filter(n => !['spring', 'decimals'].includes(n)) module.exports = Range diff --git a/src/client/widgets/sliders/slider.js b/src/client/widgets/sliders/slider.js index b2e7d731..39181b18 100644 --- a/src/client/widgets/sliders/slider.js +++ b/src/client/widgets/sliders/slider.js @@ -30,6 +30,8 @@ class Slider extends Canvas { Object.keys(this.getProp('range')[k])[0]: val + if (Math.abs(label) >= 1000) label = Math.round(label / 1000) + 'k' + this.rangeKeys.push(key) this.rangeVals.push(val) this.rangeLabels.push(label) @@ -62,9 +64,9 @@ class Slider extends Canvas { this.widget.addEventListener('mousewheel',this.mousewheelHandleProxy.bind(this)) - this.on('draginit', this.draginitHandleProxy.bind(this), {element:this.widget, multitouch: options.multitouch}) - this.on('drag', this.dragHandleProxy.bind(this), {element:this.widget, multitouch: options.multitouch}) - this.on('dragend', this.dragendHandleProxy.bind(this), {element:this.widget, multitouch: options.multitouch}) + this.on('draginit', this.draginitHandleProxy.bind(this), {element:this.container, multitouch: options.multitouch}) + this.on('drag', this.dragHandleProxy.bind(this), {element:this.container, multitouch: options.multitouch}) + this.on('dragend', this.dragendHandleProxy.bind(this), {element:this.container, multitouch: options.multitouch}) touchstate(this, {element: this.widget, multitouch: options.multitouch}) @@ -114,7 +116,7 @@ class Slider extends Canvas { this.setValue(this.steps[i + direction], {sync: true, send: true, fromLocal: true}) } } else { - this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.precision + 1)) * direction, [0,100]) + this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.decimals + 1)) * direction, [0,100]) this.setValue(this.percentToValue(this.percent), {sync: true, send: true, dragged: true}) } @@ -138,15 +140,8 @@ class Slider extends Canvas { cacheCanvasStyle(style) { - style = style || window.getComputedStyle(this.canvas) - super.cacheCanvasStyle(style) - this.colors.gauge = style.getPropertyValue('--color-gauge') || this.colors.custom - this.colors.knob = style.getPropertyValue('--color-knob') || this.colors.custom - this.colors.pips = style.getPropertyValue('--color-pips') || this.colors.custom - this.colors.gaugeOpacity = style.getPropertyValue('--gauge-opacity') - this.gaugePadding = this.cssVars.padding + PXSCALE } @@ -191,7 +186,7 @@ class Slider extends Canvas { var value = clip(v,[this.rangeValsMin,this.rangeValsMax]) - if ((options.dragged || options.fromLocal) && this.value.toFixed(this.precision) == value.toFixed(this.precision)) options.send = false + if ((options.dragged || options.fromLocal) && this.value.toFixed(this.decimals) == value.toFixed(this.decimals)) options.send = false this.value = value @@ -249,7 +244,6 @@ class Slider extends Canvas { } Slider.dynamicProps = Slider.prototype.constructor.dynamicProps - .filter(n => n !== 'precision') .concat([ 'steps', 'spring', diff --git a/src/client/widgets/utils.js b/src/client/widgets/utils.js index cd5ee873..f42853ec 100644 --- a/src/client/widgets/utils.js +++ b/src/client/widgets/utils.js @@ -12,7 +12,7 @@ module.exports = { }, // map a value from a scale to another input and output must be range arrays - mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) { + mapToScale: function(value,rangeIn,rangeOut,decimals,log,revertlog) { // clip in value = module.exports.clip(value,[rangeIn[0],rangeIn[1]]) @@ -34,8 +34,8 @@ module.exports = { // clip out value = module.exports.clip(value,[rangeOut[0],rangeOut[1]]) - // precision - if (precision !== false) value = parseFloat(value.toFixed(precision)) + // decimals + if (decimals !== false) value = parseFloat(value.toFixed(decimals)) return value diff --git a/src/scss/themes/default.scss b/src/scss/themes/default.scss index 75c34479..cdca9b40 100644 --- a/src/scss/themes/default.scss +++ b/src/scss/themes/default.scss @@ -27,8 +27,8 @@ $text: white; --color-accent: #{$accent}; - --color-foreground: #{$base}; - --color-background: #{mix($base, black, 85)}; + --color-background: #{$base}; + --color-ui-background: #{mix($base, black, 85)}; --color-grid: rgba(0,0,0, 0.1); --color-notification: #{rgba(black, 0.8)}; diff --git a/src/scss/ui/button.scss b/src/scss/ui/button.scss index 82802d4f..1b3e777e 100644 --- a/src/scss/ui/button.scss +++ b/src/scss/ui/button.scss @@ -1,5 +1,5 @@ .btn { - background: var(--color-foreground); + background: var(--color-background); display: block; padding:15rem; position: relative; diff --git a/src/scss/ui/filebrowser.scss b/src/scss/ui/filebrowser.scss index f8814292..bb53ddc5 100644 --- a/src/scss/ui/filebrowser.scss +++ b/src/scss/ui/filebrowser.scss @@ -1,3 +1,4 @@ +$padding: 8rem; .file-browser { @@ -7,23 +8,23 @@ display: flex; flex-direction: column; flex: 1; - padding: 2rem 8rem 8rem; - background: var(--color-background); + padding: 2rem $padding $padding; + background: var(--color-ui-background); .ariane { height: 40rem; flex-shrink: 0; line-height: 40rem; - padding-left: 10rem; - background: var(--color-foreground); + padding-left: $padding; + background: var(--color-background); margin-bottom: 2rem; } .file-list { overflow-y: auto; flex:1; - background: var(--color-foreground); - padding: 0 10rem; + background: var(--color-background); + padding: 0 $padding; } .file { position: relative; @@ -54,8 +55,8 @@ &:before { content:""; position: absolute; - left:-10rem; - right:-10rem; + left:-$padding; + right:-$padding; height: 100%; background: var(--color-widget); opacity: 0.1; @@ -69,9 +70,9 @@ justify-content: flex-end; height: 40rem; flex-shrink: 0; - margin-top: 10rem; + margin-top: $padding; div { - margin-left: 10rem; + margin-left: $padding; text-overflow: clip; min-width: 0; } @@ -87,7 +88,7 @@ font-size: 120%; top: -1rem; position: relative; - background: var(--color-foreground); + background: var(--color-background); min-width: 0; &[disabled] { display: none diff --git a/src/scss/ui/inspector.scss b/src/scss/ui/inspector.scss index 02c09689..6fd26d78 100644 --- a/src/scss/ui/inspector.scss +++ b/src/scss/ui/inspector.scss @@ -4,8 +4,6 @@ $padding: 8rem; #osc-inspector { - // padding: $padding; - --widget-padding: -1rem; } @@ -37,13 +35,13 @@ osc-inspector-field { resize: none; white-space: pre; display: block; - background: var(--color-foreground); + background: var(--color-background); cursor: text; --scrollbar-size: 6rem; &::-webkit-scrollbar-thumb:horizontal { - // border-top: 4rem solid var(--color-foreground); + // border-top: 4rem solid var(--color-background); cursor: normal; } @@ -78,7 +76,7 @@ osc-inspector-category { position: relative; text-transform: none; cursor: pointer; - // color: var(--color-background); + // color: var(--color-ui-background); height: $header-height; line-height: $header-height + 1; // padding: 0 8rem; @@ -138,7 +136,7 @@ osc-inspector-checkbox { height: $field-height; width: $field-height; cursor: pointer; - background: var(--color-foreground); + background: var(--color-background); text-align: center; display: flex; align-items: center; @@ -170,10 +168,10 @@ osc-inspector-select { overflow: hidden; height: $field-height; width: $field-height; - background: var(--color-foreground); + background: var(--color-background); margin-left: 4rem; select { - background: var(--color-foreground); + background: var(--color-background); // width: 100%; line-height: $field-height - 8rem; padding: 4rem 6rem; @@ -182,10 +180,10 @@ osc-inspector-select { left:0; opacity: 0; optgroup { - background: var(--color-foreground); + background: var(--color-background); font-weight: bold; option { - background: var(--color-background); + background: var(--color-ui-background); color: var(--color-text); margin-left: -4rem; font-weight: normal; @@ -221,7 +219,7 @@ osc-inspector-color { overflow: hidden; height: $field-height; width: $field-height; - background: var(--color-foreground); + background: var(--color-background); margin-left: 4rem; cursor: pointer; @@ -238,10 +236,10 @@ osc-inspector-color { .color-picker-modal { padding: 8rem; - background: var(--color-background); + background: var(--color-ui-background); .widget { - background: var(--color-foreground); + background: var(--color-background); } .actions { diff --git a/src/scss/ui/loading.scss b/src/scss/ui/loading.scss index 6504ac0a..ed10dc4b 100644 --- a/src/scss/ui/loading.scss +++ b/src/scss/ui/loading.scss @@ -25,7 +25,7 @@ top:-3rem; right:-3rem; bottom:-3rem; - border:4rem solid var(--color-background); + border:4rem solid var(--color-ui-background); border-top: 2rem solid var(--color-widget); transform: rotateZ(0deg); animation: spin .5s linear infinite; diff --git a/src/scss/ui/lobby.scss b/src/scss/ui/lobby.scss index 132d6729..b86c0b5c 100644 --- a/src/scss/ui/lobby.scss +++ b/src/scss/ui/lobby.scss @@ -1,3 +1,4 @@ +$padding: 8rem; .lobby { @@ -7,15 +8,15 @@ display: flex; flex-direction: column; flex: 1; - background: var(--color-background); - padding: 2rem 8rem 8rem; + background: var(--color-ui-background); + padding: 2rem $padding $padding; .list { overflow: auto; text-transform: none; flex: 1; - background: var(--color-foreground); - padding: 0 10rem; + background: var(--color-background); + padding: 0 $padding; a { padding-right: 30rem; } @@ -23,16 +24,16 @@ } .footer { - margin-top: 10rem; + margin-top: $padding; white-space: nowrap; text-overflow: ellipsis; flex-grow: 0; display: flex; flex-direction: row; a { - margin-left: 10rem; + margin-left: $padding; text-align: center; - background: var(--color-foreground); + background: var(--color-background); &:first-child { margin: 0; } diff --git a/src/scss/ui/modal.scss b/src/scss/ui/modal.scss index 0251e498..c6edbdd8 100644 --- a/src/scss/ui/modal.scss +++ b/src/scss/ui/modal.scss @@ -1,3 +1,5 @@ +$padding: 8rem; + @keyframes popup-backdrop-fade-in { 0% {opacity: 0} 100% {opacity: .1} @@ -42,14 +44,14 @@ min-height: var(--nav-height); height: var(--nav-height); display: flex; - padding:0 15rem; + padding:0 $padding * 2 - 1; align-items: center; - background: var(--color-background); + background: var(--color-ui-background); .title { flex:1; overflow: hidden; } - i { + > i { margin-right: 5rem; } &.closable { @@ -73,7 +75,7 @@ } } .popup-wrapper { - background: var(--color-foreground); + background: var(--color-ui-background); display: flex; flex-direction: column; align-items: stretch; diff --git a/src/scss/ui/scrollbars.scss b/src/scss/ui/scrollbars.scss index bb96f2ee..6622c2e3 100644 --- a/src/scss/ui/scrollbars.scss +++ b/src/scss/ui/scrollbars.scss @@ -4,12 +4,12 @@ } ::-webkit-scrollbar-track-piece { - background: var(--color-foreground); + background: var(--color-background); &:vertical { - border-left: 1rem solid var(--color-foreground); + border-left: 1rem solid var(--color-background); } &:horizontal { - border-top: 1rem solid var(--color-foreground); + border-top: 1rem solid var(--color-background); } } @@ -19,10 +19,10 @@ background: var(--color-scrollbar-on); } &:vertical { - border-left: 1rem solid var(--color-foreground); + border-left: 1rem solid var(--color-background); } &:horizontal { - border-top: 1rem solid var(--color-foreground); + border-top: 1rem solid var(--color-background); } } @@ -34,7 +34,7 @@ ::-webkit-scrollbar-corner { height: 0rem; width: 0rem; - background: var(--color-foreground); + background: var(--color-background); } diff --git a/src/scss/ui/workspaces.scss b/src/scss/ui/workspaces.scss index 5fbe2649..35084fd3 100644 --- a/src/scss/ui/workspaces.scss +++ b/src/scss/ui/workspaces.scss @@ -1,6 +1,6 @@ osc-workspace { - background: var(--color-background); + background: var(--color-ui-background); --color-fill: var(--color-widget); --color-stroke: var(--color-widget); @@ -42,7 +42,7 @@ osc-panel-container { } ::-webkit-scrollbar-thumb, ::-webkit-scrollbar-track-piece { - border-color: var(--color-background)!important; + border-color: var(--color-ui-background)!important; } } @@ -76,7 +76,7 @@ osc-panel-container { width: 25rem; margin-top: -25rem; cursor: pointer; - background: var(--color-background); + background: var(--color-ui-background); font-size: 14rem; z-index: 2; transition: transform 0.2s ease-out 0.1s; @@ -213,7 +213,7 @@ osc-panel-content { overflow-y: auto; &.left, &.right { - border-right: 1rem solid var(--color-background); + border-right: 1rem solid var(--color-ui-background); } diff --git a/src/scss/widgets.scss b/src/scss/widgets.scss index c002ca80..64d20799 100644 --- a/src/scss/widgets.scss +++ b/src/scss/widgets.scss @@ -12,6 +12,8 @@ width: 100rem; height: 100rem; + background-clip: content-box; + contain: strict; @supports not (contain: strict) { transform: rotateZ(0); // force new stacking context @@ -31,7 +33,8 @@ --alpha-fill-on: 0.25; --alpha-fill: var(--alpha-fill-off); - --alpha-pips: 0.7; + --alpha-pips: 0.5; + --alpha-pips-text: 0.7; color: var(--color-text); diff --git a/src/scss/widgets/buttons.scss b/src/scss/widgets/buttons.scss index 3762a173..9a27f544 100644 --- a/src/scss/widgets/buttons.scss +++ b/src/scss/widgets/buttons.scss @@ -3,7 +3,7 @@ --alpha-fill-off: 0; --alpha-fill-on: .75; --widget-padding: -1rem; - --color-text-on: var(--color-foreground); + --color-text-on: var(--color-background); inner { @@ -53,7 +53,7 @@ --alpha-fill-on: 0.75; --alpha-fill: var(--alpha-fill-off); - --color-text-on: var(--color-foreground); + --color-text-on: var(--color-background); inner { @@ -173,7 +173,7 @@ overflow: hidden; - background: var(--color-foreground); + background: var(--color-background); @include pseudo-stroke($z: 2); &:before { @@ -211,8 +211,8 @@ left: 50%; margin-left: calc(-1 * var(--size) / 8 + 6rem); margin-top: calc(-1 * var(--size) / 8 + 6rem); - background: var(--color-foreground); - box-shadow: 0 0 0 2rem var(--color-foreground), 0 0 0 3rem var(--color-stroke); + background: var(--color-background); + box-shadow: 0 0 0 2rem var(--color-background), 0 0 0 3rem var(--color-stroke); border-radius: 100%; z-index: 10; opacity: var(--alpha-stroke); @@ -225,7 +225,7 @@ height: 100%; transform-origin: 100% 100%; position: absolute; - box-shadow: 0 0 0 2rem var(--color-foreground); + box-shadow: 0 0 0 2rem var(--color-background); div { @@ -304,7 +304,7 @@ } &.on { - color: var(--color-foreground); + color: var(--color-background); div:after { opacity: var(--alpha-fill)!important; } @@ -403,7 +403,7 @@ -webkit-appearance:none; -moz-appearance:none; appearance:none; - background: var(--color-foreground); + background: var(--color-background); opacity: 0; } diff --git a/src/scss/widgets/containers.scss b/src/scss/widgets/containers.scss index 9f255a62..fa264a4b 100644 --- a/src/scss/widgets/containers.scss +++ b/src/scss/widgets/containers.scss @@ -5,7 +5,7 @@ width: 100%; height: 100%; - background-color: var(--color-foreground); + background-color: var(--color-background); > inner { flex: 1; @@ -29,8 +29,7 @@ --widget-padding: 4rem; - background-color: var(--color-foreground); - background-clip: content-box; + background-color: var(--color-background); > inner { @@ -64,7 +63,9 @@ position: relative!important; height: auto!important; min-height: auto!important; + min-width: auto!important; max-height: 100%; + max-width: 100%; } } &.layout-vertical > inner { @@ -76,7 +77,9 @@ left:auto!important; position: relative!important; width: auto!important; + min-height: auto!important; min-width: auto!important; + max-height: 100%; max-width: 100%; } @@ -129,7 +132,7 @@ width: 100%; flex: 1; height: 100%; - background-color: var(--color-foreground); + background-color: var(--color-background); &:not(.show) { display:none @@ -141,8 +144,7 @@ } -.panel-container, -.matrix-container { +.panel-container { @extend .widget-panel-base; @@ -156,7 +158,7 @@ > label { position: relative; - // background-color: var(--color-foreground); + // background-color: var(--color-background); @include pseudo-stroke($z: 10); &:before { border-width: 0 0 1rem 0; @@ -165,7 +167,7 @@ } &.contains-widgets.nolabel > inner { - border-top: 1rem solid var(--color-foreground); + border-top: 1rem solid var(--color-background); } &.contains-tabs > inner > .navigation { @@ -178,7 +180,7 @@ .navigation { - background-color: var(--color-background); + background-color: var(--color-ui-background); height:calc(var(--nav-height) - 1rem); flex-shrink:0; @@ -275,6 +277,11 @@ } } + &:before { + content: none + } + + > label { display: none; } @@ -378,7 +385,7 @@ --alpha-fill:var(--alpha-fill-on); } > label, > label:after { - color: var(--color-foreground); + color: var(--color-background); opacity: 1; } @@ -429,3 +436,17 @@ } } + + +.matrix-container { + + @extend .panel-container; + + + &.layout-vertical, &.layout-horizontal { + > inner > .widget { + flex: 1; + } + } + +} diff --git a/src/scss/widgets/inputs.scss b/src/scss/widgets/inputs.scss index feb0dba1..5369ce11 100644 --- a/src/scss/widgets/inputs.scss +++ b/src/scss/widgets/inputs.scss @@ -55,7 +55,7 @@ &:focus::selection { background: var(--color-fill); - color: var(--color-foreground); + color: var(--color-background); } } diff --git a/src/scss/widgets/plots.scss b/src/scss/widgets/plots.scss index 9e9abae2..016b2c4f 100644 --- a/src/scss/widgets/plots.scss +++ b/src/scss/widgets/plots.scss @@ -2,6 +2,9 @@ .visualizer-container, .plot-container { + width: 200rem; + height: 200rem; + --alpha-fill-off: 0.05; --alpha-fill-on: 0.1; --widget-padding: 20rem; diff --git a/src/scss/widgets/sliders.scss b/src/scss/widgets/sliders.scss index e9844359..f125d77f 100644 --- a/src/scss/widgets/sliders.scss +++ b/src/scss/widgets/sliders.scss @@ -18,8 +18,15 @@ .fader-container, .range-container { + width: 50rem; + height: 200rem; + --widget-padding: 1rem; + canvas { + text-align: left; + } + &.design-classic { --widget-padding: 10rem; --alpha-stroke: 0.5; @@ -39,6 +46,9 @@ .knob-container, .encoder-container { + width: 100rem; + height: 100rem; + --widget-padding: 1rem; --alpha-stroke: 0.75; diff --git a/src/server/callbacks.js b/src/server/callbacks.js index ba4f1c01..9e847107 100644 --- a/src/server/callbacks.js +++ b/src/server/callbacks.js @@ -314,7 +314,7 @@ module.exports = { if (port) { - osc.send(host, port, data.address, data.args, data.precision) + osc.send(host, port, data.address, data.args, data.typeTags) } diff --git a/src/server/osc/index.js b/src/server/osc/index.js index f8e68043..b0505939 100644 --- a/src/server/osc/index.js +++ b/src/server/osc/index.js @@ -113,36 +113,41 @@ class OscServer { } - parseType(type){ - var t = type[0].match(/[bhtdscrmifTFNI]/) + parseArg(arg, type){ + + if (arg === null) return null + + if (type && type[0].match(/[bhtdscrmifTFNI]/)) { + + type = type[0] + + switch (type) { + case 'i': + return {type: type, value: parseInt(arg)} + case 'd': + case 'f': + return {type: type, value: parseFloat(arg)} + case 'T': + case 'F': + case 'N': + return {type: type} + default: + return {type: type, value: arg} + + + } - if (t!==null) { - return t[0] - } else { - return 's' } - } - - parseArg(arg, precision){ - if (arg==null) return null switch (typeof arg) { case 'number': - var typeTagMatch = typeof precision == 'string' ? precision.match(/[0-9]+([a-zA-Z]{1})/) : null, - typeTag = typeTagMatch === null ? precision === 0 ? 'i' : 'f' : typeTagMatch[1], - precisionValue = parseFloat(precision) || 0 - - return {type: typeTag, value: precision === undefined ? arg : parseFloat(arg.toFixed(precisionValue))} + return {type: 'f', value: arg} case 'boolean': - return {type: arg ? 'T' : 'F', value: arg} - case 'object': - if (arg.type) { - return {type: this.parseType(arg.type), value: arg.value} - } else { - return {type: 's', value:JSON.stringify(arg)} - } + return {type: arg ? 'T' : 'F'} case 'string': return {type: 's', value:arg} + case 'object': + if (arg.type) return arg default: return {type: 's', value:JSON.stringify(arg)} } @@ -176,7 +181,7 @@ class OscServer { address: data.address, args: data.args }, data.host, data.port) - + } if (debug) console.log('OSC sent: ',{address:data.address, args: data.args}, 'To: ' + data.host + ':' + data.port) @@ -272,15 +277,24 @@ oscServer.init() module.exports = { server: oscServer, - send: function(host,port,address,args,precision) { + send: function(host, port, address, args, typeTags) { var message = [] if (!Array.isArray(args)) args = [args] - if (typeof args=='object' && args!==null) { - for (var i in args) { - var arg = oscServer.parseArg(args[i],precision) - if (arg!=null) message.push(arg) + + if (typeof args === 'object' && args !== null) { + + var typeTag, + arg + + for (var i = 0; i < args.length; i++) { + + typeTag = typeTags[i] || typeTag + arg = oscServer.parseArg(args[i], typeTag) + + if (arg !== null) message.push(arg) + } } diff --git a/src/server/utils.js b/src/server/utils.js index 865302fb..41aae6dd 100644 --- a/src/server/utils.js +++ b/src/server/utils.js @@ -1,6 +1,6 @@ module.exports = { - deepCopy: function(obj, precision) { + deepCopy: function(obj) { var copy = obj @@ -11,10 +11,8 @@ module.exports = { if (typeof obj === 'object') { copy = Array.isArray(obj) ? [] : {} for (let key in obj) { - copy[key] = module.exports.deepCopy(obj[key], precision) + copy[key] = module.exports.deepCopy(obj[key]) } - } else if (typeof obj == 'number') { - return precision === undefined ? copy : parseFloat(copy.toFixed(precision)) } return copy