From c9daa7dc8374183266dc2d17b0215776b775f063 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 24 Jan 2017 07:15:38 +0100 Subject: [PATCH] multixy: support labels for points and use them in osc addresses if split is true --- .../docs/user-guide/widgets-specifics/pads.md | 6 ++-- src/browser/js/app/widgets/pads/multixy.js | 35 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/resources/docs/user-guide/widgets-specifics/pads.md b/resources/docs/user-guide/widgets-specifics/pads.md index 394c89a8..60496936 100644 --- a/resources/docs/user-guide/widgets-specifics/pads.md +++ b/resources/docs/user-guide/widgets-specifics/pads.md @@ -62,9 +62,9 @@ Pads are multidimensional widgets that output multiple values. ``` #### `points` -- type: `integer` +- type: `integer|array` - default: `2` -- usage: defines the number of points on the pad +- usage: defines the number of points on the pad. Can be an `array` of `strings` that will be used as labels for the points (ex: `['A', 'B']`) #### `pointSize` - type: `integer` @@ -98,7 +98,7 @@ Pads are multidimensional widgets that output multiple values. - type: `boolean|object` - default: `false` - usage: - - set to `true` to send separate osc messages for each point's `x` and `y` axis. The `address` will be the same as the widget's with `/N/x` or `/N/y` appended to it, where `N` is the point's id. + - set to `true` to send separate osc messages for each point's `x` and `y` axis. The `address` will be the same as the widget's with `/N/x` or `/N/y` appended to it, where `N` is the point's id (or the point's label if `points` is an `array`). - can be set as an object to specify a different `address` : `['/0/x', '/0/y', '/1/x', '/2/y']` - note: the widget will only respond to its original osc address, not to the splitted version diff --git a/src/browser/js/app/widgets/pads/multixy.js b/src/browser/js/app/widgets/pads/multixy.js index 8a403d32..5ee42477 100644 --- a/src/browser/js/app/widgets/pads/multixy.js +++ b/src/browser/js/app/widgets/pads/multixy.js @@ -48,17 +48,21 @@ module.exports = class MultiXy extends _pads_base { super(...arguments) + this.npoints = typeof widgetData.points == 'object' ? widgetData.points.length : widgetData.points + this.labels = typeof widgetData.points == 'object' this.pointSize = parseInt(widgetData.pointSize) this.widget[0].style.setProperty("--point-size",this.pointSize + 'rem') this.split = widgetData.split? - typeof widgetData.split == 'object' && widgetData.split.length == 2 * widgetData.points ? + typeof widgetData.split == 'object' && widgetData.split.length == 2 * this.npoints ? widgetData.split : (()=>{ - var s={}; - for (var i=0; i=0;i--) { + for (var i=this.npoints-1;i>=0;i--) { this.pads[i] = new Xy({ snap:widgetData.snap, spring:widgetData.spring, @@ -144,7 +148,7 @@ module.exports = class MultiXy extends _pads_base { var v = [] - for (var i=0;i