rename precision to decimals, add typeTags, continue refactoring
This commit is contained in:
parent
37bf03a336
commit
9eb5dd5060
54 changed files with 426 additions and 256 deletions
|
|
@ -37,12 +37,8 @@
|
|||
<osc-panel-content class="right" id="osc-inspector"></osc-panel-content>
|
||||
</osc-panel-inner>
|
||||
</osc-panel-container>
|
||||
<osc-modal-container></osc-modal-container>
|
||||
<osc-modal-container class="backdrop"></osc-modal-container>
|
||||
</osc-workspace>
|
||||
<div style="display:none" class="hide">
|
||||
<div id="sidepanel-wrapper"></div>
|
||||
<div id="sidepanel-handle"></div>
|
||||
</div>
|
||||
<div id="notifications"></div>
|
||||
</body>
|
||||
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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`<osc-inspector-color type="text" name="${this.name}" value="${val}" style="--color-picker-value: ${val}"></osc-inspector-color>`
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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}</li>`
|
||||
|
||||
if (widget instanceof Panel && !(widget instanceof Matrix)) {
|
||||
if (widget instanceof Panel && !(widget instanceof Matrix || widget instanceof Keyboard)) {
|
||||
node.insertBefore(html`<span class="toggle no-widget-select"></span>`, node.childNodes[0])
|
||||
node.classList.add('container')
|
||||
if (this.expanded[id]) node.classList.add('expanded')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
])
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -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'},
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ module.exports = class Tab extends Panel {
|
|||
|
||||
isVisible() {
|
||||
|
||||
return !this.detached && super.isVisible()
|
||||
return !this.detached && super.isVisible()
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class Html extends StaticProperties(Widget, {bypass: true}) {
|
|||
' table, thead, img, caption, tbody, tr, th, td, pre'
|
||||
]},
|
||||
|
||||
}, ['precision', 'bypass'], {})
|
||||
}, ['decimals', 'bypass'], {})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)',
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class Svg extends StaticProperties(Widget, {bypass: true}) {
|
|||
'- `<path>` commands support a special percent notation (`%x` and `%y`)'
|
||||
]},
|
||||
|
||||
}, ['precision', 'bypass'], {})
|
||||
}, ['decimals', 'bypass'], {})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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'], {})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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`',
|
||||
|
|
|
|||
|
|
@ -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'], {})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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{{
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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}),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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`<div class="pips"></div>`
|
||||
for (var i=0;i<=100;i++) {
|
||||
if (pipTexts[i]==undefined) continue
|
||||
|
||||
var pos = this.getProp('horizontal')?'left':'bottom'
|
||||
|
||||
pips.appendChild(html`
|
||||
<div class="pip val" style="${pos}:${i}%">
|
||||
<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>
|
||||
</div>
|
||||
`)
|
||||
|
||||
}
|
||||
|
||||
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++
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
.btn {
|
||||
background: var(--color-foreground);
|
||||
background: var(--color-background);
|
||||
display: block;
|
||||
padding:15rem;
|
||||
position: relative;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
|
||||
&:focus::selection {
|
||||
background: var(--color-fill);
|
||||
color: var(--color-foreground);
|
||||
color: var(--color-background);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue