diff --git a/app/browser/js/app/app.js b/app/browser/js/app/app.js
index 1fa7fa42..a22831b3 100644
--- a/app/browser/js/app/app.js
+++ b/app/browser/js/app/app.js
@@ -2,5 +2,4 @@ require('./parser.js') // session file parser
require('./utils.js') // state managing & inspector
require('./widgets.js') // widgets types and behaviour definition
require('./callbacks.js')// calls from mainProcess
-require('./editor.js') // ...
require('./init.js') // ...
diff --git a/app/browser/js/app/editor.js b/app/browser/js/app/editor.js
index 05d1d0dc..618a36a6 100644
--- a/app/browser/js/app/editor.js
+++ b/app/browser/js/app/editor.js
@@ -23,8 +23,9 @@ function getdata(obj){
}
-enableEditor = function(){
- disableEditor()
+module.exports.enable = function(){
+ module.exports.disable()
+ var enableEditor = module.exports.enable
$('.widget').on('click.editor',function(e){
e.preventDefault()
e.stopPropagation()
@@ -474,7 +475,7 @@ enableEditor = function(){
$('.disable-editor').removeClass('on')
}
-disableEditor = function(){
+module.exports.disable = function(){
$('.widget.ui-resizable').resizable('destroy')
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
$('.widget').off('click.editor')
diff --git a/app/browser/js/app/init.js b/app/browser/js/app/init.js
index 98bddeeb..55d89ea1 100644
--- a/app/browser/js/app/init.js
+++ b/app/browser/js/app/init.js
@@ -1,3 +1,7 @@
+var editor = require('./editor'),
+ enableEditor = editor.enable,
+ disableEditor = editor.disable
+
init = function(session,callback) {
$('#container').empty()
diff --git a/app/browser/js/app/utils.js b/app/browser/js/app/utils.js
index 12465e9b..db7c2230 100644
--- a/app/browser/js/app/utils.js
+++ b/app/browser/js/app/utils.js
@@ -188,88 +188,3 @@ createPopup = function(title,content) {
return popup
}
-
-
-hsbToRgb = function (hsb) {
- var rgb = {}
- var h = hsb.h
- var s = hsb.s*255/100
- var v = hsb.b*255/100
- if(s == 0) {
- rgb.r = rgb.g = rgb.b = v
- } else {
- var t1 = v
- var t2 = (255-s)*v/255
- var t3 = (t1-t2)*(h%60)/60
- if(h==360) h = 0
- if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
- else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
- else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
- else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
- else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
- else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
- else {rgb.r=0; rgb.g=0; rgb.b=0}
- }
- return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}
-}
-rgbToHsb = function (rgb) {
- var hsb = {h: 0, s: 0, b: 0}
- var min = Math.min(rgb.r, rgb.g, rgb.b)
- var max = Math.max(rgb.r, rgb.g, rgb.b)
- var delta = max - min
- hsb.b = max
- hsb.s = max != 0 ? 255 * delta / max : 0
- if (hsb.s != 0) {
- if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta
- else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta
- else hsb.h = 4 + (rgb.r - rgb.g) / delta
- } else hsb.h = 0
- hsb.h *= 60
- if (hsb.h < 0) hsb.h += 360
- hsb.s *= 100/255
- hsb.b *= 100/255
- return hsb
-}
-
-sizeToAngle = function(size) {
- return clip(Math.acos((size/100))*180/Math.PI,[0,90])
-}
-clip = function(value,range) {
- var value = parseFloat(value)
-
- if (isNaN(value)) value = range[0]
- return Math.max(Math.min(range[0],range[1]),Math.min(value,Math.max(range[0],range[1])))
-
-}
-
-// map a value from a scale to another input and output must be range arrays
-mapToScale = function(value,rangeIn,rangeOut,precision) {
-
- var value = clip(value,[rangeIn[0],rangeIn[1]]),
- roundFactor = precision!=undefined?Math.pow(10,precision):100
-
- value = ((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
-
- value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
-
- value = Math.round(value*roundFactor)/roundFactor
-
- return value
-
-}
-
-function isSame(a1, a2){
- if (a1.sort && a2.sort) {
- return !(a1.sort() > a2.sort() || a1.sort() < a2.sort());
- } else {
- return a1==a2
- }
-}
-
-
-$.fn.ripple = function() {
- $(this).removeClass('ripple').addClass('ripple').delay(250).queue(function(next){
- $(this).removeClass('ripple');
- next();
- });
-}
diff --git a/app/browser/js/app/widgets.js b/app/browser/js/app/widgets.js
index 024d3ae5..174d812f 100644
--- a/app/browser/js/app/widgets.js
+++ b/app/browser/js/app/widgets.js
@@ -1,1198 +1,36 @@
-createWidget = {}
+var strip = require('./widgets/strip'),
+ panel = require('./widgets/panel'),
+ led = require('./widgets/led'),
+ fader = require('./widgets/fader'),
+ knob = require('./widgets/knob'),
+ xy = require('./widgets/xy'),
+ rgb = require('./widgets/rgb'),
+ toggle = require('./widgets/toggle'),
+ swiitch = require('./widgets/switch'),
+ push = require('./widgets/push')
widgetOptions = {
- strip: {
- type:'strip',
- id:'auto',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- horizontal:false,
- css:'',
-
- separator2:'children',
-
- widgets:[]
- },
- panel: {
- type:'panel',
- id:'auto',
-
- separator1:'style',
-
- label:'auto',
- left:'0',
- top:'0',
- width:'auto',
- height:'auto',
- stretch:false,
- css:'',
-
- separator2:'chilren',
-
- widgets:[],
- tabs:[]
- },
- led: {
- type:'led',
- id:'auto',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- color:'green',
- css:'',
-
- separator2:'osc',
-
- range:{min:0,max:1},
- path:'auto'
- },
- toggle: {
- type:'toggle',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- css:'',
-
- separator2:'osc',
-
- on:1,
- off:0,
- precision:2,
- path:'auto',
- target:[]
- },
- push: {
- type:'push',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- css:'',
-
- separator2:'osc',
-
- on:1,
- off:0,
- precision:2,
- path:'auto',
- target:[]
- },
- switch: {
- type:'switch',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- horizontal:false,
- css:'',
-
- separator2:'osc',
-
- values:{"Value 1":1,"Value 2":2},
- precision:2,
- path:'auto',
- target:[]
- },
- xy: {
- type:'xy',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- css:'',
-
- separator2:'behaviour',
-
- absolute:false,
-
- separator3:'osc',
-
- rangeX:{min:0,max:1},
- rangeY:{min:0,max:1},
- precision:2,
- path:'auto',
- split:false,
- target:[]
- },
- rgb: {
- type:'rgb',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- css:'',
-
- separator2:'behaviour',
-
- absolute:false,
-
- separator3:'osc',
-
- precision:0,
- path:'auto',
- split:false,
- target:[]
- },
- fader: {
- type:'fader',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- unit:'',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- horizontal:false,
- css:'',
-
- separator2:'behaviour',
-
- absolute:false,
-
- separator3:'osc',
-
- range:{min:0,max:1},
- precision:2,
- path:'auto',
- target:[]
- },
- knob: {
- type:'knob',
- id:'auto',
- linkId:'',
-
- separator1:'style',
-
- label:'auto',
- unit:'',
- left:'auto',
- top:'auto',
- width:'auto',
- height:'auto',
- css:'',
-
- separator2:'behaviour',
-
- absolute:false,
- pan:false,
-
-
- separator3:'osc',
-
- range:{min:0,max:1},
- precision:2,
- path:'auto',
- target:[]
- }
-
+ strip: strip.options,
+ panel: panel.options,
+ led: led.options,
+ fader: fader.options,
+ knob: knob.options,
+ xy: xy.options,
+ rgb: rgb.options,
+ toggle: toggle.options,
+ switch: swiitch.options,
+ push: push.options
}
-createWidget.strip = function(widgetData,container) {
- var widget = $(`
-
-
- `)
- if (widgetData.horizontal) {
- container.addClass('horizontal')
- } else {
- container.addClass('vertical')
- }
- parsewidgets(widgetData.widgets,widget)
- widget.getValue = function(){return}
- widget.setValue = function(){return}
- return widget
-}
-
-
-createWidget.panel = function(widgetData,container) {
- var widget = $(`
-
-
- `)
-
- if (widgetData.stretch) widget.addClass('stretch')
-
- if (widgetData.tabs.length) {
- parsetabs(widgetData.tabs,widget)
- } else {
- parsewidgets(widgetData.widgets,widget)
- }
- widget.getValue = function(){return}
- widget.setValue = function(){return}
- return widget
-}
-
-
-
-createWidget.led = function(widgetData) {
- var widget = $(`
-
- `),
- led = widget.find('span'),
- range = widgetData.range || {min:0,max:1}
-
- if (widgetData.color) led.css('background-color',widgetData.color)
-
- widget.setValue = function(v){
- led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],widgetData.precision))
- }
- widget.getValue = function(){return}
- return widget
-}
-
-
-
-createWidget.toggle = function(widgetData) {
-
- var widget = $(`
- \
- `),
- $document = $(document)
-
- widget.value = widget.find('span')
-
- widget.on('drag',function(e){e.stopPropagation()})
- widget.on('draginit.toggle',function(){
- widget.off('draginit.toggle')
- widget.fakeclick()
- })
-
- widget.fakeclick = function(){
- var newVal = widget.hasClass('on')?widgetData.off:widgetData.on
- widget.setValue(newVal,true,true)
- $document.on('dragend.toggle',function(){
- $document.off('dragend.toggle')
- widget.on('draginit.toggle',function(){
- widget.off('draginit.toggle')
- widget.fakeclick()
- })
- })
- }
-
-
- widget.getValue = function() {
- return widget.hasClass('on')?widgetData.on:widgetData.off
- }
- widget.setValue = function(v,send,sync) {
- if (v==widgetData.on) {
- widget.addClass('on').ripple()
- if (send) widget.sendValue(widgetData.on)
- } else if (v==widgetData.off) {
- widget.removeClass('on')
- if (send) widget.sendValue(widgetData.off)
- }
-
- if (sync) widget.trigger('sync')
-
- }
- widget.sendValue = function(v) {
- if (v===false) return
- sendOsc({
- target:widgetData.target,
- path:widgetData.path,
- precision:widgetData.precision,
- args:v
- })
- }
- widget.setValue()
- return widget
-}
-
-createWidget.push = function(widgetData) {
-
- var widget = $(`
- \
- `),
- $document = $(document)
-
- widget.value = widget.find('span')
-
- widget.on('drag',function(e){e.stopPropagation()})
- widget.on('draginit.push',function(){
- widget.off('draginit.push')
- widget.fakeclick()
- })
-
- widget.fakeclick = function(){
- widget.setValue(widgetData.on,true,true)
- $document.on('dragend.push',function(){
- widget.setValue(widgetData.off,true,true)
- $document.off('dragend.push')
- widget.on('draginit.push',function(){
- widget.off('draginit.push')
- widget.fakeclick()
- })
- })
- }
-
- widget.getValue = function() {
- return widget.hasClass('on')?widgetData.on:widgetData.off
- }
- widget.setValue = function(v,send,sync) {
- var on = widgetData.on,
- off= widgetData.off
- if (v==on) {
- widget.addClass('on').ripple()
- if (send) widget.sendValue(v)
- } else if (v==off) {
- widget.removeClass('on')
- if (send) widget.sendValue(v)
- }
-
- if (sync) widget.trigger('sync')
-
- }
- widget.sendValue = function(v) {
- if (v===false) return
- sendOsc({
- target:widgetData.target,
- path:widgetData.path,
- precision:widgetData.precision,
- args:v
- })
- }
- widget.setValue()
- return widget
-}
-
-
-
-createWidget.switch = function(widgetData) {
-
- var widget = $(`
-
-
- `),
- $document = $(document)
-
- if (widgetData.horizontal) {
- widget.addClass('horizontal')
- }
-
- widget.values = []
-
- for (k in widgetData.values) {
- widget.values.push(widgetData.values[k])
- $(''+k+'
').data({value:widgetData.values[k]}).appendTo(widget)
- }
-
- widget.value = undefined
-
- widget.on('drag',function(e){e.stopPropagation()})
-
- widget.on('draginit',function(e,dd){
- var data = $(dd.target).data()
- if (data.value!=widget.value || widget.value===undefined) widget.setValue(data.value,true,true)
- })
-
-
-
- widget.getValue = function() {
- return widget.value
- }
- widget.setValue = function(v,send,sync) {
- var i = widget.values.indexOf(v)
- if (i!=-1) {
- widget.value = widget.values[i]
- widget.find('.on').removeClass('on')
- widget.find('.value').eq(i).addClass('on').ripple()
- if (send) widget.sendValue(widget.value)
- if (sync) widget.trigger('sync')
- }
-
- }
- widget.sendValue = function(v) {
- sendOsc({
- target:widgetData.target,
- path:widgetData.path,
- precision:widgetData.precision,
- args:v
- })
- }
- return widget
-}
-
-
-
-createWidget.xy = function(widgetData) {
- var widget = $(`
-
- `),
- handle = widget.find('.handle'),
- pad = widget.find('.xy'),
- value = {x:widget.find('.x').fakeInput({align:'center'}),y:widget.find('.y').fakeInput({align:'center'})},
- range = {x:widgetData.rangeX,y:widgetData.rangeY},
- absolute = widgetData.absolute,
- split = widgetData.split?
- typeof widgetData.split == 'object'?
- widgetData.split:{x:widgetData.path+'/x',y:widgetData.path+'/y'}
- :false
-
-
- if (widgetData.height!='auto') widget.addClass('manual-height')
-
- pad.width = pad.innerWidth()
- pad.height = pad.innerHeight()
- handle.height = 0
- handle.width = 0
-
- pad.resize(function(){
- var width = pad.innerWidth(),
- height = pad.innerHeight()
- if (!width || (pad.height==height && pad.width==width)) return
- pad.width = width
- pad.height = height
- handle[0].setAttribute('style',`transform:translate3d(${pad.width*handle.width/100}px, -${pad.height*handle.height/100}px,0)`)
- })
-
- var off = {x:0,y:0}
- pad.on('draginit',function(e,data){
- if (absolute || data.ctrlKey || data.shiftKey) {
- var h = ((pad.height-data.offsetY) * 100 / pad.height),
- w = (data.offsetX * 100 / pad.width)
-
- handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
-
- handle.height = h
- handle.width = w
-
- var v = widget.getValue()
- widget.sendValue(v)
- widget.showValue(v)
- widget.trigger('sync')
-
- }
-
- off = {x:handle.width,y:handle.height}
-
- })
- pad.on('drag',function(e,data){
- e.stopPropagation()
-
- if (data.shiftKey) return
-
- var h = clip((-data.deltaY)*100/pad.height+off.y,[0,100]),
- w = clip((data.deltaX)*100/pad.width+off.x,[0,100])
-
- handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
-
- handle.height = h
- handle.width = w
-
- var v = widget.getValue()
- widget.sendValue(v)
- widget.showValue(v)
- widget.trigger('sync')
-
- })
-
-
-
- widget.getValue = function() {
- var x = mapToScale(handle.width,[0,100],[range.x.min,range.x.max],widgetData.precision),
- y = mapToScale(handle.height,[0,100],[range.y.min,range.y.max],widgetData.precision)
-
- return [x,y]
- }
- widget.setValue = function(v,send,sync) {
- if (v[1]==undefined) var v = [v,v]
-
- for (i in [0,1]) {
- v[i] = clip(v[i],[range[['x','y'][i]].min,range[['x','y'][i]].max])
- }
-
- var w = mapToScale(v[0],[range.x.min,range.x.max],[0,100],widgetData.precision)
- h = mapToScale(v[1],[range.y.min,range.y.max],[0,100],widgetData.precision),
-
- handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
- handle.height = h
- handle.width = w
-
- widget.showValue(v)
- if (sync) widget.trigger('sync')
- if (send) widget.sendValue(v)
- }
- widget.sendValue = function(v) {
- sendOsc({
- target:split?false:widgetData.target,
- path:widgetData.path,
- args:v,
- precision:widgetData.precision,
- })
- if (split) {
- sendOsc({
- target:widgetData.target,
- path:split.x,
- args:v[0],
- precision:widgetData.precision,
- sync:false
- })
- sendOsc({
- target:widgetData.target,
- path:split.y,
- args:v[1],
- precision:widgetData.precision,
- sync:false
- })
- }
- }
-
- widget.showValue = function(v) {
- value.x.val(v[0])
- value.y.val(v[1])
- }
-
- value.x.change(function(){
- var v = widget.getValue()
- v[0] = clip(value.x.val(),[range.x.min,range.x.max])
- widget.setValue(v,true,true)
- })
- value.y.change(function(){
- var v = widget.getValue()
- v[1] = clip(value.y.val(),[range.y.min,range.y.max])
- widget.setValue(v,true,true)
- })
-
- widget.setValue(range.x.min,range.y.min)
- return widget
-}
-
-
-
-
-
-
-createWidget.rgb = function(widgetData) {
-
- var widget = $(`
- `),
- rgbHandle = widget.find('.rgb .handle'),
- hueHandle = widget.find('.hue .handle'),
- pad = widget.find('.xy'),
- huePad = widget.find('.hue'),
- rgbBg = pad.find('.bg')[0],
- value = {r:widget.find('.r').fakeInput({align:'center'}),g:widget.find('.g').fakeInput({align:'center'}),b:widget.find('.b').fakeInput({align:'center'})},
- absolute = widgetData.absolute,
- split = widgetData.split?
- typeof widgetData.split == 'object'?
- widgetData.split:{r:widgetData.path+'/r',g:widgetData.path+'/g',b:widgetData.path+'/b'}
- :false
-
- if (widgetData.height!='auto') widget.addClass('manual-height')
-
-
- pad.width = pad.innerWidth()
- pad.height = pad.innerHeight()
- rgbHandle.height = 0
- rgbHandle.width = 0
- hueHandle.width = 0
-
- pad.resize(function(){
- var width = pad.innerWidth(),
- height = pad.innerHeight()
- if (!width || (pad.height==height && pad.width==width)) return
- pad.width = width
- pad.height = height
- rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*rgbHandle.width/100}px, -${pad.height*rgbHandle.height/100}px,0)`)
-
- })
-
-
- var rgbOff = {x:0,y:0}
- pad.on('draginit',function(e,data){
- if (absolute || data.ctrlKey || data.shiftKey) {
- var h = ((pad.height-data.offsetY) * 100 / pad.height),
- w = (data.offsetX * 100 / pad.width)
-
- rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
- rgbHandle.height = h
- rgbHandle.width = w
-
- var v = widget.getValue()
- widget.sendValue(v)
- widget.showValue(v)
- widget.trigger('sync')
-
- }
-
- rgbOff = {x:rgbHandle.width,y:rgbHandle.height}
-
- })
- pad.on('drag',function(e,data){
- e.stopPropagation()
-
- if (data.shiftKey) return
-
- var h = clip((-data.deltaY)*100/pad.height+rgbOff.y,[0,100]),
- w = clip(data.deltaX*100/pad.width+rgbOff.x,[0,100])
-
- rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
- rgbHandle.height = h
- rgbHandle.width = w
-
- var v = widget.getValue()
- widget.sendValue(v)
- widget.showValue(v)
-
- widget.trigger('sync')
-
- })
-
-
- var hueOff = 0
- huePad.on('draginit',function(e,data){
- if (absolute || data.ctrlKey || data.shiftKey) {
- var d = (data.offsetX * 100 / pad.width)
- hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*d/100}px,0,0)`)
- hueHandle.width = d
-
-
- var h = clip(hueHandle.width*3.6,[0,360]),
- rgb = hsbToRgb({h:h,s:100,b:100}),
- v = widget.getValue()
-
- rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
-
-
-
- widget.sendValue(v)
- widget.showValue(v)
- widget.trigger('sync')
-
- }
-
- hueOff = hueHandle.width
-
- })
-
-
- huePad.on('drag',function(e,data){
- e.stopPropagation()
-
- if (data.shiftKey) return
-
- var w = clip(data.deltaX*100/pad.width+hueOff,[0,100])
- hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px,0,0)`)
- hueHandle.width = w
-
- var h = clip(hueHandle.width*3.6,[0,360]),
- rgb = hsbToRgb({h:h,s:100,b:100}),
- v = widget.getValue()
-
- rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
- widget.sendValue(v)
- widget.showValue(v)
-
- widget.trigger('sync')
-
- })
-
-
-
-
-
- widget.getValue = function() {
- var s = clip(rgbHandle.width,[0,100]),
- l = clip(rgbHandle.height,[0,100]),
- h = mapToScale(hueHandle.width,[0,100],[0,360],widgetData.precision),
- rgb = hsbToRgb({h:h,s:s,b:l})
- return [rgb.r,rgb.g,rgb.b]
- }
- widget.setValue = function(v,send,sync) {
- if (v[1]==undefined && v[2]==undefined) var v = [v,v,v]
- if (v[2]==undefined) var v = [v[0],v[1],v[1]]
-
- for (i in [0,1,2]) {
- v[i] = clip(v[i],[0,255])
- }
-
-
- var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
-
- var w = mapToScale(hsb.s,[0,100],[0,100],widgetData.precision),
- h = mapToScale(hsb.b,[0,100],[0,100],widgetData.precision),
- hueW = mapToScale(hsb.h,[0,360],[0,100],widgetData.precision)
-
- rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
- hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*hueW/100}px,0,0)`)
-
- rgbHandle.height = h
- rgbHandle.width = w
- hueHandle.width = hueW
-
-
- var rgb = hsbToRgb({h:hsb.h,s:100,b:100})
- rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
-
- widget.showValue(v)
-
-
-
- if (sync) widget.trigger('sync')
- if (send) widget.sendValue(v)
- }
- widget.sendValue = function(v) {
- sendOsc({
- target:split?false:widgetData.target,
- path:widgetData.path,
- args:v,
- precision:widgetData.precision,
- })
- if (split) {
- sendOsc({
- target:widgetData.target,
- path:split.r,
- args:v[0],
- precision:widgetData.precision,
- sync:false
- })
- sendOsc({
- target:widgetData.target,
- path:split.g,
- args:v[1],
- precision:widgetData.precision,
- sync:false
- })
- sendOsc({
- target:widgetData.target,
- path:split.b,
- args:v[2],
- precision:widgetData.precision,
- sync:false
- })
- }
- }
-
-
-
- widget.showValue = function(v) {
- value.r.val(v[0])
- value.g.val(v[1])
- value.b.val(v[2])
- }
- value.r.change(function(){
- var r = clip(value.r.val(),[0,255])
- var v = widget.getValue()
- widget.setValue([r,v[1],v[2]],true,true)
- })
- value.g.change(function(){
- var g = clip(value.g.val(),[0,255])
- var v = widget.getValue()
- widget.setValue([v[0],g,v[2]],true,true)
- })
- value.b.change(function(){
- var b = clip(value.b.val(),[0,255])
- var v = widget.getValue()
- widget.setValue([v[0],v[1],b],true,true)
- })
-
- widget.setValue(0)
-
- return widget
-}
-
-
-
-createWidget.fader = function(widgetData,container){
- var widget = $(`
-
- `),
- handle = widget.find('.handle'),
- knob = widget.find('span')[0],
- wrapper = widget.find('.fader-wrapper'),
- fader = widget.find('.fader'),
- pips = widget.find('.pips'),
- input = widget.find('.input').fakeInput(),
- unit = widgetData.unit?' '+widgetData.unit.trim(): '',
- dimension = widgetData.horizontal?'width':'height',
- axe = dimension=='height'?'X':'Y',
- absolute = widgetData.absolute
- if (widgetData.horizontal) container.addClass('horizontal')
-
- handle.size = 0
- fader.size = dimension=='height'?fader.outerHeight():fader.outerWidth()
- wrapper.size = dimension=='height'?wrapper.outerHeight():wrapper.outerWidth()
-
- fader.resize(function(){
- fader.size= dimension=='height'?fader.outerHeight():fader.outerWidth()
- wrapper.size = dimension=='height'?wrapper.outerHeight():wrapper.outerWidth()
- })
-
-
- var off = 0
-
- wrapper.on('draginit',function(e,data){
- if (absolute || data.ctrlKey || data.shiftKey) {
- var d = (dimension=='height')?
- ((fader.size-data.offsetY+(wrapper.size-fader.size)/2) * 100 / fader.size):
- (data.offsetX - (wrapper.size-fader.size)/2) * 100 / fader.size
- var r = sizeToAngle(d)
- handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
- knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
- handle.size = d
-
- var v = widget.getValue()
- widget.sendValue(v)
- widget.showValue(v)
-
- widget.trigger('sync')
-
- }
-
- off = handle.size
-
- })
-
-
- wrapper.on('drag',function(e,data){
- e.stopPropagation()
-
- if (data.shiftKey) return
-
- var d = (dimension=='height')?-data.deltaY:data.deltaX
- d = clip(d*100/fader.size+off,[0,100])
- var r = sizeToAngle(d)
-
- handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
- knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
- handle.size = d
-
- var v = widget.getValue()
- widget.sendValue(v)
- widget.showValue(v)
-
- widget.trigger('sync')
-
- })
-
- widgetData.range = widgetData.range || {'min':0,'max':1}
-
- var range = {}
- for (k in widgetData.range) {
- if (k=='min') {
- range[0]=widgetData.range[k]
- } else if (k=='max') {
- range[100]=widgetData.range[k]
- } else {
- range[parseInt(k)]=widgetData.range[k]
- }
- }
-
- var scale = []
- for (var i=0;i<=100;i++) {scale.push(i)}
- for (i in scale) {
- var pip = $('')
- if (range[i]!=undefined) {
- var piptext = Math.abs(range[i])>=1000?range[i]/1000+'k':range[i]
- pip.addClass('val').append(''+piptext+'')
- }
- pips.append(pip)
- }
- if (dimension=='height') {
- pips.append(pips.find('.pip').get().reverse())
- }
-
-
-
-
- var rangeKeys = Object.keys(range).map(function (key) {return parseInt(key)}),
- rangeVals = Object.keys(range).map(function (key) {return parseFloat(range[key])})
-
-
-
- widget.getValue = function(){
- var h = clip(handle.size,[0,100])
- for (var i=0;i= rangeKeys[i]) {
- return mapToScale(h,[rangeKeys[i],rangeKeys[i+1]],[rangeVals[i],rangeVals[i+1]],widgetData.precision)
- }
- }
-
- }
- widget.setValue = function(v,send,sync) {
- var h,
- v=clip(v,[rangeVals[0],rangeVals.slice(-1)[0]])
- for (var i=0;i= rangeVals[i]) {
- h = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i],rangeKeys[i+1]],widgetData.precision)
- break
- }
- }
-
- var r = sizeToAngle(h)
-
- handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
- knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
-
- handle.size = h
-
- widget.showValue(v)
-
-
- if (sync) widget.trigger('sync')
- if (send) widget.sendValue(v)
- }
-
- widget.sendValue = function(v) {
- sendOsc({
- target:widgetData.target,
- path:widgetData.path,
- precision:widgetData.precision,
- args:v
- })
- }
-
- widget.showValue = function(v) {
- input.val(v+unit)
- }
-
- input.change(function(){
- widget.setValue(input.val(),true,true)
- })
-
- widget.setValue(rangeVals[0])
-
- return widget
-}
-
-
-createWidget.knob = function(widgetData) {
- var widget = $(`
-
- `),
- wrapper = widget.find('.knob-wrapper'),
- mask = widget.find('.knob-mask'),
- knob = widget.find('.knob'),
- handle = widget.find('.handle'),
- input = widget.find('.input').fakeInput(),
- range = widgetData.range || {min:0,max:1},
- unit = widgetData.unit?' '+widgetData.unit.trim(): '',
- absolute = widgetData.absolute,
- pan = widgetData.pan
-
-
-
- var pipmin = Math.abs(range.min)>=1000?range.min/1000+'k':range.min,
- pipmax = Math.abs(range.max)>=1000?range.max/1000+'k':range.max
-
- widget.find('.pip.min').text(pipmin)
- widget.find('.pip.max').text(pipmax)
-
-
- knob.rotation = 0
-
- var offR = 0,
- offX = 0,
- offY = 0
- wrapper.on('draginit',function(e,data){
-
- if (absolute || data.ctrlKey || data.shiftKey) {
- var w = data.target.clientWidth,
- h = data.target.clientHeight,
- x = data.offsetX-w/2,
- y = data.offsetY-h/2,
- angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
- r = angle<-90?angle+360:angle
- r = (angle>=-90 && angle<-45)?270:r
- r = clip(r,[0,270])
-
- offX = x
- offY = y
-
- knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
- handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
- knob.rotation = r
-
-
- if (pan && r<135) {mask.removeClass('pan-right').addClass('pan-left')}
- else if (pan) {mask.removeClass('pan-left').addClass('pan-right')}
-
- if (r>180) {knob.addClass('d3')}
- else if (r>90) {knob.removeClass('d3').addClass('d2')}
- else {knob.removeClass('d3 d2')}
-
- var v = mapToScale(r,[0,270],[range.min,range.max],widgetData.precision)
-
- widget.sendValue(v)
- widget.trigger('sync')
- widget.showValue(v)
-
- }
-
- offR = knob.rotation
- })
-
- wrapper.on('drag',function(e,data){
- e.stopPropagation()
-
- if (data.shiftKey) return
-
- var r = clip(-data.deltaY*2+offR,[0,270])
-
- if (absolute || data.ctrlKey || data.shiftKey) {
- var w = data.target.clientWidth,
- h = data.target.clientHeight,
- x = data.deltaX + offX,
- y = data.deltaY + offY,
- angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
- r = angle<-90?angle+360:angle
- r = (angle>=-90 && angle<-45)?270:r
- r = clip(r,[0,270])
- }
-
- knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
- handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
- knob.rotation = r
-
- if (pan && r<135) {mask.removeClass('pan-right').addClass('pan-left')}
- else if (pan) {mask.removeClass('pan-left').addClass('pan-right')}
-
- if (r>180) {knob.addClass('d3')}
- else if (r>90) {knob.removeClass('d3').addClass('d2')}
- else {knob.removeClass('d3 d2')}
-
- var v = mapToScale(r,[0,270],[range.min,range.max],widgetData.precision)
-
- widget.sendValue(v)
- widget.trigger('sync')
- widget.showValue(v)
-
- })
-
-
- widget.getValue = function() {
- return mapToScale(knob.rotation,[0,270],[range.min,range.max],widgetData.precision)
- }
- widget.showValue = function(v) {
- input.val(v+unit)
- }
- widget.sendValue = function(v) {
- sendOsc({
- target:widgetData.target,
- path:widgetData.path,
- precision:widgetData.precision,
- args:v
- })
- }
- widget.setValue = function(v,send,sync) {
- var r = mapToScale(v,[range.min,range.max],[0,270],widgetData.precision)
- knob.rotation = r
-
-
-
- if (pan && r<135) {mask.removeClass('pan-right').addClass('pan-left')}
- else if (pan) {mask.removeClass('pan-left').addClass('pan-right')}
-
- if (r>180) {knob.addClass('d3')}
- else if (r>90) {knob.removeClass('d3').addClass('d2')}
- else {knob.removeClass('d3 d2')}
-
-
- knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
- handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
- var v = widget.getValue()
-
- widget.showValue(v)
-
- if (sync) widget.trigger('sync')
- if (send) widget.sendValue(v)
- }
- input.change(function(){
- widget.setValue(input.val(),true,true)
- })
-
- widget.setValue(range.min)
- return widget
+createWidget = {
+ strip: strip.create,
+ panel: panel.create,
+ led: led.create,
+ fader: fader.create,
+ knob: knob.create,
+ xy: xy.create,
+ rgb: rgb.create,
+ toggle: toggle.create,
+ switch: swiitch.create,
+ push: push.create
}
diff --git a/app/browser/js/app/widgets/fader.js b/app/browser/js/app/widgets/fader.js
new file mode 100644
index 00000000..1bdd0e2c
--- /dev/null
+++ b/app/browser/js/app/widgets/fader.js
@@ -0,0 +1,201 @@
+var utils = require('./utils'),
+ sizeToAngle = utils.sizeToAngle,
+ clip = utils.clip,
+ mapToScale = utils.mapToScale
+
+module.exports.options = {
+ type:'fader',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ unit:'',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ horizontal:false,
+ css:'',
+
+ separator2:'behaviour',
+
+ absolute:false,
+
+ separator3:'osc',
+
+ range:{min:0,max:1},
+ precision:2,
+ path:'auto',
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+ var widget = $(`
+
+ `),
+ handle = widget.find('.handle'),
+ knob = widget.find('span')[0],
+ wrapper = widget.find('.fader-wrapper'),
+ fader = widget.find('.fader'),
+ pips = widget.find('.pips'),
+ input = widget.find('.input').fakeInput(),
+ unit = widgetData.unit?' '+widgetData.unit.trim(): '',
+ dimension = widgetData.horizontal?'width':'height',
+ axe = dimension=='height'?'X':'Y',
+ absolute = widgetData.absolute
+ if (widgetData.horizontal) container.addClass('horizontal')
+
+ handle.size = 0
+ fader.size = dimension=='height'?fader.outerHeight():fader.outerWidth()
+ wrapper.size = dimension=='height'?wrapper.outerHeight():wrapper.outerWidth()
+
+ fader.resize(function(){
+ fader.size= dimension=='height'?fader.outerHeight():fader.outerWidth()
+ wrapper.size = dimension=='height'?wrapper.outerHeight():wrapper.outerWidth()
+ })
+
+
+ var off = 0
+
+ wrapper.on('draginit',function(e,data){
+ if (absolute || data.ctrlKey || data.shiftKey) {
+ var d = (dimension=='height')?
+ ((fader.size-data.offsetY+(wrapper.size-fader.size)/2) * 100 / fader.size):
+ (data.offsetX - (wrapper.size-fader.size)/2) * 100 / fader.size
+ var r = sizeToAngle(d)
+ handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
+ knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
+ handle.size = d
+
+ var v = widget.getValue()
+ widget.sendValue(v)
+ widget.showValue(v)
+
+ widget.trigger('sync')
+
+ }
+
+ off = handle.size
+
+ })
+
+
+ wrapper.on('drag',function(e,data){
+ e.stopPropagation()
+
+ if (data.shiftKey) return
+
+ var d = (dimension=='height')?-data.deltaY:data.deltaX
+ d = clip(d*100/fader.size+off,[0,100])
+ var r = sizeToAngle(d)
+
+ handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
+ knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
+ handle.size = d
+
+ var v = widget.getValue()
+ widget.sendValue(v)
+ widget.showValue(v)
+
+ widget.trigger('sync')
+
+ })
+
+ widgetData.range = widgetData.range || {'min':0,'max':1}
+
+ var range = {}
+ for (k in widgetData.range) {
+ if (k=='min') {
+ range[0]=widgetData.range[k]
+ } else if (k=='max') {
+ range[100]=widgetData.range[k]
+ } else {
+ range[parseInt(k)]=widgetData.range[k]
+ }
+ }
+
+ var scale = []
+ for (var i=0;i<=100;i++) {scale.push(i)}
+ for (i in scale) {
+ var pip = $('')
+ if (range[i]!=undefined) {
+ var piptext = Math.abs(range[i])>=1000?range[i]/1000+'k':range[i]
+ pip.addClass('val').append(''+piptext+'')
+ }
+ pips.append(pip)
+ }
+ if (dimension=='height') {
+ pips.append(pips.find('.pip').get().reverse())
+ }
+
+
+
+
+ var rangeKeys = Object.keys(range).map(function (key) {return parseInt(key)}),
+ rangeVals = Object.keys(range).map(function (key) {return parseFloat(range[key])})
+
+
+
+ widget.getValue = function(){
+ var h = clip(handle.size,[0,100])
+ for (var i=0;i= rangeKeys[i]) {
+ return mapToScale(h,[rangeKeys[i],rangeKeys[i+1]],[rangeVals[i],rangeVals[i+1]],widgetData.precision)
+ }
+ }
+
+ }
+ widget.setValue = function(v,send,sync) {
+ var h,
+ v=clip(v,[rangeVals[0],rangeVals.slice(-1)[0]])
+ for (var i=0;i= rangeVals[i]) {
+ h = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i],rangeKeys[i+1]],widgetData.precision)
+ break
+ }
+ }
+
+ var r = sizeToAngle(h)
+
+ handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
+ knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
+
+ handle.size = h
+
+ widget.showValue(v)
+
+
+ if (sync) widget.trigger('sync')
+ if (send) widget.sendValue(v)
+ }
+
+ widget.sendValue = function(v) {
+ sendOsc({
+ target:widgetData.target,
+ path:widgetData.path,
+ precision:widgetData.precision,
+ args:v
+ })
+ }
+
+ widget.showValue = function(v) {
+ input.val(v+unit)
+ }
+
+ input.change(function(){
+ widget.setValue(input.val(),true,true)
+ })
+
+ widget.setValue(rangeVals[0])
+
+ return widget
+}
diff --git a/app/browser/js/app/widgets/knob.js b/app/browser/js/app/widgets/knob.js
new file mode 100644
index 00000000..a2ac5337
--- /dev/null
+++ b/app/browser/js/app/widgets/knob.js
@@ -0,0 +1,191 @@
+var utils = require('./utils'),
+ clip = utils.clip,
+ mapToScale = utils.mapToScale
+
+module.exports.options = {
+ type:'knob',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ unit:'',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ css:'',
+
+ separator2:'behaviour',
+
+ absolute:false,
+ pan:false,
+
+
+ separator3:'osc',
+
+ range:{min:0,max:1},
+ precision:2,
+ path:'auto',
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+ var widget = $(`
+
+ `),
+ wrapper = widget.find('.knob-wrapper'),
+ mask = widget.find('.knob-mask'),
+ knob = widget.find('.knob'),
+ handle = widget.find('.handle'),
+ input = widget.find('.input').fakeInput(),
+ range = widgetData.range || {min:0,max:1},
+ unit = widgetData.unit?' '+widgetData.unit.trim(): '',
+ absolute = widgetData.absolute,
+ pan = widgetData.pan
+
+
+
+ var pipmin = Math.abs(range.min)>=1000?range.min/1000+'k':range.min,
+ pipmax = Math.abs(range.max)>=1000?range.max/1000+'k':range.max
+
+ widget.find('.pip.min').text(pipmin)
+ widget.find('.pip.max').text(pipmax)
+
+
+ knob.rotation = 0
+
+ var offR = 0,
+ offX = 0,
+ offY = 0
+ wrapper.on('draginit',function(e,data){
+
+ if (absolute || data.ctrlKey || data.shiftKey) {
+ var w = data.target.clientWidth,
+ h = data.target.clientHeight,
+ x = data.offsetX-w/2,
+ y = data.offsetY-h/2,
+ angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
+ r = angle<-90?angle+360:angle
+ r = (angle>=-90 && angle<-45)?270:r
+ r = clip(r,[0,270])
+
+ offX = x
+ offY = y
+
+ knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
+ handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
+ knob.rotation = r
+
+
+ if (pan && r<135) {mask.removeClass('pan-right').addClass('pan-left')}
+ else if (pan) {mask.removeClass('pan-left').addClass('pan-right')}
+
+ if (r>180) {knob.addClass('d3')}
+ else if (r>90) {knob.removeClass('d3').addClass('d2')}
+ else {knob.removeClass('d3 d2')}
+
+ var v = mapToScale(r,[0,270],[range.min,range.max],widgetData.precision)
+
+ widget.sendValue(v)
+ widget.trigger('sync')
+ widget.showValue(v)
+
+ }
+
+ offR = knob.rotation
+ })
+
+ wrapper.on('drag',function(e,data){
+ e.stopPropagation()
+
+ if (data.shiftKey) return
+
+ var r = clip(-data.deltaY*2+offR,[0,270])
+
+ if (absolute || data.ctrlKey || data.shiftKey) {
+ var w = data.target.clientWidth,
+ h = data.target.clientHeight,
+ x = data.deltaX + offX,
+ y = data.deltaY + offY,
+ angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
+ r = angle<-90?angle+360:angle
+ r = (angle>=-90 && angle<-45)?270:r
+ r = clip(r,[0,270])
+ }
+
+ knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
+ handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
+ knob.rotation = r
+
+ if (pan && r<135) {mask.removeClass('pan-right').addClass('pan-left')}
+ else if (pan) {mask.removeClass('pan-left').addClass('pan-right')}
+
+ if (r>180) {knob.addClass('d3')}
+ else if (r>90) {knob.removeClass('d3').addClass('d2')}
+ else {knob.removeClass('d3 d2')}
+
+ var v = mapToScale(r,[0,270],[range.min,range.max],widgetData.precision)
+
+ widget.sendValue(v)
+ widget.trigger('sync')
+ widget.showValue(v)
+
+ })
+
+
+ widget.getValue = function() {
+ return mapToScale(knob.rotation,[0,270],[range.min,range.max],widgetData.precision)
+ }
+ widget.showValue = function(v) {
+ input.val(v+unit)
+ }
+ widget.sendValue = function(v) {
+ sendOsc({
+ target:widgetData.target,
+ path:widgetData.path,
+ precision:widgetData.precision,
+ args:v
+ })
+ }
+ widget.setValue = function(v,send,sync) {
+ var r = mapToScale(v,[range.min,range.max],[0,270],widgetData.precision)
+ knob.rotation = r
+
+
+
+ if (pan && r<135) {mask.removeClass('pan-right').addClass('pan-left')}
+ else if (pan) {mask.removeClass('pan-left').addClass('pan-right')}
+
+ if (r>180) {knob.addClass('d3')}
+ else if (r>90) {knob.removeClass('d3').addClass('d2')}
+ else {knob.removeClass('d3 d2')}
+
+
+ knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
+ handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
+ var v = widget.getValue()
+
+ widget.showValue(v)
+
+ if (sync) widget.trigger('sync')
+ if (send) widget.sendValue(v)
+ }
+ input.change(function(){
+ widget.setValue(input.val(),true,true)
+ })
+
+ widget.setValue(range.min)
+ return widget
+}
diff --git a/app/browser/js/app/widgets/led.js b/app/browser/js/app/widgets/led.js
new file mode 100644
index 00000000..58c024ee
--- /dev/null
+++ b/app/browser/js/app/widgets/led.js
@@ -0,0 +1,36 @@
+module.exports.options = {
+ type:'led',
+ id:'auto',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ color:'green',
+ css:'',
+
+ separator2:'osc',
+
+ range:{min:0,max:1},
+ path:'auto'
+}
+module.exports.create = function(widgetData,container) {
+ var widget = $(`
+
+ `),
+ led = widget.find('span'),
+ range = widgetData.range || {min:0,max:1}
+
+ if (widgetData.color) led.css('background-color',widgetData.color)
+
+ widget.setValue = function(v){
+ led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],widgetData.precision))
+ }
+ widget.getValue = function(){return}
+ return widget
+}
diff --git a/app/browser/js/app/widgets/panel.js b/app/browser/js/app/widgets/panel.js
new file mode 100644
index 00000000..2592e22f
--- /dev/null
+++ b/app/browser/js/app/widgets/panel.js
@@ -0,0 +1,36 @@
+module.exports.options = {
+ type:'panel',
+ id:'auto',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'0',
+ top:'0',
+ width:'auto',
+ height:'auto',
+ stretch:false,
+ css:'',
+
+ separator2:'chilren',
+
+ widgets:[],
+ tabs:[]
+}
+module.exports.create = function(widgetData,container) {
+ var widget = $(`
+
+
+ `)
+
+ if (widgetData.stretch) widget.addClass('stretch')
+
+ if (widgetData.tabs.length) {
+ parsetabs(widgetData.tabs,widget)
+ } else {
+ parsewidgets(widgetData.widgets,widget)
+ }
+ widget.getValue = function(){return}
+ widget.setValue = function(){return}
+ return widget
+}
diff --git a/app/browser/js/app/widgets/push.js b/app/browser/js/app/widgets/push.js
new file mode 100644
index 00000000..16d91c0c
--- /dev/null
+++ b/app/browser/js/app/widgets/push.js
@@ -0,0 +1,84 @@
+module.exports.options = {
+ type:'push',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ css:'',
+
+ separator2:'osc',
+
+ on:1,
+ off:0,
+ precision:2,
+ path:'auto',
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+
+
+ var widget = $(`
+ \
+ `),
+ $document = $(document)
+
+ widget.value = widget.find('span')
+
+ widget.on('drag',function(e){e.stopPropagation()})
+ widget.on('draginit.push',function(){
+ widget.off('draginit.push')
+ widget.fakeclick()
+ })
+
+ widget.fakeclick = function(){
+ widget.setValue(widgetData.on,true,true)
+ $document.on('dragend.push',function(){
+ widget.setValue(widgetData.off,true,true)
+ $document.off('dragend.push')
+ widget.on('draginit.push',function(){
+ widget.off('draginit.push')
+ widget.fakeclick()
+ })
+ })
+ }
+
+ widget.getValue = function() {
+ return widget.hasClass('on')?widgetData.on:widgetData.off
+ }
+ widget.setValue = function(v,send,sync) {
+ var on = widgetData.on,
+ off= widgetData.off
+ if (v==on) {
+ widget.addClass('on').removeClass('ripple').addClass('ripple').delay(250).queue(function(next){
+ widget.removeClass('ripple')
+ next()
+ })
+ if (send) widget.sendValue(v)
+ } else if (v==off) {
+ widget.removeClass('on')
+ if (send) widget.sendValue(v)
+ }
+
+ if (sync) widget.trigger('sync')
+
+ }
+ widget.sendValue = function(v) {
+ if (v===false) return
+ sendOsc({
+ target:widgetData.target,
+ path:widgetData.path,
+ precision:widgetData.precision,
+ args:v
+ })
+ }
+ widget.setValue()
+ return widget
+}
diff --git a/app/browser/js/app/widgets/rgb.js b/app/browser/js/app/widgets/rgb.js
new file mode 100644
index 00000000..d29e51b2
--- /dev/null
+++ b/app/browser/js/app/widgets/rgb.js
@@ -0,0 +1,272 @@
+var utils = require('./utils'),
+ clip = utils.clip,
+ mapToScale = utils.mapToScale,
+ hsbToRgb = utils.hsbToRgb,
+ rgbToHsb = utils.rgbToHsb
+
+module.exports.options = {
+ type:'rgb',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ css:'',
+
+ separator2:'behaviour',
+
+ absolute:false,
+
+ separator3:'osc',
+
+ precision:0,
+ path:'auto',
+ split:false,
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+
+ var widget = $(`
+ `),
+ rgbHandle = widget.find('.rgb .handle'),
+ hueHandle = widget.find('.hue .handle'),
+ pad = widget.find('.xy'),
+ huePad = widget.find('.hue'),
+ rgbBg = pad.find('.bg')[0],
+ value = {r:widget.find('.r').fakeInput({align:'center'}),g:widget.find('.g').fakeInput({align:'center'}),b:widget.find('.b').fakeInput({align:'center'})},
+ absolute = widgetData.absolute,
+ split = widgetData.split?
+ typeof widgetData.split == 'object'?
+ widgetData.split:{r:widgetData.path+'/r',g:widgetData.path+'/g',b:widgetData.path+'/b'}
+ :false
+
+ if (widgetData.height!='auto') widget.addClass('manual-height')
+
+
+ pad.width = pad.innerWidth()
+ pad.height = pad.innerHeight()
+ rgbHandle.height = 0
+ rgbHandle.width = 0
+ hueHandle.width = 0
+
+ pad.resize(function(){
+ var width = pad.innerWidth(),
+ height = pad.innerHeight()
+ if (!width || (pad.height==height && pad.width==width)) return
+ pad.width = width
+ pad.height = height
+ rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*rgbHandle.width/100}px, -${pad.height*rgbHandle.height/100}px,0)`)
+
+ })
+
+
+ var rgbOff = {x:0,y:0}
+ pad.on('draginit',function(e,data){
+ if (absolute || data.ctrlKey || data.shiftKey) {
+ var h = ((pad.height-data.offsetY) * 100 / pad.height),
+ w = (data.offsetX * 100 / pad.width)
+
+ rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
+ rgbHandle.height = h
+ rgbHandle.width = w
+
+ var v = widget.getValue()
+ widget.sendValue(v)
+ widget.showValue(v)
+ widget.trigger('sync')
+
+ }
+
+ rgbOff = {x:rgbHandle.width,y:rgbHandle.height}
+
+ })
+ pad.on('drag',function(e,data){
+ e.stopPropagation()
+
+ if (data.shiftKey) return
+
+ var h = clip((-data.deltaY)*100/pad.height+rgbOff.y,[0,100]),
+ w = clip(data.deltaX*100/pad.width+rgbOff.x,[0,100])
+
+ rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
+ rgbHandle.height = h
+ rgbHandle.width = w
+
+ var v = widget.getValue()
+ widget.sendValue(v)
+ widget.showValue(v)
+
+ widget.trigger('sync')
+
+ })
+
+
+ var hueOff = 0
+ huePad.on('draginit',function(e,data){
+ if (absolute || data.ctrlKey || data.shiftKey) {
+ var d = (data.offsetX * 100 / pad.width)
+ hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*d/100}px,0,0)`)
+ hueHandle.width = d
+
+
+ var h = clip(hueHandle.width*3.6,[0,360]),
+ rgb = hsbToRgb({h:h,s:100,b:100}),
+ v = widget.getValue()
+
+ rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
+
+
+
+ widget.sendValue(v)
+ widget.showValue(v)
+ widget.trigger('sync')
+
+ }
+
+ hueOff = hueHandle.width
+
+ })
+
+
+ huePad.on('drag',function(e,data){
+ e.stopPropagation()
+
+ if (data.shiftKey) return
+
+ var w = clip(data.deltaX*100/pad.width+hueOff,[0,100])
+ hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px,0,0)`)
+ hueHandle.width = w
+
+ var h = clip(hueHandle.width*3.6,[0,360]),
+ rgb = hsbToRgb({h:h,s:100,b:100}),
+ v = widget.getValue()
+
+ rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
+ widget.sendValue(v)
+ widget.showValue(v)
+
+ widget.trigger('sync')
+
+ })
+
+
+
+
+
+ widget.getValue = function() {
+ var s = clip(rgbHandle.width,[0,100]),
+ l = clip(rgbHandle.height,[0,100]),
+ h = mapToScale(hueHandle.width,[0,100],[0,360],widgetData.precision),
+ rgb = hsbToRgb({h:h,s:s,b:l})
+ return [rgb.r,rgb.g,rgb.b]
+ }
+ widget.setValue = function(v,send,sync) {
+ if (v[1]==undefined && v[2]==undefined) var v = [v,v,v]
+ if (v[2]==undefined) var v = [v[0],v[1],v[1]]
+
+ for (i in [0,1,2]) {
+ v[i] = clip(v[i],[0,255])
+ }
+
+
+ var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
+
+ var w = mapToScale(hsb.s,[0,100],[0,100],widgetData.precision),
+ h = mapToScale(hsb.b,[0,100],[0,100],widgetData.precision),
+ hueW = mapToScale(hsb.h,[0,360],[0,100],widgetData.precision)
+
+ rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
+ hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*hueW/100}px,0,0)`)
+
+ rgbHandle.height = h
+ rgbHandle.width = w
+ hueHandle.width = hueW
+
+
+ var rgb = hsbToRgb({h:hsb.h,s:100,b:100})
+ rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
+
+ widget.showValue(v)
+
+
+
+ if (sync) widget.trigger('sync')
+ if (send) widget.sendValue(v)
+ }
+ widget.sendValue = function(v) {
+ sendOsc({
+ target:split?false:widgetData.target,
+ path:widgetData.path,
+ args:v,
+ precision:widgetData.precision,
+ })
+ if (split) {
+ sendOsc({
+ target:widgetData.target,
+ path:split.r,
+ args:v[0],
+ precision:widgetData.precision,
+ sync:false
+ })
+ sendOsc({
+ target:widgetData.target,
+ path:split.g,
+ args:v[1],
+ precision:widgetData.precision,
+ sync:false
+ })
+ sendOsc({
+ target:widgetData.target,
+ path:split.b,
+ args:v[2],
+ precision:widgetData.precision,
+ sync:false
+ })
+ }
+ }
+
+
+
+ widget.showValue = function(v) {
+ value.r.val(v[0])
+ value.g.val(v[1])
+ value.b.val(v[2])
+ }
+ value.r.change(function(){
+ var r = clip(value.r.val(),[0,255])
+ var v = widget.getValue()
+ widget.setValue([r,v[1],v[2]],true,true)
+ })
+ value.g.change(function(){
+ var g = clip(value.g.val(),[0,255])
+ var v = widget.getValue()
+ widget.setValue([v[0],g,v[2]],true,true)
+ })
+ value.b.change(function(){
+ var b = clip(value.b.val(),[0,255])
+ var v = widget.getValue()
+ widget.setValue([v[0],v[1],b],true,true)
+ })
+
+ widget.setValue(0)
+
+ return widget
+}
diff --git a/app/browser/js/app/widgets/strip.js b/app/browser/js/app/widgets/strip.js
new file mode 100644
index 00000000..b3a7c060
--- /dev/null
+++ b/app/browser/js/app/widgets/strip.js
@@ -0,0 +1,33 @@
+module.exports.options = {
+ type:'strip',
+ id:'auto',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ horizontal:false,
+ css:'',
+
+ separator2:'children',
+
+ widgets:[]
+}
+module.exports.create = function(widgetData,container) {
+ var widget = $(`
+
+
+ `)
+ if (widgetData.horizontal) {
+ container.addClass('horizontal')
+ } else {
+ container.addClass('vertical')
+ }
+ parsewidgets(widgetData.widgets,widget)
+ widget.getValue = function(){return}
+ widget.setValue = function(){return}
+ return widget
+}
diff --git a/app/browser/js/app/widgets/switch.js b/app/browser/js/app/widgets/switch.js
new file mode 100644
index 00000000..66c534c2
--- /dev/null
+++ b/app/browser/js/app/widgets/switch.js
@@ -0,0 +1,79 @@
+module.exports.options = {
+ type:'switch',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ horizontal:false,
+ css:'',
+
+ separator2:'osc',
+
+ values:{"Value 1":1,"Value 2":2},
+ precision:2,
+ path:'auto',
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+
+ var widget = $(`
+
+
+ `),
+ $document = $(document)
+
+ if (widgetData.horizontal) {
+ widget.addClass('horizontal')
+ }
+
+ widget.values = []
+
+ for (k in widgetData.values) {
+ widget.values.push(widgetData.values[k])
+ $(''+k+'
').data({value:widgetData.values[k]}).appendTo(widget)
+ }
+
+ widget.value = undefined
+
+ widget.on('drag',function(e){e.stopPropagation()})
+
+ widget.on('draginit',function(e,dd){
+ var data = $(dd.target).data()
+ if (data.value!=widget.value || widget.value===undefined) widget.setValue(data.value,true,true)
+ })
+
+
+
+ widget.getValue = function() {
+ return widget.value
+ }
+ widget.setValue = function(v,send,sync) {
+ var i = widget.values.indexOf(v)
+ if (i!=-1) {
+ widget.value = widget.values[i]
+ widget.find('.on').removeClass('on')
+ widget.find('.value').eq(i).addClass('on').removeClass('ripple').addClass('ripple').delay(250).queue(function(next){
+ widget.removeClass('ripple')
+ next()
+ })
+ if (send) widget.sendValue(widget.value)
+ if (sync) widget.trigger('sync')
+ }
+
+ }
+ widget.sendValue = function(v) {
+ sendOsc({
+ target:widgetData.target,
+ path:widgetData.path,
+ precision:widgetData.precision,
+ args:v
+ })
+ }
+ return widget
+}
diff --git a/app/browser/js/app/widgets/toggle.js b/app/browser/js/app/widgets/toggle.js
new file mode 100644
index 00000000..c25a8232
--- /dev/null
+++ b/app/browser/js/app/widgets/toggle.js
@@ -0,0 +1,82 @@
+module.exports.options = {
+ type:'toggle',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ css:'',
+
+ separator2:'osc',
+
+ on:1,
+ off:0,
+ precision:2,
+ path:'auto',
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+
+ var widget = $(`
+ \
+ `),
+ $document = $(document)
+
+ widget.value = widget.find('span')
+
+ widget.on('drag',function(e){e.stopPropagation()})
+ widget.on('draginit.toggle',function(){
+ widget.off('draginit.toggle')
+ widget.fakeclick()
+ })
+
+ widget.fakeclick = function(){
+ var newVal = widget.hasClass('on')?widgetData.off:widgetData.on
+ widget.setValue(newVal,true,true)
+ $document.on('dragend.toggle',function(){
+ $document.off('dragend.toggle')
+ widget.on('draginit.toggle',function(){
+ widget.off('draginit.toggle')
+ widget.fakeclick()
+ })
+ })
+ }
+
+
+ widget.getValue = function() {
+ return widget.hasClass('on')?widgetData.on:widgetData.off
+ }
+ widget.setValue = function(v,send,sync) {
+ if (v==widgetData.on) {
+ widget.addClass('on').removeClass('ripple').addClass('ripple').delay(250).queue(function(next){
+ widget.removeClass('ripple')
+ next()
+ })
+ if (send) widget.sendValue(widgetData.on)
+ } else if (v==widgetData.off) {
+ widget.removeClass('on')
+ if (send) widget.sendValue(widgetData.off)
+ }
+
+ if (sync) widget.trigger('sync')
+
+ }
+ widget.sendValue = function(v) {
+ if (v===false) return
+ sendOsc({
+ target:widgetData.target,
+ path:widgetData.path,
+ precision:widgetData.precision,
+ args:v
+ })
+ }
+ widget.setValue()
+ return widget
+}
diff --git a/app/browser/js/app/widgets/utils.js b/app/browser/js/app/widgets/utils.js
new file mode 100644
index 00000000..1efa6149
--- /dev/null
+++ b/app/browser/js/app/widgets/utils.js
@@ -0,0 +1,71 @@
+module.exports = {
+ clip: function(value,range) {
+ var value = parseFloat(value)
+
+ if (isNaN(value)) value = range[0]
+ return Math.max(Math.min(range[0],range[1]),Math.min(value,Math.max(range[0],range[1])))
+
+ },
+
+ // map a value from a scale to another input and output must be range arrays
+ mapToScale: function(value,rangeIn,rangeOut,precision) {
+
+ var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]]),
+ roundFactor = precision!=undefined?Math.pow(10,precision):100
+
+ value = ((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
+
+ value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
+
+ value = Math.round(value*roundFactor)/roundFactor
+
+ return value
+
+ },
+
+ sizeToAngle: function(size) {
+ return module.exports.clip(Math.acos((size/100))*180/Math.PI,[0,90])
+ },
+
+ hsbToRgb: function (hsb) {
+ var rgb = {}
+ var h = hsb.h
+ var s = hsb.s*255/100
+ var v = hsb.b*255/100
+ if(s == 0) {
+ rgb.r = rgb.g = rgb.b = v
+ } else {
+ var t1 = v
+ var t2 = (255-s)*v/255
+ var t3 = (t1-t2)*(h%60)/60
+ if(h==360) h = 0
+ if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
+ else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
+ else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
+ else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
+ else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
+ else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
+ else {rgb.r=0; rgb.g=0; rgb.b=0}
+ }
+ return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}
+ },
+
+ rgbToHsb: function (rgb) {
+ var hsb = {h: 0, s: 0, b: 0}
+ var min = Math.min(rgb.r, rgb.g, rgb.b)
+ var max = Math.max(rgb.r, rgb.g, rgb.b)
+ var delta = max - min
+ hsb.b = max
+ hsb.s = max != 0 ? 255 * delta / max : 0
+ if (hsb.s != 0) {
+ if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta
+ else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta
+ else hsb.h = 4 + (rgb.r - rgb.g) / delta
+ } else hsb.h = 0
+ hsb.h *= 60
+ if (hsb.h < 0) hsb.h += 360
+ hsb.s *= 100/255
+ hsb.b *= 100/255
+ return hsb
+ }
+}
diff --git a/app/browser/js/app/widgets/xy.js b/app/browser/js/app/widgets/xy.js
new file mode 100644
index 00000000..e7509262
--- /dev/null
+++ b/app/browser/js/app/widgets/xy.js
@@ -0,0 +1,181 @@
+var utils = require('./utils'),
+ clip = utils.clip,
+ mapToScale = utils.mapToScale
+
+module.exports.options = {
+ type:'xy',
+ id:'auto',
+ linkId:'',
+
+ separator1:'style',
+
+ label:'auto',
+ left:'auto',
+ top:'auto',
+ width:'auto',
+ height:'auto',
+ css:'',
+
+ separator2:'behaviour',
+
+ absolute:false,
+
+ separator3:'osc',
+
+ rangeX:{min:0,max:1},
+ rangeY:{min:0,max:1},
+ precision:2,
+ path:'auto',
+ split:false,
+ target:[]
+}
+module.exports.create = function(widgetData,container) {
+ var widget = $(`
+
+ `),
+ handle = widget.find('.handle'),
+ pad = widget.find('.xy'),
+ value = {x:widget.find('.x').fakeInput({align:'center'}),y:widget.find('.y').fakeInput({align:'center'})},
+ range = {x:widgetData.rangeX,y:widgetData.rangeY},
+ absolute = widgetData.absolute,
+ split = widgetData.split?
+ typeof widgetData.split == 'object'?
+ widgetData.split:{x:widgetData.path+'/x',y:widgetData.path+'/y'}
+ :false
+
+
+ if (widgetData.height!='auto') widget.addClass('manual-height')
+
+ pad.width = pad.innerWidth()
+ pad.height = pad.innerHeight()
+ handle.height = 0
+ handle.width = 0
+
+ pad.resize(function(){
+ var width = pad.innerWidth(),
+ height = pad.innerHeight()
+ if (!width || (pad.height==height && pad.width==width)) return
+ pad.width = width
+ pad.height = height
+ handle[0].setAttribute('style',`transform:translate3d(${pad.width*handle.width/100}px, -${pad.height*handle.height/100}px,0)`)
+ })
+
+ var off = {x:0,y:0}
+ pad.on('draginit',function(e,data){
+ if (absolute || data.ctrlKey || data.shiftKey) {
+ var h = ((pad.height-data.offsetY) * 100 / pad.height),
+ w = (data.offsetX * 100 / pad.width)
+
+ handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
+
+ handle.height = h
+ handle.width = w
+
+ var v = widget.getValue()
+ widget.sendValue(v)
+ widget.showValue(v)
+ widget.trigger('sync')
+
+ }
+
+ off = {x:handle.width,y:handle.height}
+
+ })
+ pad.on('drag',function(e,data){
+ e.stopPropagation()
+
+ if (data.shiftKey) return
+
+ var h = clip((-data.deltaY)*100/pad.height+off.y,[0,100]),
+ w = clip((data.deltaX)*100/pad.width+off.x,[0,100])
+
+ handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
+
+ handle.height = h
+ handle.width = w
+
+ var v = widget.getValue()
+ widget.sendValue(v)
+ widget.showValue(v)
+ widget.trigger('sync')
+
+ })
+
+
+
+ widget.getValue = function() {
+ var x = mapToScale(handle.width,[0,100],[range.x.min,range.x.max],widgetData.precision),
+ y = mapToScale(handle.height,[0,100],[range.y.min,range.y.max],widgetData.precision)
+
+ return [x,y]
+ }
+ widget.setValue = function(v,send,sync) {
+ if (v[1]==undefined) var v = [v,v]
+
+ for (i in [0,1]) {
+ v[i] = clip(v[i],[range[['x','y'][i]].min,range[['x','y'][i]].max])
+ }
+
+ var w = mapToScale(v[0],[range.x.min,range.x.max],[0,100],widgetData.precision)
+ h = mapToScale(v[1],[range.y.min,range.y.max],[0,100],widgetData.precision),
+
+ handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
+ handle.height = h
+ handle.width = w
+
+ widget.showValue(v)
+ if (sync) widget.trigger('sync')
+ if (send) widget.sendValue(v)
+ }
+ widget.sendValue = function(v) {
+ sendOsc({
+ target:split?false:widgetData.target,
+ path:widgetData.path,
+ args:v,
+ precision:widgetData.precision,
+ })
+ if (split) {
+ sendOsc({
+ target:widgetData.target,
+ path:split.x,
+ args:v[0],
+ precision:widgetData.precision,
+ sync:false
+ })
+ sendOsc({
+ target:widgetData.target,
+ path:split.y,
+ args:v[1],
+ precision:widgetData.precision,
+ sync:false
+ })
+ }
+ }
+
+ widget.showValue = function(v) {
+ value.x.val(v[0])
+ value.y.val(v[1])
+ }
+
+ value.x.change(function(){
+ var v = widget.getValue()
+ v[0] = clip(value.x.val(),[range.x.min,range.x.max])
+ widget.setValue(v,true,true)
+ })
+ value.y.change(function(){
+ var v = widget.getValue()
+ v[1] = clip(value.y.val(),[range.y.min,range.y.max])
+ widget.setValue(v,true,true)
+ })
+
+ widget.setValue(range.x.min,range.y.min)
+ return widget
+}
diff --git a/app/main/callbacks.js b/app/main/callbacks.js
new file mode 100644
index 00000000..31ead8fb
--- /dev/null
+++ b/app/main/callbacks.js
@@ -0,0 +1,125 @@
+var vm = require('vm')
+
+module.exports = function(settings,fs,ipc,osc,dialog) {
+
+ return {
+
+ ready: function(data,clientId) {
+ if (settings.read('sessionFile')) this.sessionOpen({path:settings.read('sessionFile')},clientId)
+ var recentSessions = settings.read('recentSessions')
+ ipc.send('sessionList',recentSessions,clientId)
+ },
+
+ sessionBrowse: function(data) {
+ var sessionlist = settings.read('recentSessions'),
+ self = this
+ dialog.showOpenDialog(window,{title:'Load session file',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
+ if (file==undefined) {return}
+ settings.write('sessionPath',file[0].replace(file[0].split('/').pop(),''))
+ self.sessionOpen({path:file[0]})
+ })
+ },
+
+ sessionSave: function(data) {
+ dialog.showSaveDialog(window,{title:'Save current session',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
+
+ if (file==undefined) {return}
+ settings.write('sessionPath',file.replace(file.split('/').pop(),''))
+
+ if (file.indexOf('.js')==-1){file+='.js'}
+ fs.writeFile(file,data, function (err, data) {
+ if (err) throw err
+ console.log('The session was saved in '+file)
+ })
+ })
+ },
+
+
+ sessionAddToHistory: function(data) {
+ var sessionlist = settings.read('recentSessions')
+ // add session to history
+ sessionlist.unshift(data)
+ // remove doubles from history
+ sessionlist = sessionlist.filter(function(elem, index, self) {
+ return index == self.indexOf(elem)
+ })
+ // save history
+ settings.write('recentSessions',sessionlist)
+ },
+
+ sessionRemoveFromHistory: function(data) {
+ var sessionlist = settings.read('recentSessions')
+ sessionlist.splice(data,1)
+ settings.write('recentSessions',sessionlist)
+ },
+
+ sessionOpen: function(data,clientId) {
+ var file = data.file || (function(){try {return fs.readFileSync(data.path,'utf8')} catch(err) {return false}})(),
+ error = file===false&&data.path?'Session file "' + data.path + '" not found.':false,
+ session
+
+ try {
+ session = vm.runInNewContext(file)
+ } catch(err) {
+ error = err
+ }
+
+ if (!error) {
+ if (data.path) this.sessionAddToHistory(data.path)
+ ipc.send('sessionOpen',JSON.stringify(session),clientId)
+ } else {
+ ipc.send('error',{title:'Error: invalid session file',text:error})
+ }
+ },
+
+ sendOsc: function(data) {
+
+ var targets = []
+
+ if (settings.read('syncTargets') && data.sync!==false) Array.prototype.push.apply(targets, settings.read('syncTargets'))
+ if (data.target) Array.prototype.push.apply(targets, data.target)
+
+
+ for (i in targets) {
+
+ var host = targets[i].split(':')[0],
+ port = targets[i].split(':')[1]
+
+ if (port) osc.send(host,port,data.path,data.args,data.precision)
+
+ }
+ },
+
+ stateSave: function(data) {
+ dialog.showSaveDialog(window,{title:'Save current state to preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
+
+ if (file==undefined) {return}
+ settings.write('presetPath',file)
+
+ if (file.indexOf('.preset')==-1){file+='.preset'}
+ fs.writeFile(file,data, function (err, data) {
+ if (err) throw err
+ console.log('The current state was saved in '+file)
+ })
+ })
+ },
+
+ stateLoad: function(data,clientId) {
+ dialog.showOpenDialog(window,{title:'Load preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
+
+ if (file==undefined) {return}
+ settings.write('presetPath',file[0])
+
+ fs.readFile(file[0],'utf-8', function read(err, data) {
+ if (err) throw err
+ ipc.send('stateLoad',data,clientId)
+ })
+ })
+ },
+
+ fullscreen: function(data) {
+ window.setFullScreen(!window.isFullScreen())
+ }
+ }
+
+}
diff --git a/app/main/main.js b/app/main/main.js
index 6f0e880a..6058677c 100644
--- a/app/main/main.js
+++ b/app/main/main.js
@@ -1,61 +1,8 @@
-// This prevents argv parsing to be breaked when the app is packaged (executed without 'electron' prefix)
-if (process.argv[1]&&process.argv[1].indexOf('-')==0) process.argv.unshift('')
-
-var argv = require('yargs')
- .help('help').usage(`\nUsage:\n $0 [options]`).alias('h', 'help')
- .options({
- 's':{alias:'sync',type:'array',describe:'synchronized hosts (ip:port pairs)'},
- 'c':{alias:'compile',type:'string',describe:'recompile stylesheets (increases startup time)'},
- 'l':{alias:'load',type:'string',describe:'session file to load'},
- 'p':{alias:'port',describe:'osc input port (for synchronization)'},
- 'n':{alias:'nogui',describe:'disable default gui and makes the app availabe through http on specified port'},
- })
- .check(function(a,x){if(a.port==undefined || !isNaN(a.p)&&a.p>1023&&parseInt(a.p)===a.p){return true}else{throw 'Error: Port must be an integer >= 1024'}})
- .check(function(a,x){if(a.n==undefined || !isNaN(a.n)&&a.n>1023&&parseInt(a.n)===a.n){return true}else{throw 'Error: Port must be an integer >= 1024'}})
- .check(function(a,x){if(a.sync==undefined || a.s.join(' ').match('^([^:\s]*:[0-9]{4,5}[\s]*)*$')!=null){return true}else{throw 'Error: Sync hosts must be ip:port pairs & port must be >= 1024'}})
- .strict()
- .argv
-
- , osc = require('node-osc')
- , fs = require('fs')
- , vm = require('vm')
- , ipc = {}
-
- , window = null
-
- , settings = {
- presetPath : process.cwd(),
- sessionPath: process.cwd(),
- recentSessions: [],
-
- appName: 'OSC Controller',
- syncTargets: argv.s || false,
- oscInPort: argv.p || false,
- compileScss: argv.c!==undefined || false,
- lightTheme: argv.c && argv.c.match(/light/),
- sessionFile: argv.l || false,
- noGui: argv.n || false,
+var fs = require('fs'),
+ settings = require('./settings')(fs)
- persistent: function(){var c = {};try {c=require( __dirname + '/config.json')} finally {return c}}(),
-
- read:function(key){
- var x = this.persistent[key] || this[key]
- return x
- },
- write:function(key,value) {
- this.persistent[key] = value
- fs.writeFile(__dirname + '/config.json',JSON.stringify(this.persistent,null,4), function (err, data) {
- if (err) throw err
- })
- }
-}
-
-
-
-// Sass
-
-compileScss = function(){
+if (settings.compileScss) {
var sass = require(__dirname + '/../browser/js/sass/sass.sync.js')
var filenames = fs.readdirSync(__dirname + '/../browser/scss/')
for (i in filenames) {
@@ -68,323 +15,44 @@ compileScss = function(){
})
}
}
-if (settings.compileScss) compileScss()
-
-// OSC
-
-if (settings.read('oscInPort')) {
- var oscServer = new osc.Server(settings.read('oscInPort'), '127.0.0.1')
-
- oscServer.on('message', function (msg, rinfo) {
- var data = {path:msg.shift(),args:msg}
- if (data.args.length==1) data.args = data.args[0]
- ipc.send('receiveOsc',data)
- })
-}
-
-sendOsc = function(host,port,path,args,precision) {
- var client = new osc.Client(host, port)
-
- var message = new osc.Message(path)
-
- var numberType = precision==0?'integer':'float'
-
- if (typeof args=='object') {
- for (i in args) {
- var arg = args[i]
- if (typeof arg == 'number') {
- message.append({type:numberType,value:arg})
- } else {
- message.append({type:'string',value:arg})
- }
- }
- } else {
- if (typeof args == 'number') {
- message.append({type:numberType,value:args})
- } else {
- message.append({type:'string',value:args})
- }
- }
-
- client.send(message, function () {
- client.kill()
- })
-}
-
-
-
-// callbacks !
-
-var callbacks = {}
-callbacks.ready = function(data,clientId) {
- if (settings.read('sessionFile')) callbacks.sessionOpen({path:settings.read('sessionFile')},clientId)
- var recentSessions = settings.read('recentSessions')
- ipc.send('sessionList',recentSessions,clientId)
-}
-
-callbacks.sessionBrowse = function(data) {
- var sessionlist = settings.read('recentSessions')
- dialog.showOpenDialog(window,{title:'Load session file',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
- if (file==undefined) {return}
- settings.write('sessionPath',file[0].replace(file[0].split('/').pop(),''))
- callbacks.sessionOpen({path:file[0]})
- })
-}
-callbacks.sessionSave = function(data) {
- dialog.showSaveDialog(window,{title:'Save current session',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
-
- if (file==undefined) {return}
- settings.write('sessionPath',file.replace(file.split('/').pop(),''))
-
- if (file.indexOf('.js')==-1){file+='.js'}
- fs.writeFile(file,data, function (err, data) {
- if (err) throw err
- console.log('The session was saved in '+file)
- })
- })
-}
-
-
-callbacks.sessionAddToHistory = function(data) {
- var sessionlist = settings.read('recentSessions')
- // add session to history
- sessionlist.unshift(data)
- // remove doubles from history
- sessionlist = sessionlist.filter(function(elem, index, self) {
- return index == self.indexOf(elem)
- })
- // save history
- settings.write('recentSessions',sessionlist)
-}
-
-callbacks.sessionRemoveFromHistory = function(data) {
- var sessionlist = settings.read('recentSessions')
- sessionlist.splice(data,1)
- settings.write('recentSessions',sessionlist)
-}
-
-callbacks.sessionOpen = function(data,clientId) {
- var file = data.file || (function(){try {return fs.readFileSync(data.path,'utf8')} catch(err) {return false}})(),
- error = file===false&&data.path?'Session file "' + data.path + '" not found.':false,
- session
-
- try {
- session = vm.runInNewContext(file)
- } catch(err) {
- error = err
- }
-
- if (!error) {
- if (data.path) callbacks.sessionAddToHistory(data.path)
- ipc.send('sessionOpen',JSON.stringify(session),clientId)
- } else {
- ipc.send('error',{title:'Error: invalid session file',text:error})
- }
-}
-
-callbacks.sendOsc = function(data) {
-
- var targets = []
-
- if (settings.read('syncTargets') && data.sync!==false) Array.prototype.push.apply(targets, settings.read('syncTargets'))
- if (data.target) Array.prototype.push.apply(targets, data.target)
-
-
- for (i in targets) {
-
- var host = targets[i].split(':')[0],
- port = targets[i].split(':')[1]
-
- if (port) sendOsc(host,port,data.path,data.args,data.precision)
-
- }
-}
-
-callbacks.stateSave = function(data) {
- dialog.showSaveDialog(window,{title:'Save current state to preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
-
- if (file==undefined) {return}
- settings.write('presetPath',file)
-
- if (file.indexOf('.preset')==-1){file+='.preset'}
- fs.writeFile(file,data, function (err, data) {
- if (err) throw err
- console.log('The current state was saved in '+file)
- })
- })
-}
-
-callbacks.stateLoad = function(data,clientId) {
- dialog.showOpenDialog(window,{title:'Load preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
-
- if (file==undefined) {return}
- settings.write('presetPath',file[0])
-
- fs.readFile(file[0],'utf-8', function read(err, data) {
- if (err) throw err
- ipc.send('stateLoad',data,clientId)
- })
- })
-}
-
-callbacks.fullscreen = function(data) {
- window.setFullScreen(!window.isFullScreen())
-}
-
-
-
-// GUI mode (electron)
-
if (!settings.noGui) {
- var app = require('app')
- , browserWindow = require('browser-window')
- , dialog = require('dialog')
- , ipc = require('ipc-main')
-
- app.commandLine.appendSwitch('--touch-events')
-
-
- app.on('window-all-closed', function() {
- if (process.platform != 'darwin') {
- app.quit()
- }
- })
-
- app.on('ready', function() {
-
- window = new browserWindow({
- width: 800,
- height: 600,
- title:settings.read('appName'),
- 'auto-hide-menu-bar':true,
- 'background-color':'#1a1d22'
- })
-
- window.loadURL('file://' + __dirname + '/../browser/index.html')
-
- window.on('closed', function() {
- window = null
- })
-
-
- var Menu = require('menu')
- var MenuItem = require('menu-item')
-
- var template = [
- {
- label: 'View',
- submenu: [
- {
- label: 'Restart',
- accelerator: 'CmdOrCtrl+R',
- click: restartApp// function() { window.reload(); }//restartApp
- },
- {
- label: 'Toggle DevTools',
- accelerator: 'F12',
- click: function() { window.toggleDevTools(); }
- },
- {
- label: 'Toggle Fullscreen',
- accelerator: 'F11',
- click: function() { window.setFullScreen(!window.isFullScreen()); }
- }
- ]
- },
- ]
- menu = Menu.buildFromTemplate(template)
- Menu.setApplicationMenu(menu)
- })
-
- var restartApp = function(){
- var exec = require('child_process').exec
- exec(process.argv.join(' '))
- app.quit()
- }
-
- // mainProcess > renderProcess ipc shorthand
-
- ipc.send = function(name,data) {
- window.webContents.send(name,data)
- }
-
-
- // ipc bindings
-
- var bindCallback = function(i) {
- ipc.on(i,function(event,data){
- callbacks[i](data)
- })
- }
- for (i in callbacks) {
- bindCallback(i)
- }
-
- // prevent annoying error popups
+ var app = require('app'),
+ browserWindow = require('browser-window'),
+ dialog = require('dialog'),
+ ipc = require('ipc-main')
dialog.showErrorBox = function(title,err) {
console.log(title + ': ' + err)
}
+ app.commandLine.appendSwitch('--touch-events')
-}
-
-
-
-
-
-
-// Headless (noGui) mode
-
-if (settings.noGui) {
- console.log('Headless mode: app available at http://127.0.0.1:'+settings.noGui)
-
- var express = require('express')()
- ,path = require('path')
- ,http = require('http')
- ,server = http.createServer(express)
- ,io = require('socket.io')()
- ,ioWildcard = require('socketio-wildcard')()
- ,browserify = require('browserify')
- ,jsadded = 0
- express.get('/', function(req, res){
- res.sendFile(path.resolve(__dirname + '/../browser/index-headless.html'))
- })
- express.get('*browser-headless.js', function(req, res){
- browserify().add(path.resolve(__dirname + '/../browser' + req.path)).bundle().pipe(res);
- })
- express.get('*', function(req, res){
- res.sendFile(path.resolve(__dirname + '/../browser' + req.path))
- })
-
-
- io.use(ioWildcard)
-
- io.on('connection', function(socket) {
- socket.on('*', function(e){
- var name = e.data[0],
- data = e.data[1]
- if (callbacks[name]) callbacks[name](data,socket.id)
- if (name=='sendOsc' && data.sync!==false) {
- // synchronize all other connected clients
- socket.broadcast.emit('receiveOsc',data)
- }
- });
- });
-
- io.listen(server);
-
- server.listen(settings.noGui)
-
- ipc.send = function(name,data,clientId) {
- if (clientId) {
- io.to(clientId).emit(name,data)
- } else {
- io.emit(name,data)
+ app.on('window-all-closed', function() {
+ if (process.platform != 'darwin') {
+ app.quit()
}
- }
+ })
+
+ app.on('ready',function(){
+ var server = require('./server-electron')(settings,app,ipc,browserWindow),
+ osc = require('./osc')(ipc,settings),
+ callbacks = require('./callbacks')(settings,fs,ipc,osc,dialog)
+
+
+ server.bindCallbacks(callbacks)
+ })
+
+} else {
+
+ var server = require('./server-express')(settings),
+ ipc = server.ipc,
+ osc = require('./osc')(ipc,settings),
+ callbacks = require('./callbacks')(settings,fs,ipc,osc,dialog)
+
+ server.bindCallbacks(callbacks)
+
}
diff --git a/app/main/osc.js b/app/main/osc.js
new file mode 100644
index 00000000..66660d36
--- /dev/null
+++ b/app/main/osc.js
@@ -0,0 +1,47 @@
+var osc = require('node-osc')
+
+module.exports = function(ipc, settings) {
+
+ if (settings.read('oscInPort')) {
+ var oscServer = new osc.Server(settings.read('oscInPort'), '127.0.0.1')
+
+ oscServer.on('message', function (msg, rinfo) {
+ var data = {path:msg.shift(),args:msg}
+ if (data.args.length==1) data.args = data.args[0]
+ ipc.send('receiveOsc',data)
+ })
+ }
+
+ return {
+ send: function(host,port,path,args,precision) {
+
+ var client = new osc.Client(host, port)
+
+ var message = new osc.Message(path)
+
+ var numberType = precision==0?'integer':'float'
+
+ if (typeof args=='object') {
+ for (i in args) {
+ var arg = args[i]
+ if (typeof arg == 'number') {
+ message.append({type:numberType,value:arg})
+ } else {
+ message.append({type:'string',value:arg})
+ }
+ }
+ } else {
+ if (typeof args == 'number') {
+ message.append({type:numberType,value:args})
+ } else {
+ message.append({type:'string',value:args})
+ }
+ }
+
+ client.send(message, function () {
+ client.kill()
+ })
+ }
+ }
+
+}
diff --git a/app/main/server-electron.js b/app/main/server-electron.js
new file mode 100644
index 00000000..dbb63341
--- /dev/null
+++ b/app/main/server-electron.js
@@ -0,0 +1,82 @@
+module.exports = function(settings,app,ipc,browserWindow) {
+
+ window = new browserWindow({
+ width: 800,
+ height: 600,
+ title:settings.read('appName'),
+ autoHideMenuBar:true,
+ backgroundColor:'#1a1d22',
+ show:false
+ })
+
+ window.loadURL('file://' + __dirname + '/../browser/index.html')
+
+ window.on('closed', function() {
+ window = null
+ })
+
+
+ var Menu = require('menu')
+
+ Menu.setApplicationMenu(Menu.buildFromTemplate(
+ [
+ {
+ label: 'View',
+ submenu: [
+ {
+ label: 'Restart',
+ accelerator: 'CmdOrCtrl+R',
+ click: function(){
+ var exec = require('child_process').exec
+ exec(process.argv.join(' '))
+ app.quit()
+ }// function() { window.reload(); }//restartApp
+ },
+ {
+ label: 'Toggle DevTools',
+ accelerator: 'F12',
+ click: function() { window.toggleDevTools(); }
+ },
+ {
+ label: 'Toggle Fullscreen',
+ accelerator: 'F11',
+ click: function() { window.setFullScreen(!window.isFullScreen()); }
+ }
+ ]
+ },
+ ]
+ ))
+
+ // mainProcess > renderProcess ipc shorthand
+
+ ipc.send = function(name,data) {
+ window.webContents.send(name,data)
+ }
+
+
+ // ipc bindings
+
+ var bindCallbacks = function(callbacks) {
+
+ var bindCallback = function(i) {
+ ipc.on(i,function(event,data){
+ callbacks[i](data)
+ })
+ }
+
+ for (i in callbacks) {
+ bindCallback(i)
+ }
+
+ ipc.on('ready',function(){
+ window.show()
+ })
+
+ }
+
+ return {
+ ipc:ipc,
+ bindCallbacks:bindCallbacks
+ }
+
+}
diff --git a/app/main/server-express.js b/app/main/server-express.js
new file mode 100644
index 00000000..11a258cf
--- /dev/null
+++ b/app/main/server-express.js
@@ -0,0 +1,62 @@
+module.exports = function(settings) {
+
+ // Headless (noGui) mode
+
+ var express = require('express')(),
+ path = require('path'),
+ http = require('http'),
+ server = http.createServer(express),
+ io = require('socket.io')(),
+ ioWildcard = require('socketio-wildcard')(),
+ browserify = require('browserify'),
+ ipc = {}
+
+ express.get('/', function(req, res){
+ res.sendFile(path.resolve(__dirname + '/../browser/index-headless.html'))
+ })
+ express.get('*browser-headless.js', function(req, res){
+ browserify().add(path.resolve(__dirname + '/../browser' + req.path)).bundle().pipe(res);
+ })
+ express.get('*', function(req, res){
+ res.sendFile(path.resolve(__dirname + '/../browser' + req.path))
+ })
+
+
+ io.use(ioWildcard)
+
+
+ io.listen(server);
+
+ server.listen(settings.noGui)
+
+ ipc.send = function(name,data,clientId) {
+ if (clientId) {
+ io.to(clientId).emit(name,data)
+ } else {
+ io.emit(name,data)
+ }
+ }
+
+ var bindCallbacks = function(callbacks) {
+ io.on('connection', function(socket) {
+ socket.on('*', function(e){
+ var name = e.data[0],
+ data = e.data[1]
+ if (callbacks[name]) callbacks[name](data,socket.id)
+ if (name=='sendOsc' && data.sync!==false) {
+ // synchronize all other connected clients
+ socket.broadcast.emit('receiveOsc',data)
+ }
+ });
+ });
+ }
+
+
+ console.log('Headless mode: app available at http://127.0.0.1:'+settings.noGui)
+
+ return {
+ ipc:ipc,
+ bindCallbacks:bindCallbacks
+ }
+
+}
diff --git a/app/main/settings.js b/app/main/settings.js
new file mode 100644
index 00000000..6459469d
--- /dev/null
+++ b/app/main/settings.js
@@ -0,0 +1,47 @@
+// This prevents argv parsing to be breaked when the app is packaged (executed without 'electron' prefix)
+if (process.argv[1]&&process.argv[1].indexOf('-')==0) process.argv.unshift('')
+
+var argv = require('yargs')
+ .help('help').usage(`\nUsage:\n $0 [options]`).alias('h', 'help')
+ .options({
+ 's':{alias:'sync',type:'array',describe:'synchronized hosts (ip:port pairs)'},
+ 'c':{alias:'compile',type:'string',describe:'recompile stylesheets (increases startup time)'},
+ 'l':{alias:'load',type:'string',describe:'session file to load'},
+ 'p':{alias:'port',describe:'osc input port (for synchronization)'},
+ 'n':{alias:'nogui',describe:'disable default gui and makes the app availabe through http on specified port'},
+ })
+ .check(function(a,x){if(a.port==undefined || !isNaN(a.p)&&a.p>1023&&parseInt(a.p)===a.p){return true}else{throw 'Error: Port must be an integer >= 1024'}})
+ .check(function(a,x){if(a.n==undefined || !isNaN(a.n)&&a.n>1023&&parseInt(a.n)===a.n){return true}else{throw 'Error: Port must be an integer >= 1024'}})
+ .check(function(a,x){if(a.sync==undefined || a.s.join(' ').match('^([^:\s]*:[0-9]{4,5}[\s]*)*$')!=null){return true}else{throw 'Error: Sync hosts must be ip:port pairs & port must be >= 1024'}})
+ .strict()
+ .argv
+
+module.exports = function(fs) {
+ return {
+ presetPath : process.cwd(),
+ sessionPath: process.cwd(),
+ recentSessions: [],
+
+ appName: 'OSC Controller',
+ syncTargets: argv.s || false,
+ oscInPort: argv.p || false,
+ compileScss: argv.c!==undefined || false,
+ lightTheme: argv.c && argv.c.match(/light/),
+ sessionFile: argv.l || false,
+ noGui: argv.n || false,
+
+
+ persistent: function(){var c = {};try {c=require( __dirname + '/config.json')} finally {return c}}(),
+
+ read:function(key){
+ var x = this.persistent[key] || this[key]
+ return x
+ },
+ write:function(key,value) {
+ this.persistent[key] = value
+ fs.writeFile(__dirname + '/config.json',JSON.stringify(this.persistent,null,4), function (err, data) {
+ if (err) throw err
+ })
+ }
+ }
+}