diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d592a66..851868df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## next +- custom module + - remove support for extra args (avoid path issues) + - widgets - knob: add `solid` & `line` designs - fader: add `knobSize` property diff --git a/resources/docs/docs/getting-started/server-configuration.md b/resources/docs/docs/getting-started/server-configuration.md index aa834a31..eec3dfe2 100644 --- a/resources/docs/docs/getting-started/server-configuration.md +++ b/resources/docs/docs/getting-started/server-configuration.md @@ -12,16 +12,16 @@ The **server** can be configured with many options, either from a terminal or wi === "load" - Path to a session file. All clients connecting the server will load it. + Path to a session file (.json). All clients connecting the server will load it. === "state" - Path to a state file. All clients connecting the server will load it. + Path to a state file (.state). All clients connecting the server will load it. === "custom-module" - Path to a custom module file. Additional options can be passed after the path, they'll be accessible in the custom module's context. + Path to a custom module file (.js). === "port" diff --git a/src/client/editor/data-workers.js b/src/client/editor/data-workers.js index d3a4eb47..7e7de5d9 100644 --- a/src/client/editor/data-workers.js +++ b/src/client/editor/data-workers.js @@ -176,7 +176,7 @@ var incrementWidget = function(data, root){ data.address = 'auto' } else if (address !== 'auto') { - + var addressref while (fakeStore.address.indexOf(address) != -1 || widgetManager.getWidgetByAddress(addressref).length) { address = address.replace(/([0-9]*)$/,function(m){ diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index ea96a0ef..5dcc720f 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -80,6 +80,7 @@ class Widget extends EventEmitter { alphaFillOff: {type: 'number', value: 'auto', help: 'Fill color opacity (off).'}, alphaFillOn: {type: 'number', value: 'auto', help: 'Fill color opacity (on).'}, + strokeWidth: {type: 'number', value: 'auto', help: 'Stroke width.'}, padding: {type: 'number', value: 'auto', help: 'Inner spacing.'}, @@ -1038,6 +1039,7 @@ Widget.cssVariables = [ {js: 'colorStroke', css: '--color-stroke'}, {js: 'colorText', css: '--color-text'}, {js: 'padding', css: '--widget-padding', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE}, + {js: 'strokeWidth', css: '--stroke-width', 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)}, diff --git a/src/client/widgets/frames/image.js b/src/client/widgets/frames/image.js index 86a4fb1f..c5c65885 100644 --- a/src/client/widgets/frames/image.js +++ b/src/client/widgets/frames/image.js @@ -55,6 +55,8 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) { setValue(v, options={}) { + if (typeof this.value !== 'string') return + var s = v==null ? '' : '' + v, cache_query = '' diff --git a/src/client/widgets/graphs/plot.js b/src/client/widgets/graphs/plot.js index 8cc8325e..d104fbcb 100644 --- a/src/client/widgets/graphs/plot.js +++ b/src/client/widgets/graphs/plot.js @@ -88,7 +88,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte this.ctx.fillStyle = this.cssVars.colorText this.ctx.globalAlpha = this.cssVars.alphaPips - var margin = this.cssVars.padding + var margin = this.cssVars.padding + this.cssVars.strokeWidth if (margin < this.fontSize * 1.5) return @@ -114,7 +114,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte draw_line() { var points = [], - padding = this.cssVars.padding + PXSCALE, + padding = this.cssVars.padding + this.cssVars.strokeWidth, decimals = this.getProp('smooth') ? 1 : 0, length = this.value.length, x, y, i, previousValue, nx, ny diff --git a/src/client/widgets/pads/pad.js b/src/client/widgets/pads/pad.js index 7bd3d9ec..e9c925ce 100644 --- a/src/client/widgets/pads/pad.js +++ b/src/client/widgets/pads/pad.js @@ -22,7 +22,7 @@ class Pad extends Canvas { super.cacheCanvasStyle(style) this.pointSize = parseFloat(style.getPropertyValue('--pointSize')) * PXSCALE - this.padPadding = (this.cssVars.padding + PXSCALE) + this.padPadding = (this.cssVars.padding + this.cssVars.strokeWidth) } diff --git a/src/client/widgets/sliders/encoder.js b/src/client/widgets/sliders/encoder.js index 563b8b41..ac8716ce 100644 --- a/src/client/widgets/sliders/encoder.js +++ b/src/client/widgets/sliders/encoder.js @@ -213,7 +213,7 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range min = this.percentToAngle(0), max = this.percentToAngle(100), minRadius = this.minDimension / 6, - maxRadius = this.minDimension / 2 - PXSCALE, + maxRadius = this.minDimension / 2 - this.cssVars.strokeWidth, gaugeWidth = maxRadius - minRadius, gaugeRadius = maxRadius - gaugeWidth / 2 @@ -245,20 +245,23 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range } // stroke + if (this.cssVars.strokeWidth) { - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.lineWidth = PXSCALE + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.lineWidth = this.cssVars.strokeWidth + + if (this.minDimension > 40) { + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI) + this.ctx.stroke() + } - if (this.minDimension > 40) { this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI) + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) this.ctx.stroke() + } - - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) - this.ctx.stroke() } diff --git a/src/client/widgets/sliders/fader.js b/src/client/widgets/sliders/fader.js index 3da9cff5..5821fe0e 100644 --- a/src/client/widgets/sliders/fader.js +++ b/src/client/widgets/sliders/fader.js @@ -91,7 +91,7 @@ class Fader extends Slider { super.dragHandle(...arguments) var padding = this.gaugePadding - if (this.getProp('design') === 'compact') padding += this.cssVars.knobSize * PXSCALE / 2 + if (this.getProp('design') === 'compact') padding += this.cssVars.knobSize / 2 this.percent = this.getProp('horizontal')? this.percent + ( e.movementX / (this.width - padding * 2)) * 100 / e.inertia * this.getProp('sensitivity'): @@ -235,18 +235,21 @@ class Fader extends Slider { if (compact) { // stroke + if (this.cssVars.strokeWidth) { - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.beginPath() - this.ctx.moveTo(0, 0) - this.ctx.lineTo(width, 0) - this.ctx.lineTo(width, height) - this.ctx.lineTo(0, height) - this.ctx.closePath() - this.ctx.lineWidth = 2 * PXSCALE - this.ctx.stroke() + this.ctx.beginPath() + this.ctx.moveTo(0, 0) + this.ctx.lineTo(width, 0) + this.ctx.lineTo(width, height) + this.ctx.lineTo(0, height) + this.ctx.closePath() + this.ctx.lineWidth = 2 * this.cssVars.strokeWidth + this.ctx.stroke() + + } // flat knob diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index c9f101ba..c25f8daf 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -176,8 +176,8 @@ module.exports = class Knob extends Slider { max = this.percentToAngle(100), dashed = this.getProp('dashed'), pips = this.getProp('pips'), - minRadius = this.minDimension / 6 - (pips ? this.fontSize * 0.75 : PXSCALE), - maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 2 : PXSCALE) + minRadius = this.minDimension / 6 - (pips ? this.fontSize * 0.75 : 0) - this.cssVars.strokeWidth / 2, + maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 2 : 0) - this.cssVars.strokeWidth / 2 if (dashed) dashed = Array.isArray(dashed) ? dashed.map(x=>parseFloat(x)) : [1.5, 1.5] @@ -218,14 +218,15 @@ module.exports = class Knob extends Slider { // stroke + if (this.cssVars.strokeWidth) { + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.lineWidth = this.cssVars.strokeWidth - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.lineWidth = PXSCALE - - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) - this.ctx.stroke() + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) + this.ctx.stroke() + } // knob diff --git a/src/client/widgets/sliders/range.js b/src/client/widgets/sliders/range.js index 5100623f..6f72c620 100644 --- a/src/client/widgets/sliders/range.js +++ b/src/client/widgets/sliders/range.js @@ -275,7 +275,7 @@ class Range extends Fader { this.ctx.lineTo(width, height) this.ctx.lineTo(0, height) this.ctx.closePath() - this.ctx.lineWidth = 2 * PXSCALE + this.ctx.lineWidth = 2 * this.cssVars.strokeWidth this.ctx.stroke() diff --git a/src/client/widgets/sliders/slider.js b/src/client/widgets/sliders/slider.js index 6cbac1ae..a5c76a13 100644 --- a/src/client/widgets/sliders/slider.js +++ b/src/client/widgets/sliders/slider.js @@ -144,7 +144,7 @@ class Slider extends Canvas { super.cacheCanvasStyle(style) - this.gaugePadding = this.cssVars.padding + PXSCALE + this.gaugePadding = this.cssVars.padding + this.cssVars.strokeWidth } diff --git a/src/scss/mixins.scss b/src/scss/mixins.scss index bd36870f..3eec8e69 100644 --- a/src/scss/mixins.scss +++ b/src/scss/mixins.scss @@ -2,7 +2,7 @@ &:before { content:""; position: absolute; - border: 1rem solid var(--color-stroke); + border: var(--stroke-width) solid var(--color-stroke); opacity: var(--alpha-stroke); top: 0; left: 0; @@ -20,10 +20,10 @@ position: absolute; background: var(--color-fill); opacity: var(--alpha-fill); - top: 1rem; - left: 1rem; - right: 1rem; - bottom: 1rem; + top: var(--stroke-width); + left: var(--stroke-width); + right: var(--stroke-width); + bottom: var(--stroke-width); pointer-events: none; margin: var(--widget-padding); z-index: $z; diff --git a/src/scss/themes/default.scss b/src/scss/themes/default.scss index 2997ce9a..e5f296ca 100644 --- a/src/scss/themes/default.scss +++ b/src/scss/themes/default.scss @@ -29,6 +29,8 @@ $font-menu: sans-serif; --color-context-menu-text: #{$nord1}; + --stroke-width: 1rem; + --alpha-scrollbar: 0.25; --alpha-scrollbar-on: 0.75; --scrollbar-size: 12rem; diff --git a/src/scss/widgets.scss b/src/scss/widgets.scss index 2179da29..89874732 100644 --- a/src/scss/widgets.scss +++ b/src/scss/widgets.scss @@ -23,6 +23,7 @@ // transform-origin: top left; + --stroke-width: 1rem; --widget-padding: 1rem; --color-stroke:var(--color-widget); diff --git a/src/scss/widgets/basics.scss b/src/scss/widgets/basics.scss index 3215a9c9..e43b2b73 100644 --- a/src/scss/widgets/basics.scss +++ b/src/scss/widgets/basics.scss @@ -88,7 +88,7 @@ display: flex; flex-direction: column; --widget-spacing: calc(var(--widget-padding) / 2); - margin: calc(var(--widget-spacing) + 1rem); + margin: calc(var(--widget-spacing) + var(--stroke-width)); } @@ -125,6 +125,7 @@ overflow: hidden; @include pseudo-fill($z: -1); &:after { + --stroke-width: 1rem; margin: calc(var(--widget-spacing) - 1rem); } diff --git a/src/scss/widgets/containers.scss b/src/scss/widgets/containers.scss index d72284f8..619abb83 100644 --- a/src/scss/widgets/containers.scss +++ b/src/scss/widgets/containers.scss @@ -188,7 +188,7 @@ &.contains-widgets { > inner { - margin: calc(var(--widget-spacing) + 1rem); + margin: calc(var(--widget-spacing) + var(--stroke-width)); } &.no-inner-padding > inner { @@ -533,6 +533,7 @@ .patchbaynode-container { justify-content: center; + background: transparent; } .patchbay-container { @@ -555,21 +556,23 @@ display: flex; flex-direction: column; align-items:stretch; - margin-bottom: 1rem; + margin-bottom: var(--stroke-width); width: 25%; } .inputs, .outputs { position: relative; @include pseudo-stroke(); - top: 1rem; + top: var(--stroke-width); + margin-top: -1rem; + height: calc(100% - var(--stroke-width) * 2 + 2rem); } .inputs:before { - border-width: 0 1rem 0 0; + border-width: 0 var(--stroke-width) 0 0; } .outputs:before { - border-width: 0 0 0 1rem; + border-width: 0 0 0 var(--stroke-width); } } diff --git a/src/scss/widgets/pads.scss b/src/scss/widgets/pads.scss index 6522d176..e502a506 100644 --- a/src/scss/widgets/pads.scss +++ b/src/scss/widgets/pads.scss @@ -52,7 +52,7 @@ --widget-spacing: calc(var(--widget-padding) / 2); - padding: var(--widget-spacing); + padding: calc(var(--stroke-width) + var(--widget-spacing)); grid-template: "a a b" auto / 1fr; @@ -70,6 +70,7 @@ width: auto; margin: var(--widget-spacing); --widget-padding: 2rem; + --stroke-width: 0; } .pad { @@ -98,7 +99,7 @@ --alpha-fill-off: 0.5; --alpha-fill-on: 0; --alpha-stroke: 0; - --widget-padding: -1rem; + --widget-padding: 0rem; &:after { content:""; @@ -120,7 +121,7 @@ --alpha-stroke: 0; --alpha-fill-off: 0.1; --alpha-fill-on: 0.25; - --widget-padding: -1rem; + --widget-padding: 0rem; } } diff --git a/src/server/options.js b/src/server/options.js index 85cd5e63..c667ce4c 100644 --- a/src/server/options.js +++ b/src/server/options.js @@ -7,31 +7,19 @@ module.exports = { 'Targets must be ip:port or hostname:port pairs (port must be >= 1024) or midi:port_name pairs' : true } }, - 'l': {alias: 'load', type: 'string', file: {name: 'OSC Session (.json)', extensions: ['json', 'js']}, describe: 'session file to load', + 'l': {alias: 'load', type: 'string', file: {name: 'OSC Session (.json)', extensions: ['json']}, describe: 'session file to load (.json)', check: (arg)=>{ return fs.existsSync(arg) ? true : 'Session file not found: ' + arg } }, - 'state': {type: 'string', file: {name: 'OSC State (.state)', extensions: ['state']}, describe: 'state file to load', + 'state': {type: 'string', file: {name: 'OSC State (.state)', extensions: ['state']}, describe: 'state file to load (.state)', check: (arg)=>{ return fs.existsSync(arg) ? true : 'State file not found: ' + arg } }, - 'c': {alias: 'custom-module', type: 'array', file: {name: 'OSC Custom module (.js)', extensions: ['js']}, describe: 'custom module file to load (custom options can be passed after the filename)', + 'c': {alias: 'custom-module', type: 'string', file: {name: 'OSC Custom module (.js)', extensions: ['js']}, describe: 'custom module file to load (.js)', check: (arg)=>{ - - var customModule = arg.slice() - - // consolidate path containing whitespaces - if (!customModule[0].includes('.js')) { - var index = customModule.findIndex(x => typeof x === 'string' && x.includes('.js')) - if (index !== undefined) { - var _path = customModule.slice(0, index + 1).join(' ') - customModule.splice(0, index + 1, _path) - } - } - - return fs.existsSync(customModule[0]) ? true : 'Custom module file not found: ' + customModule[0] + return fs.existsSync(arg) ? true : 'Custom module file not found: ' + arg }, }, 'p': {alias: 'port', type: 'number', describe: 'http port of the server (default to 8080)', diff --git a/src/server/osc/index.js b/src/server/osc/index.js index cd36d31d..88140a71 100644 --- a/src/server/osc/index.js +++ b/src/server/osc/index.js @@ -21,22 +21,14 @@ class OscServer { this.customModule = (()=>{ var customModule = settings.read('custom-module') - if (!customModule) return false - // consolidate path containing whitespaces - if (!customModule[0].includes('.js')) { - var index = customModule.findIndex(x => typeof x === 'string' && x.includes('.js')) - if (index !== undefined) { - var _path = customModule.slice(0, index + 1).join(' ') - customModule.splice(0, index + 1, _path) - } - } + if (!customModule) return false var file = (()=>{ try { - return fs.readFileSync(customModule[0], 'utf8') + return fs.readFileSync(customModule, 'utf8') } catch(err) { - console.error('(ERROR) Custom module not found: ' + customModule[0]) + console.error('(ERROR) Custom module not found: ' + customModule) return false } })(), @@ -66,7 +58,7 @@ class OscServer { loadJSON: (url)=>{ if (url.split('.').pop() === 'json') { try { - url = path.resolve(path.dirname(customModule[0]), url) + url = path.resolve(path.dirname(customModule), url) return JSON.parse(fs.readFileSync(url, 'utf8')) } catch(e) { console.error('(ERROR) could not load json file from ' + url) @@ -78,7 +70,7 @@ class OscServer { }, saveJSON: (url, data)=>{ if (url.split('.').pop() === 'json') { - url = path.resolve(path.dirname(customModule[0]), url) + url = path.resolve(path.dirname(customModule), url) try { return fs.writeFileSync(url, JSON.stringify(data, null, ' ')) } catch(e) { @@ -93,7 +85,6 @@ class OscServer { setTimeout, clearTimeout, setInterval, clearInterval, settings, - options: customModule.slice(1, customModule.length), module: {}, }) @@ -103,7 +94,7 @@ class OscServer { process.mainModule.require = process.dlopen = null // run mod = vm.runInContext(file, context, { - filename: customModule[0] + filename: customModule }) if (context.module.exports) mod = context.module.exports } catch(err) {