From f776645ce067e33f5c79c7e9d68e8f6cdb9d20e0 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 7 Oct 2016 23:59:44 +0200 Subject: [PATCH] buttons: - remove special `false` value case for push/toggles (which used to disable osc sending) - add `norelease` option to `push` for disabling osc messages when releasing the button --- CHANGELOG.md | 2 ++ app/browser/js/app/widgets/push.js | 19 +++++++++++-------- app/browser/js/app/widgets/toggle.js | 11 ++++++----- .../user-guide/widgets-specifics/buttons.md | 10 +++++----- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ff19925..8ae08b81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - explicit loadings - widgets - make push's backlight only respond to external osc messages (not to synchronization messages from other widgets or clients) + - remove special `false` value case for push/toggles (which used to disable osc sending) + - add `norelease` option to `push` for disabling osc messages when releasing the button - misc - rewritten matrices with prototypes inheritance diff --git a/app/browser/js/app/widgets/push.js b/app/browser/js/app/widgets/push.js index e10f5126..3177d84b 100644 --- a/app/browser/js/app/widgets/push.js +++ b/app/browser/js/app/widgets/push.js @@ -19,6 +19,7 @@ module.exports.options = { on:1, off:0, + norelease:false, precision:2, path:'auto', preArgs:[], @@ -57,20 +58,23 @@ module.exports.create = function(widgetData,container) { } widget.getValue = function() { - return widget[widget.lastChanged]?widgetData.on:widgetData.off + return widget[widget.lastChanged] ? + widgetData.on.value !== undefined ? widgetData.on.value : widgetData.on + : + widgetData.off.value !== undefined ? widgetData.off.value : widgetData.off } widget.setValuePrivate = function(v,options={}) { - if (v===widgetData.on || (v=='false'&&widgetData.on===false)) { + if (v===widgetData.on || (v.value === widgetData.on.value && v.value !== undefined)) { widget.addClass('active') widget.active = 1 if (options.send) widget.sendValue(v) widget.lastChanged = 'active' if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options:options}) - } else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) { + } else if (v===widgetData.off || (v.value === widgetData.off.value && v.value !== undefined)) { widget.removeClass('active') widget.active = 0 - if (options.send) widget.sendValue(v) + if (options.send && !widgetData.norelease) widget.sendValue(v) widget.lastChanged = 'active' if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options:options}) } @@ -81,13 +85,13 @@ module.exports.create = function(widgetData,container) { if (options.send || options.sync) widget.setValuePrivate(v,options) return } - if (v===widgetData.on || (v=='false'&&widgetData.on===false)) { + if (v===widgetData.on || (v.value === widgetData.on.value && v.value !== undefined)) { widget.addClass('on') widget.state = 1 if (options.send) widget.sendValue(v) widget.lastChanged = 'state' if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId,options:options}) - } else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) { + } else if (v===widgetData.off || (v.value === widgetData.off.value && v.value !== undefined)) { widget.removeClass('on') widget.state = 0 if (options.send) widget.sendValue(v) @@ -97,8 +101,8 @@ module.exports.create = function(widgetData,container) { } widget.sendValue = function(v) { - if (v===false) return var args = widgetData.preArgs.concat(v) + sendOsc({ target:widgetData.target, path:widgetData.path, @@ -106,6 +110,5 @@ module.exports.create = function(widgetData,container) { args:args }) } - widget.setValue() return widget } diff --git a/app/browser/js/app/widgets/toggle.js b/app/browser/js/app/widgets/toggle.js index 0d4c985f..ee1d31a6 100644 --- a/app/browser/js/app/widgets/toggle.js +++ b/app/browser/js/app/widgets/toggle.js @@ -55,14 +55,17 @@ module.exports.create = function(widgetData,container) { widget.getValue = function() { - return widget.state?widgetData.on:widgetData.off + return widget.state ? + widgetData.on.value !== undefined ? widgetData.on.value : widgetData.on + : + widgetData.off.value !== undefined ? widgetData.off.value : widgetData.off } widget.setValue = function(v,options={}) { - if (v===widgetData.on || (v=='false'&&widgetData.on===false)) { + if (v===widgetData.on || (v.value === widgetData.on.value && v.value !== undefined)) { widget.addClass('on') widget.state = 1 if (options.send) widget.sendValue(widgetData.on) - } else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) { + } else if (v===widgetData.off || (v.value === widgetData.off.value && v.value !== undefined)) { widget.removeClass('on') widget.state = 0 if (options.send) widget.sendValue(widgetData.off) @@ -72,7 +75,6 @@ module.exports.create = function(widgetData,container) { } widget.sendValue = function(v) { - if (v===false) return var args = widgetData.preArgs.concat(v) sendOsc({ @@ -82,6 +84,5 @@ module.exports.create = function(widgetData,container) { args:args }) } - widget.setValue() return widget } diff --git a/app/resources/docs/user-guide/widgets-specifics/buttons.md b/app/resources/docs/user-guide/widgets-specifics/buttons.md index 424ca591..789b1e5f 100644 --- a/app/resources/docs/user-guide/widgets-specifics/buttons.md +++ b/app/resources/docs/user-guide/widgets-specifics/buttons.md @@ -17,7 +17,6 @@ Buttons are exactly what you think they are. - default: `1` - usage: defines which value is sent on `on` position - set to `null` to send send no argument in the osc message - - set to `false` to prevent sending any osc message - can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs)) #### `off` @@ -25,7 +24,6 @@ Buttons are exactly what you think they are. - default: `0` - usage: defines which value is sent on `off` position - set to `null` to send send no argument in the osc message - - set to `false` to prevent sending any osc message - can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs)) @@ -44,7 +42,6 @@ Buttons are exactly what you think they are. - default: `1` - usage: defines which value is sent when pushing the button - set to `null` to send send no argument in the osc message - - set to `false` to prevent sending any osc message - can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs)) #### `off` @@ -52,11 +49,14 @@ Buttons are exactly what you think they are. - default: `0` - usage: defines which value is sent when releasing the button - set to `null` to send send no argument in the osc message - - set to `false` to prevent sending any osc message - can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs)) +### `norelease` +- type: `bool` +- default: `false` +- usage: set to true to prevent sending any osc message when releasing the button -Setting the `push`'s value externally (via osc or widget linking/cloning) will toggle it's inner light. +Setting the `push`'s value externally (via osc) will toggle it's inner light. ----