- browser-side js splitted in smaller units
- no more default target, no osc send if no target specified - css updates (cursors, button links)
This commit is contained in:
parent
b9d8ce39ff
commit
674c5d295c
10 changed files with 795 additions and 829 deletions
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"presetPath": "/home/bordun/oscwork/oschtmlgui/",
|
||||
"presetPath": "/home/bordun/oscwork/oschtmlgui/presets/",
|
||||
"sessionPath": "/home/bordun/oscwork/oschtmlgui/sessions/",
|
||||
"recentSessions": [
|
||||
"/home/bordun/oscwork/oschtmlgui/sessions/demo.js",
|
||||
"/home/bordun/oscwork/oschtmlgui/sessions/demo-full.js"
|
||||
"/home/bordun/oscwork/oschtmlgui/sessions/demo-full.js",
|
||||
"/home/bordun/oscwork/oschtmlgui/sessions/demo.js"
|
||||
]
|
||||
}
|
||||
|
|
@ -108,20 +108,18 @@
|
|||
|
||||
}
|
||||
|
||||
/* Handles and cursors;
|
||||
/* Handles;
|
||||
*/
|
||||
.noUi-dragable {
|
||||
cursor: w-resize;
|
||||
}
|
||||
.noUi-vertical .noUi-dragable {
|
||||
cursor: n-resize;
|
||||
}
|
||||
|
||||
.noUi-handle {
|
||||
background: #FFF;
|
||||
cursor: default;
|
||||
box-shadow: inset 0 0 1px #FFF,
|
||||
inset 0 1px 7px #EBEBEB,
|
||||
0 3px 6px -3px #BBB;
|
||||
cursor: -webkit-grab;
|
||||
&:active {
|
||||
cursor: -webkit-grabbing;
|
||||
}
|
||||
}
|
||||
.noUi-active {
|
||||
box-shadow: inset 0 0 1px #FFF,
|
||||
|
|
@ -264,34 +262,16 @@
|
|||
|
||||
border-color:rgba(255,255,255,0.4);
|
||||
}
|
||||
.noUi-handle:after {
|
||||
display:none;
|
||||
}
|
||||
|
||||
|
||||
.noUi-horizontal .noUi-dragable:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
height:100%;
|
||||
left:-5000px;
|
||||
width:10000px;
|
||||
}
|
||||
|
||||
.noUi-connect {
|
||||
background:$color-accent;
|
||||
border:0;
|
||||
border-radius:0;
|
||||
}
|
||||
|
||||
.noUi-vertical .noUi-dragable:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
height:10000px;
|
||||
top:-5000px;
|
||||
width:500px;
|
||||
left:-250px;
|
||||
}
|
||||
.noUi-horizontal .noUi-handle:after {
|
||||
|
||||
.noUi-handle:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
height:500px;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/////////////
|
||||
|
||||
$color-text:rgba(white,.9);
|
||||
$color-text:rgba(white,.8);
|
||||
$color-text-fade:transparentize($color-text,.4);
|
||||
|
||||
|
||||
|
|
@ -13,6 +13,7 @@ $nav-height:50px;
|
|||
|
||||
$bg-title:rgba(white,.05);
|
||||
$bg-button:linear-gradient(#3a3f4b, #353b45);
|
||||
$bg-button-hover:linear-gradient(lighten(#3a3f4b,2), lighten(#353b45,2));
|
||||
|
||||
$sidepanel-size:300px;
|
||||
|
||||
|
|
@ -36,9 +37,11 @@ $sidepanel-size:300px;
|
|||
text-decoration:none;
|
||||
outline:0;
|
||||
font:inherit;
|
||||
cursor: url('data:image/x-icon;base64,AAACAAEAICAQAAcACADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAAAIAAAAAAAAAAAAAEAAAAAAAAAAAAAAAuLW0AL+8uwAwMC8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACIiEDASIiAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////////////////////////////////////////////////////////////////////////////////////////7////+/////v////7////+/////////4KD/////////v////7////+/////v////7//////////////w=='),auto!important;
|
||||
cursor: inherit;
|
||||
}
|
||||
a {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
$scrollbar-margin:5px;
|
||||
::-webkit-scrollbar {
|
||||
|
|
@ -103,15 +106,23 @@ html, body {
|
|||
body {
|
||||
font-size:14px;
|
||||
line-height:16px;
|
||||
font-family:'Open Sans';
|
||||
font-family:sans;
|
||||
color:$color-text;
|
||||
white-space:nowrap;
|
||||
opacity:1
|
||||
opacity:1;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
a.btn {
|
||||
background: $bg-button;
|
||||
display: block;
|
||||
padding:10px;
|
||||
&:hover {
|
||||
background: $bg-button-hover;
|
||||
}
|
||||
}
|
||||
|
||||
#lobby {
|
||||
background: $color-bg;
|
||||
|
|
@ -131,23 +142,19 @@ body {
|
|||
box-shadow: 0 0 0 1px $color-border inset;
|
||||
}
|
||||
a {
|
||||
display: block;
|
||||
padding:10px;
|
||||
padding-right:25px;
|
||||
overflow: hidden;
|
||||
background: $bg-button;
|
||||
margin-top:10px;
|
||||
box-shadow: 0 0 0 1px $color-border inset;
|
||||
position: relative;
|
||||
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
span {
|
||||
position: absolute;
|
||||
right:1px;
|
||||
top:1px;
|
||||
bottom:1px;
|
||||
|
||||
padding:9px;
|
||||
background: $bg-button;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -240,17 +247,16 @@ body {
|
|||
padding:5px;
|
||||
list-style:none;
|
||||
background:$color-fg;
|
||||
|
||||
li {
|
||||
display:block;
|
||||
margin-bottom:15px;
|
||||
background:$bg-button;
|
||||
border:1px solid $color-border;
|
||||
> div {
|
||||
padding:10px;
|
||||
}
|
||||
}
|
||||
|
||||
.inspector {
|
||||
padding: 10px;
|
||||
.result {
|
||||
background: $color-border;
|
||||
border-radius: 3px;
|
||||
|
|
@ -544,6 +550,7 @@ $button-size:20px;
|
|||
outline-offset: -10px;
|
||||
background:$bg-button;
|
||||
box-shadow: 0 0 0 1px $color-bg inset;
|
||||
cursor: pointer;
|
||||
&:after{
|
||||
content:"";
|
||||
position:absolute;
|
||||
|
|
@ -707,6 +714,10 @@ width:400px;
|
|||
height:0;
|
||||
width:0;
|
||||
z-index:2;
|
||||
cursor: -webkit-grab;
|
||||
&:active {
|
||||
cursor: -webkit-grabbing;
|
||||
}
|
||||
&:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
|
|
@ -721,15 +732,14 @@ width:400px;
|
|||
box-shadow: 0 0 0 1000px rgba(black,.5), 0 0 0 1px rgba(white,.2);
|
||||
}
|
||||
|
||||
span {
|
||||
&::before {
|
||||
content:"";
|
||||
position:absolute;
|
||||
top:-.5px;
|
||||
left:-1px;
|
||||
width:2000px;
|
||||
height:2000px;
|
||||
margin:-1000px 0 0 -1000px;
|
||||
-webkit-mask: radial-gradient(circle,rgba(black,0) 0px , rgba(black,1) 1%);
|
||||
opacity:.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ for (i in styles) {
|
|||
|
||||
ipc.on('listSessions',function(data){
|
||||
for (i in data) {
|
||||
$('#lobby .list').append('<li><a data-session="'+i+'">'+data[i]+'<span>x</span></a></li>')
|
||||
$('#lobby .list').append('<li><a class="btn" data-session="'+i+'">'+data[i]+'<span>x</span></a></li>')
|
||||
}
|
||||
$('#lobby .list').append('<a data-session="browse">...</a>')
|
||||
$('#lobby .list').append('<a class="btn" data-session="browse">...</a>')
|
||||
$('#lobby a').click(function(){
|
||||
ipc.send('loadSession',$(this).data('session'))
|
||||
})
|
||||
|
|
|
|||
13
browser/js/app/callbacks.js
Normal file
13
browser/js/app/callbacks.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
ipc.on('receiveOsc',function(data){
|
||||
// fetch id
|
||||
var path = data.address;
|
||||
var id = $('[path="'+path+'"]').attr('widgetId');
|
||||
|
||||
// update
|
||||
if (__widgets__[id]!=undefined) __widgets__[id][0].setValue(data.args,false,true)
|
||||
|
||||
})
|
||||
|
||||
ipc.on('load',function(preset){
|
||||
setState(preset)
|
||||
})
|
||||
131
browser/js/app/init.js
Normal file
131
browser/js/app/init.js
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
|
||||
init = function(callback) {
|
||||
|
||||
parsetabs(TABS,false,false)
|
||||
|
||||
|
||||
|
||||
// Widget Synchronization : widget that share the same id will update each other
|
||||
// without sending any extra osc message (they must be of the same type as well)
|
||||
|
||||
$.each(__widgets__,function(i,widget) {
|
||||
if (widget.length>1) {
|
||||
var script ='';
|
||||
for (j in widget) {
|
||||
|
||||
// Oh dear this looks hacky
|
||||
// I didn't manage to cross-bind all widgets together the usual way
|
||||
// ( getValue() always returns the last element's value, maybe a scope problem)
|
||||
|
||||
script += ' \n\
|
||||
widget['+j+'].on(\'sync\',function(){ \n\
|
||||
var v = widget['+j+'].getValue() \n\
|
||||
for (k=0;k<widget.length;k++) { \n\
|
||||
if ('+j+'!=k) { \n\
|
||||
widget[k].setValue(v,false,false) \n\
|
||||
} \n\
|
||||
} \n\
|
||||
}) \n\
|
||||
';
|
||||
}
|
||||
eval(script)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
// Tabs...
|
||||
$('.tablist a').click(function(){
|
||||
|
||||
var id = $(this).attr('href');
|
||||
$(id).siblings('.on').removeClass('on');
|
||||
$(id).addClass('on');
|
||||
$(this).parents('ul').find('.on').removeClass('on');
|
||||
$(this).addClass('on');$(this).parent().addClass('on');
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
// Activate first tabs
|
||||
$('.tablist li:first-child a').click();
|
||||
|
||||
|
||||
|
||||
|
||||
// horizontal scrolling with mousewheel
|
||||
// if shift is pressed or if mouse is on h-scrollbar
|
||||
$('.tab').on('mousewheel',function(e) {
|
||||
// console.log(e)
|
||||
var h = $('#container').innerHeight()-20-$(this).parents('.tab').length*5;
|
||||
if (e.shiftKey) {
|
||||
$(this).scrollLeft($(this).scrollLeft()+e.originalEvent.deltaX);
|
||||
e.preventDefault();
|
||||
} else if (e.pageY>=h) {
|
||||
$(this).scrollLeft($(this).scrollLeft()+e.originalEvent.deltaY);
|
||||
e.preventDefault()
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// sidepanel
|
||||
|
||||
|
||||
$('#sidepanel').append('\
|
||||
<div class="open-toggle">\
|
||||
<span class="bars"></span>\
|
||||
</div>\
|
||||
<ul id="options">\
|
||||
<li><a class="saveState btn">Save</a></li>\
|
||||
<li><a href="#" class="loadState btn">Load</a></li>\
|
||||
<li><a href="#" class="sendState btn">Send ALL</a></li>\
|
||||
<li><a href="#" class="goFullscreen btn">Fullscreen</a></li>\
|
||||
<li>\
|
||||
<div class="inspector">\
|
||||
Inspector\
|
||||
<div class="result"><em>Click on a widges\'s title to inspect</em></div>\
|
||||
</div>\
|
||||
</li>\
|
||||
</ul>\
|
||||
')
|
||||
|
||||
$('#sidepanel .open-toggle').click(function(){
|
||||
$('#sidepanel .open-toggle, #sidepanel .open-toggle .bars, #sidepanel, #container').toggleClass('sidepanel-open');
|
||||
})
|
||||
|
||||
$('.title').click(function(){
|
||||
if (!$('#sidepanel').hasClass('sidepanel-open')){return}
|
||||
var id = $(this).parents('.widget').attr('widgetid');
|
||||
var data = id + ': <br/>' + String(JSON.stringify(findNode(id,TABS),null,2)).split('\n').join('<br/> ')
|
||||
$('.inspector .result').html(data);
|
||||
})
|
||||
|
||||
|
||||
// Options menu
|
||||
$('.showOptions a').click(function(e){
|
||||
e.preventDefault();
|
||||
$('#options').toggleClass('open');
|
||||
})
|
||||
$('.goFullscreen').click(function(e){
|
||||
e.preventDefault();
|
||||
ipc.send('fullscreen')
|
||||
})
|
||||
|
||||
$('.saveState').click(function(e){
|
||||
e.preventDefault();
|
||||
saveState();
|
||||
})
|
||||
$('.loadState').click(function(e){
|
||||
e.preventDefault();
|
||||
loadState();
|
||||
})
|
||||
$('.sendState').click(function(e){
|
||||
e.preventDefault();
|
||||
sendState();
|
||||
})
|
||||
|
||||
if (callback) callback()
|
||||
|
||||
}
|
||||
|
|
@ -1,778 +1,5 @@
|
|||
// defaultTarget
|
||||
defaultTarget = '127.0.0.1:9999'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
createWidget= {}
|
||||
__widgets__ = {}
|
||||
|
||||
function parsetabs(tabs,parent,sub){
|
||||
|
||||
if (!sub) {
|
||||
var $nav = $(document.createElement('div')).addClass('main navigation'),
|
||||
$navtabs = $(document.createElement('ul')).addClass('tablist'),
|
||||
$content = $(document.createElement('div')).addClass('content');
|
||||
$nav.append($navtabs)
|
||||
$('#container').append($nav).append($content);
|
||||
} else {
|
||||
var $nav = $(document.createElement('div')).addClass('sub navigation'),
|
||||
$navtabs = $(document.createElement('ul')).addClass('tablist'),
|
||||
|
||||
$content = $(document.createElement('div')).addClass('content hastabs');
|
||||
$nav.append($navtabs);
|
||||
parent.append($nav).append($content);
|
||||
|
||||
}
|
||||
|
||||
for (tabId in tabs) {
|
||||
var tabData = tabs[tabId]
|
||||
|
||||
var title = tabData.title||tabId
|
||||
|
||||
var id = parent?parent.attr('id')+tabId:tabId
|
||||
$navtabs.append('<li><a href="#'+id+'"><span>'+title+'</span></a></li>');
|
||||
|
||||
var $tabContent = $(document.createElement('div')).addClass('tab').attr('id',id);
|
||||
|
||||
if (tabData.tabs) {
|
||||
parsetabs(tabData.tabs,parent=$tabContent,sub=true);
|
||||
} else {
|
||||
parsewidgets(tabData.widgets,$tabContent)
|
||||
}
|
||||
|
||||
$content.append($tabContent);
|
||||
// console.log('OK parsing tab ' + title )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function parsewidgets(widgets,parent) {
|
||||
|
||||
for (widgetId in widgets) {
|
||||
var widgetData = widgets[widgetId]
|
||||
|
||||
var color = widgetData.color?'style="background:'+widgetData.color+'"':'';
|
||||
var title = widgetData.title || widgetId;
|
||||
var type = widgetData.type || 'fader'
|
||||
widgetData.path = widgetData.path || '/' + widgetId
|
||||
|
||||
var widget = $('\
|
||||
<div class="widget" widgetType="'+type+'" widgetId="'+widgetId+'" path="'+widgetData.path+'">\
|
||||
<div class="title" '+color+'>'+title+'</div>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
|
||||
var widgetInner = createWidget[type](widgetData,parent)
|
||||
widgetInner.type = widgetData.type || 'fader'
|
||||
|
||||
widget.append(widgetInner)
|
||||
if (__widgets__[widgetId]==undefined) {
|
||||
__widgets__[widgetId] = []
|
||||
}
|
||||
__widgets__[widgetId].push(widgetInner)
|
||||
|
||||
|
||||
parent.append(widget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
createWidget.stack = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="stack">\
|
||||
</div>\
|
||||
');
|
||||
parsewidgets(widgetData.widgets,widget)
|
||||
widget.getValue = function(){return}
|
||||
widget.setValue = function(){return}
|
||||
return widget;
|
||||
}
|
||||
|
||||
createWidget.button = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="button-wrapper">\
|
||||
<div class="button"></div>\
|
||||
<input disabled></input>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
widget.input = widget.find('input')
|
||||
widget.button = widget.find('.button')
|
||||
|
||||
widgetData.args = widgetData.args || {off:0,on:1}
|
||||
|
||||
widget.button.click(function(){
|
||||
var newVal = widget.button.hasClass('on')?widgetData.args.off||0:widgetData.args.on||1
|
||||
widget.setValue(newVal,true)
|
||||
})
|
||||
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.button.hasClass('on')?widgetData.args.on||1:widgetData.args.off||0
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
var on = widgetData.args.on||1,
|
||||
off= widgetData.args.off||0
|
||||
if (v==on) {
|
||||
widget.button.addClass('on')
|
||||
if (send) widget.sendValue(v)
|
||||
} else if (v==off) {
|
||||
widget.button.removeClass('on')
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
widget.input.val(widget.getValue())
|
||||
if (send) widget.trigger('sync')
|
||||
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path
|
||||
sendOsc([t,p,v]);
|
||||
}
|
||||
widget.setValue()
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
createWidget.xy = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="xy-wrapper">\
|
||||
<div class="xy">\
|
||||
<div class="handle"><span></span></div>\
|
||||
</div>\
|
||||
<div class="value">\
|
||||
<input disabled value="X"></input><input disabled value="Y"></input>\
|
||||
<input type="number" class="x"></input><input type="number" class="y"></input>\
|
||||
</div>\
|
||||
</div>\
|
||||
');
|
||||
widget.xy = widget.find('.xy')
|
||||
widget.xy.handle = widget.find('.handle')
|
||||
widget.xy.handle.css({top:0,left:0}).draggable({
|
||||
addClasses: false,
|
||||
scroll:false,
|
||||
containment:'parent'
|
||||
});
|
||||
|
||||
widget.xy.value = {x:widget.find('.x'),y:widget.find('.y')}
|
||||
|
||||
|
||||
widget.xy.on('drag',function(e, data){
|
||||
var v = widget.getValue();
|
||||
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v)
|
||||
widget.trigger('sync')
|
||||
})
|
||||
|
||||
widgetData.range = widgetData.range || {x:{min:0,max:1},y:{min:0,max:1}}
|
||||
|
||||
widget.getValue = function() {
|
||||
var x = mapToScale(widget.xy.handle.css('left'),[0,widget.xy.innerWidth()],[widgetData.range.x.min,widgetData.range.x.max]),
|
||||
y = mapToScale(widget.xy.handle.css('top'),[0,widget.xy.innerHeight()],[widgetData.range.y.min,widgetData.range.y.max],true)
|
||||
|
||||
return [x,y]
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (v[1]==undefined) var v = [v,v]
|
||||
var left = mapToScale(v[0],[widgetData.range.x.min,widgetData.range.x.max],[0,widget.xy.innerWidth()])
|
||||
ytop = mapToScale(v[1],[widgetData.range.y.min,widgetData.range.y.max],[0,widget.xy.innerHeight()],true),
|
||||
|
||||
widget.xy.handle.css({'top':ytop+'px','left':left+'px'})
|
||||
|
||||
widget.showValue(v)
|
||||
if (sync) widget.trigger('sync')
|
||||
if (send) widget.sendValue(v);
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path
|
||||
sendOsc([t,p,v]);
|
||||
}
|
||||
|
||||
widget.showValue = function(v) {
|
||||
widget.xy.value.x.val(v[0])
|
||||
widget.xy.value.y.val(v[1])
|
||||
}
|
||||
|
||||
widget.xy.value.x.change(function(){
|
||||
var v = widget.getValue();
|
||||
v[0] = limit($(this).val(),[widgetData.range.x.min,widgetData.range.x.max])
|
||||
widget.setValue(v,true,true)
|
||||
})
|
||||
widget.xy.value.y.change(function(){
|
||||
var v = widget.getValue();
|
||||
v[1] = limit($(this).val(),[widgetData.range.y.min,widgetData.range.y.max])
|
||||
widget.setValue(v,true,true)
|
||||
})
|
||||
|
||||
|
||||
return widget;
|
||||
|
||||
|
||||
// alternate technique to jqueryui using css transform (hw accelerated)
|
||||
// doesn't seem to increase performance (there's no transition to optimize)
|
||||
// add require( __dirname + "/js/jquery.event.drag-2.2.js") to index.html to enable
|
||||
|
||||
// widget.xy.handle.drag(function( ev, dd ){
|
||||
// var x = limit(dd.offsetX,[0,widget.xy.innerWidth()]),
|
||||
// y = limit(dd.offsetY,[0,widget.xy.innerHeight()])
|
||||
// $( this ).css({
|
||||
// 'transform': 'translate3d('+x+'px,'+y+'px,0px)'
|
||||
// });
|
||||
//
|
||||
// var v = widget.getValue([0,0,0,x,y]);
|
||||
// widget.sendValue(v);
|
||||
// widget.showValue(v)
|
||||
// widget.trigger('sync')
|
||||
// },{ relative:true });
|
||||
//
|
||||
// widgetData.range = widgetData.range || {x:{min:0,max:1},y:{min:0,max:1}}
|
||||
//
|
||||
// widget.getValue = function(css) {
|
||||
// var css = css || widget.xy.handle.css('transform').split('(')[1].split(',')
|
||||
// x = mapToScale(css[4],[0,widget.xy.innerWidth()],[widgetData.range.x.min,widgetData.range.x.max]),
|
||||
// y = mapToScale(css[5],[0,widget.xy.innerHeight()],[widgetData.range.y.min,widgetData.range.y.max],true)
|
||||
// return [x,y]
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
var 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)};
|
||||
};
|
||||
var 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 = -1;
|
||||
hsb.h *= 60;
|
||||
if (hsb.h < 0) hsb.h += 360;
|
||||
hsb.s *= 100/255;
|
||||
hsb.b *= 100/255;
|
||||
return hsb;
|
||||
};
|
||||
|
||||
|
||||
var limit = function(value,range) {
|
||||
var max = Math.max,
|
||||
min = Math.min
|
||||
|
||||
return max(min(range[0],range[1]),min(parseFloat(value),max(range[0],range[1])))
|
||||
|
||||
}
|
||||
|
||||
// map a value from a scale to another input and output must be range arrays
|
||||
var mapToScale = function(value,rangeIn,rangeOut,reverse) {
|
||||
|
||||
var max = Math.max,
|
||||
min = Math.min,
|
||||
round = Math.round
|
||||
|
||||
value = max(min(rangeIn[0],rangeIn[1]),min(parseFloat(value),max(rangeIn[0],rangeIn[1])))
|
||||
|
||||
value = (value/rangeIn[1]-rangeIn[0]) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
|
||||
|
||||
if (reverse) value = max(rangeOut[0],rangeOut[1])+min(rangeOut[0],rangeOut[1])-value
|
||||
|
||||
value = max(min(rangeOut[0],rangeOut[1]),min(value,max(rangeOut[0],rangeOut[1])))
|
||||
|
||||
value = round(value*100)/100
|
||||
|
||||
return value
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
createWidget.rgb = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="xy-wrapper rgb-wrapper">\
|
||||
<div class="xy rgb">\
|
||||
<div class="handle"><span></span></div>\
|
||||
</div>\
|
||||
<div class="hue">\
|
||||
<div class="handle"><span></span></div>\
|
||||
</div>\
|
||||
<div class="value">\
|
||||
<input disabled value="R"></input><input disabled value="G"></input><input disabled value="B"></input>\
|
||||
<input class="r" type="number"></input><input class="g" type="number"></input><input class="b" type="number"></input>\
|
||||
</div>\
|
||||
</div>\
|
||||
');
|
||||
widget.xy = widget.find('.xy')
|
||||
widget.xy.saturation = widget.find('.rgb .handle')
|
||||
widget.xy.hue = widget.find('.hue .handle')
|
||||
widget.xy.saturation.css({top:0,left:0}).draggable({
|
||||
addClasses: false,
|
||||
scroll:false,
|
||||
containment:'parent'
|
||||
});
|
||||
widget.xy.hue.css({left:0}).draggable({
|
||||
addClasses: false,
|
||||
scroll:false,
|
||||
containment:'parent'
|
||||
});
|
||||
|
||||
widget.xy.value = {r:widget.find('input.r'),g:widget.find('input.g'),b:widget.find('input.b')}
|
||||
|
||||
|
||||
|
||||
widget.xy.hue.on('drag',function(e, data){
|
||||
var h = parseFloat(widget.xy.hue.css('left'))/widget.xy.innerWidth()*360,
|
||||
rgb = hsbToRgb({h:h,s:100,b:100}),
|
||||
v = widget.getValue();
|
||||
|
||||
widget.xy.css('background-color','rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v);
|
||||
|
||||
widget.trigger('sync')
|
||||
})
|
||||
|
||||
widget.xy.saturation.on('drag',function(e, data){
|
||||
var v = widget.getValue();
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v);
|
||||
|
||||
widget.trigger('sync')
|
||||
|
||||
})
|
||||
widget.xy.saturation.on('stop',function(e, data){
|
||||
var v = widget.getValue();
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v);
|
||||
|
||||
//widget.trigger('sync')
|
||||
})
|
||||
|
||||
|
||||
widgetData.range = {r:{min:0,max:255},g:{min:0,max:255},b:{min:255}}
|
||||
|
||||
|
||||
|
||||
widget.getValue = function() {
|
||||
var s = mapToScale(widget.xy.saturation.css('left'),[0,widget.xy.innerWidth()],[0,100]),
|
||||
l = mapToScale(widget.xy.saturation.css('top'),[0,widget.xy.innerHeight()],[0,100],true),
|
||||
h = mapToScale(widget.xy.hue.css('left'),[0,widget.xy.innerWidth()],[0,360]),
|
||||
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]) {
|
||||
if (!0<=v[i]<=255) {v[i]=Math.min(255,Math.max(0,v[i]))}
|
||||
}
|
||||
|
||||
|
||||
var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
|
||||
|
||||
var left = mapToScale(hsb.s,[0,100],[0,widget.xy.innerWidth()]),
|
||||
top = mapToScale(hsb.b,[0,100],[0,widget.xy.innerHeight()],true),
|
||||
leftHue = mapToScale(hsb.h,[0,360],[0,widget.xy.innerWidth()])
|
||||
widget.xy.saturation.css({'top':top+'px','left':left+'px'})
|
||||
widget.xy.hue.css({'left':leftHue+'px'})
|
||||
|
||||
|
||||
var rgb = hsbToRgb({h:hsb.h,s:100,b:100})
|
||||
widget.xy.css('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) {
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path
|
||||
sendOsc([t,p,v]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
widget.showValue = function(v) {
|
||||
widget.xy.value.r.val(v[0])
|
||||
widget.xy.value.g.val(v[1])
|
||||
widget.xy.value.b.val(v[2])
|
||||
}
|
||||
widget.xy.value.r.change(function(){
|
||||
if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))}
|
||||
var v = widget.getValue()
|
||||
widget.setValue([$(this).val(),v[1],v[2]],true,true)
|
||||
})
|
||||
widget.xy.value.g.change(function(){
|
||||
if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))}
|
||||
var v = widget.getValue()
|
||||
widget.setValue([v[0],$(this).val(),v[2]],true,true)
|
||||
})
|
||||
widget.xy.value.b.change(function(){
|
||||
if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))}
|
||||
var v = widget.getValue()
|
||||
widget.setValue([v[0],v[1],$(this).val()],true,true)
|
||||
})
|
||||
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
createWidget.fader = function(widgetData,parent) {
|
||||
var widget = $('\
|
||||
<div class="fader-wrapper-outer">\
|
||||
<div class="fader-wrapper">\
|
||||
<div class="fader locked"></div>\
|
||||
</div>\
|
||||
<input value="0"></input>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
widget.fader = widget.find('.fader')
|
||||
widget.lock = false
|
||||
var range = (widgetData.range=='db'||!widgetData.range)?{'min': -70,'20%': -40,'45%': -20,'60%': -10,'max': 6}:widgetData.range;
|
||||
|
||||
|
||||
var pips = function() {
|
||||
if (widgetData.range=='db'||!widgetData.range) {
|
||||
return [-70,-60,-50,-40,-30,-20,-10,-6,-3,0,3,6];
|
||||
} else {
|
||||
var autopips = [];
|
||||
var i=0;
|
||||
for (key in range) {
|
||||
autopips[i]=range[key];
|
||||
i=i+1;
|
||||
}
|
||||
if (range.min<0 && 0<range.max){
|
||||
autopips.push(0);
|
||||
}
|
||||
//autopips.push((range.max-range.min)/2);
|
||||
//autopips.push((range.max-range.min)/4);
|
||||
//autopips.push((range.max-range.min)*.75);
|
||||
return autopips;
|
||||
}
|
||||
}
|
||||
var pips = pips();
|
||||
|
||||
var orientation = parent.hasClass('stack')?'horizontal':'vertical',
|
||||
direction = parent.hasClass('stack')?'ltr':'rtl',
|
||||
density = parent.hasClass('stack')?'2':'1';
|
||||
|
||||
widget.fader
|
||||
.noUiSlider({
|
||||
orientation:orientation,
|
||||
direction: direction,
|
||||
behaviour: "drag",
|
||||
connect: "lower",
|
||||
//animate:false,
|
||||
start: 0,
|
||||
range: range
|
||||
})
|
||||
.noUiSlider_pips({
|
||||
mode: 'values',
|
||||
density: density,
|
||||
filter:function(v,t){return v==0?1:2;},
|
||||
values: pips,
|
||||
format: wNumb({})
|
||||
})
|
||||
.Link('lower').to(widget.find('input'))
|
||||
.on('slide',function(){
|
||||
|
||||
if (!widget.lock) {
|
||||
widget.sendValue();
|
||||
}
|
||||
})
|
||||
.on('set',function(){
|
||||
if (!widget.lock) {
|
||||
widget.sendValue();
|
||||
widget.trigger('sync')
|
||||
}
|
||||
});
|
||||
|
||||
widget.getValue = function(v,send){
|
||||
return widget.fader.val();
|
||||
}
|
||||
|
||||
widget.setValue = function(v,send,sync){
|
||||
if (!send) {widget.lock=true}
|
||||
widget.fader.val(v);
|
||||
if (sync) widget.trigger('sync')
|
||||
widget.lock=false;
|
||||
|
||||
}
|
||||
widget.sendValue = function(){
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path,
|
||||
v = widgetData.scale1?
|
||||
Math.max(0,Math.round(10000*((Math.abs(range.min)/(range.max-range.min)) + widget.fader.val()/(range.max-range.min)))/10000)
|
||||
: widget.fader.val();
|
||||
sendOsc([t,p,parseFloat(v)]);
|
||||
}
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function sendOsc(data){
|
||||
// Unpack args for osc sending function
|
||||
ipc.send('sendOsc', {target:data[0],path:data[1],args:data[2]});
|
||||
}
|
||||
|
||||
function saveState() {
|
||||
var data = getState()
|
||||
ipc.send('save',data.join('\n'))
|
||||
}
|
||||
function getState(){
|
||||
var data = []
|
||||
$.each(__widgets__,function(i,widget) {
|
||||
data.push(widget[0].type+':'+i+':'+widget[0].getValue())
|
||||
})
|
||||
return data
|
||||
}
|
||||
function loadState() {
|
||||
ipc.send('load')
|
||||
}
|
||||
|
||||
function sendState(){
|
||||
var data = getState().join('\n')
|
||||
setState(data)
|
||||
|
||||
}
|
||||
function setState(preset){
|
||||
|
||||
$.each(preset.split('\n'),function(i,d) {
|
||||
var data = d.split(':')
|
||||
|
||||
setTimeout(function(){
|
||||
if (__widgets__[data[1]]!=undefined) {
|
||||
__widgets__[data[1]][0].setValue(data[2].split(','),true,true)
|
||||
}
|
||||
},i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// inspector
|
||||
function findNode(searchID, searchObject) {
|
||||
var result=false;
|
||||
$.each(searchObject,function(id,object){
|
||||
|
||||
if (id==searchID) {
|
||||
result = searchObject[id]
|
||||
return false
|
||||
} else if (typeof searchObject[id] === 'object'){
|
||||
result = findNode(searchID, searchObject[id])
|
||||
}
|
||||
if (result !== false) {return false}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
// CALLBACKS
|
||||
|
||||
ipc.on('receiveOsc',function(data){
|
||||
// fetch id
|
||||
var path = data.address;
|
||||
var id = $('[path="'+path+'"]').attr('widgetId');
|
||||
|
||||
// update
|
||||
if (__widgets__[id]!=undefined) __widgets__[id][0].setValue(data.args,false,true)
|
||||
|
||||
})
|
||||
|
||||
ipc.on('load',function(preset){
|
||||
setState(preset)
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
init = function(callback) {
|
||||
|
||||
|
||||
parsetabs(TABS,false,false)
|
||||
|
||||
|
||||
|
||||
// Widget Synchronization : widget that share the same id will update each other
|
||||
// without sending any extra osc message (they must be of the same type as well)
|
||||
|
||||
$.each(__widgets__,function(i,widget) {
|
||||
if (widget.length>1) {
|
||||
var script ='';
|
||||
for (j in widget) {
|
||||
|
||||
// Oh dear this looks hacky
|
||||
// I didn't manage to cross-bind all widgets together the usual way
|
||||
// ( getValue() always returns the last element's value, maybe a scope problem)
|
||||
|
||||
script += ' \n\
|
||||
widget['+j+'].on(\'sync\',function(){ \n\
|
||||
var v = widget['+j+'].getValue() \n\
|
||||
for (k=0;k<widget.length;k++) { \n\
|
||||
if ('+j+'!=k) { \n\
|
||||
widget[k].setValue(v,false,false) \n\
|
||||
} \n\
|
||||
} \n\
|
||||
}) \n\
|
||||
';
|
||||
}
|
||||
eval(script)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
// Tabs...
|
||||
$('.tablist a').click(function(){
|
||||
|
||||
var id = $(this).attr('href');
|
||||
$(id).siblings('.on').removeClass('on');
|
||||
$(id).addClass('on');
|
||||
$(this).parents('ul').find('.on').removeClass('on');
|
||||
$(this).addClass('on');$(this).parent().addClass('on');
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
// Activate first tabs
|
||||
$('.tablist li:first-child a').click();
|
||||
|
||||
|
||||
|
||||
|
||||
// horizontal scrolling with mousewheel
|
||||
// if shift is pressed or if mouse is on h-scrollbar
|
||||
$('.tab').on('mousewheel',function(e) {
|
||||
// console.log(e)
|
||||
var h = $('#container').innerHeight()-20-$(this).parents('.tab').length*5;
|
||||
if (e.shiftKey) {
|
||||
$(this).scrollLeft($(this).scrollLeft()+e.originalEvent.deltaX);
|
||||
e.preventDefault();
|
||||
} else if (e.pageY>=h) {
|
||||
$(this).scrollLeft($(this).scrollLeft()+e.originalEvent.deltaY);
|
||||
e.preventDefault()
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// sidepanel
|
||||
|
||||
|
||||
$('#sidepanel').append('\
|
||||
<div class="open-toggle">\
|
||||
<span class="bars"></span>\
|
||||
</div>\
|
||||
<ul id="options">\
|
||||
<li><div class="saveState">Save</div></li>\
|
||||
<li><div href="#" class="loadState">Load</div></li>\
|
||||
<li><div href="#" class="sendState">Send ALL</div></li>\
|
||||
<li><div href="#" class="goFullscreen">Fullscreen</div></li>\
|
||||
<li>\
|
||||
<div class="inspector">\
|
||||
Inspector\
|
||||
<div class="result"><em>Click on a widges\'s title to inspect</em></div>\
|
||||
</div>\
|
||||
</li>\
|
||||
</ul>\
|
||||
')
|
||||
|
||||
$('#sidepanel .open-toggle').click(function(){
|
||||
$('#sidepanel .open-toggle, #sidepanel .open-toggle .bars, #sidepanel, #container').toggleClass('sidepanel-open');
|
||||
})
|
||||
|
||||
$('.title').click(function(){
|
||||
if (!$('#sidepanel').hasClass('sidepanel-open')){return}
|
||||
var id = $(this).parents('.widget').attr('widgetid');
|
||||
var data = id + ': <br/>' + String(JSON.stringify(findNode(id,TABS),null,2)).split('\n').join('<br/> ')
|
||||
$('.inspector .result').html(data);
|
||||
})
|
||||
|
||||
|
||||
// Options menu
|
||||
$('.showOptions a').click(function(e){
|
||||
e.preventDefault();
|
||||
$('#options').toggleClass('open');
|
||||
})
|
||||
$('.goFullscreen').click(function(e){
|
||||
e.preventDefault();
|
||||
ipc.send('fullscreen')
|
||||
})
|
||||
|
||||
$('.saveState').click(function(e){
|
||||
e.preventDefault();
|
||||
saveState();
|
||||
})
|
||||
$('.loadState').click(function(e){
|
||||
e.preventDefault();
|
||||
loadState();
|
||||
})
|
||||
$('.sendState').click(function(e){
|
||||
e.preventDefault();
|
||||
sendState();
|
||||
})
|
||||
|
||||
if (callback) callback()
|
||||
|
||||
}// END INIT
|
||||
require(__dirname + '/parser.js') // session file parser
|
||||
require(__dirname + '/widgets.js') // widgets types and behaviour definition
|
||||
require(__dirname + '/utils.js') // state managing & inspector
|
||||
require(__dirname + '/callbacks.js')// calls from mainProcess
|
||||
require(__dirname + '/init.js') // ...
|
||||
|
|
|
|||
72
browser/js/app/parser.js
Normal file
72
browser/js/app/parser.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
parsetabs = function(tabs,parent,sub){
|
||||
|
||||
if (!sub) {
|
||||
var $nav = $(document.createElement('div')).addClass('main navigation'),
|
||||
$navtabs = $(document.createElement('ul')).addClass('tablist'),
|
||||
$content = $(document.createElement('div')).addClass('content');
|
||||
$nav.append($navtabs)
|
||||
$('#container').append($nav).append($content);
|
||||
} else {
|
||||
var $nav = $(document.createElement('div')).addClass('sub navigation'),
|
||||
$navtabs = $(document.createElement('ul')).addClass('tablist'),
|
||||
|
||||
$content = $(document.createElement('div')).addClass('content hastabs');
|
||||
$nav.append($navtabs);
|
||||
parent.append($nav).append($content);
|
||||
|
||||
}
|
||||
|
||||
for (tabId in tabs) {
|
||||
var tabData = tabs[tabId]
|
||||
|
||||
var title = tabData.title||tabId
|
||||
|
||||
var id = parent?parent.attr('id')+tabId:tabId
|
||||
$navtabs.append('<li><a href="#'+id+'"><span>'+title+'</span></a></li>');
|
||||
|
||||
var $tabContent = $(document.createElement('div')).addClass('tab').attr('id',id);
|
||||
|
||||
if (tabData.tabs) {
|
||||
parsetabs(tabData.tabs,parent=$tabContent,sub=true);
|
||||
} else {
|
||||
parsewidgets(tabData.widgets,$tabContent)
|
||||
}
|
||||
|
||||
$content.append($tabContent);
|
||||
// console.log('OK parsing tab ' + title )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
__widgets__ = {}
|
||||
|
||||
parsewidgets = function(widgets,parent) {
|
||||
|
||||
for (widgetId in widgets) {
|
||||
var widgetData = widgets[widgetId]
|
||||
|
||||
var color = widgetData.color?'style="background:'+widgetData.color+'"':'';
|
||||
var title = widgetData.title || widgetId;
|
||||
var type = widgetData.type || 'fader'
|
||||
widgetData.path = widgetData.path || '/' + widgetId
|
||||
|
||||
var widget = $('\
|
||||
<div class="widget" widgetType="'+type+'" widgetId="'+widgetId+'" path="'+widgetData.path+'">\
|
||||
<div class="title" '+color+'>'+title+'</div>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
|
||||
var widgetInner = createWidget[type](widgetData,parent)
|
||||
widgetInner.type = widgetData.type || 'fader'
|
||||
|
||||
widget.append(widgetInner)
|
||||
if (__widgets__[widgetId]==undefined) {
|
||||
__widgets__[widgetId] = []
|
||||
}
|
||||
__widgets__[widgetId].push(widgetInner)
|
||||
|
||||
|
||||
parent.append(widget);
|
||||
}
|
||||
}
|
||||
51
browser/js/app/utils.js
Normal file
51
browser/js/app/utils.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
|
||||
saveState = function () {
|
||||
var data = getState()
|
||||
ipc.send('save',data.join('\n'))
|
||||
}
|
||||
getState = function (){
|
||||
var data = []
|
||||
$.each(__widgets__,function(i,widget) {
|
||||
data.push(widget[0].type+':'+i+':'+widget[0].getValue())
|
||||
})
|
||||
return data
|
||||
}
|
||||
loadState = function() {
|
||||
ipc.send('load')
|
||||
}
|
||||
|
||||
sendState = function(){
|
||||
var data = getState().join('\n')
|
||||
setState(data)
|
||||
|
||||
}
|
||||
setState = function(preset){
|
||||
|
||||
$.each(preset.split('\n'),function(i,d) {
|
||||
var data = d.split(':')
|
||||
|
||||
setTimeout(function(){
|
||||
if (__widgets__[data[1]]!=undefined) {
|
||||
__widgets__[data[1]][0].setValue(data[2].split(','),true,true)
|
||||
}
|
||||
},i)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// inspector
|
||||
findNode = function(searchID, searchObject) {
|
||||
var result=false;
|
||||
$.each(searchObject,function(id,object){
|
||||
|
||||
if (id==searchID) {
|
||||
result = searchObject[id]
|
||||
return false
|
||||
} else if (typeof searchObject[id] === 'object'){
|
||||
result = findNode(searchID, searchObject[id])
|
||||
}
|
||||
if (result !== false) {return false}
|
||||
})
|
||||
return result
|
||||
}
|
||||
482
browser/js/app/widgets.js
Normal file
482
browser/js/app/widgets.js
Normal file
|
|
@ -0,0 +1,482 @@
|
|||
|
||||
sendOsc = function(data){
|
||||
// Unpack args for osc sending function
|
||||
if (data[0]) {
|
||||
ipc.send('sendOsc', {target:data[0],path:data[1],args:data[2]});
|
||||
}
|
||||
}
|
||||
|
||||
createWidget= {}
|
||||
|
||||
|
||||
createWidget.stack = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="stack">\
|
||||
</div>\
|
||||
');
|
||||
parsewidgets(widgetData.widgets,widget)
|
||||
widget.getValue = function(){return}
|
||||
widget.setValue = function(){return}
|
||||
return widget;
|
||||
}
|
||||
|
||||
createWidget.button = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="button-wrapper">\
|
||||
<div class="button"></div>\
|
||||
<input disabled></input>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
widget.input = widget.find('input')
|
||||
widget.button = widget.find('.button')
|
||||
|
||||
widgetData.args = widgetData.args || {off:0,on:1}
|
||||
|
||||
widget.button.click(function(){
|
||||
var newVal = widget.button.hasClass('on')?widgetData.args.off||0:widgetData.args.on||1
|
||||
widget.setValue(newVal,true)
|
||||
})
|
||||
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.button.hasClass('on')?widgetData.args.on||1:widgetData.args.off||0
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
var on = widgetData.args.on||1,
|
||||
off= widgetData.args.off||0
|
||||
if (v==on) {
|
||||
widget.button.addClass('on')
|
||||
if (send) widget.sendValue(v)
|
||||
} else if (v==off) {
|
||||
widget.button.removeClass('on')
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
widget.input.val(widget.getValue())
|
||||
if (send) widget.trigger('sync')
|
||||
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path
|
||||
sendOsc([t,p,v]);
|
||||
}
|
||||
widget.setValue()
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
createWidget.xy = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="xy-wrapper">\
|
||||
<div class="xy">\
|
||||
<div class="handle"><span></span></div>\
|
||||
</div>\
|
||||
<div class="value">\
|
||||
<input disabled value="X"></input><input disabled value="Y"></input>\
|
||||
<input type="number" class="x"></input><input type="number" class="y"></input>\
|
||||
</div>\
|
||||
</div>\
|
||||
');
|
||||
widget.xy = widget.find('.xy')
|
||||
widget.xy.handle = widget.find('.handle')
|
||||
widget.xy.handle.css({top:0,left:0}).draggable({
|
||||
addClasses: false,
|
||||
scroll:false,
|
||||
containment:'parent'
|
||||
});
|
||||
|
||||
widget.xy.value = {x:widget.find('.x'),y:widget.find('.y')}
|
||||
|
||||
|
||||
widget.xy.on('drag',function(e, data){
|
||||
var v = widget.getValue();
|
||||
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v)
|
||||
widget.trigger('sync')
|
||||
})
|
||||
|
||||
widgetData.range = widgetData.range || {x:{min:0,max:1},y:{min:0,max:1}}
|
||||
|
||||
widget.getValue = function() {
|
||||
var x = mapToScale(widget.xy.handle.css('left'),[0,widget.xy.innerWidth()],[widgetData.range.x.min,widgetData.range.x.max]),
|
||||
y = mapToScale(widget.xy.handle.css('top'),[0,widget.xy.innerHeight()],[widgetData.range.y.min,widgetData.range.y.max],true)
|
||||
|
||||
return [x,y]
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (v[1]==undefined) var v = [v,v]
|
||||
var left = mapToScale(v[0],[widgetData.range.x.min,widgetData.range.x.max],[0,widget.xy.innerWidth()])
|
||||
ytop = mapToScale(v[1],[widgetData.range.y.min,widgetData.range.y.max],[0,widget.xy.innerHeight()],true),
|
||||
|
||||
widget.xy.handle.css({'top':ytop+'px','left':left+'px'})
|
||||
|
||||
widget.showValue(v)
|
||||
if (sync) widget.trigger('sync')
|
||||
if (send) widget.sendValue(v);
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path
|
||||
sendOsc([t,p,v]);
|
||||
}
|
||||
|
||||
widget.showValue = function(v) {
|
||||
widget.xy.value.x.val(v[0])
|
||||
widget.xy.value.y.val(v[1])
|
||||
}
|
||||
|
||||
widget.xy.value.x.change(function(){
|
||||
var v = widget.getValue();
|
||||
v[0] = limit($(this).val(),[widgetData.range.x.min,widgetData.range.x.max])
|
||||
widget.setValue(v,true,true)
|
||||
})
|
||||
widget.xy.value.y.change(function(){
|
||||
var v = widget.getValue();
|
||||
v[1] = limit($(this).val(),[widgetData.range.y.min,widgetData.range.y.max])
|
||||
widget.setValue(v,true,true)
|
||||
})
|
||||
|
||||
|
||||
return widget;
|
||||
|
||||
|
||||
// alternate technique to jqueryui using css transform (hw accelerated)
|
||||
// doesn't seem to increase performance (there's no transition to optimize)
|
||||
// add require( __dirname + "/js/jquery.event.drag-2.2.js") to index.html to enable
|
||||
|
||||
// widget.xy.handle.drag(function( ev, dd ){
|
||||
// var x = limit(dd.offsetX,[0,widget.xy.innerWidth()]),
|
||||
// y = limit(dd.offsetY,[0,widget.xy.innerHeight()])
|
||||
// $( this ).css({
|
||||
// 'transform': 'translate3d('+x+'px,'+y+'px,0px)'
|
||||
// });
|
||||
//
|
||||
// var v = widget.getValue([0,0,0,x,y]);
|
||||
// widget.sendValue(v);
|
||||
// widget.showValue(v)
|
||||
// widget.trigger('sync')
|
||||
// },{ relative:true });
|
||||
//
|
||||
// widgetData.range = widgetData.range || {x:{min:0,max:1},y:{min:0,max:1}}
|
||||
//
|
||||
// widget.getValue = function(css) {
|
||||
// var css = css || widget.xy.handle.css('transform').split('(')[1].split(',')
|
||||
// x = mapToScale(css[4],[0,widget.xy.innerWidth()],[widgetData.range.x.min,widgetData.range.x.max]),
|
||||
// y = mapToScale(css[5],[0,widget.xy.innerHeight()],[widgetData.range.y.min,widgetData.range.y.max],true)
|
||||
// return [x,y]
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
var 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)};
|
||||
};
|
||||
var 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 = -1;
|
||||
hsb.h *= 60;
|
||||
if (hsb.h < 0) hsb.h += 360;
|
||||
hsb.s *= 100/255;
|
||||
hsb.b *= 100/255;
|
||||
return hsb;
|
||||
};
|
||||
|
||||
|
||||
var limit = function(value,range) {
|
||||
var max = Math.max,
|
||||
min = Math.min
|
||||
|
||||
return max(min(range[0],range[1]),min(parseFloat(value),max(range[0],range[1])))
|
||||
|
||||
}
|
||||
|
||||
// map a value from a scale to another input and output must be range arrays
|
||||
var mapToScale = function(value,rangeIn,rangeOut,reverse) {
|
||||
|
||||
var max = Math.max,
|
||||
min = Math.min,
|
||||
round = Math.round
|
||||
|
||||
value = max(min(rangeIn[0],rangeIn[1]),min(parseFloat(value),max(rangeIn[0],rangeIn[1])))
|
||||
|
||||
value = (value/rangeIn[1]-rangeIn[0]) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
|
||||
|
||||
if (reverse) value = max(rangeOut[0],rangeOut[1])+min(rangeOut[0],rangeOut[1])-value
|
||||
|
||||
value = max(min(rangeOut[0],rangeOut[1]),min(value,max(rangeOut[0],rangeOut[1])))
|
||||
|
||||
value = round(value*100)/100
|
||||
|
||||
return value
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
createWidget.rgb = function(widgetData) {
|
||||
var widget = $('\
|
||||
<div class="xy-wrapper rgb-wrapper">\
|
||||
<div class="xy rgb">\
|
||||
<div class="handle"><span></span></div>\
|
||||
</div>\
|
||||
<div class="hue">\
|
||||
<div class="handle"><span></span></div>\
|
||||
</div>\
|
||||
<div class="value">\
|
||||
<input disabled value="R"></input><input disabled value="G"></input><input disabled value="B"></input>\
|
||||
<input class="r" type="number"></input><input class="g" type="number"></input><input class="b" type="number"></input>\
|
||||
</div>\
|
||||
</div>\
|
||||
');
|
||||
widget.xy = widget.find('.xy')
|
||||
widget.xy.saturation = widget.find('.rgb .handle')
|
||||
widget.xy.hue = widget.find('.hue .handle')
|
||||
widget.xy.saturation.css({top:0,left:0}).draggable({
|
||||
addClasses: false,
|
||||
scroll:false,
|
||||
containment:'parent'
|
||||
});
|
||||
widget.xy.hue.css({left:0}).draggable({
|
||||
addClasses: false,
|
||||
scroll:false,
|
||||
containment:'parent'
|
||||
});
|
||||
|
||||
widget.xy.value = {r:widget.find('input.r'),g:widget.find('input.g'),b:widget.find('input.b')}
|
||||
|
||||
|
||||
|
||||
widget.xy.hue.on('drag',function(e, data){
|
||||
var h = parseFloat(widget.xy.hue.css('left'))/widget.xy.innerWidth()*360,
|
||||
rgb = hsbToRgb({h:h,s:100,b:100}),
|
||||
v = widget.getValue();
|
||||
|
||||
widget.xy.css('background-color','rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v);
|
||||
|
||||
widget.trigger('sync')
|
||||
})
|
||||
|
||||
widget.xy.saturation.on('drag',function(e, data){
|
||||
var v = widget.getValue();
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v);
|
||||
|
||||
widget.trigger('sync')
|
||||
|
||||
})
|
||||
widget.xy.saturation.on('stop',function(e, data){
|
||||
var v = widget.getValue();
|
||||
widget.sendValue(v);
|
||||
widget.showValue(v);
|
||||
|
||||
//widget.trigger('sync')
|
||||
})
|
||||
|
||||
|
||||
widgetData.range = {r:{min:0,max:255},g:{min:0,max:255},b:{min:255}}
|
||||
|
||||
|
||||
|
||||
widget.getValue = function() {
|
||||
var s = mapToScale(widget.xy.saturation.css('left'),[0,widget.xy.innerWidth()],[0,100]),
|
||||
l = mapToScale(widget.xy.saturation.css('top'),[0,widget.xy.innerHeight()],[0,100],true),
|
||||
h = mapToScale(widget.xy.hue.css('left'),[0,widget.xy.innerWidth()],[0,360]),
|
||||
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]) {
|
||||
if (!0<=v[i]<=255) {v[i]=Math.min(255,Math.max(0,v[i]))}
|
||||
}
|
||||
|
||||
|
||||
var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
|
||||
|
||||
var left = mapToScale(hsb.s,[0,100],[0,widget.xy.innerWidth()]),
|
||||
top = mapToScale(hsb.b,[0,100],[0,widget.xy.innerHeight()],true),
|
||||
leftHue = mapToScale(hsb.h,[0,360],[0,widget.xy.innerWidth()])
|
||||
widget.xy.saturation.css({'top':top+'px','left':left+'px'})
|
||||
widget.xy.hue.css({'left':leftHue+'px'})
|
||||
|
||||
|
||||
var rgb = hsbToRgb({h:hsb.h,s:100,b:100})
|
||||
widget.xy.css('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) {
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path
|
||||
sendOsc([t,p,v]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
widget.showValue = function(v) {
|
||||
widget.xy.value.r.val(v[0])
|
||||
widget.xy.value.g.val(v[1])
|
||||
widget.xy.value.b.val(v[2])
|
||||
}
|
||||
widget.xy.value.r.change(function(){
|
||||
if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))}
|
||||
var v = widget.getValue()
|
||||
widget.setValue([$(this).val(),v[1],v[2]],true,true)
|
||||
})
|
||||
widget.xy.value.g.change(function(){
|
||||
if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))}
|
||||
var v = widget.getValue()
|
||||
widget.setValue([v[0],$(this).val(),v[2]],true,true)
|
||||
})
|
||||
widget.xy.value.b.change(function(){
|
||||
if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))}
|
||||
var v = widget.getValue()
|
||||
widget.setValue([v[0],v[1],$(this).val()],true,true)
|
||||
})
|
||||
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
createWidget.fader = function(widgetData,parent) {
|
||||
var widget = $('\
|
||||
<div class="fader-wrapper-outer">\
|
||||
<div class="fader-wrapper">\
|
||||
<div class="fader locked"></div>\
|
||||
</div>\
|
||||
<input value="0"></input>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
widget.fader = widget.find('.fader')
|
||||
widget.lock = false
|
||||
var range = (widgetData.range=='db'||!widgetData.range)?{'min': -70,'20%': -40,'45%': -20,'60%': -10,'max': 6}:widgetData.range;
|
||||
|
||||
|
||||
var pips = function() {
|
||||
if (widgetData.range=='db'||!widgetData.range) {
|
||||
return [-70,-60,-50,-40,-30,-20,-10,-6,-3,0,3,6];
|
||||
} else {
|
||||
var autopips = [];
|
||||
var i=0;
|
||||
for (key in range) {
|
||||
autopips[i]=range[key];
|
||||
i=i+1;
|
||||
}
|
||||
if (range.min<0 && 0<range.max){
|
||||
autopips.push(0);
|
||||
}
|
||||
//autopips.push((range.max-range.min)/2);
|
||||
//autopips.push((range.max-range.min)/4);
|
||||
//autopips.push((range.max-range.min)*.75);
|
||||
return autopips;
|
||||
}
|
||||
}
|
||||
var pips = pips();
|
||||
|
||||
var orientation = parent.hasClass('stack')?'horizontal':'vertical',
|
||||
direction = parent.hasClass('stack')?'ltr':'rtl',
|
||||
density = parent.hasClass('stack')?'2':'1';
|
||||
|
||||
widget.fader
|
||||
.noUiSlider({
|
||||
orientation:orientation,
|
||||
direction: direction,
|
||||
behaviour: "drag",
|
||||
connect: "lower",
|
||||
//animate:false,
|
||||
start: 0,
|
||||
range: range
|
||||
})
|
||||
.noUiSlider_pips({
|
||||
mode: 'values',
|
||||
density: density,
|
||||
filter:function(v,t){return v==0?1:2;},
|
||||
values: pips,
|
||||
format: wNumb({})
|
||||
})
|
||||
.Link('lower').to(widget.find('input'))
|
||||
.on('slide',function(){
|
||||
|
||||
if (!widget.lock) {
|
||||
widget.sendValue();
|
||||
}
|
||||
})
|
||||
.on('set',function(){
|
||||
if (!widget.lock) {
|
||||
widget.sendValue();
|
||||
widget.trigger('sync')
|
||||
}
|
||||
});
|
||||
|
||||
widget.getValue = function(v,send){
|
||||
return widget.fader.val();
|
||||
}
|
||||
|
||||
widget.setValue = function(v,send,sync){
|
||||
if (!send) {widget.lock=true}
|
||||
widget.fader.val(v);
|
||||
if (sync) widget.trigger('sync')
|
||||
widget.lock=false;
|
||||
|
||||
}
|
||||
widget.sendValue = function(){
|
||||
var t = widgetData.target,
|
||||
p = widgetData.path,
|
||||
v = widgetData.scale1?
|
||||
Math.max(0,Math.round(10000*((Math.abs(range.min)/(range.max-range.min)) + widget.fader.val()/(range.max-range.min)))/10000)
|
||||
: widget.fader.val();
|
||||
sendOsc([t,p,parseFloat(v)]);
|
||||
}
|
||||
|
||||
return widget
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue