Kaynağa Gözat

added followCursor

eLandon 4 yıl önce
ebeveyn
işleme
59e5b644b1
1 değiştirilmiş dosya ile 72 ekleme ve 15 silme
  1. 72 15
      SequenceMgr.js

+ 72 - 15
SequenceMgr.js

@@ -47,7 +47,10 @@ var TrigprintKeys = script.addTrigger("printKeys","truc");
 var clearSeq = script.addTrigger("clear Sequence","truc");
 
 var UIposGet = script.addTrigger("get UIPos", "");
-var UIpos = script.addFloatParameter("UIpos", "", 0., 0.);
+var viewZoom = script.addFloatParameter("View Zoom", "", 0.5, 0., 1.); //part of sequence time to show
+var viewFollowCursor = script.addBoolParameter("follow Cursor", "", false);
+var followCursor = false ;
+var followZoom = 0.5 ;
 
 // var sequence_structure = {	params: {}, 
 // 							groups:{},
@@ -84,7 +87,7 @@ function init() {
 	// newClip.setName("testAudio");
 	// newClip.startTime.set(12);
 
-	// printMethodsAndProperties(newClip);
+	printMethodsAndProperties(root.sequences.truc);
 	// script.log(local.getChild("values").groups.group0.cue.get());
 
 	//test if a sequence is already choosen else refresh and unlock sequence enum
@@ -105,9 +108,15 @@ function init() {
 function scriptParameterChanged(param){
 	
 	if (param.is(TrigprintKeys) ){printKeys();}
-	else if(param.is(UIpos)) {script.log("uipos"); root.sequences.truc.viewUIPosition(UIpos.get());}
+	else if(param.is(viewZoom)) {
+		script.log("view zoom changed");
+		followZoom = param.get();
+	}
 
-	if (param.is(UIposGet)){script.log("getUIpos");}
+	if (param.is(viewFollowCursor)){
+		script.log("follow cursor " + (param.get() ? "ON" : "OFF"));
+		followCursor = param.get();
+	}
 
 	else if(param.is(rebuildValues)){struct_buildValuesFromSeq();}
 
@@ -142,7 +151,9 @@ function update(deltaTime){
 			exportSequenceFile(saveFile);
 			script.log("sequence autosave");
 		}
-
+		if(followCursor){
+			seq_followCursor() ;
+		}
 	}
 }
 
@@ -295,17 +306,28 @@ function importSequenceFile(loadFile){
 		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(loadData.values.keys.layers[layersList[i]].type);
+				var layerType = loadData.values.keys.layers[layersList[i]].type ;
+				var layer = tl_sequence.layers.addItem(layerType);
 				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);
+					if (layerType != "Audio"){
+						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();	
 					}
-					layer.automation.reorderItems();		
+					else {
+						for(var j=0; j<keysList.length; j++){						
+							var clip = layer.clips.addItem();
+							clip.setName(keysList[j]);
+							clip.filePath.set(loadData.values.keys.layers[layersList[i]][keysList[j]].filePath);
+							clip.startTime.set(loadData.values.keys.layers[layersList[i]][keysList[j]].startTime);
+						}	
+					}		
 				}
 				
 			}
@@ -396,7 +418,7 @@ function exportSequenceFile(fileObj){
 				for(var j=0; j<currentLayersKeys.length; j++){
 					if (exportLayer["type"]!= "Audio"){
 						if(currentLayersKeys[j]!="type"){
-							script.log(currentLayersKeys[j]);
+							// script.log(currentLayersKeys[j]);
 							// script.log(groupsList[i]+ "  "+ currentGroupLayers[j]);
 							exportLayer[currentLayersKeys[j]] = {key:"", value:0., time:0.};
 							exportLayer[currentLayersKeys[j]].value = currentLayer.getChild(currentLayersKeys[j]).value.get();
@@ -510,12 +532,16 @@ function struct_buildValuesFromSeq(){
 			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.);
 					local.getChild("values").keys.layerTypes.addStringParameter("newLayer"+i, "", "");
 					newLayer.setCollapsed(true);
-					local.getChild("values").newGroup.layers.addFloatParameter("newLayer"+i, "value for this layer at group creation", 0., 0., 1.);
+					if (tl_layers[i].getType()!="Audio"){
+						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]);
@@ -542,6 +568,7 @@ function struct_buildValuesFromSeq(){
 			var layerTemplate = util.getObjectProperties(template, true, false);
 
 			if(tl_layers.length){
+				var layer_offset = 0 ;
 				for (var i=0; i<tl_layers.length; i++){
 					var currentLayer = layers.getChild(layerList[i]);
 					// currentLayer.getChild("type").set(tl_layers[i].getType());
@@ -550,7 +577,8 @@ function struct_buildValuesFromSeq(){
 					currentLayerType.setName(tl_layers[i].name);
 					currentLayerType.set(tl_layers[i].getType());
 					var currentTemplate = template.getChild(layerTemplate[i]) ;
-					currentTemplate.setName(tl_layers[i].name);
+					if (tl_layers[i].getType()!="Audio"){layer_offset+=1;}
+					currentTemplate.setName(tl_layers[i+layer_offset].name);
 				}
 			}
 		}
@@ -804,6 +832,9 @@ function struct_buildValuesFromSeq(){
 	
 // }
 
+
+
+
 ///////////////////////		TIMELINE FUNCTIONS		///////////////////////
 
 function seq_clearSequence(){
@@ -815,6 +846,7 @@ function seq_clearSequence(){
 	if(layers.length){
 		for (var i = 0; i<layers.length; i++){
 			if(layers[i].automation){layers[i].automation.removeAll();}
+			if(layers[i].clips){layers[i].clips.removeAll();}
 		}
 	}
 
@@ -831,6 +863,18 @@ function seq_clearSequence(){
 
 }
 
+
+function seq_reorderSequence(){
+	var seq = root.sequences.getItemWithName(sequence) ;
+	script.log("reordering sequence : "+seq.name);
+	var layers = seq.layers.getItems();
+	if(layers.length){
+		for (var i = 0; i<layers.length; i++){
+			if(layers[i].automation){layers[i].automation.reorderItems();}
+			if(layers[i].clips){layers[i].clips.reorderItems();}
+		}
+	}
+}
 //use Values structure to rebuild the sequence
 function seq_buildSeqFromValues(){}
 
@@ -893,4 +937,17 @@ function createNewGroup(){
 	}
 	// seq = seq.getItems();
 
+}
+
+
+function seq_followCursor(){
+	var tl_seq = root.sequences.getItemWithName(sequence);
+	var tl_cursor = tl_seq.currentTime.get();
+	var tl_totalTime = tl_seq.totalTime.get() ;
+	var viewTime = followZoom * tl_totalTime ;
+	var startTime = tl_cursor - viewTime/2. ;
+	var endTime = tl_cursor + viewTime/2. ;
+	tl_seq.viewStartTime.set(startTime);
+	tl_seq.viewEndTime.set(endTime);
+	
 }