clean and split code

This commit is contained in:
bordun 2016-02-26 13:05:23 +01:00
parent 4648f6857a
commit 148dd7e8ca
23 changed files with 580 additions and 542 deletions

45
app/browser/js/app.js Normal file
View file

@ -0,0 +1,45 @@
// Global defs
WIDGETS = {} //__widgets__
WIDGETS_LINKED = {} //__widgetdId__
WIDGETS_ID_BY_PATH = {} // __widgetsLinks__
SESSION = [] // session
MISC = {
iterators: {
widget:{},
tab:{}
}
}
// jquery
window.$ = window.jQuery = require('./jquery/jquery.min')
// third-party js libraries
require('./jquery/jquery.resizable-draggable')
require('./jquery/jquery.sortable')
require('./jquery/jquery.drag')
require('./jquery/jquery.resize')
require('./jquery/jquery.fake-input')
require('./app/utils')
var callbacks = require('./app/callbacks')
var bindCallback = function(i) {
IPC.on(i,function(event,data){
callbacks[i](event,data)
})
}
for (i in callbacks) {
bindCallback(i)
}
IPC.send('ready')

View file

@ -1,5 +0,0 @@
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('./init.js') // ...

View file

@ -1,77 +1,83 @@
var init = require('./init'),
utils = require('./utils')
ipc.on('receiveOsc',function(event,data){
var data = data || event
module.exports = {
// fetch id
var path = data.path
var id = __widgetsIds__[path]
receiveOsc: function(event,data){
var data = data || event
// update
if (__widgets__[id]!=undefined) {
for (i in __widgets__[id]){
__widgets__[id][i].setValue(data.args,false,false)
// fetch id
var path = data.path
var id = WIDGETS_ID_BY_PATH[path]
// update
if (WIDGETS[id]!=undefined) {
for (i in WIDGETS[id]){
WIDGETS[id][i].setValue(data.args,false,false)
}
}
}
})
},
ipc.on('stateLoad',function(event,data){
var data = data || event
stateSet(data,true)
stateQuickSave(data)
})
stateLoad: function(event,data){
var data = data || event
utils.stateSet(data,true)
utils.stateQuickSave(data)
},
ipc.on('sessionList',function(event,data){
var data = data || event
$('#lobby').append('\
<div class="main">\
<div class="header">\
Session selection\
</div>\
<div class="list"></div>\
</div>')
sessionList: function(event,data){
var data = data || event
$('#lobby').append('\
<div class="main">\
<div class="header">\
Session selection\
</div>\
<div class="list"></div>\
</div>')
for (i in data) {
$('#lobby .list').append('<li><a class="btn load" data-session="'+data[i]+'">'+data[i]+'<span>'+utils.icon('remove')+'</span></a></li>')
}
$('#lobby .list').append('<a class="btn browse">...</a>')
$('#lobby .list').append('<a class="btn new">New</a>')
$('#lobby .load').click(function(e){
e.stopPropagation()
IPC.send('sessionOpen',{path:$(this).data('session')})
})
$('#lobby a span').click(function(e){
e.stopPropagation()
IPC.send('sessionRemoveFromHistory',$(this).parent().data('session'))
$(this).parents('li').hide()
})
$('#lobby .browse').click(function(e){
e.stopPropagation()
utils.sessionBrowse()
})
$('#lobby .new').click(function(e){
e.stopPropagation()
$('#lobby').remove()
setTimeout(function(){
init([{}],function(){$('#open-toggle, .enable-editor, .editor-root').click()})
},25)
})
},
sessionOpen: function(event,data){
var data = data || event
var session = JSON.parse(data)
for (i in data) {
$('#lobby .list').append('<li><a class="btn load" data-session="'+data[i]+'">'+data[i]+'<span>'+icon('remove')+'</span></a></li>')
}
$('#lobby .list').append('<a class="btn browse">...</a>')
$('#lobby .list').append('<a class="btn new">New</a>')
$('#lobby .load').click(function(e){
e.stopPropagation()
ipc.send('sessionOpen',{path:$(this).data('session')})
})
$('#lobby a span').click(function(e){
e.stopPropagation()
ipc.send('sessionRemoveFromHistory',$(this).parent().data('session'))
$(this).parents('li').hide()
})
$('#lobby .browse').click(function(e){
e.stopPropagation()
sessionBrowse()
})
$('#lobby .new').click(function(e){
e.stopPropagation()
$('#lobby').remove()
$('#container').empty().append('<div id="loading"><div class="spinner"></div></div>')
setTimeout(function(){
init([{}],function(){$('#open-toggle, .enable-editor, .editor-root').click()})
init(session,function(){$('#loading').hide()})
},25)
})
})
ipc.on('sessionOpen',function(event,data){
var data = data || event
var session = JSON.parse(data)
},
$('#lobby').remove()
$('#container').empty().append('<div id="loading"><div class="spinner"></div></div>')
setTimeout(function(){
init(session,function(){$('#loading').hide()})
},25)
error: function(event,data){
var data = data || event
})
createPopup(utils.icon('warning')+'&nbsp;'+data.title,data.text)
}
ipc.on('error',function(event,data){
var data = data || event
createPopup(icon('warning')+'&nbsp;'+data.title,data.text)
})
}

View file

@ -1,3 +1,7 @@
var widgets = require('./widgets'),
widgetOptions = widgets.widgetOptions,
parsewidgets = require('./parser').widgets
function getdata(obj){
var path = []
@ -16,7 +20,7 @@ function getdata(obj){
path.splice(0,1)
for (var i=0,obj=session, path=path, len=path.length; i<len; i++){
for (var i=0,obj=SESSION, path=path, len=path.length; i<len; i++){
obj = obj[path[i]];
};
return obj;
@ -227,7 +231,6 @@ module.exports.enable = function(){
}
$('.editor-container').html(form)
scrolls()
})
@ -278,7 +281,7 @@ module.exports.enable = function(){
var state = stateGet()
init(session,function(){
init(SESSION,function(){
stateSet(state,false)
enableEditor()
for (i in ontab) {
@ -387,13 +390,13 @@ module.exports.enable = function(){
}
$('.editor-container').html(form)
scrolls()
})
$('.editor-root').removeClass('disabled').on('click.editor',function(e){
e.preventDefault()
e.stopPropagation()
var data = session,
var data = SESSION,
form = $('<div class="form"></div>'),
container = $('#container')
@ -413,7 +416,7 @@ module.exports.enable = function(){
var state = stateGet()
init(session,function(){
init(SESSION,function(){
stateSet(state,false)
enableEditor()
for (i in ontab) {

View file

@ -1,222 +1,17 @@
var editor = require('./editor'),
enableEditor = editor.enable,
disableEditor = editor.disable
var parsetabs = require('./parser').tabs,
ui = require('./ui'),
sync = require('./widgets').sync
init = function(session,callback) {
module.exports = function(session,callback) {
$('#container').empty()
parsetabs(session,$('#container'),true)
// create sidepanel
ui()
$('#sidepanel').append(createMenu([
{
label:'Fullscreen (F11)',
click:toggleFullscreen,
icon:'tv'
},
{
html: `
<div>
<div class="title"><i class="fa fa-sliders"></i>&nbsp;Snapshot</div>
<div class="actions">
<a class="btn" data-action="stateQuickSave">Store</a>
<a class="btn disabled" data-action="stateQuickLoad">Recall</a>
<a class="btn" data-action="stateSend">Send</a>
</div>
<div class="actions">
<a class="btn" data-action="stateLoad">Import</a>
<a class="btn" data-action="stateSave">Export</a>
</div>
</div>
`
},
{
html:`<div class="editor">
<div class="title"><i class="fa fa-edit"></i>&nbsp;Session editor</div>
<div class="actions">
<a class="enable-editor btn" data-action="enableEditor">On</a>
<a class="disable-editor btn on" data-action="disableEditor">Off</a>
<a class="editor-root btn disabled">Root</a>
</div>
<div class="actions">
<a class="editor-import btn" data-action="sessionBrowse">Load</a>
<a class="editor-export btn" data-action="sessionSave">Save</a>
</div>
<div class="editor-container"></div>
</div>`,
}
]))
disableEditor()
$('[data-action]').each(function(){
$(this).click(function(){
eval($(this).attr('data-action')+'()')
})
})
// MASTER DRAGGING (while shift key pressed)
var target
$(document).keydown(function (e) {
if (e.keyCode == 16) {
$('body').on('drag',function(ev,dd){
dd.target = dd.originalEvent.changedTouches?
document.elementFromPoint(dd.originalEvent.changedTouches[0].clientX, dd.originalEvent.changedTouches[0].clientY)
:dd.target
$(dd.target).trigger('draginit',[dd])
target = dd.target
})
}
});
$(document).keyup(function (e) {
if (e.keyCode == 16) {
$('body').off('drag')
}
});
sidepanel = function() {
$(`<a id="open-toggle">${icon('navicon')}</a>`).appendTo('#container').click(function(){
$('#open-toggle, #sidepanel, #container').toggleClass('sidepanel-open')
})
// in case where are hot loading a session
if ($('#sidepanel').hasClass('sidepanel-open')) {
$('#open-toggle, #container').addClass('sidepanel-open')
}
}
sidepanel()
// Widget Synchronization
sync = function() {
// Widget that share the same id will update each other
// without sending any extra osc message
$.each(__widgets__,function(i,widget) {
if (widget.length>1) {
var closureSync = function(x) {
return function() {
var v = widget[x].getValue()
for (k=0;k<widget.length;k++) {
if (x!=k) {
if (document.body.contains(widget[k][0].parentNode))
widget[k].setValue(v,false,false)
}
}
}
}
for (j in widget) {
widget[j].off('sync.id').on('sync.id',closureSync(j))
}
}
})
// widgets that share the same linkId will update each other.
// Updated widgets will send osc messages normally
$.each(__widgetsLinks__,function(i,widget) {
if (widget.length>1) {
var closureSync = function(x) {
return function() {
var v = widget[x].getValue()
for (k=0;k<widget.length;k++) {
if (x!=k) {
if (document.body.contains(widget[k][0].parentNode))
widget[k].setValue(v,true,false)
}
}
}
}
for (j in widget) {
widget[j].off('sync.link').on('sync.link',closureSync(j))
}
}
})
}
sync()
// Tabs...
tabs = function() {
$('.tablist a').click(function(){
var id = $(this).data('tab')
$(id).siblings('.on').removeClass('on')
$(id).addClass('on')
$(this).parents('ul').find('.on').removeClass('on')
$(this).addClass('on');$(this).parent().addClass('on')
})
}
tabs()
// horizontal scrolling & zoom with mousewheel
// if shift is pressed (native), or if there is no vertical scrollbar,
// or if mouse is on h-scrollbar
var scrollbarHeight = 20
scrolls = function(){
if (webFrame) {
$('html').on('mousewheel.zoom',function(e) {
// console.log(e)
if (e.ctrlKey) {
e.preventDefault()
if (e.originalEvent.deltaY==0) return
var d = -e.originalEvent.deltaY/Math.abs(e.originalEvent.deltaY)/20,
s = d+webFrame.getZoomFactor()
webFrame.setZoomFactor(s)
}
})
$(document).on('keydown.resetzoom', function(e){
if (e.keyCode==96||e.keyCode==48) webFrame.setZoomFactor(1)
})
}
$('.tab').on('mousewheel.scroll',function(e) {
if (!e.ctrlKey) {
if ($(this).height()>$(this).get(0).scrollHeight) {
var scroll = e.originalEvent.deltaY || e.originalEvent.deltaX
$(this).scrollLeft($(this).scrollLeft()+scroll)
e.preventDefault()
} else if (e.pageY>window.innerHeight-scrollbarHeight) {
$(this).scrollLeft($(this).scrollLeft()+e.originalEvent.deltaY)
e.preventDefault()
}
}
})
$('.panel').on('mousewheel.scroll',function(e) {
if (!e.ctrlKey) {
var h = $(this).parent().innerHeight()-scrollbarHeight-$(this).parents('.tab').length*5
if ($(this).get(0).scrollHeight+scrollbarHeight == $(this).parent().height()) {
var scroll = e.originalEvent.deltaY || e.originalEvent.deltaX
$(this).scrollLeft($(this).scrollLeft()+scroll)
e.preventDefault()
}
}
})
}
scrolls()
if (callback) callback()
}

View file

@ -1,34 +1,28 @@
__widgets__ = {}
__widgetsLinks__ = {}
__widgetsIds__ = {}
var widgets = require('./widgets'),
widgetOptions = widgets.widgetOptions,
createWidget = widgets.createWidget
widgetIterator = {}
tabIterator = {}
getIterator = function(type,tab){
var iterator = tab?tabIterator:widgetIterator
if (iterator[type]==undefined) iterator[type] = 0
iterator[type] += 1
return iterator[type]
var getIterator = function(id,type){
var iterator = MISC.iterators[type]
if (iterator[id]==undefined) iterator[id] = 0
iterator[id] += 1
return iterator[id]
}
hashCode = function(s){
var hashCode = function(s){
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
}
// Global session variable
session = []
parsetabs = function(tabs,parent,main){
module.exports.tabs = function(data,parent,main){
if (main) {
__widgets__ = {}
__widgetsLinks__ = {}
__widgetsIds__ = {}
// Reset Globals
WIDGETS = {}
WIDGETS_LINKED = {}
WIDGETS_ID_BY_PATH = {}
SESSION = data
tabIterator = {}
session = tabs
MISC.iterators.tab = {}
}
var main = main?'main ':'',
@ -40,13 +34,13 @@ parsetabs = function(tabs,parent,main){
parent.append(nav).append(content)
for (i in tabs) {
var tabData = tabs[i]
for (i in data) {
var tabData = data[i]
var label = tabData.label||tabData.id||'Unnamed',
hash = hashCode(label),
id = 'tab_'+hash+'_'+getIterator('tab'+hash,true),
id = 'tab_'+hash+'_'+getIterator('tab'+hash,'tab'),
on = i==0?'on':''
tabData.label = label
@ -61,9 +55,9 @@ parsetabs = function(tabs,parent,main){
if (tabData.stretch) tabContent.addClass('stretch')
if (tabData.tabs) {
parsetabs(tabData.tabs,parent=tabContent)
module.exports.tabs(tabData.tabs,parent=tabContent)
} else if (tabData.widgets) {
parsewidgets(tabData.widgets,tabContent)
module.exports.widgets(tabData.widgets,tabContent)
}
content.append(tabContent)
@ -73,10 +67,10 @@ parsetabs = function(tabs,parent,main){
parsewidgets = function(widgets,parent) {
module.exports.widgets = function(data,parent) {
for (i in widgets) {
var widgetData = widgets[i]
for (i in data) {
var widgetData = data[i]
widgetData.type = widgetData.type || 'fader'
@ -86,7 +80,7 @@ parsewidgets = function(widgets,parent) {
if (i.indexOf('separator')==-1 && widgetData[i]===undefined) widgetData[i] = tmpWidgetOptions[widgetData.type][i]
}
widgetData.id = widgetData.id=='auto'?widgetData.type+'_'+getIterator(widgetData.type):widgetData.id.replace(' ','_')
widgetData.id = widgetData.id=='auto'?widgetData.type+'_'+getIterator(widgetData.type,'widget'):widgetData.id.replace(' ','_')
widgetData.label = widgetData.label=='auto'?widgetData.id:widgetData.label
widgetData.path = widgetData.path=='auto'?'/' + widgetData.id:widgetData.path
widgetData.target = widgetData.target?(Array.isArray(widgetData.target)?widgetData.target:[widgetData.target]):false
@ -139,22 +133,23 @@ parsewidgets = function(widgets,parent) {
widgetContainer.append(widgetInner)
// store widget reference for cross widget sync
if (__widgets__[widgetData.id]==undefined) __widgets__[widgetData.id] = []
__widgets__[widgetData.id].push(widgetInner)
if (WIDGETS[widgetData.id]==undefined) WIDGETS[widgetData.id] = []
WIDGETS[widgetData.id].push(widgetInner)
// store widget with linkId for widgte linking
if (widgetData.linkId && widgetData.linkId.length) {
if (__widgetsLinks__[widgetData.linkId]==undefined) __widgetsLinks__[widgetData.linkId] = []
__widgetsLinks__[widgetData.linkId].push(widgetInner)
if (WIDGETS_LINKED[widgetData.linkId]==undefined) WIDGETS_LINKED[widgetData.linkId] = []
WIDGETS_LINKED[widgetData.linkId].push(widgetInner)
}
// store path vs widget id for faster cross-app sync
__widgetsIds__[widgetData.path] = widgetData.id
WIDGETS_ID_BY_PATH[widgetData.path] = widgetData.id
parent.append(widgetContainer)
}
if (widgets && widgets.length==1) return widgetContainer
// Editor needs to get the container object
if (data && data.length==1) return widgetContainer
}

135
app/browser/js/app/ui.js Normal file
View file

@ -0,0 +1,135 @@
var editor = require('./editor'),
enableEditor = editor.enable,
disableEditor = editor.disable,
utils = require('./utils')
var sidepanel = function() {
$('#sidepanel').append(utils.createMenu([
{
label:'Fullscreen (F11)',
click:utils.toggleFullscreen,
icon:'tv'
},
{
html: `
<div>
<div class="title"><i class="fa fa-sliders"></i>&nbsp;Snapshot</div>
<div class="actions">
<a class="btn" data-action="utils.stateQuickSave">Store</a>
<a class="btn disabled quickload" data-action="utils.stateQuickLoad">Recall</a>
<a class="btn" data-action="utils.stateSend">Send</a>
</div>
<div class="actions">
<a class="btn" data-action="utils.stateLoad">Import</a>
<a class="btn" data-action="utils.stateSave">Export</a>
</div>
</div>
`
},
{
html:`<div class="editor">
<div class="title"><i class="fa fa-edit"></i>&nbsp;Session editor</div>
<div class="actions">
<a class="enable-editor btn" data-action="utils.enableEditor">On</a>
<a class="disable-editor btn on" data-action="utils.disableEditor">Off</a>
<a class="editor-root btn disabled">Root</a>
</div>
<div class="actions">
<a class="editor-import btn" data-action="utils.sessionBrowse">Load</a>
<a class="editor-export btn" data-action="utils.sessionSave">Save</a>
</div>
<div class="editor-container"></div>
</div>`,
}
]))
disableEditor()
$('[data-action]').each(function(){
$(this).click(function(){
eval($(this).attr('data-action')+'()')
})
})
$(`<a id="open-toggle">${utils.icon('navicon')}</a>`).appendTo('#container').click(function(){
$('#open-toggle, #sidepanel, #container').toggleClass('sidepanel-open')
})
// in case where are hot loading a session
if ($('#sidepanel').hasClass('sidepanel-open')) {
$('#open-toggle, #container').addClass('sidepanel-open')
}
}
// Tabs...
var tabs = function() {
$('.tablist a').click(function(){
var id = $(this).data('tab')
$(id).siblings('.on').removeClass('on')
$(id).addClass('on')
$(this).parents('ul').find('.on').removeClass('on')
$(this).addClass('on');$(this).parent().addClass('on')
})
}
// horizontal scrolling & zoom with mousewheel
// if shift is pressed (native), or if there is no vertical scrollbar,
// or if mouse is on h-scrollbar
var scrollbarHeight = 20
var scrolls = function(){
if (WEBFRAME) {
$('html').on('mousewheel.zoom',function(e) {
// console.log(e)
if (e.ctrlKey) {
e.preventDefault()
if (e.originalEvent.deltaY==0) return
var d = -e.originalEvent.deltaY/Math.abs(e.originalEvent.deltaY)/20,
s = d+WEBFRAME.getZoomFactor()
WEBFRAME.setZoomFactor(s)
}
})
$(document).on('keydown.resetzoom', function(e){
if (e.keyCode==96||e.keyCode==48) WEBFRAME.setZoomFactor(1)
})
}
$('.tab').on('mousewheel.scroll',function(e) {
if (!e.ctrlKey) {
if ($(this).height()>$(this).get(0).scrollHeight) {
var scroll = e.originalEvent.deltaY || e.originalEvent.deltaX
$(this).scrollLeft($(this).scrollLeft()+scroll)
e.preventDefault()
} else if (e.pageY>window.innerHeight-scrollbarHeight) {
$(this).scrollLeft($(this).scrollLeft()+e.originalEvent.deltaY)
e.preventDefault()
}
}
})
$('.panel').on('mousewheel.scroll',function(e) {
if (!e.ctrlKey) {
var h = $(this).parent().innerHeight()-scrollbarHeight-$(this).parents('.tab').length*5
if ($(this).get(0).scrollHeight+scrollbarHeight == $(this).parent().height()) {
var scroll = e.originalEvent.deltaY || e.originalEvent.deltaX
$(this).scrollLeft($(this).scrollLeft()+scroll)
e.preventDefault()
}
}
})
}
module.exports = function(){
sidepanel()
tabs()
scrolls()
}

View file

@ -1,190 +1,197 @@
sendOsc = function(data){
ipc.send('sendOsc', data)
}
module.exports = {
var state
stateQuickSave = function(preset){
if (preset) {
state = preset
} else {
state = stateGet()
}
$('[data-action="stateQuickLoad"]').removeClass('disabled')
}
stateQuickLoad = function(){
stateSet(state,true)
}
stateSave = function() {
state = stateGet()
if (webFrame) {
ipc.send('stateSave',state)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.preset"></a>')
var blob = new Blob([state],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
}
stateGet = function (){
var data = []
$.each(__widgets__,function(i,widget) {
var v = widget[widget.length-1].getValue()
if (v!=undefined) data.push(i+' '+v)
})
return data.join('\n')
}
stateLoad = function() {
if (webFrame) {
ipc.send('stateLoad')
} else {
var prompt = $('<input type="file" accept=".preset"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var preset = e.target.result
stateSet(preset,true)
laststate = preset
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
}
stateSend = function(){
var data = stateGet()
stateSet(data,true)
}
stateSet = function(preset,send){
$.each(preset.split('\n'),function(i,d) {
var data = d.split(' ')
setTimeout(function(){
if (__widgets__[data[0]]!=undefined) {
__widgets__[data[0]][__widgets__[data[0]].length-1].setValue(data[1].split(','),send,true)
}
},i)
})
}
toggleFullscreen = function(){
if (webFrame) {
ipc.send('fullscreen')
} else {
var isInFullScreen = document.webkitIsFullScreen
if (isInFullScreen) {
document.webkitExitFullscreen()
stateQuickSave: function(preset){
if (preset) {
STATE = preset
} else {
document.documentElement.webkitRequestFullScreen()
STATE = module.exports.stateGet()
}
}
}
$('.quickload').removeClass('disabled')
},
sessionBrowse = function(){
stateQuickLoad: function(){
module.exports.stateSet(STATE,true)
},
if (webFrame) {
ipc.send('sessionBrowse')
} else {
var prompt = $('<input type="file" accept=".js"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var session = e.target.result
ipc.send('sessionOpen',{file:session})
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
}
sessionSave = function() {
var sessionfile = JSON.stringify(session,null,' ')
if (webFrame) {
ipc.send('sessionSave',sessionfile)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.js"></a>')
var blob = new Blob([sessionfile],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
}
icon = function(i) {
return `<i class="fa fa-fw fa-${i}"></i>`
}
createMenu = function(template) {
var menu = $('<ul id="options"></ul>')
var closureClick = function(item) {
return function() {
item.click()
return false
}
}
for (i in template) {
var item = template[i],
label = item.label || 'undefined',
classname = item.class || '',
wrapper = $('<li></li>'),
html
if (!item.html) {
html = $(`<a class="${classname} btn">${label}</a>`)
stateSave: function() {
state = module.exports.stateGet()
if (WEBFRAME) {
IPC.send('stateSave',STATE)
} else {
html = $(item.html)
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.preset"></a>')
var blob = new Blob([STATE],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
if (item.icon) html.prepend(icon(item.icon)+'&nbsp;')
},
if (item.click) html.on('click',closureClick(item))
stateGet: function (){
var data = []
$.each(WIDGETS,function(i,widget) {
var v = widget[widget.length-1].getValue()
if (v!=undefined) data.push(i+' '+v)
})
return data.join('\n')
},
wrapper.append(html)
menu.append(wrapper)
stateLoad: function() {
if (WEBFRAME) {
IPC.send('stateLoad')
} else {
var prompt = $('<input type="file" accept=".preset"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var preset = e.target.result
stateSet(preset,true)
laststate = preset
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
},
stateSend: function(){
var data = module.exports.stateGet()
module.exports.stateSet(data,true)
},
stateSet: function(preset,send){
$.each(preset.split('\n'),function(i,d) {
var data = d.split(' ')
setTimeout(function(){
if (WIDGETS[data[0]]!=undefined) {
WIDGETS[data[0]][WIDGETS[data[0]].length-1].setValue(data[1].split(','),send,true)
}
},i)
})
},
toggleFullscreen: function(){
if (WEBFRAME) {
IPC.send('fullscreen')
} else {
var isInFullScreen = document.webkitIsFullScreen
if (isInFullScreen) {
document.webkitExitFullscreen()
} else {
document.documentElement.webkitRequestFullScreen()
}
}
},
sessionBrowse: function(){
if (WEBFRAME) {
IPC.send('sessionBrowse')
} else {
var prompt = $('<input type="file" accept=".js"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var session = e.target.result
IPC.send('sessionOpen',{file:session})
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
},
sessionSave: function() {
var sessionfile = JSON.stringify(SESSION,null,' ')
if (WEBFRAME) {
IPC.send('sessionSave',sessionfile)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.js"></a>')
var blob = new Blob([sessionfile],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
},
createMenu: function(template) {
var menu = $('<ul id="options"></ul>')
var closureClick = function(item) {
return function() {
item.click()
return false
}
}
for (i in template) {
var item = template[i],
label = item.label || 'undefined',
classname = item.class || '',
wrapper = $('<li></li>'),
html
if (!item.html) {
html = $(`<a class="${classname} btn">${label}</a>`)
} else {
html = $(item.html)
}
if (item.icon) html.prepend(module.exports.icon(item.icon)+'&nbsp;')
if (item.click) html.on('click',closureClick(item))
wrapper.append(html)
menu.append(wrapper)
}
return menu
},
createPopup: function(title,content) {
var popup = $(`
<div class="popup">
<div class="popup-wrapper">
<div class="popup-title">${title}<span class="closer">${module.exports.icon('remove')}</span></div>
<div class="popup-content"></div>
</div>
</div>`),
closer = popup.find('.popup-title .closer')
closer.click(function(){
popup.close()
})
popup.close = function(){
$(document).unbind('keydown.popup')
popup.remove()
}
popup.find('.popup-content').append(content)
$('body').append(popup)
$(document).on('keydown.popup', function(e){
if (e.keyCode==27) popup.close()
})
return popup
},
icon: function(i) {
return `<i class="fa fa-fw fa-${i}"></i>`
}
return menu
}
createPopup = function(title,content) {
var popup = $(`
<div class="popup">
<div class="popup-wrapper">
<div class="popup-title">${title}<span class="closer">${icon('remove')}</span></div>
<div class="popup-content"></div>
</div>
</div>`),
closer = popup.find('.popup-title .closer')
closer.click(function(){
popup.close()
})
popup.close = function(){
$(document).unbind('keydown.popup')
popup.remove()
}
popup.find('.popup-content').append(content)
$('body').append(popup)
$(document).on('keydown.popup', function(e){
if (e.keyCode==27) popup.close()
})
return popup
}

View file

@ -9,7 +9,7 @@ var strip = require('./widgets/strip'),
swiitch = require('./widgets/switch'),
push = require('./widgets/push')
widgetOptions = {
module.exports.widgetOptions = {
strip: strip.options,
panel: panel.options,
led: led.options,
@ -22,7 +22,7 @@ widgetOptions = {
push: push.options
}
createWidget = {
module.exports.createWidget = {
strip: strip.create,
panel: panel.create,
led: led.create,
@ -34,3 +34,46 @@ createWidget = {
switch: swiitch.create,
push: push.create
}
module.exports.sync = function() {
// Widget that share the same id will update each other
// without sending any extra osc message
$.each(WIDGETS,function(i,widget) {
if (widget.length>1) {
var closureSync = function(x) {
return function() {
var v = widget[x].getValue()
for (k=0;k<widget.length;k++) {
if (x!=k) {
if (document.body.contains(widget[k][0].parentNode))
widget[k].setValue(v,false,false)
}
}
}
}
for (j in widget) {
widget[j].off('sync.id').on('sync.id',closureSync(j))
}
}
})
// widgets that share the same linkId will update each other.
// Updated widgets will send osc messages normally
$.each(WIDGETS_LINKED,function(i,widget) {
if (widget.length>1) {
var closureSync = function(x) {
return function() {
var v = widget[x].getValue()
for (k=0;k<widget.length;k++) {
if (x!=k) {
if (document.body.contains(widget[k][0].parentNode))
widget[k].setValue(v,true,false)
}
}
}
}
for (j in widget) {
widget[j].off('sync.link').on('sync.link',closureSync(j))
}
}
})
}

View file

@ -1,7 +1,8 @@
var utils = require('./utils'),
sizeToAngle = utils.sizeToAngle,
clip = utils.clip,
mapToScale = utils.mapToScale
mapToScale = utils.mapToScale,
sendOsc = utils.sendOsc
module.exports.options = {
type:'fader',

View file

@ -1,6 +1,7 @@
var utils = require('./utils'),
clip = utils.clip,
mapToScale = utils.mapToScale
mapToScale = utils.mapToScale,
sendOsc = utils.sendOsc
module.exports.options = {
type:'knob',

View file

@ -18,6 +18,11 @@ module.exports.options = {
tabs:[]
}
module.exports.create = function(widgetData,container) {
var parser = require('../parser'),
parsewidgets = parser.widgets,
parsetabs = parser.tabs
var widget = $(`
<div class="panel">
</div>

View file

@ -1,3 +1,5 @@
var sendOsc = require('./utils').sendOsc
module.exports.options = {
type:'push',
id:'auto',

View file

@ -2,7 +2,8 @@ var utils = require('./utils'),
clip = utils.clip,
mapToScale = utils.mapToScale,
hsbToRgb = utils.hsbToRgb,
rgbToHsb = utils.rgbToHsb
rgbToHsb = utils.rgbToHsb,
sendOsc = utils.sendOsc
module.exports.options = {
type:'rgb',

View file

@ -1,3 +1,4 @@
module.exports.options = {
type:'strip',
id:'auto',
@ -17,6 +18,9 @@ module.exports.options = {
widgets:[]
}
module.exports.create = function(widgetData,container) {
var parsewidgets = require('../parser').widgets
var widget = $(`
<div class="strip">
</div>

View file

@ -1,3 +1,5 @@
var sendOsc = require('./utils').sendOsc
module.exports.options = {
type:'switch',
id:'auto',

View file

@ -1,3 +1,5 @@
var sendOsc = require('./utils').sendOsc
module.exports.options = {
type:'toggle',
id:'auto',

View file

@ -1,4 +1,9 @@
module.exports = {
sendOsc: function(data){
IPC.send('sendOsc', data)
},
clip: function(value,range) {
var value = parseFloat(value)

View file

@ -1,6 +1,7 @@
var utils = require('./utils'),
clip = utils.clip,
mapToScale = utils.mapToScale
mapToScale = utils.mapToScale,
sendOsc = utils.sendOsc
module.exports.options = {
type:'xy',

View file

@ -1,27 +1,11 @@
webFrame = false
WEBFRAME = false
// mainProcess & renderProcess communication engine
// electron's ipc module is not available here, we use socket.io as a replacement
socket = require('socket.io-client')
var socket = require('socket.io-client')
ipc=socket.connect();
ipc.send = ipc.emit
IPC = socket.connect()
IPC.send = IPC.emit
// jquery
window.$ = window.jQuery = require('./jquery/jquery.min.js')
// third-party js libraries
require('./jquery/jquery.resizable-draggable.js')
require('./jquery/jquery.sortable.js')
require('./jquery/jquery.drag.js')
require('./jquery/jquery.resize.js')
require('./jquery/jquery.fake-input.js')
// main js
require('./app/app.js')
ipc.send('ready')
require('./app')

View file

@ -1,20 +1,6 @@
webFrame = require('web-frame')
WEBFRAME = require('web-frame')
// mainProcess & renderProcess communication engine
ipc = require('ipc-renderer')
IPC = require('ipc-renderer')
// jquery
window.$ = window.jQuery = require('./jquery/jquery.min.js')
// third-party js libraries
require('./jquery/jquery.resizable-draggable.js')
require('./jquery/jquery.sortable.js')
require('./jquery/jquery.drag.js')
require('./jquery/jquery.resize.js')
require('./jquery/jquery.fake-input.js')
// main js
require('./app/app.js')
ipc.send('ready')
require('./app')

View file

@ -124,6 +124,26 @@
}
}
// MASTER DRAGGING (while shift key pressed)
var target
$(document).keydown(function (e) {
if (e.keyCode == 16) {
$('body').on('drag',function(ev,dd){
dd.target = dd.originalEvent.changedTouches?
document.elementFromPoint(dd.originalEvent.changedTouches[0].clientX, dd.originalEvent.changedTouches[0].clientY)
:dd.target
$(dd.target).trigger('draginit',[dd])
target = dd.target
})
}
});
$(document).keyup(function (e) {
if (e.keyCode == 16) {
$('body').off('drag')
}
});
})(jQuery)

View file

@ -6,7 +6,7 @@ module.exports = function(settings,app,ipc,browserWindow) {
title:settings.read('appName'),
autoHideMenuBar:true,
backgroundColor:'#1a1d22',
show:false
// show:false
})
window.loadURL('file://' + __dirname + '/../browser/index.html')