Merge branch 'master' of github.com:jean-emmanuel/open-stage-control

This commit is contained in:
jean-emmanuel 2021-05-01 17:57:05 +02:00
commit eea4e11cf0
5 changed files with 56 additions and 4 deletions

View file

@ -5,6 +5,12 @@
- bug fixes
- prevent error with empty `OSC{}` blocks
- advanced syntaxes
- new syntax for using custom variables in properties: `VAR{name, default}`
- scripting
- add `getVar()` and `setVar` for reading and modifying custom variables. This allows modifying properties directly from scripts.
## 1.9.3
- bug fixes

View file

@ -56,10 +56,14 @@ Options can contain `@{}` blocks.
}}
```
## Custom variables: `VAR{variableName, default}`
This syntax creates a custom variable in the widget that can be read and modified from any widget's `script` property (see [scripting](./scripting.md#getvarid-name)). Changes made to this variable will be applied automatically.
## Javascript: `JS{{ <code> }}`
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.
This syntax allows defining a property using [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

View file

@ -109,6 +109,23 @@ If the event that triggered the script's execution was initiated by a user inter
----
#### `getVar(id, name)`
- `id`: widget `id` as a string.
- `name`: variable name as a string.
Returns the value of a widget's custom variable.
----
#### `setVar(id, name, value)`
- `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 ('\*').
- `name`: variable name as a string.
- `value`: new value for the variable.
Sets the value of a widget's custom variable. If `ìd` contains wildcards, affects all matching widgets.
----
#### `send(target, address, ...args)`
- `target` (optional): `"ip:port"` or `"midi:device_name"` string. If omitted, the widget's target will be used.
- `address`: osc address, must start with a `/`

View file

@ -20,6 +20,14 @@ function text(id, str) {
el.textContent = str
}
var names = {
'amd64': 'GNU/Linux Debian (64-bit)',
'linux-x64': 'GNU/Linux (64-bit)',
'node': 'Node.js',
'osx': 'MacOS',
'win32-x64': 'Windows (64-bit)'
}
function reqListener () {
var data = JSON.parse(this.responseText)
@ -30,9 +38,16 @@ function reqListener () {
var list = document.createElement('ul')
for (var i in data.assets) {
var item = document.createElement('li'),
link = document.createElement('a')
link = document.createElement('a'),
name = data.assets[i].name
link.textContent = data.assets[i].name + ' (' + (data.assets[i].size / 1024 / 1024).toFixed(1) + 'M)'
try {
name = names[name.match(/[0-9]+\.[0-9]+\.[0-9]+\-([^\.]+)/)[1]]
} catch(e) {
console.log(e)
}
link.innerHTML = '<i class="fa fa-download"></i> ' + name + ' <span class="download-size">(' + (data.assets[i].size / 1024 / 1024).toFixed(0) + 'M)</span>'
link.href = data.assets[i].browser_download_url
item.appendChild(link)
@ -67,6 +82,16 @@ html {
margin-left: .8rem;
margin-right: .6rem;
}
li {
list-style: none;
}
li i {
margin-right: 10px
}
.download-size {
color: var(--md-typeset-color);
opacity: 0.5;
}
</style>
<div>

View file

@ -430,7 +430,7 @@ class ScriptVm extends Vm {
for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar',
'openUrl']) {
'openUrl', 'getVar', 'setVar']) {
this.sanitize(this.sandbox.contentWindow[imports])
}