- session file format modifier : json or self-invoking function

- session history handling modified, session opening function moved to utils
This commit is contained in:
jean-emmanuel 2015-09-17 18:06:50 +02:00 • committed by bordun
parent 60967e0e89
commit 84e7303bb7
10 changed files with 143 additions and 131 deletions

View file

@ -2,10 +2,10 @@
### Session file structure
A valid session file is just a javascript file that defines the global variable `TABS` as an array of tab objects :
A valid session file is a javascript file that returns, when eval'd, an array of tab objects. It can be written as a standard json file (except for double quotes around names which are not required) :
```
TABS = [
[
{
id:"my_tab_id", // [string] optional, default unique tab id
label:"My tab", // [string] default to id
@ -15,55 +15,84 @@ TABS = [
// A tab cannot contain widgets and tabs simultaneously
},
{
etc...
// etc
}
]
```
It can also be a self invoking function that returns an array of objects :
```
(function(){
var tabs = []
for (for i in [0,1,2,3]) {
tabs.push({
id:'tab'+i,
widgets: [
{
id:'tab'+i+'fader',
type:'fader'
}
// etc
]
})
}
}()
```
### Widgets
```
{
id:"my_widget_id", // [string] widgets with same id will be synchronized
label:"My widget", // [string] default to id
target:false, // [string] List of target hosts (ip:port pairs), separated by spaces
path:false, // [string] osc path, default to '/widget_id'
widget_option:value // each widget type has specific options
}
```
#### Strip
```
horizontal:false, // [bool] set to true to display widgets horizontally
widgets: [] // [array] of widget objects
horizontal:false, // [bool] set to true to display widgets horizontally
widgets: [] // [array] of widget objects
```
#### Fader
```
horizontal:false, // [bool] set to true to display fader horizontally
range: {min:0,max:1}, // [object] defining the breakpoints of the fader
// keys can be percentages or 'min' / 'max'
unit: false, // [string] value suffix
horizontal:false, // [bool] set to true to display fader horizontally
range: {min:0,max:1}, // [object] defining the breakpoints of the fader
// keys can be percentages or 'min' / 'max'
unit: false, // [string] value suffix
```
#### Knob
```
range: {min:0,max:1}, // [object] minimum and maximum values
unit: false, // [string] value suffix
```
#### Toggle
```
on: 1,
off:0
```
#### Switch
```
values:[] // [array] of values (string or number)
range: {min:0,max:1}, // [object] minimum and maximum values
unit: false, // [string] value suffix
```
#### XY pad
```
range:{ // [object] minimum and maximum values for x and y axis
range:{ // [object] minimum and maximum values for x and y axis
x:{min:0,max:1},
y:{min:0,max:1}
}
```
#### RGB pad
```
no option
```
#### Toggle
```
on: 1, // [string|number] value sent when toggle is on
off:0 // [string|number] value sent when toggle is off
```
#### Switch
```
values:[] // [array] of values (string or number)
```

View file

@ -28,31 +28,23 @@ ipc.on('listSessions',function(data){
</div>')
for (i in data) {
$('#lobby .list').append('<li><a class="btn" data-session="'+i+'">'+data[i]+'<span>'+icon('remove')+'</span></a></li>')
$('#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" data-session="browse">...</a>')
$('#lobby a').click(function(){
ipc.send('loadSession',$(this).data('session'))
$('#lobby .list').append('<a class="btn browse">...</a>')
$('#lobby .load').click(function(e){
e.stopPropagation()
openSession($(this).data('session'))
})
$('#lobby a span').click(function(e){
e.stopPropagation()
ipc.send('removeSessionFromHistory',$(this).parent().data('session'))
$(this).parents('li').hide()
})
$('#lobby .browse').click(function(e){
e.stopPropagation()
ipc.send('browseSessions')
})
})
ipc.on('openSession',function(data){
TABS=false
require(data)
if (TABS!=false) {
$('#lobby').hide()
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
setTimeout(function(){
init(function(){$('#loading').hide()});
},1)
} else {
console.log('ERROR: invalid session file (TABS must be defined)')
}
openSession(data)
})

View file

@ -1,8 +1,8 @@
init = function(callback) {
init = function(session,callback) {
parsetabs(TABS,false,false)
parsetabs(session,false,false)

View file

@ -39,6 +39,38 @@ setState = function(preset){
}
openSession = function(path){
var fs = require('fs'),
data = fs.readFileSync(path,'utf8'),
session,
error
try {
session = eval(data)
} catch(err) {
error = err
}
if (!error) {
ipc.send('addSessionToHistory',path)
$('#lobby').hide()
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
setTimeout(function(){
init(session,function(){$('#loading').hide()});
},1)
} else {
createPopup(icon('warning')+'&nbsp;Error: invalid session file',error)
}
}
icon = function(i) {
return '<i class="fa fa-fw fa-'+i+'"></i>'
}

View file

@ -14,19 +14,6 @@ var app = require('app')
compileScss = function(){
var sass = require(__dirname + '/../browser/js/sass/sass.sync.js')
var filenames = fs.readdirSync(__dirname + '/../browser/scss/')
for (i in filenames) {
if (filenames[i].indexOf('.scss')!=-1)
var file = __dirname + '/../browser/scss/' + filenames[i]
var content = fs.readFileSync(file,'utf8')
sass.compile(content,{style: sass.style.compact,linefeed: ''}, function(result) {
fs.writeFileSync(__dirname + '/../browser/css/'+filenames[i].replace('.scss','.css'),result.text,'utf8')
});
}
}
dialog.showErrorBox = function(title,err) {
console.log(title + ': ' + err)
@ -85,40 +72,44 @@ restartApp = function(){
}
compileScss = function(){
var sass = require(__dirname + '/../browser/js/sass/sass.sync.js')
var filenames = fs.readdirSync(__dirname + '/../browser/scss/')
for (i in filenames) {
if (filenames[i].indexOf('.scss')!=-1)
var file = __dirname + '/../browser/scss/' + filenames[i]
var content = fs.readFileSync(file,'utf8')
sass.compile(content,{style: sass.style.compact,linefeed: ''}, function(result) {
fs.writeFileSync(__dirname + '/../browser/css/'+filenames[i].replace('.scss','.css'),result.text,'utf8')
});
}
}
var window = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != 'darwin') {
app.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
if (args.indexOf('-c')!=-1) {
compileScss()
}
// Create the browser window.
window = new BrowserWindow({
width: 810,
width: 800,
height: 600,
'auto-hide-menu-bar':true
});
// and load the index.html of the app.
window.loadUrl('file://' + __dirname + '/../browser/index.html');
// Emitted when the window is closed.
window.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
window = null;
});
@ -171,48 +162,24 @@ renderProcess = {
}
}
ipc.on('loadSession',function(event, data){
ipc.on('browseSessions',function(event, data){
var sessionlist = readConfig('recentSessions')
if (data == 'browse') {
dialog.showOpenDialog(window,{title:'Load session file',defaultPath:readConfig('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
if (file==undefined) {return}
// save path to configfile
writeConfig({sessionPath:file[0].replace(file[0].split('/').pop(),'')})
// open session
renderProcess.send('openSession',file[0]);
// add session to history
sessionlist.unshift(file[0])
// remove doubles from history
sessionlist = sessionlist.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
// save history
writeConfig({recentSessions:sessionlist})
renderProcess.send('openSession',file[0])
})
})
} else {
// open session
renderProcess.send('openSession',sessionlist[data]);
// add session to history
sessionlist.unshift(sessionlist[data])
// remove doubles from history
sessionlist = sessionlist.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
// save history
writeConfig({recentSessions:sessionlist})
}
ipc.on('addSessionToHistory',function(event, data){
var sessionlist = readConfig('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
writeConfig({recentSessions:sessionlist})
})
ipc.on('removeSessionFromHistory',function(event, data){
@ -254,15 +221,6 @@ ipc.on('sendOsc', function (event,data) {
});
}
// try {
// udpPort.send({
// address: data.path,
// args: data.args
// }, host, port);
// } catch(err) {
// console.log(err)
// }
}
@ -299,5 +257,4 @@ ipc.on('load', function(event, data){
ipc.on('fullscreen', function(event){
window.setFullScreen(!window.isFullScreen())
})

View file

@ -1,7 +1,6 @@
TABS = function(){
(function(){
var db = {'min': -70,'20%': -40,'45%': -20,'60%': -10,'71%':-6,'78%':-3,'85%':0,'92%':3,'max': 6}
var target = '127.0.0.1:6666'
var target = '127.0.0.1:5555'
var tabs = new Array()
tabs.push(function(){
var tab = {}
@ -12,7 +11,7 @@ TABS = function(){
type:'strip',
widgets: [
{
type:"knob",
"type":"knob",
target:target
},
{
@ -22,7 +21,8 @@ TABS = function(){
},
{
type:"fader",
target:target
target:target,
range:db
},
{
type:"toggle",
@ -33,15 +33,12 @@ TABS = function(){
})
}
return tab
}())
tabs.push({id:'test'})
tabs.push({id:'test'})
return tabs
}()
})()

View file

@ -1,12 +1,10 @@
(function(){
nmPorts = {
'MonitorsDag':'SCSon:6675',
'MonitorsJeannot':'SCSon:6676',
'MonitorsORL':'SCSon:6677',
'Mains':'SCSon:6678',
}
nmRange = {'min': -70,'20%': -40,'45%': -20,'60%': -10,'71%':-6,'78%':-3,'85%':0,'92%':3,'max': 6}
TABS = [
return [
{
id:'MonitorsDag',
widgets: [
@ -91,3 +89,4 @@ TABS = [
]
}
]
})()

View file

@ -1,3 +1,4 @@
(function(){
nmPorts = {
'MonitorsDag':'SCSon:6675',
'MonitorsJeannot':'SCSon:6676',
@ -6,7 +7,7 @@ nmPorts = {
}
nmRange = {'min': -70,'20%': -40,'45%': -20,'60%': -10,'71%':-6,'78%':-3,'85%':0,'92%':3,'max': 6}
TABS = [
return [
{
id:'MonitorsJeannot',
widgets: [
@ -70,3 +71,4 @@ TABS = [
]
}
]
})()

View file

@ -1,3 +1,4 @@
(function(){
nmPorts = {
'MonitorsDag':'SCSon:6675',
'MonitorsJeannot':'SCSon:6676',
@ -8,7 +9,7 @@ nmPorts = {
nmRange = {'min': -70,'20%': -40,'45%': -20,'60%': -10,'71%':-6,'78%':-3,'85%':0,'92%':3,'max': 6}
TABS =  [
return  [
{
id: 'MonitorORL',
widgets : [
@ -93,3 +94,4 @@ TABS =  [
]
}
]
})()

View file

@ -1,3 +1,5 @@
(function(){
nmPorts = {
'MainMix':'SCSon:6666',
'Drums':'SCSon:6667',
@ -16,8 +18,7 @@ nmPorts = {
nmRange = {'min': -70,'20%': -40,'45%': -20,'60%': -10,'71%':-6,'78%':-3,'85%':0,'92%':3,'max': 6}
TABS =
[
return [
{
id: "MainMix",
label: "MainMix",
@ -4066,3 +4067,4 @@ TABS =
]
}
]
})()