Browse Source

prevent sync loop if sequence not present

eLandon 4 years ago
parent
commit
975f97bfaf
1 changed files with 204 additions and 202 deletions
  1. 204 202
      SequenceMgr.js

+ 204 - 202
SequenceMgr.js

@@ -417,238 +417,240 @@ function struct_buildValuesFromSeq(){
 	
 	var tl_seq = root.sequences.getItemWithName(sequence);
 	
-	
-	//build cues if needed
-	var tl_cues = tl_seq.cues.getItems();
-	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("cues "+ 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 = ;
+	if(tl_sequence!=undefined){
+		//build cues if needed
+		var tl_cues = tl_seq.cues.getItems();
+		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("cues "+ 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 = ;
+				
+			}
+			hasUpdated = true;
 		}
-		hasUpdated = true;
-	}
 
-	//update cues
-	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());
+		//update cues
+		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 if needed
-	var layersChanged = false ;
-	var tl_layers = tl_seq.layers.getItems();
-	layers = local.getChild("values").keys.layers ;
-	var layersList = util.getObjectProperties(layers, true, false);
-	if (layersList.length != tl_layers.length){
-		layersChanged = true ;
-		var delta = layersList.length-tl_layers.length;
-		var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
-		delta = Math.abs(delta);
-		script.log("layers "+ delta + (addRemove ? " up" : " down"));
-		for(var i=0; i<delta; i++){
-			// script.log(i);
-			if(addRemove){
-				var newLayer = layers.addContainer("newLayer"+i);
-				// newLayer.addFloatParameter("time", "position in time", 0., 0.);
-				newLayer.setCollapsed(true);
-				local.getChild("values").newGroup.layers.addFloatParameter("newLayer"+i, "value for this layer at group creation", 0., 0., 1.);
-			}
-			else {
-				script.log(util.getObjectProperties(layers, true, false)[0]);
-				layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
-				local.getChild("values").newGroup.layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
+		
+		//build layers if needed
+		var layersChanged = false ;
+		var tl_layers = tl_seq.layers.getItems();
+		layers = local.getChild("values").keys.layers ;
+		var layersList = util.getObjectProperties(layers, true, false);
+		if (layersList.length != tl_layers.length){
+			layersChanged = true ;
+			var delta = layersList.length-tl_layers.length;
+			var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
+			delta = Math.abs(delta);
+			script.log("layers "+ delta + (addRemove ? " up" : " down"));
+			for(var i=0; i<delta; i++){
+				// script.log(i);
+				if(addRemove){
+					var newLayer = layers.addContainer("newLayer"+i);
+					// newLayer.addFloatParameter("time", "position in time", 0., 0.);
+					newLayer.setCollapsed(true);
+					local.getChild("values").newGroup.layers.addFloatParameter("newLayer"+i, "value for this layer at group creation", 0., 0., 1.);
+				}
+				else {
+					script.log(util.getObjectProperties(layers, true, false)[0]);
+					layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
+					local.getChild("values").newGroup.layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
+				}
+				// cuesList = ;
+				
 			}
-			// cuesList = ;
-			
+			hasUpdated = true;
 		}
-		hasUpdated = true;
-	}
-	//update layers value if there was a change in structure
-	if(layersChanged){
-		layers = local.getChild("values").keys.layers ;
-		var layerList = util.getObjectProperties(layers, true, false);
-		var template = local.getChild("values").newGroup.layers;
-		var layerTemplate = util.getObjectProperties(template, true, false);
-
-		if(tl_layers.length){
-			for (var i=0; i<tl_layers.length; i++){
-				var currentLayer = layers.getChild(layerList[i]);
-				currentLayer.setName(tl_layers[i].name);
-				var currentTemplate = template.getChild(layerTemplate[i]) ;
-				currentTemplate.setName(tl_layers[i].name);
+		//update layers value if there was a change in structure
+		if(layersChanged){
+			layers = local.getChild("values").keys.layers ;
+			var layerList = util.getObjectProperties(layers, true, false);
+			var template = local.getChild("values").newGroup.layers;
+			var layerTemplate = util.getObjectProperties(template, true, false);
+
+			if(tl_layers.length){
+				for (var i=0; i<tl_layers.length; i++){
+					var currentLayer = layers.getChild(layerList[i]);
+					currentLayer.setName(tl_layers[i].name);
+					var currentTemplate = template.getChild(layerTemplate[i]) ;
+					currentTemplate.setName(tl_layers[i].name);
+				}
 			}
 		}
-	}
 
-	//build keys if needed
-	layers = local.getChild("values").keys.layers ;
-	layersList = util.getObjectProperties(layers, true, false);
-	
-	if(layersList.length){
-		for(var layerIndex=0; layerIndex<layersList.length; layerIndex++){
-
-			var currentLayer = layers.getChild(layersList[layerIndex]);
-			var keyList = util.getObjectProperties(currentLayer, true, false);
-
-			var tl_lay = tl_seq.layers.getItemWithName(layersList[layerIndex]);
-			var tl_keys;
-			if(tl_lay.automation!=undefined){tl_keys = tl_lay.automation.getItems();}
-			//rebuild key structure for currentLayer
-			if (keyList.length != tl_keys.length){
-				var delta = keyList.length-tl_keys.length;
-				var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
-				delta = Math.abs(delta);
-				script.log("keys "+ delta + (addRemove ? " up" : " down"));
-				for(var i=0; i<delta; i++){
-					
-					// script.log(i);
-					if(addRemove){
-						var newKey = currentLayer.addContainer("newkey"+i);
-						newKey.addFloatParameter("time", "position in time", 0., 0.);
-						newKey.addFloatParameter("value", "vertical value", 0., 0.);
-						newKey.setCollapsed(true);
+		//build keys if needed
+		layers = local.getChild("values").keys.layers ;
+		layersList = util.getObjectProperties(layers, true, false);
+		
+		if(layersList.length){
+			for(var layerIndex=0; layerIndex<layersList.length; layerIndex++){
+
+				var currentLayer = layers.getChild(layersList[layerIndex]);
+				var keyList = util.getObjectProperties(currentLayer, true, false);
+
+				var tl_lay = tl_seq.layers.getItemWithName(layersList[layerIndex]);
+				var tl_keys;
+				if(tl_lay.automation!=undefined){tl_keys = tl_lay.automation.getItems();}
+				//rebuild key structure for currentLayer
+				if (keyList.length != tl_keys.length){
+					var delta = keyList.length-tl_keys.length;
+					var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
+					delta = Math.abs(delta);
+					script.log("keys "+ delta + (addRemove ? " up" : " down"));
+					for(var i=0; i<delta; i++){
+						
+						// script.log(i);
+						if(addRemove){
+							var newKey = currentLayer.addContainer("newkey"+i);
+							newKey.addFloatParameter("time", "position in time", 0., 0.);
+							newKey.addFloatParameter("value", "vertical value", 0., 0.);
+							newKey.setCollapsed(true);
+						}
+						else {
+							script.log(util.getObjectProperties(currentLayer, true, false)[0]);
+							currentLayer.removeContainer(util.getObjectProperties(currentLayer, true, false)[0]);
+						}		
+						
+						
 					}
-					else {
-						script.log(util.getObjectProperties(currentLayer, true, false)[0]);
-						currentLayer.removeContainer(util.getObjectProperties(currentLayer, true, false)[0]);
-					}		
-					
-					
+					hasUpdated = true;
 				}
-				hasUpdated = true;
-			}
 
-			currentLayer = layers.getChild(layersList[layerIndex]);
-			keyList = util.getObjectProperties(currentLayer, true, false);
-			//update values for currentLayer
-			if(tl_keys.length){
-				for(var i=0; i<tl_keys.length; i++){
-					var currentKey = currentLayer.getChild(keyList[i]);
-					currentKey.setName(tl_keys[i].name);
-					currentKey.time.set(tl_keys[i].position.get());
-					currentKey.value.set(tl_keys[i].value.get());
+				currentLayer = layers.getChild(layersList[layerIndex]);
+				keyList = util.getObjectProperties(currentLayer, true, false);
+				//update values for currentLayer
+				if(tl_keys.length){
+					for(var i=0; i<tl_keys.length; i++){
+						var currentKey = currentLayer.getChild(keyList[i]);
+						currentKey.setName(tl_keys[i].name);
+						currentKey.time.set(tl_keys[i].position.get());
+						currentKey.value.set(tl_keys[i].value.get());
 
+					}
 				}
 			}
 		}
-	}
 
-	//Groups
-	tl_seq = root.sequences.getItemWithName(sequence);
-	var groups = local.getChild("values").groups ;
-	var groupList = util.getObjectProperties(groups, true, false);
-	// printMethodsAndProperties(tl_seq.cues.getItemWithName("group0"));
-	if(groupList.length){
-		for (var i = 0; i<groupList.length; i++){
-			//check if cue exist, else remove group
-			// script.log(groupList[i]);
-			var groupCue = tl_seq.cues.getItemWithName(groupList[i]);
-			if(groupCue.name==undefined){
-				script.log("cue " + groupList[i] + "not found, removing group (keys survive this)");
-				groups.removeContainer(groupList[i]);
-				hasUpdated = true;
-				break;
-			}
+		//Groups
+		tl_seq = root.sequences.getItemWithName(sequence);
+		var groups = local.getChild("values").groups ;
+		var groupList = util.getObjectProperties(groups, true, false);
+		// printMethodsAndProperties(tl_seq.cues.getItemWithName("group0"));
+		if(groupList.length){
+			for (var i = 0; i<groupList.length; i++){
+				//check if cue exist, else remove group
+				// script.log(groupList[i]);
+				var groupCue = tl_seq.cues.getItemWithName(groupList[i]);
+				if(groupCue.name==undefined){
+					script.log("cue " + groupList[i] + "not found, removing group (keys survive this)");
+					groups.removeContainer(groupList[i]);
+					hasUpdated = true;
+					break;
+				}
 
-			//else check at key level
-			else {
-				groups = local.getChild("values").groups ;
-				groupList = util.getObjectProperties(groups, true, false);
-				var currentGroup = groups.getChild(groupList[i]);
-				var currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
-				//update cue time
-				var groupTime = groupCue.time.get();
-				currentGroup.cue.set(groupTime);
-
-				if (currentGroupLayers.length){
-					// script.log(currentGroupLayers.length);
-					for(var j=0; j<currentGroupLayers.length; j++){
-						// script.log("in loop" + j);
-						groups = local.getChild("values").groups ;
-						groupList = util.getObjectProperties(groups, true, false);
-						currentGroup = groups.getChild(groupList[i]);
-						currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
-						var tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
-						var keyName = currentGroup.keys.getChild(tl_layer.name).get();
-						// script.log(tl_layer.name + "  " +tl_layer.automation.getItemWithName(keyName).name);
-						//if key dosn't exist anymore, remove it from group
-						if(tl_layer.automation.getItemWithName(keyName).name == undefined){
+				//else check at key level
+				else {
+					groups = local.getChild("values").groups ;
+					groupList = util.getObjectProperties(groups, true, false);
+					var currentGroup = groups.getChild(groupList[i]);
+					var currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
+					//update cue time
+					var groupTime = groupCue.time.get();
+					currentGroup.cue.set(groupTime);
+
+					if (currentGroupLayers.length){
+						// script.log(currentGroupLayers.length);
+						for(var j=0; j<currentGroupLayers.length; j++){
+							// script.log("in loop" + j);
 							groups = local.getChild("values").groups ;
 							groupList = util.getObjectProperties(groups, true, false);
 							currentGroup = groups.getChild(groupList[i]);
 							currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
-							tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
-							keyName = currentGroup.keys.getChild(tl_layer.name).get();
-							script.log("should remove" + currentGroup.name + "  " + currentGroupLayers[j]);
-							currentGroup.keys.removeParameter(currentGroupLayers[j]);
-							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
-						else{
-							//apply groupTime
-							var tl_key = tl_layer.automation.getItemWithName(keyName);
-							tl_key.position.set(groupTime);
-							//get tl value
-							var keyValue = tl_key.value.get();
-							
-							var currentKey = currentGroup.getChild(tl_layer.name);
-							// script.log(tl_layer.name + "  " +keyName+"  " + keyValue);
-							// script.log(currentKey.name + "  " +keyName+"  " + keyValue);
-							currentKey.set(keyValue);
-							// script.log(currentKey.get());
+							var tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
+							var keyName = currentGroup.keys.getChild(tl_layer.name).get();
+							// script.log(tl_layer.name + "  " +tl_layer.automation.getItemWithName(keyName).name);
+							//if key dosn't exist anymore, remove it from group
+							if(tl_layer.automation.getItemWithName(keyName).name == undefined){
+								groups = local.getChild("values").groups ;
+								groupList = util.getObjectProperties(groups, true, false);
+								currentGroup = groups.getChild(groupList[i]);
+								currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
+								tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
+								keyName = currentGroup.keys.getChild(tl_layer.name).get();
+								script.log("should remove" + currentGroup.name + "  " + currentGroupLayers[j]);
+								currentGroup.keys.removeParameter(currentGroupLayers[j]);
+								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
+							else{
+								//apply groupTime
+								var tl_key = tl_layer.automation.getItemWithName(keyName);
+								tl_key.position.set(groupTime);
+								//get tl value
+								var keyValue = tl_key.value.get();
+								
+								var currentKey = currentGroup.getChild(tl_layer.name);
+								// script.log(tl_layer.name + "  " +keyName+"  " + keyValue);
+								// script.log(currentKey.name + "  " +keyName+"  " + keyValue);
+								currentKey.set(keyValue);
+								// script.log(currentKey.get());
+							}
 						}
 					}
+					// //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
+					
+					
 				}
-				// //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
-				
-				
 			}
 		}
-	}
 
 
-	inibValuesChanged = false;
-	return hasUpdated;
+		inibValuesChanged = false;
+		return hasUpdated;
+	}
+	
 
 }