osc: modularize osc manager

This commit is contained in:
jean-emmanuel 2016-12-07 20:41:26 +01:00
parent 8ede297040
commit 8bf834750f
6 changed files with 76 additions and 18 deletions

View file

@ -3,7 +3,8 @@ var init = require('./init'),
utils = require('./utils'),
icon = utils.icon,
remoteExec = require('./remote-exec'),
{WidgetManager} = require('./managers')
{WidgetManager} = require('./managers'),
osc = require('./osc')
module.exports = {
@ -133,9 +134,9 @@ module.exports = {
setTimeout(function(){
OSCSYNCONLY = true
osc.syncOnly = true
actions.stateSend()
OSCSYNCONLY = false
osc.syncOnly = false
p.close()
},150)

65
src/browser/js/app/osc.js Normal file
View file

@ -0,0 +1,65 @@
var remoteExec = require('./remote-exec'),
{WidgetManager} = require('./managers'),
ipc = require('./ipc')
var Osc = function(){
this.syncOnly = false
}
Osc.prototype.send = function(data) {
if (this.syncOnly) {
ipc.send('syncOsc', data)
} else {
ipc.send('sendOsc', data)
}
}
Osc.prototype.receive = function(data){
if (data.address == '/EXEC') return remoteExec(data.args)
// fetch ids corresponding to the osc address
var address = data.address,
addressref = address,
args = data.args,
target = data.target
if (typeof data.args == 'object') {
for (var i=data.args.length-1;i>=0;i--) {
var ref = address+'||||'+data.args.slice(0,i).join('||||')
if (WidgetManager.getWidgetByAddress(ref).length) {
addressref = ref
args = data.args.slice(i,data.args.length)
continue
}
}
} else {
args = data.args
}
if (args.length==0) args = null
else if (args.length==1) args = args[0]
let widget = WidgetManager.getWidgetByAddress(addressref)
for (i in widget) {
// 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].widgetData.target < target || widget[i].widgetData.target > target)) {
// update matching widgets
if (widget[i]) widget[i].setValue(args,{send:false,sync:true,fromExternal:!target})
}
}
}

View file

@ -1,6 +1,6 @@
var _widgets_base = require('../common/_widgets_base'),
$document = $(document),
{sendOsc} = require('../utils')
osc = require('../../osc')
module.exports.options = {
type:'push',
@ -116,7 +116,7 @@ Push.prototype.sendValue = function(v, norelease) {
var args = this.widgetData.preArgs.concat(v)
sendOsc({
osc.send({
target: this.widgetData.target,
address: this.widgetData.address,
precision: this.widgetData.precision,

View file

@ -1,4 +1,4 @@
var {sendOsc} = require('../utils')
var osc = require('../../osc')
var _widget_base = module.exports = function(widgetData) {
@ -9,7 +9,7 @@ _widget_base.prototype.sendValue = function() {
var args = this.widgetData.preArgs.concat(this.value)
sendOsc({
osc.send({
target:this.widgetData.target,
address:this.widgetData.address,
precision:this.widgetData.precision,
@ -20,7 +20,7 @@ _widget_base.prototype.sendValue = function() {
if (this.split) {
var n = 0
for (i in this.split) {
sendOsc({
osc.send({
target:this.widgetData.target,
address:this.split[i],
precision:this.widgetData.precision,
@ -45,7 +45,7 @@ _widget_base.prototype.getValue = function() {
for (i in this.value) {
a.push(this.value[i])
}
return a
})()

View file

@ -1,4 +1,4 @@
var {clip, mapToScale, sendOsc} = require('../utils')
var {clip, mapToScale} = require('../utils')
var _canvas_base = require('../common/_canvas_base')
var _sliders_base = module.exports = function(){

View file

@ -1,13 +1,5 @@
module.exports = {
sendOsc: function(data){
if (!OSCSYNCONLY) {
IPC.send('sendOsc', data)
} else {
IPC.send('syncOsc', data)
}
},
clip: function(value,range) {
var value = parseFloat(value)