|
@@ -17,6 +17,10 @@ var syncDelta = 0.;
|
|
|
var doSync = false ;
|
|
|
var inibValuesChanged = false ;
|
|
|
|
|
|
+var saveFile = script.addFileParameter("auto save sequence","");
|
|
|
+var saveRatems = 30;
|
|
|
+var saveDelta = 0.;
|
|
|
+
|
|
|
var debug = true;
|
|
|
var debugFile;
|
|
|
|
|
@@ -37,7 +41,6 @@ var layers = local.getChild("values").keys.layers ;
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
var rebuildValues = script.addTrigger("rebuild values", "adds a key at current cursor position" );
|
|
|
var refreshKeys = script.addTrigger("refresh keys", "truc");
|
|
|
var printKeys = script.addTrigger("printKeys","truc");
|
|
@@ -65,9 +68,12 @@ function init() {
|
|
|
//adapt update rate
|
|
|
updateSyncRate();
|
|
|
updateSynchronize();
|
|
|
+
|
|
|
+ saveFile.set("sequence_autosave.json");
|
|
|
+ saveFile.setAttribute("readonly", true);
|
|
|
|
|
|
// layers = local.getChild("values").keys.layers ;
|
|
|
- // printMethodsAndProperties(layers);
|
|
|
+ // printMethodsAndProperties(local.getChild("values"));
|
|
|
|
|
|
//test if a sequence is already choosen else refresh and unlock sequence enum
|
|
|
sequence = local.getChild("parameters").sequence.getKey();
|
|
@@ -108,9 +114,18 @@ function update(deltaTime){
|
|
|
// script.log(syncDelta);
|
|
|
if (syncDelta >= syncRatems){
|
|
|
syncDelta = 0. ;
|
|
|
- struct_buildValuesFromSeq();
|
|
|
+ var autosave = struct_buildValuesFromSeq();
|
|
|
+ if(autosave){exportSequenceFile(saveFile);}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ saveDelta += deltaTime ;
|
|
|
+ if (saveDelta >= saveRatems){
|
|
|
+ saveDelta = 0. ;
|
|
|
+ exportSequenceFile(saveFile);
|
|
|
+ script.log("sequence autosave");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -163,9 +178,12 @@ function moduleParameterChanged(param){
|
|
|
|
|
|
if (param.is(parametersPath.importExport.sequenceFile)) {}
|
|
|
|
|
|
- else if (param.is(parametersPath.importExport.loadSequence)){importSequenceFile();}
|
|
|
+ else if (param.is(parametersPath.importExport.importSequence)){importSequenceFile(parametersPath.importExport.sequenceFile);}
|
|
|
|
|
|
- else if (param.is(parametersPath.importExport.exportSequence)) { exportSequenceFile();}
|
|
|
+ else if (param.is(parametersPath.importExport.exportSequence)) {
|
|
|
+ exportSequenceFile(parametersPath.importExport.sequenceFile);
|
|
|
+ exportSequenceFile(saveFile);
|
|
|
+ }
|
|
|
|
|
|
else if (param.is(parametersPath.synchronize)){updateSynchronize();}
|
|
|
|
|
@@ -173,11 +191,13 @@ function moduleParameterChanged(param){
|
|
|
|
|
|
else if (param.is(parametersPath.clearSequence)){seq_clearSequence();}
|
|
|
|
|
|
+ else if (param.is(parametersPath.reorderSequence)){seq_reorderSequence();}
|
|
|
+
|
|
|
else if (param.is(parametersPath.changeSequence)){refreshSequenceEnum();}
|
|
|
|
|
|
else if (param.is(parametersPath.sequence)){
|
|
|
sequence = sequencePath.getKey();
|
|
|
- if(sequence!="choose sequence"){
|
|
|
+ if(sequence!=""){
|
|
|
script.log("watching "+ sequence);
|
|
|
local.parameters.sequence.setAttribute("readonly",true);
|
|
|
|
|
@@ -215,50 +235,74 @@ function refreshSequenceEnum(){
|
|
|
|
|
|
}
|
|
|
|
|
|
-// function testSequenceFile(){
|
|
|
-// var file = local.parameters.sequenceFile;
|
|
|
-// //test if a file is declared
|
|
|
-// if( file.getAbsolutePath() != ""){
|
|
|
-// script.log("testing file " + file.getAbsolutePath() );
|
|
|
-// var data = file.readFile(true);
|
|
|
-// // test if expected fields are absent
|
|
|
-// if (data.groups == undefined){
|
|
|
-// script.log("file structure not recognized");
|
|
|
-// refreshSequenceEnum();
|
|
|
-// }
|
|
|
-// //if all is well, let's load in sequence_structure
|
|
|
-// else {
|
|
|
-// script.log("ready to import");
|
|
|
-// return 1;
|
|
|
-// // loadSequenceFile();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// script.log("no file to load");
|
|
|
-// refreshSequenceEnum();
|
|
|
-// return 0;
|
|
|
-// }
|
|
|
-// }
|
|
|
+function importSequenceFile(loadFile){
|
|
|
|
|
|
-function importSequenceFile(){
|
|
|
+ doSync = false ;
|
|
|
script.log("loading file");
|
|
|
- sequence_structure = local.parameters.sequenceFile.readFile(true);
|
|
|
- //lock enum with curent sequence name
|
|
|
- var sequenceList = local.parameters.sequence;
|
|
|
- sequenceList.removeOptions();
|
|
|
- sequenceList.addOption(sequence_structure.params.sequence, 0);
|
|
|
- local.parameters.sequence.setAttribute("readonly",true);
|
|
|
+ loadData = loadFile.readFile(true);
|
|
|
+
|
|
|
+ //load parameters
|
|
|
+ var parameters = local.getChild("parameters");
|
|
|
+ parameters.syncRate.set(loadData.parameters.SyncRate);
|
|
|
+ parameters.synchronize.set(loadData.parameters.Synchronize);
|
|
|
+ sequence = loadData.parameters.Sequence;
|
|
|
+ parameters.sequence.removeOptions();
|
|
|
+ parameters.sequence.addOption(sequence,0);
|
|
|
+ parameters.sequence.setAttribute("readonly", true);
|
|
|
+ // script.log(parameters.synchronize.get());
|
|
|
+ //
|
|
|
+ //check if Sequence already exists in sequences manager, else create it
|
|
|
+ var tl_sequence = root.sequences.getItemWithName(sequence) ;
|
|
|
+ if(tl_sequence == undefined){
|
|
|
+ tl_sequence = root.sequences.addItem();
|
|
|
+ tl_sequence.setName(sequence);
|
|
|
+ }
|
|
|
+
|
|
|
+ //recreate cues
|
|
|
+ tl_sequence.cues.removeAll();
|
|
|
+ var cuesList = util.getObjectProperties(loadData.values.keys.cues, true, false);
|
|
|
+ if(cuesList.length){
|
|
|
+ for(var i=0; i<cuesList.length; i++){
|
|
|
+ var cue = tl_sequence.cues.addItem();
|
|
|
+ cue.setName(cuesList[i]);
|
|
|
+ cue.time.set(loadData.values.keys.cues[cuesList[i]].time);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //recreate layers and keys
|
|
|
+ tl_sequence.layers.removeAll();
|
|
|
+ var layersList = util.getObjectProperties(loadData.values.keys.layers, true, false);
|
|
|
+ if(layersList.length){
|
|
|
+ for(var i=0; i<layersList.length; i++ ){
|
|
|
+ var layer = tl_sequence.layers.addItem("Mapping");
|
|
|
+ layer.setName(layersList[i]);
|
|
|
+ var keysList = util.getObjectProperties(loadData.values.keys.layers[layersList[i]], true, false);
|
|
|
+ if(keysList.length){
|
|
|
+ for(var j=0; j<keysList.length; j++){
|
|
|
+ var key = layer.automation.addItem();
|
|
|
+ key.setName(keysList[j]);
|
|
|
+ key.value.set(loadData.values.keys.layers[layersList[i]][keysList[j]].value);
|
|
|
+ key.position.set(loadData.values.keys.layers[layersList[i]][keysList[j]].time);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ layer.automation.reorderItems();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // script.log(layersList[0]);
|
|
|
+ doSync = true;
|
|
|
+ // updateSynchronize() ;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-function exportSequenceFile(){
|
|
|
+function exportSequenceFile(fileObj){
|
|
|
script.log("exporting file");
|
|
|
var exportData = {parameters:{}, values:{groups:{}, keys:{cues:{}, layers:{}}}};
|
|
|
|
|
|
//collect parameters
|
|
|
var parameters = local.getChild("parameters");
|
|
|
- var parametersList = util.getObjectProperties(parametersPath, true, false);
|
|
|
exportData.parameters["Sequence"] = parameters.sequence.getKey();
|
|
|
- exportData.parameters["Synchronise"] = parameters.synchronize.get();
|
|
|
+ exportData.parameters["Synchronize"] = parameters.synchronize.get();
|
|
|
exportData.parameters["Sync Rate"] = parameters.syncRate.get();
|
|
|
|
|
|
//collect values
|
|
@@ -305,14 +349,14 @@ function exportSequenceFile(){
|
|
|
exportLayer[currentLayersKeys[j]] = {key:"", value:0., time:0.};
|
|
|
exportLayer[currentLayersKeys[j]].value = currentLayer.getChild(currentLayersKeys[j]).value.get();
|
|
|
exportLayer[currentLayersKeys[j]].key = currentLayer.getChild(currentLayersKeys[j]).name;
|
|
|
- exportLayer[currentLayersKeys[j]].key = currentLayer.getChild(currentLayersKeys[j]).time.get();
|
|
|
+ exportLayer[currentLayersKeys[j]].time = currentLayer.getChild(currentLayersKeys[j]).time.get();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// exportData.groups
|
|
|
- parameters.importExport.sequenceFile.writeFile(JSON.stringify(exportData), true);
|
|
|
+ fileObj.writeFile(JSON.stringify(exportData), true);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -346,7 +390,8 @@ function moduleValueChanged(value){
|
|
|
function struct_buildValuesFromSeq(){
|
|
|
|
|
|
inibValuesChanged = true;
|
|
|
-
|
|
|
+ var hasUpdated = false ;
|
|
|
+
|
|
|
var tl_seq = root.sequences.getItemWithName(sequence);
|
|
|
|
|
|
|
|
@@ -357,6 +402,7 @@ function struct_buildValuesFromSeq(){
|
|
|
// script.log("cueList : " +cuesList.length);
|
|
|
// script.log("tl List : " +tl_cues.length);
|
|
|
if (cuesList.length != tl_cues.length){
|
|
|
+
|
|
|
var delta = cuesList.length-tl_cues.length;
|
|
|
var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
|
|
|
|
|
@@ -376,6 +422,7 @@ function struct_buildValuesFromSeq(){
|
|
|
// cuesList = ;
|
|
|
|
|
|
}
|
|
|
+ hasUpdated = true;
|
|
|
}
|
|
|
|
|
|
//update cues
|
|
@@ -417,6 +464,7 @@ function struct_buildValuesFromSeq(){
|
|
|
// cuesList = ;
|
|
|
|
|
|
}
|
|
|
+ hasUpdated = true;
|
|
|
}
|
|
|
//update layers value if there was a change in structure
|
|
|
if(layersChanged){
|
|
@@ -470,6 +518,7 @@ function struct_buildValuesFromSeq(){
|
|
|
|
|
|
|
|
|
}
|
|
|
+ hasUpdated = true;
|
|
|
}
|
|
|
|
|
|
currentLayer = layers.getChild(layersList[layerIndex]);
|
|
@@ -500,6 +549,7 @@ function struct_buildValuesFromSeq(){
|
|
|
if(groupCue.name==undefined){
|
|
|
script.log("cue " + groupList[i] + "not found, removing group (keys survive this)");
|
|
|
groups.removeContainer(groupList[i]);
|
|
|
+ hasUpdated = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -537,6 +587,7 @@ function struct_buildValuesFromSeq(){
|
|
|
currentGroup.removeParameter(currentGroupLayers[j]);
|
|
|
currentGroup.setCollapsed(true);
|
|
|
currentGroup.setCollapsed(false);
|
|
|
+ hasUpdated = true;
|
|
|
|
|
|
}
|
|
|
//if key exists, update value from tl and update time from group cue
|
|
@@ -555,17 +606,18 @@ function struct_buildValuesFromSeq(){
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //if cue doesn't exist, remove whole group
|
|
|
- if(tl_layers.length){
|
|
|
- for (var j=0; j<tl_layers.length; j++){
|
|
|
- if(!tl_layers[j].automation.getItemWithName(groupList[i])){
|
|
|
- script.log("key " + groupList[i] + "not found, removing group (keys survive this)");
|
|
|
- groups.removeContainer(groupList[i]);}
|
|
|
- }
|
|
|
- }
|
|
|
+ // //if cue doesn't exist, remove whole group
|
|
|
+ // if(tl_layers.length){
|
|
|
+ // for (var j=0; j<tl_layers.length; j++){
|
|
|
+ // if(!tl_layers[j].automation.getItemWithName(groupList[i])){
|
|
|
+ // script.log("key " + groupList[i] + "not found, removing group (keys survive this)");
|
|
|
+ // groups.removeContainer(groupList[i]);}
|
|
|
+ // hasUpdated = true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
//update group values
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -573,6 +625,7 @@ function struct_buildValuesFromSeq(){
|
|
|
|
|
|
|
|
|
inibValuesChanged = false;
|
|
|
+ return hasUpdated;
|
|
|
|
|
|
}
|
|
|
|