widgets/osc: add support for null target item to disable osc sending

This commit is contained in:
jean-emmanuel 2017-10-05 11:12:24 +02:00
parent b67513625d
commit 9904f06742
4 changed files with 33 additions and 29 deletions

View file

@ -188,37 +188,40 @@ module.exports = {
}
}
if (data.target.indexOf(null) == -1) {
var targets = []
var targets = []
if (settings.read('syncTargets')) Array.prototype.push.apply(targets, settings.read('syncTargets'))
if (data.target) Array.prototype.push.apply(targets, data.target)
if (settings.read('syncTargets')) Array.prototype.push.apply(targets, settings.read('syncTargets'))
if (data.target) Array.prototype.push.apply(targets, data.target)
for (var i in targets) {
if (targets[i] == 'self') {
ipc.send('receiveOsc',data,clientId)
continue
}
var host = targets[i].split(':')[0],
port = targets[i].split(':')[1]
if (port) {
if (data.split) {
for (var j in data.split) {
osc.send(host,port,data.split[j],data.args[j],data.precision)
}
} else {
osc.send(host,port,data.address,data.args,data.precision)
for (var i in targets) {
if (targets[i] == 'self') {
ipc.send('receiveOsc',data,clientId)
continue
}
var host = targets[i].split(':')[0],
port = targets[i].split(':')[1]
if (port) {
if (data.split) {
for (var j in data.split) {
osc.send(host,port,data.split[j],data.args[j],data.precision)
}
} else {
osc.send(host,port,data.address,data.args,data.precision)
}
}
}

View file

@ -77,9 +77,10 @@ All widgets share a set of generic properties described below.
- this defines the targets of the widget's osc messages
- each element of the `array` must be a string formatted as follows : `"ip:port"`
- multiple targets can be specified : `["ip1:port1","ip2:port2"]`
- if no target is set, messages can still be sent if the server has synchronized hosts (`-s / --sync`)
- if [`midi`](../extras/midi.md) is enabled, targets can be `"midi:device_name"`
- special target "self" will directly send the message back to the client
- special item `"self"` can be used to refer to the emitting client directly
- if no target is set (empty array `[]`), messages can still be sent if the server has defaults targets (`-s / --send`)
- to disable osc regardless of the previous point, set `target` to `[null]`
### `address`
- type: `string`

View file

@ -70,7 +70,7 @@ Osc.prototype.receive = function(data){
// if the message target is provided (when message comes from another client connected to the same server)
// then we only update the widgets that have the same target
// compare arrays using > and < operators (both false = equality)
if (!target || !(widget[i].getProp('target') < target || widget[i].getProp('target') > target)) {
if (!target || !(widget[i].getProp('target') < target || widget[i].getProp('target') > target || widget[i].getProp('target').length != target.length)) {
// update matching widgets
if (widget[i] && widget[i].setValue) widget[i].setValue(args,{send:false,sync:true,fromExternal:!target})
}

View file

@ -27,12 +27,12 @@ module.exports = class _widgets_base {
this.hash = _widgets_base.createHash()
// Turn preArgs into array
if (this.props.preArgs != undefined && !Array.isArray(this.resolveProp('preArgs', undefined, false))) {
if (this.props.preArgs !== undefined && !Array.isArray(this.resolveProp('preArgs', undefined, false))) {
this.props.preArgs = [this.props.preArgs]
}
// Turn preArgs into array
if (this.props.target != undefined && !Array.isArray(this.resolveProp('target', undefined, false))) {
if (this.props.target !== undefined && !Array.isArray(this.resolveProp('target', undefined, false))) {
this.props.target = [this.props.target]
}