Jelajahi Sumber

sync base between tl and module cues

eLandon 4 tahun lalu
induk
melakukan
42501e68bd
3 mengubah file dengan 99 tambahan dan 31 penghapusan
  1. 94 30
      SequenceMgr.js
  2. 4 0
      module.json
  3. 1 1
      testSequenceMgr.noisette

+ 94 - 30
SequenceMgr.js

@@ -12,8 +12,9 @@ module values structure are in sync. If out of sync, you may either rebuild valu
 from sequence or rebuild sequence from values
 
 */
-var syncRate = 10;
-var synchronize = false ;
+var syncRatems = 10;
+var syncDelta = 0.;
+var doSync = false ;
 
 var debug = true;
 var debugFile;
@@ -26,10 +27,13 @@ var file ;
 var filePath = local.parameters.sequenceFile ;
 
 
-var newGroup = local.values.newGroup ;
-var groups = local.value.groups ;
-var cues = local.keys.cues ;
-var layers = local.keys.layers ;
+var newGroupLayers = local.values.newGroup.layers ;
+var groups = local.values.groups ;
+var cues = local.getChild("values").keys.cues ;
+// var cuesList = []; //holds cues containers reference
+var layers = local.values.keys.layers ;
+var layerList = {}; //holds layer container as object with reference and an array of keys containers references
+
 
 
 
@@ -59,6 +63,8 @@ function init() {
 	
 	//adapt update rate
 	updateSyncRate();
+	updateSynchronize();
+	
 	
 
 	//test if a sequence is already choosen else refresh and unlock sequence enum
@@ -72,7 +78,7 @@ function scriptParameterChanged(param){
 	
 	if (param.is(printKeys) ){printKeys();}
 
-	else if(param.is(rebuildValues)){rebuildValuesStructure();}
+	else if(param.is(rebuildValues)){struct_buildValuesFromSeq();}
 
 	else if (param.is(refreshKeys)){
 		script.log("refreshKeys");
@@ -84,19 +90,15 @@ function scriptParameterChanged(param){
 	else {script.log("scriptparamchanged" + param.name);}
 }
 
-var syncDelta = 0.;
 
-function update(deltaTime){
 
-	if(synchronize){
+function update(deltaTime){
+	
+	if(doSync){
 		syncDelta += deltaTime ;
-		if (syncDelta > syncRate){
+		// script.log(syncDelta);
+		if (syncDelta >= syncRatems){
 			syncDelta = 0. ;
-			// if (debug ){
-			// 	// script.log(debugFile.getAbsolutePath());
-			// 	debugFile.writeFile(JSON.stringify(sequence_structure), true);
-			// }
-			// refreshKeysList();
 			struct_buildValuesFromSeq();
 		}
 	}	
@@ -109,8 +111,8 @@ function update(deltaTime){
 
 function printMethodsAndProperties(obj){
 	script.log(" ");
-	// var name = obj.getControlAddress() == undefined ? "object" : obj.getControlAddress();
-	var name = "object";
+	var name = obj.getControlAddress() == undefined ? "object" : obj.getControlAddress();
+	// var name = "object";
 	script.log("  METHODS OF " + name);
 	var methods = util.getObjectMethods(obj);
 	for(var i=0 ; i<methods.length ; i++){
@@ -151,11 +153,11 @@ function moduleParameterChanged(param){
 
 	if (param.is(parametersPath.importExport.sequenceFile)) {}
 
-	else if (param.is(parametersPath.importExport.loadSequence)){loadSequenceFile();}
+	else if (param.is(parametersPath.importExport.loadSequence)){importSequenceFile();}
 	
 	else if (param.is(parametersPath.importExport.exportSequence)) { exportSequenceFile();}
 
-	else if (param.is(parametersPath.synchronize)){}
+	else if (param.is(parametersPath.synchronize)){updateSynchronize();}
 
 	else if (param.is(parametersPath.syncRate)){updateSyncRate();}
 
@@ -169,10 +171,15 @@ function moduleParameterChanged(param){
 	else{script.log("received module param :" + param.name);}
 }
 
+function updateSynchronize(){
+	doSync = parametersPath.synchronize.get();
+	script.log(doSync ? "sync ON" : "sync OFF" );
+}
+
 function updateSyncRate(){
-	syncRate = parametersPath.syncRate.get();
-	script.log("new sync rate : " + syncRate);
-	script.setUpdateRate(syncRate);
+	syncRatems = parametersPath.syncRate.get() / 1000.;
+	script.log("new sync rate : " + syncRatems);
+	// script.setUpdateRate(syncRatems);
 
 }
 
@@ -213,7 +220,7 @@ function testSequenceFile(){
 	}	
 }
 
-function loadSequenceFile(){
+function importSequenceFile(){
 	script.log("loading file");
 			sequence_structure = local.parameters.sequenceFile.readFile(true);
 			//lock enum with curent sequence name
@@ -241,16 +248,73 @@ function moduleValueChanged(value){
 	if (value.name == "addGroup"){createNewGroup(sequence_structure.params.sequence);}
 }
 
-//check if sequence and value structures are in sync (same cues, layers, and keys)
-function struct_checkSync(){
+//rebuild container references lists reading values structure
+function struct_syncList(){
+
+
+}
+
+//check if sequence and structure lists are in sync (same cues, layers, and keys)
+function struct_checkSeqSync(){
+
 
 }
 
 //rebuild values.keys structure from sequence
+
 function struct_buildValuesFromSeq(){
 	
+	var tl_seq = root.sequences.getItemWithName(sequence);
+	
+	var tl_cues = tl_seq.cues.getItems();
+	var tl_layers = tl_seq.layers.getItems();
+	
+	//clear and rebuild containers
+	// local.values.removeContainer("keys");
+	// keys = local.values.addContainer("keys");
+	// cues = keys.addContainer("Cues");
+	// layers = keys.addContainer("layers");
+
+
 	//build cues
+	cues = local.getChild("values").keys.cues ;
+	var cuesList = util.getObjectProperties(cues, true, false);
+	// 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
+		
+		delta = Math.abs(delta);
+		script.log("change "+ delta + (addRemove ? " up" : " down"));
+		for(var i=0; i<delta; i++){
+			// script.log(i);
+			if(addRemove){
+				var newCue = cues.addContainer("newCue"+i);
+				newCue.addFloatParameter("time", "position in time", 0., 0.);
+				newCue.setCollapsed(true);
+			}
+			else {
+				script.log(util.getObjectProperties(cues, true, false)[0]);
+				cues.removeContainer(util.getObjectProperties(cues, true, false)[0]);
+			}
+			// cuesList = ;
+			
+		}
+	}
 
+	//update values
+	cues = local.getChild("values").keys.cues ;
+	var cuesList = util.getObjectProperties(cues, true, false);
+	if(tl_cues.length){
+		for (var i=0; i<tl_cues.length; i++){
+			var currentCue = cues.getChild(cuesList[i]);
+			currentCue.setName(tl_cues[i].name);
+			currentCue.time.set(tl_cues[i].time.get());
+		}
+	}
+	
+	
 	//build layers
 
 	//build keys in layers
@@ -297,10 +361,10 @@ function rebuildValuesStructure() {
 
 function seq_clearSequence(){
 	
-	var sequence = root.sequences.getItemWithName(sequence_structure.params.sequence) ;
-	script.log("clearing all keys and cues of sequence : "+sequence.name);
-	sequence.cues.removeAll();
-	var layers = sequence.layers.getItems();
+	var seq = root.sequences.getItemWithName(sequence) ;
+	script.log("clearing all keys and cues of sequence : "+seq.name);
+	seq.cues.removeAll();
+	var layers = seq.layers.getItems();
 	if(layers.length){
 		for (var i = 0; i<layers.length; i++){
 			layers[i].automation.removeAll();

+ 4 - 0
module.json

@@ -65,6 +65,10 @@
 			"Create": {
 				"type": "Trigger",
 				"description": "create a new key group"
+			},
+			"Layers":{
+				"type": "Container",
+				"collapsed": true
 			}
 		},
 		"groups": {

File diff ditekan karena terlalu besar
+ 1 - 1
testSequenceMgr.noisette