Browse Source

groups structure update ok

eLandon 4 years ago
parent
commit
b50c3d1ef2
2 changed files with 100 additions and 61 deletions
  1. 99 60
      SequenceMgr.js
  2. 1 1
      testSequenceMgr.noisette

+ 99 - 60
SequenceMgr.js

@@ -29,7 +29,7 @@ var filePath = local.parameters.sequenceFile ;
 
 
 var newGroupLayers = local.values.newGroup.layers ;
-var groups = local.getChild("values").groups ;
+// var groups = local.getChild("values").groups ;
 var cues = local.getChild("values").keys.cues ;
 // var cuesList = []; //holds cues containers reference
 var layers = local.getChild("values").keys.layers ;
@@ -283,7 +283,7 @@ function struct_buildValuesFromSeq(){
 		var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
 		
 		delta = Math.abs(delta);
-		script.log("change "+ delta + (addRemove ? " up" : " down"));
+		script.log("cues "+ delta + (addRemove ? " up" : " down"));
 		for(var i=0; i<delta; i++){
 			// script.log(i);
 			if(addRemove){
@@ -322,7 +322,7 @@ function struct_buildValuesFromSeq(){
 		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("change "+ delta + (addRemove ? " up" : " down"));
+		script.log("layers "+ delta + (addRemove ? " up" : " down"));
 		for(var i=0; i<delta; i++){
 			// script.log(i);
 			if(addRemove){
@@ -370,7 +370,7 @@ function struct_buildValuesFromSeq(){
 				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("change "+ delta + (addRemove ? " up" : " down"));
+				script.log("keys "+ delta + (addRemove ? " up" : " down"));
 				for(var i=0; i<delta; i++){
 					
 					// script.log(i);
@@ -403,7 +403,69 @@ function struct_buildValuesFromSeq(){
 			}
 		}
 	}
-	
+
+	//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]);
+			if(tl_seq.cues.getItemWithName(groupList[i]).name==undefined){
+				script.log("cue " + groupList[i] + "not found, removing group (keys survive this)");
+				groups.removeContainer(groupList[i]);
+			}
+
+			//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);
+				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(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);
+							
+						}
+						
+					}
+				}
+				//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]);}
+					}
+				}
+				
+			}
+		}
+	}
+
+
 	inibValuesChanged = false;
 
 }
@@ -447,17 +509,28 @@ function struct_exportToFile(){}
 ///////////////////////		TIMELINE FUNCTIONS		///////////////////////
 
 function seq_clearSequence(){
-	
+
 	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();
+			if(layers[i].automation){layers[i].automation.removeAll();}
 		}
 	}
 
+	//clear all groups
+	var groups = local.getChild("values").groups;
+	var groupsList = util.getObjectProperties(groups, true, false);
+	if (groupsList.length){
+		for(var i=0; i<groupsList.length; i++){
+			groups.removeContainer(groupsList[i]);
+		}
+	}
+	
+	
+
 }
 
 //use Values structure to rebuild the sequence
@@ -466,62 +539,14 @@ function seq_buildSeqFromValues(){}
 //use file to rebuild sequence
 function seq_buildSeqFromFile(){}
 
-// function refreshKeysList(){
-
-// 	var sequence = root.sequences.getItemWithName(sequence_structure.params.sequence);
-// 	var cues = sequence.cues.getItems();
-// 	sequence_structure.keys.cues = {};
-// 	if(cues.length){
-// 		for (var i = 0 ; i < cues.length ; i++){
-// 			sequence_structure.keys.cues['cue'+i] = {index : i};
-// 			sequence_structure.keys['cues']['cue'+i]['name'] =  cues[i].name;
-// 			sequence_structure.keys['cues']['cue'+i]['niceName'] =  cues[i].niceName;
-// 			sequence_structure.keys['cues']['cue'+i]['time'] =  cues[i].time.get();
-// 			// script.log(tl_keyframes['cues']['cue'+i].time);
-// 		}
-// 	}
-
-// 	var layers = sequence.layers.getItems();
-// 	sequence_structure.keys.layers={};
-// 	if(layers.length){
-// 		for (var i = 0 ; i < layers.length ; i++){
-// 			sequence_structure['keys']['layers'][layers[i].name] = {};
-// 			// script.log(currentLayer.name);
-
-// 			if(layers[i].automation.getItems().length){
-// 				// script.log(currentLayer.automation.items.length);
-// 				for (var j = 0 ; j < layers[i].automation.getItems().length ; j++){
-
-// 					var currentkey = layers[i].automation.getItems()[j] ;
-// 					sequence_structure['keys']['layers'][layers[i].name][currentkey.name] = {
-// 																				position : currentkey.position.get(),
-// 																				value : currentkey.value.get(),
-// 																				name : currentkey.name,
-// 																				niceName : currentkey.niceName,
-// 																				//la propriete "group" est écrite 
-// 																				group : currentkey.group
-// 																				// group : currentkey.hasChild("group") != undefined ? currentkey.group.get() : "ungrouped"
-// 																				};
-// 					// script.log(tl_keyframes['keys'][currentLayer.name][currentkey.name].value);
-// 				}
-// 			}
-// 		}
-// 	}
-
-// 	// myFile.writeFile(JSON.stringify(tl_keyframes), 1);
-// }
-
-// function writeKeyGroup(){
-// 	var groups = sequence_structure.groups
-// }
 
 function createNewGroup(){
 	script.log("create new group");
 	//create a cue and a key in each layer at cursor position in selected sequence
-	groups = local.getChild("values").groups;
+	var groups = local.getChild("values").groups;
 	var groupsList = util.getObjectProperties(groups, true, false);
 	var index = groupsList.length == undefined ? 0 : groupsList.length;
-	var currentGroup = groups.addContainer("Group"+ index);
+	var currentGroup;
 
 	var tl_seq = root.sequences.getItemWithName(sequence);
 	var tl_layers = tl_seq.layers.getItems();
@@ -533,9 +558,22 @@ function createNewGroup(){
 	script.log(currentTime);
 	newCue = tl_seq.cues.addItem();
 	newCue.time.set(currentTime);
-	newCue.setName(currentGroup.name);
+	//test for holes in the sequence to rename the cue
+
+	for (var i=0; i<=groupsList.length+1; i++){
+		if(tl_seq.cues.getChild("group"+i)==undefined){
+			newCue.setName("group"+i);
+			currentGroup = groups.addContainer("group"+i);
+			script.log("create new group: group"+i);
+			break;
+		}
+	}
+ 
+	
+	
 	currentGroup.addFloatParameter(newCue.name, "cue of the group", currentTime, 0.);
-
+	var keysContainer = currentGroup.addContainer("keys");
+	keysContainer.setCollapsed(true);
 
 	// var struc_layers = util.getObjectProperties(sequence_structure.keys.layers);
 	if(tl_layers.length){
@@ -546,7 +584,8 @@ function createNewGroup(){
 				newKey.position.set(currentTime);
 				// newKey.value.set(local.values.newGroup.layersValues[layers[i].name].get());
 				newKey.value.set(Math.random());
-				currentGroup.addFloatParameter(tl_layers[i].name,tl_layers[i].name+" value" , newKey.value.get(), 0.);
+				keysContainer.addStringParameter(tl_layers[i].name, "",newKey.name );
+				currentGroup.addFloatParameter(tl_layers[i].name,tl_layers[i].name+" value" , newKey.value.get(), 0., 0., 1.);
 				// newKey.addStringParameter("group", "key is part of this group","mongroupe");
 				tl_layers[i].automation.reorderItems();
 			}

File diff suppressed because it is too large
+ 1 - 1
testSequenceMgr.noisette