osc: add support for osc typetag in widget's precision property (issue #137)
This commit is contained in:
parent
99c8dcb856
commit
3e9a56e3e8
4 changed files with 14 additions and 7 deletions
|
|
@ -14,6 +14,7 @@
|
|||
- switch: added `showValues` to display both values and labels in the buttons; array values can now be selected via osc
|
||||
- rgb: **removed** `touchAddress` option
|
||||
- labels/texts: multiple white spaces are no longer merged
|
||||
- widgets' `precision` option allows setting a specific data type for numbers (sliders can send doubles !)
|
||||
- misc
|
||||
- event system rewritten
|
||||
- js build size reduced
|
||||
|
|
|
|||
|
|
@ -38,11 +38,15 @@ var parseType = function(type){
|
|||
|
||||
}
|
||||
|
||||
var parseArg = function(arg,precision){
|
||||
var parseArg = function(arg, precision){
|
||||
if (arg==null) return null
|
||||
switch (typeof arg) {
|
||||
case 'number':
|
||||
return {type: precision == 0 ? 'i' : 'f', value: parseFloat(arg.toFixed(precision))}
|
||||
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: parseFloat(arg.toFixed(precisionValue))}
|
||||
case 'boolean':
|
||||
return {type: arg ? 'T' : 'F', value: arg}
|
||||
case 'object':
|
||||
|
|
|
|||
|
|
@ -66,9 +66,11 @@ All widgets share a set of generic properties described below.
|
|||
|
||||
|
||||
### `precision`
|
||||
- type: `integer`
|
||||
- type: `integer|string`
|
||||
- default: `2`
|
||||
- usage: the `precision` property defines the number of decimals to display and to send. Set to `0` to send `integers` only.
|
||||
- usage: the `precision` property defines the number of decimals to display and to send.
|
||||
- set to `0` to send `integers` only.
|
||||
- a specific 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
|
||||
|
||||
### `target`
|
||||
- type: `array`
|
||||
|
|
@ -100,7 +102,7 @@ All widgets share a set of generic properties described below.
|
|||
- default: `[]`
|
||||
- usage:
|
||||
- each element of the `array` defines a constant value that will be prepended to the osc message
|
||||
- values can be defined as objects if the type needs to be specified (ie different from the default implied by the `precision`)
|
||||
- values can be defined as objects if the osc data type needs to be specified (ie different from the default implied by the `precision` option)
|
||||
- example:
|
||||
```js
|
||||
preArgs: [
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
ipc.send('addWidget', {
|
||||
hash:hash,
|
||||
data:{
|
||||
precision: this.widgets[hash].precision,
|
||||
precision: this.widgets[hash].getProp('precision'),
|
||||
preArgs: this.widgets[hash].getProp('preArgs'),
|
||||
split: this.widgets[hash].split,
|
||||
target: this.widgets[hash].getProp('target'),
|
||||
|
|
@ -107,7 +107,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
ipc.send('addWidget', {
|
||||
hash:hash,
|
||||
data:{
|
||||
precision: widget.precision,
|
||||
precision: widget.getProp('precision'),
|
||||
preArgs: widget.getProp('preArgs'),
|
||||
split: widget.split,
|
||||
target: widget.getProp('target'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue