瀏覽代碼

fix: check keys only if layer has automation

eLandon 4 年之前
父節點
當前提交
c96e717ba7
共有 2 個文件被更改,包括 109 次插入94 次删除
  1. 108 93
      SequenceMgr.js
  2. 1 1
      testSequenceMgr.noisette

+ 108 - 93
SequenceMgr.js

@@ -29,7 +29,7 @@ var filePath = local.parameters.sequenceFile ;
 
 
 var newGroupLayers = local.values.newGroup.layers ;
-var groups = local.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 ;
@@ -255,9 +255,11 @@ function moduleValueChanged(value){
 		doSync = true;
 	
 	}
+
+	if (value.is(local.values.newGroup.create)){createNewGroup();}
 	// script.log(value.getParent().name);
 	// if(value.getParent().name = "cue"){script.log("changed");}
-	if (value.name == "addGroup"){createNewGroup(sequence_structure.params.sequence);}
+	if (value.name == "addGroup"){createNewGroup();}
 }
 
 
@@ -361,7 +363,8 @@ function struct_buildValuesFromSeq(){
 			var keyList = util.getObjectProperties(currentLayer, true, false);
 
 			var tl_lay = tl_seq.layers.getItemWithName(layersList[layerIndex]);
-			var tl_keys = tl_lay.automation.getItems();
+			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;
@@ -409,37 +412,37 @@ function struct_buildValuesFromSeq(){
 function struct_exportToFile(){}
 
 
-function rebuildValuesStructure() {
-	script.log("updating values structure");
-	//empty current structure 
-	// local.values.removeAll();
-	local.getChild("Values").removeContainer("newGroup");
-	local.getChild("Values").removeContainer("groups");
-	local.getChild("Values").removeContainer("ungrouped");
+// function rebuildValuesStructure() {
+// 	script.log("updating values structure");
+// 	//empty current structure 
+// 	// local.values.removeAll();
+// 	local.getChild("Values").removeContainer("newGroup");
+// 	local.getChild("Values").removeContainer("groups");
+// 	local.getChild("Values").removeContainer("ungrouped");
 
-	//rebuild containers
-	var ng_cont = local.values.addContainer("New group");
-	var g_cont = local.values.addContainer("groups");
-	var ug_cont = local.values.addContainer("ungrouped");
+// 	//rebuild containers
+// 	var ng_cont = local.values.addContainer("New group");
+// 	var g_cont = local.values.addContainer("groups");
+// 	var ug_cont = local.values.addContainer("ungrouped");
 	
-	// rebuild new group
-	ng_cont.addTrigger("add group", "adds a new group at cursor time with below values");
-	ng_cont.addFloatParameter("group time", "time position where the group will be created ", 0., 0.);
-	var layer_cont = ng_cont.addContainer("layers values");
-	var layers = util.getObjectProperties(sequence_structure.keys.layers) ;
-	for (var i=0; i<layers.length; i++){
-		//add a float value in each layer for group creation
-		layer_cont.addFloatParameter(layers[i], "", 0., 0., 1.);
-		ug_cont.addContainer(layers[i]);
-	}
-
-	//rebuild keys grouped/ungrouped
-	//first create group containers in groups 
-
-	// //then create layer containers in ungrouped
-	// var layer_cont = ug_cont.addContainer("layers values");
+// 	// rebuild new group
+// 	ng_cont.addTrigger("add group", "adds a new group at cursor time with below values");
+// 	ng_cont.addFloatParameter("group time", "time position where the group will be created ", 0., 0.);
+// 	var layer_cont = ng_cont.addContainer("layers values");
+// 	var layers = util.getObjectProperties(sequence_structure.keys.layers) ;
+// 	for (var i=0; i<layers.length; i++){
+// 		//add a float value in each layer for group creation
+// 		layer_cont.addFloatParameter(layers[i], "", 0., 0., 1.);
+// 		ug_cont.addContainer(layers[i]);
+// 	}
+
+// 	//rebuild keys grouped/ungrouped
+// 	//first create group containers in groups 
+
+// 	// //then create layer containers in ungrouped
+// 	// var layer_cont = ug_cont.addContainer("layers values");
 	
-}
+// }
 
 ///////////////////////		TIMELINE FUNCTIONS		///////////////////////
 
@@ -463,78 +466,90 @@ 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 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(seqName){
+function createNewGroup(){
+	script.log("create new group");
 	//create a cue and a key in each layer at cursor position in selected sequence
-	var groupIndex =  util.getObjectProperties(sequence_structure.groups) ;
-	script.log(groupIndex.length);
-	// printMethodsAndProperties(groupIndex);
-	var seq = root.sequences.getItemWithName(seqName);
-	var currentTime = seq.currentTime.get() ;
+	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 tl_seq = root.sequences.getItemWithName(sequence);
+	var tl_layers = tl_seq.layers.getItems();
+	script.log(groupList.length);
+
+	//Get current sequence time position and create cue at this position, with group name
+	var currentTime = tl_seq.currentTime.get() ;
 	// var currentTime = local.values.newGroup.groupTime.get();
 	script.log(currentTime);
-	newCue = seq.cues.addItem();
+	newCue = tl_seq.cues.addItem();
 	newCue.time.set(currentTime);
-	var layers = seq.layers.getItems();
-	script.log(layers.length);
+	newCue.setName(currentGroup.name);
+	currentGroup.addFloatParameter(newCue.name, "cue of the group", currentTime, 0.);
+
+
 	// var struc_layers = util.getObjectProperties(sequence_structure.keys.layers);
-	if(layers.length){
-		for(var i=0;i<layers.length; i++ ){
-			// script.log(sequence_structure.keys.layers[layers[i].name]);
-			newKey = layers[i].automation.addItem();
-			newKey.position.set(currentTime);
-			script.log(local.values.newGroup.layersValues[layers[i].name].get());
-			newKey.value.set(local.values.newGroup.layersValues[layers[i].name].get());
-			newKey.addStringParameter("group", "key is part of this group","mongroupe");
-			layers[i].automation.reorderItems();
+	if(tl_layers.length){
+		for(var i=0;i<tl_layers.length; i++ ){
+			if(tl_layers[i].automation!=undefined){//only for mapping layers
+				// script.log(sequence_structure.keys.layers[layers[i].name]);
+				var newKey = tl_layers[i].automation.addItem();
+				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.);
+				// newKey.addStringParameter("group", "key is part of this group","mongroupe");
+				tl_layers[i].automation.reorderItems();
+			}
 		}
 	}
 	// seq = seq.getItems();

文件差異過大導致無法顯示
+ 1 - 1
testSequenceMgr.noisette