diff --git a/CHANGELOG.md b/CHANGELOG.md index 738af287..825eabbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,61 @@ # Changelog +## 1.6.3 + +- bug fixes + - missing context menu (copy, paste) in inspector inputs + - osc listeners not resolving "auto" address + - `ELECTRON_RUN_AS_NODE` headless mode not working without `--no-gui` option + +- editor + - add console panel under the inspector to ease debugging + +- widgets + - keyboard: add `velocity` property (allows mapping the touch coordinates between `off` (top) and `on` (bottom)) + - input: add `validation` property (allows defining a regular expression that the valud must match) +- midi + - accept sending sysex strings without spaces between the bytes + +- misc + - sessions converted from v0 will use the widget's html property to display the former label property + +## 1.6.2 + +- bug fixes + - matrix: issues when changing non-dynamic properties (content not properly removed) + - input: apply default value when receiving an empty value or no value at all + +## 1.6.1 + +- bug fixes + - keyboard: prevent `script` property from being copied to each key + +- widgets + - keyboard: make `on` and `off` properties dynamic + - script: add `getIndex` function + - matrix/keyboard: `id` variable in script is now the `id` of the child widget that triggered the event + ## 1.6.0 +- bug fixes + - range: error when setting `default` property + - range: fix `doubleTap` property + - widgets - all: add `html` property to allow inserting custom content in widgets (label, value, etc) and style it with the `css` property. +- scripting: + - `send()`: ignore the widget's `bypass` property (allows bypassing default messages and define custom ones) + - `set()`: add supports for wildcards in the id parameter + - `set()`: add a 3rd optional parameter for preventing further script executions and/or osc messages from being sent + - custom module - automatically reload custom module when the file is modified - add support for loading submodules with `require()` +- theme + - automatically reload theme when the file is modified + ## 1.5.4 - bug fixes diff --git a/package.json b/package.json index 3566ac61..35bdd1e8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-stage-control", "productName": "Open Stage Control", "description": "Libre and modular OSC / MIDI controller", - "version": "1.5.4", + "version": "1.6.2", "author": { "name": "Jean-Emmanuel Doucet", "email": "jean-emmanuel@ammd.net" diff --git a/resources/docs/docs/custom-module/custom-module.md b/resources/docs/docs/custom-module/custom-module.md index 40e2b465..f36dcb0c 100644 --- a/resources/docs/docs/custom-module/custom-module.md +++ b/resources/docs/docs/custom-module/custom-module.md @@ -81,6 +81,12 @@ Returns specified server option. `name` must be the option's long name without t ---- +#### `settings.appAddresses()` + +Returns the server's http addresses. + +---- + #### `options` `Array` containing the extra options passed to `--custom-module` after the filename diff --git a/resources/docs/docs/widgets/advanced-syntaxes.md b/resources/docs/docs/widgets/advanced-syntaxes.md index 75574649..8b5b91d5 100644 --- a/resources/docs/docs/widgets/advanced-syntaxes.md +++ b/resources/docs/docs/widgets/advanced-syntaxes.md @@ -18,7 +18,7 @@ A widget can fetch its own properties or its direct parent's by using the keywor #### `uuid` -Each widget has a unique random identifier that can be retreived with the property name `uuid` (e.g. `@{this.uuid}`, `@{parent.uuid}`). +Each widget has a unique random identifier that can be retreived with the property name `uuid` (e.g. `@{this.uuid}`, `@{parent.uuid}`). #### Dynamic properties @@ -34,12 +34,12 @@ Some properties have much cheaper update routines and can be considered as `dyna #### Object properties -If the retreived property is an object (`{}`) or an array (`[]`), a subset can be retreived directly by appending a dot and a key (array index or object key) : `@{parent.variables.key}` +If the retreived property is an object (`{}`), a subset can be retreived directly by appending a dot and a key (array index or object key) : `@{parent.variables.key}` #### Nesting -The inheritance syntax supports 1-level nesting : `@{fader_@{toggle_1}}` +The inheritance syntax supports 1-level nesting for defining the target widget's id dynamically : `@{fader_@{toggle_1}}` ## OSC listeners: `OSC{address, default, usePreArgs}` @@ -65,7 +65,7 @@ Options can contain `@{}` blocks. ## Javascript: `JS{{ }}` -This syntax allows writing formulas in pure javascript. The code will be compiled as a function and executed in a restricted context. +This syntax allows writing formulas in [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). The code will be compiled as a function and executed in a restricted context. - if no `return` statement is found, the formula will return an empty string - javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled @@ -84,7 +84,7 @@ A property cannot contain multiple `JS{{}}` blocks - `url`: server url, - `platform`: operating system as seen by the client -In this context, `@{} / OSC{}` are also seen as variables (named `VAR_XXX`), not as the value they hold, +In this context, `@{} / OSC{}` are also seen as variables (named `VAR_XXX`), not as the value they hold. Parsing errors can be read in the DevTool console (F12). diff --git a/resources/docs/docs/widgets/properties-reference.md b/resources/docs/docs/widgets/properties-reference.md index 30414203..7c83ddd1 100644 --- a/resources/docs/docs/widgets/properties-reference.md +++ b/resources/docs/docs/widgets/properties-reference.md @@ -42,6 +42,7 @@ |
alphaFillOn#
| `number` | "auto" | Fill color opacity (on). | |
lineWidth#
| `number` | "auto" | Stroke width. | |
padding#
| `number` | "auto" | Inner spacing. | + |
html#
| `string` | "" | Custom html content to be inserted in the widget (before the widget's content).

The code is automatically wrapped in <div class="html"></div>

Allowed HTML tags:

  h1-6, blockquote, p, a, ul, ol, nl, li,

  b, i, strong, em, strike, code, hr, br, div,

  table, thead, img, caption, tbody, tr, th, td, pre

Allowed attributes:

  <*>: class, style, title

  <img>: src, width, height | |
css#
| `string` | "" | CSS rules. See documentation.

Available css variables:
- `--color-background`: `colorBg`
- `--color-widget`: `colorWidget`
- `--color-fill`: `colorFill`
- `--color-stroke`: `colorStroke`
- `--color-text`: `colorText`
- `--widget-padding`: `padding`
- `--line-width`: `lineWidth`
- `--alpha-fill-on`: `alphaFillOn`
- `--alpha-fill-off`: `alphaFillOff`
- `--alpha-stroke`: `alphaStroke` | @@ -341,8 +342,8 @@ |
keys#
| `number` | 25 | Defines the number keys | |
start#
| `number` | 48 | MIDI note number to start with (default is C4)

Standard keyboards settings are: `[25, 48]`, `[49, 36]`, `[61, 36]`, `[88, 21]` | |
traversing#
| `boolean` | true | Set to `false` to disable traversing gestures | - |
on#
| `*` | 1 | 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#
| `*` | 0 | 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) | + |
on#
| `*` | 1 | 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#
| `*` | 0 | 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) | |
mode#
| `string` | "push" | Interraction mode:
- `push` (press & release)
- `toggle` (on/off switches)
- `tap` (no release)

Choices: `push`, `toggle`, `tap` | ??? api "
patchbay#
" @@ -456,12 +457,6 @@ ??? api "
html#
" Simple HTML parser. - === "html" - - | property | type |default | description | - | --- | --- | --- | --- | - |
html#
| `string` | "" | Allowed HTML tags:

  h1-6, blockquote, p, a, ul, ol, nl, li,

  b, i, strong, em, strike, code, hr, br, div,

  table, thead, img, caption, tbody, tr, th, td, pre

Allowed attributes:

  <*>: class, style, title

  : src, width, height | - ??? api "
image#
" Load a image (url or base64-encoded). diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 81cdf34f..b0910ec2 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -1,12 +1,11 @@ # Scripting -The `script` property allows widgets to run javascript code when their value update. It differs from the [javascript property syntax ](./advanced-syntaxes.md#available-variables) in the following ways: +The `script` property allows widgets to run [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) code when their value update. -- no `JS{{}}` wrapper, just the code -- `@{}`, `OSC{}`, `JS{{}}` and `#{}` blocks are replaced with their value before the script's compilation +!!! info "It's slightly different from the [javascript property syntax ](./advanced-syntaxes/#javascript-js-code)" -!!! warning "Avoid advanced syntax in scripts" - To avoid syntax errors it is recommended to use `getProp()` and `get()` instead of `@{}` and `OSC{}`. `JS{{}}` and `#{}` blocks should be avoided here as well. + - no `JS{{}}` wrapper, just the code + - `@{}`, `OSC{}`, `JS{{}}` and `#{}` blocks are replaced with their literal value before the script's compilation, therefore **it is recommended to avoid these syntaxes** and use `getProp()` and `get()` instead. ## Event-dependent variables @@ -18,6 +17,13 @@ Depending on what triggered the script's execution, a few variables are availabl - `value`: widget's value - `touch`: see [Touch state](#touch-state) +??? infos "Keyboard & Matrix" + In keyboards and matrices, `id` is the id of the child widget that triggered the event, and `value` is an array containing the children's values. + The touched widget's value can be retrieved with: + ```javascript + value[getIndex(id)] + ``` + **Event: keyboard** (script widget only) - `type` (`string`): `keydown` or `keyup` @@ -63,12 +69,16 @@ Returns the value of the first matching widget. ---- -#### `set(id, value)` -- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. +#### `set(id, value, options)` +- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. `id` may contains wildcards ('\*'). - `value`: new value for the widget. +- `options` (optional): `object`, accepts the following items: + - `sync: false` (prevents widgets from triggering synchronization and scripts) + - `send: false` (prevents widgets from sending osc messages) -Sets the value of the first matching widget. -If the event that triggered the script's execution was initiated by a user interaction, this will make the widget send its value as well. +Sets the value of the first matching widget. If `ìd` contains wildcards, affects all matching widgets **except** the emitting widget. + +If the event that triggered the script's execution was initiated by a user interaction, this will make the widget send its value as well (unless `options` is set to `{send: false}`). ---- @@ -77,8 +87,12 @@ If the event that triggered the script's execution was initiated by a user inter - `address`: osc address, must start with a `/` - `args`: value or `{type: "OSC_TYPE_LETTER", value: VALUE}` `object` +Sends an osc message. + If the event that triggered the script's execution was not initiated by a user interaction, this function will have no effect. +This function ignores the widget's `bypass` property. + ---- #### `getProp(id, name)` @@ -89,11 +103,18 @@ Returns the property called `"name"` of the first matching widget. ---- +#### `getIndex(id)` +- `id` (optional): widget `id` as a string. Defaults to `"this"`. + +Returns the widget's index in its container. + +---- + #### `updateProp(id, name)` - `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. - `name`: property name. -Forcers a widget to check if one of its properties has changed and update itself if needed. +Forces a widget to check if one of its properties has changed and update itself if needed. ---- @@ -174,9 +195,11 @@ Sets the scroll state of a container. #### `toolbar(i1, i2, ...)` - `iX`: menu entry index -Trigger toolbar action at specified index. Examples: +Trigger toolbar action at specified index. -- `toolbar(0, 0)` -> Open a new session -- `toolbar(3)` -> Toggle full screen +!!! example "Examples" -Actions will only be triggered if initiated with a user interaction. Fullscreen cannot be toggled with a simulated interaction (i.e. using `/SET`) + - `toolbar(0, 0)` -> Open a new session + - `toolbar(3)` -> Toggle full screen + + Actions will only be triggered if initiated with a user interaction. Fullscreen cannot be toggled with a simulated interaction (i.e. using `/SET`) diff --git a/src/client/editor/data-workers.js b/src/client/editor/data-workers.js index 3265ecb2..124ca0d3 100644 --- a/src/client/editor/data-workers.js +++ b/src/client/editor/data-workers.js @@ -2,13 +2,14 @@ var widgetManager = require('../managers/widgets'), resize = require('../events/resize'), stateManager = require('../managers/state'), parser = require('../parser'), - Panel, + Panel, Matrix, editor, scrollState = {} setTimeout(()=>{ editor = require('./') Panel = require('../widgets/containers/panel') + Matrix = require('../widgets/containers/matrix') }) function updateWidget(widget, options={}) { @@ -43,6 +44,7 @@ function updateWidget(widget, options={}) { } var reuseChildren = options.reuseChildren !== false && widget instanceof Panel + && !(widget instanceof Matrix) var children = undefined, removedChildren = [] diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 95ee749c..600b057e 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -9,6 +9,7 @@ var {updateWidget, incrementWidget} = require('./data-workers'), UiInspector = require('../ui/ui-inspector'), UiTree = require('../ui/ui-tree'), UiDragResize = require('../ui/ui-dragresize'), + uiConsole = require('../ui/ui-console'), notifications = require('../ui/notifications'), locales = require('../locales'), {leftUiSidePanel, rightUiSidePanel} = require('../ui/'), @@ -51,17 +52,19 @@ class Editor { w.props[propName] = previousValue updateWidget(w, {changedProps: [propName], preventSelect: this.selectedWidgets.length > 1}) - notifications.add({ + if (uiConsole.minimized || rightUiSidePanel.minimized) notifications.add({ class: 'error', message: locales('inspector_error'), duration: 7000 }) console.error( - `Error while setting ${propName} to: ${JSON.stringify(value)}.`, - 'It\'s probably a bug, please a new bug ticket with these informations (https://github.com/jean-emmanuel/open-stage-control/issues).' + `Error while setting ${propName} to: ${JSON.stringify(value)}.\n` + + 'It\'s probably a bug, please open a new bug ticket with the followigin informations at' + + 'https://github.com/jean-emmanuel/open-stage-control/issues' ) - console.error(e) - error = true + throw e + // console.error(e) + // error = true } } diff --git a/src/client/events/click.js b/src/client/events/click.js index 0a9bc274..206072c0 100644 --- a/src/client/events/click.js +++ b/src/client/events/click.js @@ -17,7 +17,9 @@ if (macOs) { DOM.dispatchEvent(event.target, 'fast-right-click', event) }) } else { - document.body.setAttribute('oncontextmenu', 'return false') + document.body.addEventListener('contextmenu', (event)=>{ + if (event.target && (!event.target.tagName.match(/INPUT|TEXTAREA|OSC-CONSOLE|OSC-CONSOLE-MESSAGE/))) event.preventDefault() + }) } function mouseToFastClick(event) { diff --git a/src/client/locales/en.js b/src/client/locales/en.js index af6581aa..c229f005 100644 --- a/src/client/locales/en.js +++ b/src/client/locales/en.js @@ -1,5 +1,10 @@ module.exports = { + // console + console_title: 'Console', + console_clear: 'Clear console', + + // editor editor: 'Editor', editor_enabled: 'Enabled', @@ -46,7 +51,7 @@ module.exports = { // inspector inspector_color_confirm: 'Confirm', inspector_color_apply: 'Apply', - inspector_error: 'An error just occured, open F12 to read more.', + inspector_error: 'An error just occured, open the console to read more.', // nosleep nosleep: 'Prevent sleep', diff --git a/src/client/locales/fr.js b/src/client/locales/fr.js index ad25a951..b58e710b 100644 --- a/src/client/locales/fr.js +++ b/src/client/locales/fr.js @@ -1,5 +1,9 @@ module.exports = { + // console + console_title: 'Console', + console_clear: 'Vider la console', + // editor editor: 'Editeur', editor_enabled: 'Activé', @@ -46,7 +50,7 @@ module.exports = { // inspector inspector_color_confirm: 'Confirmer', inspector_color_apply: 'Appliquer', - inspector_error: 'Une erreur vient de survenir, appuyez sur F12 pour en savoir plus.', + inspector_error: 'Une erreur vient de survenir, ouvrez la console pour en savoir plus.', // nosleep nosleep: 'Empêcher la veille', diff --git a/src/client/managers/session/index.js b/src/client/managers/session/index.js index 66deae87..b11af14f 100644 --- a/src/client/managers/session/index.js +++ b/src/client/managers/session/index.js @@ -5,6 +5,7 @@ var ipc = require('../../ipc/'), uiFileupload = require('../../ui/ui-fileupload'), UiModal = require('../../ui/ui-modal'), uiLoading = require('../../ui/ui-loading'), + uiConsole = require('../../ui/ui-console'), {saveAs} = require('file-saver'), widgetManager = require('../widgets'), locales = require('../../locales'), @@ -39,6 +40,7 @@ var SessionManager = class SessionManager { setTimeout(()=>{ try { + uiConsole.clear() this.session = new Session(session) container.innerHTML = '' parser.reset() diff --git a/src/client/managers/session/session.js b/src/client/managers/session/session.js index afc5a453..c9a17aaa 100644 --- a/src/client/managers/session/session.js +++ b/src/client/managers/session/session.js @@ -211,6 +211,12 @@ var converters = [ } + var label = data.label === undefined ? 'auto' : data.label + if (label !== false && data.type && !data.type.match(/button|menu|modal|clone|html/)) { + label = label === 'auto' ? '@{this.id}' : label + data.html = label + } + } }, { diff --git a/src/client/stacktrace.js b/src/client/stacktrace.js index 86067d7d..692b2f21 100644 --- a/src/client/stacktrace.js +++ b/src/client/stacktrace.js @@ -1,5 +1,6 @@ var StackTrace = require('stacktrace-js'), - ipc = require('./ipc') + ipc = require('./ipc'), + uiConsole window.onerror = function(msg,url,row,col, error) { @@ -17,10 +18,14 @@ window.onerror = function(msg,url,row,col, error) { }).join('\n') + if (!uiConsole) uiConsole = require('./ui/ui-console') + uiConsole.log('error', `${msg}\n${stringifiedStack}`) ipc.send('errorLog', `(ERROR, CLIENT) ${msg}\n${stringifiedStack}`) }).catch(()=>{ + if (!uiConsole) uiConsole = require('./ui/ui-console') + uiConsole.log('error', `${msg}\n at ${url}:${row}:${col}\n (no stacktrace available)`) ipc.send('errorLog', `(ERROR, CLIENT) ${msg}\n at ${url}:${row}:${col}\n (no stacktrace available)`) }) diff --git a/src/client/ui/index.js b/src/client/ui/index.js index 16f94311..f49195cc 100644 --- a/src/client/ui/index.js +++ b/src/client/ui/index.js @@ -1,7 +1,6 @@ var UiSidePanel = require('./ui-sidepanel'), locales = require('../locales') - module.exports = { leftUiSidePanel: new UiSidePanel({selector: 'osc-panel-container.left', label: locales('editor_tree')}), rightUiSidePanel: new UiSidePanel({selector: 'osc-panel-container.right', label: locales('editor_inspector')}) diff --git a/src/client/ui/init.js b/src/client/ui/init.js index f88ad20a..a93d9d2f 100644 --- a/src/client/ui/init.js +++ b/src/client/ui/init.js @@ -3,4 +3,5 @@ require('../events/click') require('./ios') require('./notifications') require('./ui-workspace') -require('./ui-toolbar') +require('./main-menu') +require('./ui-console') diff --git a/src/client/ui/main-menu.js b/src/client/ui/main-menu.js new file mode 100644 index 00000000..243ffca8 --- /dev/null +++ b/src/client/ui/main-menu.js @@ -0,0 +1,236 @@ +var UiToolbar = require('./ui-toolbar'), + ipc = require('../ipc'), + locales = require('../locales'), + notifications = require('./notifications'), + fullscreen = require('./fullscreen'), + editor = require('../editor'), + sessionManager = require('../managers/session/'), + stateManager = require('../managers/state'), + {leftUiSidePanel, rightUiSidePanel} = require('../ui/'), + uiConsole = require('../ui/ui-console') + + +var recentSessions = [{label: locales('file_open_recent_wait'), class: 'disabled'}] +var menuEntries = [ + + { + label: locales('session'), + action: [ + { + label: locales('session_new'), + action: sessionManager.create.bind(sessionManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + separator: true + }, + { + label: locales('file_open'), + action: sessionManager.browse.bind(sessionManager), + shortcut: 'mod + o', + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + label: locales('file_open_recent'), + action: recentSessions, + class: ()=>{return !recentSessions.length ? 'disabled' :''} + }, + { + separator: true + }, + { + label: locales('file_save'), + action: sessionManager.save.bind(sessionManager), + shortcut: 'mod + s', + class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''} + }, + { + label: locales('file_save_as'), + action: sessionManager.saveAs.bind(sessionManager), + shortcut: 'mod + shift + s', + class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''} + }, + { + separator: true + }, + { + label: locales('file_import'), + action: sessionManager.import.bind(sessionManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + label: locales('file_export'), + action: sessionManager.export.bind(sessionManager), + class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''} + }, + + ] + }, + { + label: locales('state'), + class: ()=>{return sessionManager.session === null ? 'disabled' : ''}, + action: [ + { + label: locales('state_store'), + action: stateManager.quickSave.bind(stateManager) + }, + { + label: locales('state_recall'), + class: ()=>{return stateManager.quickState === null ? 'disabled' : ''}, + action: stateManager.quickLoad.bind(stateManager) + }, + { + label: locales('state_send'), + action: ()=>{ + stateManager.send() + notifications.add({ + icon: 'sliders-h', + message: locales('state_sendsuccess') + }) + } + }, + { + separator: true + }, + { + label: locales('file_open'), + action: stateManager.browse.bind(stateManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + label: locales('file_save'), + action: stateManager.save.bind(stateManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + label: locales('file_save_as'), + action: stateManager.saveAs.bind(stateManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + separator: true + }, + { + label: locales('file_import'), + action: stateManager.import.bind(stateManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + { + label: locales('file_export'), + action: stateManager.export.bind(stateManager), + class: ()=>{return READ_ONLY ? 'disabled' :''} + }, + ] + }, + { + label: locales('editor'), + class: ()=>{return sessionManager.session === null || READ_ONLY ? 'disabled' : ''}, + action: [ + { + label: locales('editor_enabled'), + class: ()=>{return 'toggle ' + (editor.enabled ? 'on' : 'off')}, + action: ()=>{ + if (editor.enabled) editor.disable() + else editor.enable() + }, + shortcut: 'mod + e' + }, + { + separator: true + }, + { + label: locales('editor_grid'), + class: ()=>{return 'toggle ' + (editor.grid ? 'on' : 'off')}, + action: editor.toggleGrid.bind(editor), + shortcut: 'mod + g' + + }, + { + label: locales('editor_tree'), + class: ()=>{return 'toggle ' + (leftUiSidePanel.minimized ? 'off' : 'on')}, + action: ()=>{return leftUiSidePanel.minimized ? leftUiSidePanel.restore() : leftUiSidePanel.minimize()}, + shortcut: 'mod + t' + + + }, + { + label: locales('editor_inspector'), + class: ()=>{return 'toggle ' + (rightUiSidePanel.minimized ? 'off' : 'on')}, + action: ()=>{return rightUiSidePanel.minimized ? rightUiSidePanel.restore() : rightUiSidePanel.minimize()}, + shortcut: 'mod + i' + }, + { + label: locales('console_title'), + class: ()=>{return 'toggle ' + (uiConsole.minimized ? 'off' : 'on')}, + action: ()=>{return uiConsole.minimized ? uiConsole.restore() : uiConsole.minimize()} + }, + { + separator: true + }, + { + label: locales('editor_percents'), + class: ()=>{return 'toggle ' + (editor.usePercents ? 'on' : 'off')}, + action: ()=>{editor.usePercents = !editor.usePercents} + } + ] + }, + { + separator: true + }, + { + label: locales('fullscreen'), + class: ()=>{return 'toggle ' + (fullscreen.isFullscreen ? 'on' : 'off')}, + action: ()=>{ + if (fullscreen.isEnabled) fullscreen.toggle() + }, + shortcut: 'f11' + } + +] + +if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) { + + var NoSleep = require('nosleep.js'), + noSleep = new NoSleep(), + noSleepState = false + + menuEntries.push({ + label: locales('nosleep'), + class: ()=>{return 'toggle ' + (noSleepState ? 'on' : 'off')}, + action:()=>{ + noSleepState = !noSleepState + if (noSleepState) noSleep.disable() + else noSleep.enable() + } + }) + +} + + + + + +class MainMenu extends UiToolbar { + + constructor(options) { + + super(options) + + ipc.on('sessionList', (data)=>{ + if (recentSessions.length) { + recentSessions.splice(0, 10) + } + for (let s of data) [ + recentSessions.push({ + label: s, + action: ()=>{sessionManager.requestOpen(s)} + }) + ] + }) + + } + +} + + +module.exports = new MainMenu({selector: '#main-menu', position: [40, 1], entries: menuEntries}) diff --git a/src/client/ui/ui-console.js b/src/client/ui/ui-console.js new file mode 100644 index 00000000..54c0aa4f --- /dev/null +++ b/src/client/ui/ui-console.js @@ -0,0 +1,113 @@ +var UiSidePanel = require('./ui-sidepanel'), + html = require('nanohtml'), + raw = require('nanohtml/raw'), + locales = require('../locales'), + {icon} = require('./utils') + +class UiConsole extends UiSidePanel { + + constructor(options) { + + super(options) + + this.header = DOM.get(this.container, 'osc-panel-header')[0] + + this.header.appendChild(html``) + this.messages = this.content.appendChild(html``) + // this.inputWrapper = this.container.appendChild(html``) + // this.input = this.inputWrapper.appendChild(html``) + + this.actions = this.header.appendChild(html`
`) + this.clearBtn = this.actions.appendChild(html`
${raw(icon('trash'))}
`) + this.clearBtn.addEventListener('click', ()=>{ + this.clear() + }) + + this.length = 0 + this.maxLength = 200 + + var _this = this, + log = console.log, + error = console.error + + console.log = function(message){ + _this.log('log', message) + log(...arguments) + } + + console.error = function(message){ + _this.log('error', message) + error(...arguments) + } + + // this.input.addEventListener('keydown', (event)=>{ + // if (event.keyCode === 13 && !event.shiftKey) { + // + // event.preventDefault() + // DOM.dispatchEvent(event.target, 'change') + // + // } + // }) + // + // this.input.addEventListener('change', (event)=>{ + // try { + // console.log(eval(this.input.value)) + // } catch (err) { + // console.error(err) + // } + // this.input.value = '' + // }) + + + this.enable() + + } + + log(type, message) { + + var node = this.messages.appendChild(html` + + + + `) + + if (typeof message === 'object') { + if (!(message instanceof Error)) { + try { + message = JSON.stringify(message) + } catch (_) {} + } else { + message = String(message) + message.stack + } + } + + node.textContent = message + if (type !== 'error' && node.textContent.match(/error/i)) node.classList.add('error') + + node.scrollIntoView() + + if (++this.length > this.maxLength) this.purge() + + + } + + purge() { + + var children = [...this.messages.children] + for (var i = 0; i < this.maxLength / 2; i++) { + this.messages.removeChild(children[i]) + } + this.length = this.maxLength / 2 + 1 + + } + + clear() { + + this.messages.innerHTML = '' + this.length = 0 + + } + +} + +module.exports = new UiConsole({selector: '#osc-console', size: 40}) diff --git a/src/client/ui/ui-inspector.js b/src/client/ui/ui-inspector.js index 23d68252..24274723 100644 --- a/src/client/ui/ui-inspector.js +++ b/src/client/ui/ui-inspector.js @@ -223,6 +223,8 @@ class UiInspector extends UiWidget { value: v }) + // this may not be reached if an error is thrown + // but the lock will undone at the next inspect() call this.lock = false } diff --git a/src/client/ui/ui-sidepanel.js b/src/client/ui/ui-sidepanel.js index f2feb746..6b70fbf1 100644 --- a/src/client/ui/ui-sidepanel.js +++ b/src/client/ui/ui-sidepanel.js @@ -17,7 +17,7 @@ class UiSidePanel extends UiWidget { this.cacheKey = 'ui.' + options.selector - this.minWidth = options.size || 250 + this.minWidth = options.size === undefined ? 250 : options.size this.width = cache.get(this.cacheKey + '.width') || options.size || 250 this.disabled = false diff --git a/src/client/ui/ui-toolbar.js b/src/client/ui/ui-toolbar.js index 95fb7b8f..91bc4d7a 100644 --- a/src/client/ui/ui-toolbar.js +++ b/src/client/ui/ui-toolbar.js @@ -1,209 +1,5 @@ var UiWidget = require('./ui-widget'), - ContextMenu = require('./context-menu'), - ipc = require('../ipc'), - locales = require('../locales'), - notifications = require('./notifications'), - fullscreen = require('./fullscreen'), - editor = require('../editor'), - sessionManager = require('../managers/session/'), - stateManager = require('../managers/state'), - {leftUiSidePanel, rightUiSidePanel} = require('../ui/') - - -var recentSessions = [{label: locales('file_open_recent_wait'), class: 'disabled'}] -var menuEntries = [ - - { - label: locales('session'), - action: [ - { - label: locales('session_new'), - action: sessionManager.create.bind(sessionManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - separator: true - }, - { - label: locales('file_open'), - action: sessionManager.browse.bind(sessionManager), - shortcut: 'mod + o', - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - label: locales('file_open_recent'), - action: recentSessions, - class: ()=>{return !recentSessions.length ? 'disabled' :''} - }, - { - separator: true - }, - { - label: locales('file_save'), - action: sessionManager.save.bind(sessionManager), - shortcut: 'mod + s', - class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''} - }, - { - label: locales('file_save_as'), - action: sessionManager.saveAs.bind(sessionManager), - shortcut: 'mod + shift + s', - class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''} - }, - { - separator: true - }, - { - label: locales('file_import'), - action: sessionManager.import.bind(sessionManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - label: locales('file_export'), - action: sessionManager.export.bind(sessionManager), - class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''} - }, - - ] - }, - { - label: locales('state'), - class: ()=>{return sessionManager.session === null ? 'disabled' : ''}, - action: [ - { - label: locales('state_store'), - action: stateManager.quickSave.bind(stateManager) - }, - { - label: locales('state_recall'), - class: ()=>{return stateManager.quickState === null ? 'disabled' : ''}, - action: stateManager.quickLoad.bind(stateManager) - }, - { - label: locales('state_send'), - action: ()=>{ - stateManager.send() - notifications.add({ - icon: 'sliders-h', - message: locales('state_sendsuccess') - }) - } - }, - { - separator: true - }, - { - label: locales('file_open'), - action: stateManager.browse.bind(stateManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - label: locales('file_save'), - action: stateManager.save.bind(stateManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - label: locales('file_save_as'), - action: stateManager.saveAs.bind(stateManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - separator: true - }, - { - label: locales('file_import'), - action: stateManager.import.bind(stateManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - { - label: locales('file_export'), - action: stateManager.export.bind(stateManager), - class: ()=>{return READ_ONLY ? 'disabled' :''} - }, - ] - }, - { - label: locales('editor'), - class: ()=>{return sessionManager.session === null || READ_ONLY ? 'disabled' : ''}, - action: [ - { - label: locales('editor_enabled'), - class: ()=>{return 'toggle ' + (editor.enabled ? 'on' : 'off')}, - action: ()=>{ - if (editor.enabled) editor.disable() - else editor.enable() - }, - shortcut: 'mod + e' - }, - { - separator: true - }, - { - label: locales('editor_grid'), - class: ()=>{return 'toggle ' + (editor.grid ? 'on' : 'off')}, - action: editor.toggleGrid.bind(editor), - shortcut: 'mod + g' - - }, - { - label: locales('editor_tree'), - class: ()=>{return 'toggle ' + (leftUiSidePanel.minimized ? 'off' : 'on')}, - action: ()=>{return leftUiSidePanel.minimized ? leftUiSidePanel.restore() : leftUiSidePanel.minimize()}, - shortcut: 'mod + t' - - - }, - { - label: locales('editor_inspector'), - class: ()=>{return 'toggle ' + (rightUiSidePanel.minimized ? 'off' : 'on')}, - action: ()=>{return rightUiSidePanel.minimized ? rightUiSidePanel.restore() : rightUiSidePanel.minimize()}, - shortcut: 'mod + i' - }, - { - separator: true - }, - { - label: locales('editor_percents'), - class: ()=>{return 'toggle ' + (editor.usePercents ? 'on' : 'off')}, - action: ()=>{editor.usePercents = !editor.usePercents} - } - ] - }, - { - separator: true - }, - { - label: locales('fullscreen'), - class: ()=>{return 'toggle ' + (fullscreen.isFullscreen ? 'on' : 'off')}, - action: ()=>{ - if (fullscreen.isEnabled) fullscreen.toggle() - }, - shortcut: 'f11' - } - -] - -if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) { - - var NoSleep = require('nosleep.js'), - noSleep = new NoSleep(), - noSleepState = false - - menuEntries.push({ - label: locales('nosleep'), - class: ()=>{return 'toggle ' + (noSleepState ? 'on' : 'off')}, - action:()=>{ - noSleepState = !noSleepState - if (noSleepState) noSleep.disable() - else noSleep.enable() - } - }) - -} - - - - + ContextMenu = require('./context-menu') class UiToolbar extends UiWidget { @@ -212,23 +8,11 @@ class UiToolbar extends UiWidget { super(options) this.menu = new ContextMenu({ - position: [40, 1] + position: options.position }) this.opened = false - this.entries = menuEntries - this.menu.bindShortcuts(menuEntries) - - ipc.on('sessionList', (data)=>{ - if (recentSessions.length) { - recentSessions.splice(0, 10) - } - for (let s of data) [ - recentSessions.push({ - label: s, - action: ()=>{sessionManager.requestOpen(s)} - }) - ] - }) + this.entries = options.entries + this.menu.bindShortcuts(this.entries) this.container.addEventListener('fast-click', (e)=>{ if (this.opened) this.close() @@ -247,8 +31,7 @@ class UiToolbar extends UiWidget { open(e) { if (this.opened) return - - this.menu.open(e, menuEntries) + this.menu.open(e.detail, this.entries) this.opened = true this.toggleState() @@ -276,4 +59,4 @@ class UiToolbar extends UiWidget { } -module.exports = new UiToolbar({selector: 'osc-toolbar'}) +module.exports = UiToolbar diff --git a/src/client/widgets/basics/button.js b/src/client/widgets/basics/button.js index 9af22b43..19b736c5 100644 --- a/src/client/widgets/basics/button.js +++ b/src/client/widgets/basics/button.js @@ -63,10 +63,10 @@ class Button extends Widget { if (this.getProp('doubleTap')) { - doubletab(this.widget, ()=>{ + doubletab(this.container, (e)=>{ this.active = true - this.setValue(this.getProp('on'), {sync: true, send: true}) + this.setValue(this.getProp('on'), {sync: true, send: true, y: e.offsetY}) if (tap) this.container.classList.add('active') @@ -74,17 +74,17 @@ class Button extends Widget { } else { - this.on('draginit',()=>{ + this.on('draginit',(e)=>{ if (this.active) return this.active = true - this.setValue(this.getProp('on'), {sync: true, send: true}) + this.setValue(this.getProp('on'), {sync: true, send: true, y: e.offsetY}) if (tap) this.container.classList.add('active') - }, {element: this.widget}) + }, {element: this.container}) } @@ -97,36 +97,36 @@ class Button extends Widget { if (!tap) this.setValue(this.getProp('off'), {sync: true, send: true}) if (tap) this.container.classList.remove('active') - }, {element: this.widget}) + }, {element: this.container}) } else { if (this.getProp('doubleTap')) { - doubletab(this.widget, ()=>{ + doubletab(this.container, (e)=>{ this.active = true - this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) + this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true, y: e.offsetY}) }) } else { - this.on('draginit',()=>{ + this.on('draginit',(e)=>{ if (this.active) return this.active = true - this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) + this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true, y: e.offsetY}) - }, {element: this.widget}) + }, {element: this.container}) this.on('dragend',()=>{ this.active = false - }, {element: this.widget}) + }, {element: this.container}) } diff --git a/src/client/widgets/basics/input.js b/src/client/widgets/basics/input.js index eac66e36..150e4347 100644 --- a/src/client/widgets/basics/input.js +++ b/src/client/widgets/basics/input.js @@ -19,7 +19,14 @@ class Input extends Canvas { unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'}, }, class_specific: { - asYouType: {type: 'boolean', value: false, help: 'Set to `true` to make the input send its value at each keystroke'} + asYouType: {type: 'boolean', value: false, help: 'Set to `true` to make the input send its value at each keystroke'}, + validation: {type: 'string', value: '', help: [ + 'Regular expression: if the submitted value doesn\'t match the regular expression, it will be reset to the last valid value.', + 'If leading and trailing slashes are omitted, they will be added automatically and the flag will be set to "gm"', + 'Examples:', + '- `^[0-9]*$` accepts digits only, any number of them', + '- `/^[a-z\s]{0,10}$/i` accept between 0 and 10 alphabetic characters and spaces (case insensitive)', + ]} } }) @@ -37,6 +44,7 @@ class Input extends Canvas { this.stringValue = '' this.focused = false this.tabKeyBlur = false + this.validation = null if (this.getProp('vertical')) this.widget.classList.add('vertical') if (this.getProp('align') === 'left') this.widget.classList.add('left') @@ -53,6 +61,17 @@ class Input extends Canvas { this.tabKeyBlur = false }) var asYouType = this.getProp('asYouType') + + if (this.getProp('validation') !== '') { + var validation = String(this.getProp('validation')), + flags = validation.match(/^\/.*\/.*$/) ? validation.split('/').pop() : 'gm', + regExpString = validation.match(/^\/.*\/.*$/) ? validation.replace(/^\/(.*)\/.*$/, '$1') : validation + + if (!regExpString.match(/^\^.*\$$/)) regExpString = '^' + regExpString + '$' + + this.validation = new RegExp(regExpString, flags) + } + this.input.addEventListener('keydown', (e)=>{ if (e.keyCode === 13) this.blur() // enter else if (e.keyCode === 27) this.blur(false) // esc @@ -120,12 +139,19 @@ class Input extends Canvas { setValue(v, options={} ) { + if (this.validation && !String(v).match(this.validation)) { + this.input.value = this.value + return + } + try { this.value = JSON.parse(v) } catch (err) { this.value = v } + if (this.value === '' || this.value === null) this.value = this.getProp('default') + this.stringValue = this.getStringValue() this.batchDraw() diff --git a/src/client/widgets/common/osc-receiver.js b/src/client/widgets/common/osc-receiver.js index 3f3ed4b2..e5ed93f1 100644 --- a/src/client/widgets/common/osc-receiver.js +++ b/src/client/widgets/common/osc-receiver.js @@ -36,7 +36,10 @@ module.exports = class OscReceiver { if (this.address[0] !== '/') { var parentAddress = this.parent.getProp('address') || this.parent.resolveProp('address', undefined, false, this) - if (parentAddress === 'auto') parentAddress = '/' + this.parent.getProp('id') + if (parentAddress === 'auto') { + var id = this.parent.getProp('id') || this.parent.resolveProp('id', undefined, false, this) + parentAddress = '/' + id + } this.prefix = parentAddress if (this.prefix[this.prefix.length - 1] !== '/') this.prefix += '/' } diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index df7a7a77..a9ecad9a 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -216,7 +216,9 @@ class Widget extends EventEmitter { event: 'value' }, builtIn: true, parent: this}) this.on('change', (e)=>{ - if (e.widget === this && this.mounted && !e.options.fromEdit) this.script.setValue(this.value, {...e.options, id: e.options.id || e.id}) + if (e.widget === this && this.mounted && !e.options.fromEdit) { + this.script.setValue(e.options.widget ? e.options.widget.value : this.value, {...e.options, id: e.options.id || e.id}) + } }) if (String(this.getProp('script')).includes('touch')) { this.on('touch', (e)=>{ @@ -659,7 +661,7 @@ class Widget extends EventEmitter { } catch (err) { let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.log((this.getProp('id') || this.props.id) + '.' + propName + ': JS{{}} error:\n' + err + line) + console.error((this.getProp('id') || this.props.id) + '.' + propName + ': JS{{}} error:\n' + err + line) } try { @@ -680,7 +682,7 @@ class Widget extends EventEmitter { } catch (err) { let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.log((this.getProp('id') || this.props.id) + '.' + propName + ': #{} error:\n' + err + line) + console.error((this.getProp('id') || this.props.id) + '.' + propName + ': #{} error:\n' + err + line) } for (let k in variables) { diff --git a/src/client/widgets/containers/keyboard.js b/src/client/widgets/containers/keyboard.js index 01cfa1fe..00616517 100644 --- a/src/client/widgets/containers/keyboard.js +++ b/src/client/widgets/containers/keyboard.js @@ -1,6 +1,7 @@ var Panel = require('./panel'), Widget = require('../common/widget'), - parser = require('../../parser') + parser = require('../../parser'), + {mapToScale} = require('../utils') class Keyboard extends Panel { @@ -28,11 +29,12 @@ class Keyboard extends Panel { traversing: {type: 'boolean', value: true, help: 'Set to `false` to disable traversing gestures'}, 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)' + ]}, + velocity: {type: 'boolean', value: false, help: [ + 'Set to `true` to map the touch coordinates between `off` (top) and `on` (bottom). Requires `on` and `off` to be numbers', ]}, mode: {type: 'string', value: 'push', choices: ['push', 'toggle', 'tap'], help: [ 'Interraction mode:', @@ -51,21 +53,53 @@ class Keyboard extends Panel { this.childrenType = undefined this.value = [] + this.keyHeight = 100 + + this.on('resize', (e)=>{ + this.keyHeight = e.height + }, {element: this.widget}) + this.on('change',(e)=>{ - if (e.widget === this) return + var widget = e.widget + + if (widget === this) return + + + var value + if (widget.getValue()) { + if (this.getProp('velocity')) { + var height = widget._black ? this.keyHeight * 0.65 : this.keyHeight + value = mapToScale(e.options.y, [0, height * 0.9], [this.getProp('off'), this.getProp('on')], this.decimals) + } else { + value = this.getProp('on') + } + } else { + value = this.getProp('off') + } + + this.value[widget._index] = value + + if (e.options.send) { + var start = parseInt(this.getProp('start')) + this.sendValue({ + v: [e.widget._index + start, value] + }) + } + + this.changed({ + ...e.options, + id: widget.getProp('id') + }) - this.value[e.widget._index] = e.widget.getValue() - this.changed(e.options) }) var start = parseInt(this.getProp('start')), keys = parseInt(this.getProp('keys')) - var strData = JSON.stringify(options.props), - pattern = 'wbwbwwbwbwbw', + var pattern = 'wbwbwwbwbwbw', whiteKeys = 0, whiteKeys2 = 0, i for (i = start; i < keys + start && i < 109; i++) { @@ -76,24 +110,20 @@ class Keyboard extends Panel { for (i = start; i < keys + start && i < 109; i++) { - var data = JSON.parse(strData) - - data.top = data.left = data.height = data.width = 'auto' - data.type = 'button' - data.mode = this.getProp('mode') - data.id = this.getProp('id') + '/' + i - data.label = false - data.css = '' - - data.target = '@{parent.target}' - data.decimals = '@{parent.decimals}' - - data.address = '@{parent.address}' - data.preArgs = `JS{{ - var a = @{parent.preArgs}; - var b = typeof a === 'string' && a === '' ? [] : Array.isArray(a) ? a : [a]; - return b.concat([${i}]) - }}` + var data = { + top: 'auto', + left: 'auto', + height: 'auto', + width: 'auto', + type: 'button', + mode: this.getProp('mode'), + id: this.getProp('id') + '/' + i, + label: false, + css: '', + bypass: true, + on: 1, + off: 0, + } var key = parser.parse({ data: data, @@ -111,6 +141,7 @@ class Keyboard extends Panel { } else { key.container.classList.add('black') key.container.style.setProperty('--rank', whiteKeys2) + key._black = true } this.value[i - start] = this.getProp('off') @@ -119,8 +150,24 @@ class Keyboard extends Panel { } + setValue(v, options={}) { + + if (!Array.isArray(v) || v.length !== 2) return + if (v[1] !== this.getProp('on') && v[1] !== this.getProp('off')) return + + var start = parseInt(this.getProp('start')) + this.children[v[0] - start].setValue(v[1] === this.getProp('on') ? 1 : 0, options) + + } + } + +Keyboard.dynamicProps = Keyboard.prototype.constructor.dynamicProps.concat( + 'on', + 'off', +) + Keyboard.cssVariables = Keyboard.prototype.constructor.cssVariables.concat( {js: 'colorWhite', css: '--color-white-key'}, {js: 'colorBlack', css: '--color-black-key'} diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index bcfb4569..e2f12132 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -1,10 +1,9 @@ var Panel = require('./panel'), - StaticProperties = require('../mixins/static_properties'), parser = require('../../parser'), {deepCopy} = require('../../utils') -class Matrix extends StaticProperties(Panel) { +class Matrix extends Panel { static description() { @@ -45,22 +44,16 @@ class Matrix extends StaticProperties(Panel) { if (e.widget === this) return - if (this.getProp('widgetType') === 'clone') { + var widget = this.getProp('widgetType') === 'clone' ? e.widget.parent : e.widget - if (e.widget.parent.parent !== this) return + if (widget.parent !== this) return - this.value[e.widget.parent._index] = e.widget.getValue() + this.value[widget._index] = e.widget.getValue() - } else { - - if (e.widget.parent !== this) return - - this.value[e.widget._index] = e.widget.getValue() - - - } - - this.changed(e.options) + this.changed({ + ...e.options, + id: widget.getProp('id') + }) }) diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index 0c1a1452..239fbe90 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -59,7 +59,7 @@ class ScriptVm extends Vm { super.registerGlobals() - this.sandbox.contentWindow.set = (id, value)=>{ + this.sandbox.contentWindow.set = (id, value, extraOptions = {send: true, sync: true})=>{ var options = this.getValueOptions() options.fromScript = true @@ -67,11 +67,24 @@ class ScriptVm extends Vm { // if (id === options.id) options.sync = false // loop stop // if (this.getWidget() === options.widget) options.sync = false // loop stop - var widgets = this.resolveId(id) + if (extraOptions.send === false) options.send = false + if (extraOptions.sync === false) options.sync = false + + var widgets + if (id.includes('*')) { + var widget = this.getWidget() + if (widget.builtIn) widget = widget.parent + widgets = this.resolveId( + Object.keys(widgetManager.idRoute).filter(key => key.match(new RegExp('^' + id.replace(/\*/g, '.*') + '$'))) + ).filter(w => w !== widget) + } else { + widgets = this.resolveId(id).slice(0, 1) + } + for (var i = widgets.length - 1; i >= 0; i--) { - return widgets[i].setValue(value, options) + widgets[i].setValue(value, options) } @@ -100,7 +113,7 @@ class ScriptVm extends Vm { var widget = this.getWidget() if (widget.builtIn) widget = widget.parent - widget.sendValue(overrides) + widget.sendValue(overrides, {force: true}) } @@ -149,6 +162,13 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.getIndex = (id = 'this')=>{ + + var widget = this.resolveId(id).pop() + if (widget) return widget.parent.children.indexOf(widget) + + } + this.sandbox.contentWindow.getScroll = (id)=>{ var widgets = this.resolveId(id) @@ -319,7 +339,7 @@ class ScriptVm extends Vm { if (!options.send) return - toolbar = toolbar || require('../../ui/ui-toolbar') + toolbar = toolbar || require('../../ui/main-menu') var action = toolbar.entries.filter(x=>!x.separator) @@ -333,7 +353,7 @@ class ScriptVm extends Vm { } - for (var imports of ['set', 'get', 'getProp', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', + for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) { this.sanitize(this.sandbox.contentWindow[imports]) } diff --git a/src/client/widgets/scripts/script.js b/src/client/widgets/scripts/script.js index 7d77591e..0108bdb6 100644 --- a/src/client/widgets/scripts/script.js +++ b/src/client/widgets/scripts/script.js @@ -91,7 +91,7 @@ class Script extends Widget { let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.log((this.getProp('id') || this.props.id) + '.script error:\n' + err + line) + console.error((this.getProp('id') || this.props.id) + '.script error:\n' + err + line) this.script = ()=>{} } @@ -107,8 +107,10 @@ class Script extends Widget { this.scriptLock = true try { this.script(context, this.builtIn ? this.parent.parsersLocalScope : this.parsersLocalScope) - } catch(e) { - console.log(e) + } catch(err) { + let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', + line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' + console.error((this.getProp('id') || this.props.id) + '.script error:\n' + err + line) } this.scriptLock = false diff --git a/src/client/widgets/sliders/range.js b/src/client/widgets/sliders/range.js index b4051c24..8dc2d2fd 100644 --- a/src/client/widgets/sliders/range.js +++ b/src/client/widgets/sliders/range.js @@ -40,6 +40,7 @@ class Range extends Fader { visible: false, horizontal:this.getProp('horizontal'), default:this.getProp('default').length === 2 ? this.getProp('default')[1] : this.getProp('range').max, + origin: this.getProp('default').length === 2 ? this.getProp('default')[1] : this.getProp('range').max, snap:this.getProp('snap'), spring:this.getProp('spring'), range:this.getProp('range'), @@ -67,10 +68,9 @@ class Range extends Fader { this.touchMap = {} - this.setValue([ - this.faders[0].rangeValsMin, - this.faders[1].rangeValsMax - ]) + + this.originValue = this.faders.map(f => f.originValue) + this.setValue(this.getSpringValue()) } @@ -170,15 +170,20 @@ class Range extends Fader { setValue(v, options={}) { + if (!this.faders) return // prevent Fader.constructor if (!v || !v.length || v.length!=2) return - this.faders[0].rangeValsMax = v[1] this.faders[1].rangeValsMin = v[0] if (!options.dragged) { - this.faders[0].setValue(v[0]) - this.faders[1].setValue(v[1]) + var opt = { + ...options, + send: false, + sync: false + } + this.faders[0].setValue(v[0], opt) + this.faders[1].setValue(v[1], opt) } this.value = [ this.faders[0].getValue(), diff --git a/src/client/widgets/sliders/slider.js b/src/client/widgets/sliders/slider.js index 792579e3..23736c26 100644 --- a/src/client/widgets/sliders/slider.js +++ b/src/client/widgets/sliders/slider.js @@ -56,7 +56,7 @@ class Slider extends Canvas { } else { doubletab(this.widget, ()=>{ - this.setValue(this.getSpringValue(),{sync:true, send:true, fromLocal:true}) + this.setValue(this.getSpringValue(),{sync:true, send:true, fromLocal:true, doubleTab:true}) }) } @@ -184,7 +184,7 @@ class Slider extends Canvas { setValue(v,options={}) { if (typeof v != 'number') return - if (this.touched && !options.dragged) return this.setValueTouchedQueue = [v, options] + if (this.touched && !options.dragged && !options.doubleTab) return this.setValueTouchedQueue = [v, options] var value = clip(v,[this.rangeValsMin,this.rangeValsMax]) diff --git a/src/html/client.html b/src/html/client.html index 5d1f18f0..7aee3ab4 100644 --- a/src/html/client.html +++ b/src/html/client.html @@ -18,7 +18,7 @@ - +
@@ -37,6 +37,17 @@ + + +
+
+ + + + +
+ +
diff --git a/src/python/midi.py b/src/python/midi.py index 1f6501c3..8a0220ca 100644 --- a/src/python/midi.py +++ b/src/python/midi.py @@ -194,8 +194,9 @@ def send_midi(name, event, *args): m = [] for arg in args: if type(arg) is str: - arg = arg.split(' ') - arg = [int(x, 16) for x in arg] + arg = arg.replace(' ', '') # remove spaces + arg = [arg[i:i+2] for i in range(0, len(arg), 2)] # split in 2 chars bytes + arg = [int(x, 16) for x in arg] # parse hex bytes for x in arg: m.append(x) else: diff --git a/src/python/requirements.txt b/src/python/requirements.txt index 3aa7f400..fddc08e3 100644 --- a/src/python/requirements.txt +++ b/src/python/requirements.txt @@ -1 +1,2 @@ python-rtmidi == 1.4.2 +pyinstaller diff --git a/src/scss/ui.scss b/src/scss/ui.scss index 6b08170c..357868a7 100644 --- a/src/scss/ui.scss +++ b/src/scss/ui.scss @@ -4,6 +4,7 @@ @import 'ui/notifications'; @import 'ui/grid'; @import 'ui/inspector'; +@import 'ui/console'; @import 'ui/tree'; @import 'ui/dragresize'; @import 'ui/selectarea'; diff --git a/src/scss/ui/console.scss b/src/scss/ui/console.scss new file mode 100644 index 00000000..2a7f8430 --- /dev/null +++ b/src/scss/ui/console.scss @@ -0,0 +1,72 @@ +$padding: 8rem; + +#osc-console { + osc-panel-header { + border-top: 1rem solid var(--color-background); + } + .toggle-button { + border-bottom: none; + } + + display: flex; + position: relative; + flex-direction: column; + ::-webkit-scrollbar-thumb, ::-webkit-scrollbar-track-piece { + border-left-color: var(--color-background)!important; + border-top-color: var(--color-background)!important; + } + + .actions { + position: absolute; + right: 0; + padding: $padding; + + div { + cursor: pointer; + color: var(--color-text); + opacity: 0.25; + &:hover { + opacity: 0.5 + } + } + i { + pointer-events: none; + } + } + +} + +osc-console { + display: block; + height: 100%; + padding: $padding; + overflow-y: auto; + background: var(--color-background); +} + +osc-console-message { + user-select: text; + cursor: text; + display: block; + white-space: pre; + &.error { + color: var(--color-error); + } + + margin-bottom: 4rem; +} + +osc-console-input { + display: block; + padding: 4rem; + background: var(--color-ui-background); + height: 30rem; + textarea { + padding: 4rem; + display: block; + background: var(--color-background); + width: 100%; + height: 100%; + resize: none; + } +} diff --git a/src/scss/ui/toolbar.scss b/src/scss/ui/toolbar.scss index deb3df59..0c051e61 100644 --- a/src/scss/ui/toolbar.scss +++ b/src/scss/ui/toolbar.scss @@ -1,6 +1,6 @@ osc-toolbar { --size: 34rem; - position: fixed; + position: absolute; top: 0; left: 0; height:var(--size); diff --git a/src/scss/ui/workspaces.scss b/src/scss/ui/workspaces.scss index e34b4c7f..521c4730 100644 --- a/src/scss/ui/workspaces.scss +++ b/src/scss/ui/workspaces.scss @@ -126,7 +126,7 @@ osc-panel-container { background: var(--color-ui-background); font-size: 14rem; z-index: 2; - transition: transform 0.2s ease-out 0.1s, border-color 0.2s ease-out 0.1s; + transition: transform 0.2s ease-out 0.1s, border-color 0.1s ease-out 0.1s; will-change: transform; border-style: solid; @@ -215,8 +215,8 @@ osc-panel-container { } - &:hover .toggle-button, .toggle-button:hover { - transition: transform 0.2s ease-out 0s, border-color 0.2s ease-out 0s; + &:hover > .toggle-button, .toggle-button:hover { + transition: transform 0.2s ease-out 0s, border-color 0.3s ease-out 0s; transform: translateX(0) translateY(0); border-color: var(--color-background); &:after { @@ -298,6 +298,7 @@ osc-panel-header { font-size: 109%; text-overflow: ellipsis; padding: 0 8rem; + flex-shrink: 0; &:before { content: ""; diff --git a/src/scss/widgets/basics.scss b/src/scss/widgets/basics.scss index 734e82ac..a28b3d24 100644 --- a/src/scss/widgets/basics.scss +++ b/src/scss/widgets/basics.scss @@ -32,6 +32,7 @@ bottom:0; margin: var(--widget-spacing); padding: var(--widget-padding); + pointer-events: none; @include pseudo-stroke($z: -1); @@ -577,7 +578,7 @@ color:var(--color-fill); caret-color: var(--color-fill); - + height: 100%; &:focus::selection { background: var(--color-fill); diff --git a/src/server/callbacks.js b/src/server/callbacks.js index 470139b5..746551cf 100644 --- a/src/server/callbacks.js +++ b/src/server/callbacks.js @@ -3,8 +3,7 @@ var path = require('path'), settings = require('./settings'), osc = require('./osc'), {ipc} = require('./server'), - {deepCopy, resolveHomeDir} = require('./utils'), - theme = require('./theme') + {deepCopy, resolveHomeDir} = require('./utils') var widgetHashTable = {}, clipboard = {clipboard: null, idClipboard: null} @@ -404,8 +403,6 @@ module.exports = { reloadCss() { // (dev) hot css reload - - theme.load() ipc.send('reloadCss') }, diff --git a/src/server/custom-module.js b/src/server/custom-module.js index 85035ece..982fb8b3 100644 --- a/src/server/custom-module.js +++ b/src/server/custom-module.js @@ -52,7 +52,10 @@ class CustomModule { } }, console: console, - settings: settings, + settings: { + read: settings.read, + appAddresses: settings.appAddresses, + }, setTimeout: this.setTimeout.bind(this), clearTimeout: this.clearTimeout.bind(this), setInterval: this.setInterval.bind(this), @@ -153,7 +156,7 @@ class CustomModule { if (this.load()) { console.log('(INFO) Custom module reloaded successfully') } else { - console.log('(ERROR) Failed to reload custom module') + console.error('(ERROR) Failed to reload custom module') this.unload() } } diff --git a/src/server/electron-app.js b/src/server/electron-app.js index 686369bb..e69f24ff 100644 --- a/src/server/electron-app.js +++ b/src/server/electron-app.js @@ -36,7 +36,7 @@ var template = [{ if (process.platform === 'darwin') { // Add app menu (macOs) template.unshift({ - label: settings.infos.appName, + label: settings.infos.productName, submenu: [ { label: 'Hide ' + infos.productName, diff --git a/src/server/electron-window.js b/src/server/electron-window.js index 2b50c20b..85a20ec0 100644 --- a/src/server/electron-window.js +++ b/src/server/electron-window.js @@ -1,5 +1,5 @@ var path = require('path'), - {BrowserWindow, dialog, shell, screen} = require('electron'), + {BrowserWindow, dialog, shell, screen, Menu, MenuItem} = require('electron'), shortcut = require('electron-localshortcut'), app = require('./electron-app'), settings = require('./settings'), @@ -10,7 +10,7 @@ module.exports = function(options={}) { var window window = new BrowserWindow({ - title: options.title || settings.infos.appName, + title: options.title || settings.infos.productName, icon: path.resolve(__dirname + '/../assets/logo.png'), backgroundColor: options.color || theme.backgroundColor, type: options.type, @@ -131,6 +131,15 @@ module.exports = function(options={}) { settings.write('geometry', geometry) }) + var menu = new Menu() + menu.append(new MenuItem({role: 'copy'})) + menu.append(new MenuItem({role: 'paste'})) + window.webContents.on('context-menu', (e, data) => { + menu.items[0].enabled = data.editFlags.canCopy + menu.items[1].enabled = data.editFlags.canPaste + menu.popup({window: window, x: e.x, y: e.y }) + }, false) + if (options.shortcuts) { shortcut.register(window,'CmdOrCtrl+R',function(){ diff --git a/src/server/index.js b/src/server/index.js index 134a6e84..c7fe4a8e 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -32,8 +32,7 @@ function nodeMode() { }) } - -if (process.title === 'node' || process.title === 'node.exe') { +if (process.title === 'node' || process.title === 'node.exe' || process.env.ELECTRON_RUN_AS_NODE) { nodeMode() diff --git a/src/server/osc/tcp.js b/src/server/osc/tcp.js index e9207ab7..89d76546 100644 --- a/src/server/osc/tcp.js +++ b/src/server/osc/tcp.js @@ -129,7 +129,7 @@ class OscTCPServer extends EventEmitter { } zeroconf.publish({ - name: settings.infos.appName + (settings.read('instance-name') ? ' (' + settings.read('instance-name') + ')' : ''), + name: settings.infos.productName + (settings.read('instance-name') ? ' (' + settings.read('instance-name') + ')' : ''), protocol: 'tcp', type: 'osc', port: tcpInPort diff --git a/src/server/osc/udp.js b/src/server/osc/udp.js index 2eab0b41..f819ea5a 100644 --- a/src/server/osc/udp.js +++ b/src/server/osc/udp.js @@ -19,7 +19,7 @@ oscUDPServer.on('error', function(e) { }) zeroconf.publish({ - name: settings.infos.appName + (settings.read('instance-name') ? ' (' + settings.read('instance-name') + ')' : ''), + name: settings.infos.productName + (settings.read('instance-name') ? ' (' + settings.read('instance-name') + ')' : ''), protocol: 'udp', type: 'osc', port: oscInPort diff --git a/src/server/server.js b/src/server/server.js index c442f078..133251a3 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -144,7 +144,7 @@ function httpCheck(ok, error){ } zeroconf.publish({ - name: settings.infos.appName + (settings.read('instanceName') ? ' (' + settings.read('instanceName') + ')' : ''), + name: settings.infos.productName + (settings.read('instanceName') ? ' (' + settings.read('instanceName') + ')' : ''), type: 'http', port: settings.read('port') || 8080 }).on('error', (e)=>{ diff --git a/src/server/settings.js b/src/server/settings.js index 84673cd2..67c387e7 100644 --- a/src/server/settings.js +++ b/src/server/settings.js @@ -68,7 +68,7 @@ var cli = false for (let i in argv) { if (!cliOnly.includes(i)) cli = true } -if (process.title === 'node' || process.title === 'node.exe') { +if (process.title === 'node' || process.title === 'node.exe' || process.env.ELECTRON_RUN_AS_NODE) { cli = true } diff --git a/src/server/theme.js b/src/server/theme.js index b0d97fe3..b6d22e7f 100644 --- a/src/server/theme.js +++ b/src/server/theme.js @@ -1,6 +1,8 @@ var fs = require('fs'), path = require('path'), - settings = require('./settings') + settings = require('./settings'), + chokidar = require('chokidar'), + ipc class Theme { @@ -9,6 +11,7 @@ class Theme { this.themes = [] this.files = [] this.css = [] + this.watcher = null this.defaultColor = '#151a24' this.backgroundColor = this.defaultColor @@ -31,6 +34,12 @@ class Theme { } } + this.watcher = chokidar.watch(this.files).on('change', ()=>{ + if (!ipc) ipc = require('./server').ipc + this.load() + ipc.send('reloadCss') + }) + this.load() return this