- widgets: pass setValue's options to the sync event to make sure linked widgets don't send osc when synced by another client
- osc callback: use fromExternal instead of fromLocal to tell widgets where the message comes from (default case = external) - push: make the backlight respond only to external osc messages
This commit is contained in:
parent
f35cfbb3a6
commit
dd38a399dd
13 changed files with 32 additions and 31 deletions
|
|
@ -37,7 +37,7 @@ module.exports = {
|
|||
// compare arrays using > and < operators (both false = equality)
|
||||
if (!target || !(WIDGETS_BY_PATH[pathref][i].target < target || WIDGETS_BY_PATH[pathref][i].target > target)) {
|
||||
// update matching widgets
|
||||
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,{send:false,sync:true,fromLocal:target})
|
||||
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,{send:false,sync:true,fromExternal:!target})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,14 +56,15 @@ module.exports.createWidget = function(){
|
|||
}()
|
||||
|
||||
module.exports.sync = function() {
|
||||
$('body').off('sync.global').on('sync.global',function(e,id,widget,linkId){
|
||||
$('body').off('sync.global').on('sync.global',function(e){
|
||||
var {id, widget, linkId, fromExternal, options} = e
|
||||
// Widget that share the same id will update each other
|
||||
// without sending any extra osc message
|
||||
if (WIDGETS[id] && WIDGETS[id].length>1) {
|
||||
var v = widget.getValue()
|
||||
for (i in WIDGETS[id]) {
|
||||
if (!WIDGETS[id][i].is(widget) && WIDGETS[id][i].setValue) {
|
||||
WIDGETS[id][i].setValue(v,{fromLocal:true})
|
||||
WIDGETS[id][i].setValue(v,{send:false,sync:false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +74,7 @@ module.exports.sync = function() {
|
|||
var v = widget.getValue()
|
||||
for (i in WIDGETS_LINKED[linkId]) {
|
||||
if (!WIDGETS_LINKED[linkId][i].is(widget) && WIDGETS_LINKED[linkId][i].setValue) {
|
||||
WIDGETS_LINKED[linkId][i].setValue(v,{send:true,sync:false,fromLocal:true})
|
||||
WIDGETS_LINKED[linkId][i].setValue(v,{send:options.send,sync:false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.on('sync',function(e,id,w){
|
||||
if (id==widgetData.id) return
|
||||
widget.value[w.parent().index()] = w.getValue()
|
||||
widget.trigger('sync',[widgetData.id,widget])
|
||||
widget.trigger('sync',{id:widgetData.id,widget:widget})
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.on('sync',function(e,id,w){
|
||||
if (id==widgetData.id) return
|
||||
widget.value[w.parent().index()] = w.getValue()
|
||||
widget.trigger('sync',[widgetData.id,widget])
|
||||
widget.trigger('sync',{id:widgetData.id,widget:widget})
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.on('sync',function(e,id,w){
|
||||
if (id==widgetData.id) return
|
||||
widget.value[w.parent().index()] = w.getValue()
|
||||
widget.trigger('sync',[widgetData.id,widget])
|
||||
widget.trigger('sync',{id:widgetData.id,widget:widget})
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ module.exports.create = function(widgetData,container) {
|
|||
led = widget.find('span'),
|
||||
range = widgetData.range
|
||||
|
||||
widget.setValue = function(v,send,sync){
|
||||
widget.setValue = function(v){
|
||||
if (typeof v != 'number') return
|
||||
led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],widgetData.precision,widgetData.logScale,true))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ module.exports.create = function(widgetData,container) {
|
|||
|
||||
if (widgetData.vertical) widget.addClass('vertical')
|
||||
|
||||
widget.setValue = function(v,send,sync){
|
||||
widget.setValue = function(v){
|
||||
text = typeof v=='object' && !v.length?label:v
|
||||
widget.text(text)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ module.exports.create = function(widgetData,container) {
|
|||
})
|
||||
|
||||
widget.fakeclick = function(){
|
||||
if (!widget.active) widget.setValuePrivate(widgetData.on,true,true)
|
||||
if (!widget.active) widget.setValuePrivate(widgetData.on,{send:true,sync:true})
|
||||
$document.on('dragend.push',function(){
|
||||
widget.setValuePrivate(widgetData.off,true,true)
|
||||
widget.setValuePrivate(widgetData.off,{send:true,sync:true})
|
||||
$document.off('dragend.push')
|
||||
widget.on('draginit.push',function(){
|
||||
widget.off('draginit.push')
|
||||
|
|
@ -60,25 +60,25 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget[widget.lastChanged]?widgetData.on:widgetData.off
|
||||
}
|
||||
|
||||
widget.setValuePrivate = function(v,send,sync) {
|
||||
widget.setValuePrivate = function(v,options={}) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('active')
|
||||
widget.active = 1
|
||||
if (send) widget.sendValue(v)
|
||||
if (options.send) widget.sendValue(v)
|
||||
widget.lastChanged = 'active'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
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)) {
|
||||
widget.removeClass('active')
|
||||
widget.active = 0
|
||||
if (send) widget.sendValue(v)
|
||||
if (options.send) widget.sendValue(v)
|
||||
widget.lastChanged = 'active'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options:options})
|
||||
}
|
||||
}
|
||||
|
||||
widget.setValue = function(v,options={}) {
|
||||
if (options.fromLocal) {
|
||||
widget.setValuePrivate(v,options.send,false)
|
||||
if (!options.fromExternal) {
|
||||
if (options.send || options.sync) widget.setValuePrivate(v,options)
|
||||
return
|
||||
}
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
|
|
@ -86,13 +86,13 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.state = 1
|
||||
if (options.send) widget.sendValue(v)
|
||||
widget.lastChanged = 'state'
|
||||
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
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)) {
|
||||
widget.removeClass('on')
|
||||
widget.state = 0
|
||||
if (options.send) widget.sendValue(v)
|
||||
widget.lastChanged = 'state'
|
||||
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId,options:options})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -151,7 +151,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -226,7 +226,7 @@ module.exports.create = function(widgetData,container) {
|
|||
|
||||
|
||||
|
||||
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
if (options.send) widget.sendValue(v)
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ _sliders_base.prototype.setValue = function(v,options={}) {
|
|||
|
||||
this.showValue()
|
||||
|
||||
if (options.sync) this.widget.trigger('sync',[this.widgetData.id,this.widget,this.widgetData.linkId])
|
||||
if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
|
||||
if (options.send) this.sendValue(v)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ module.exports.create = function(widgetData,container) {
|
|||
next()
|
||||
})
|
||||
if (options.send) widget.sendValue(widget.value)
|
||||
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ module.exports.create = function(widgetData,container) {
|
|||
if (options.send) widget.sendValue(widgetData.off)
|
||||
}
|
||||
|
||||
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -158,7 +158,7 @@ module.exports.create = function(widgetData,container) {
|
|||
widget.value = v
|
||||
|
||||
widget.showValue(v)
|
||||
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
|
||||
if (options.send) widget.sendValue(v)
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue