Browse Source

fixed sequence enum init and moved clearSequence to module parameters

eLandon 4 years ago
parent
commit
a5afc453e7
2 changed files with 68 additions and 46 deletions
  1. 62 43
      SequenceMgr.js
  2. 6 3
      module.json

+ 62 - 43
SequenceMgr.js

@@ -22,8 +22,8 @@ var debugFile;
 
 var parametersPath = local.parameters ;
 
-var sequence ;
-var sequencePath = local.parameters.sequence ;
+var sequence = '' ;
+var sequencePath = local.getChild("parameters").sequence ;
 var file ;
 var filePath = local.parameters.sequenceFile ;
 
@@ -70,9 +70,15 @@ function init() {
 	// printMethodsAndProperties(layers);
 
 	//test if a sequence is already choosen else refresh and unlock sequence enum
-	sequence = sequencePath.getKey();
+	sequence = local.getChild("parameters").sequence.getKey();
+	// var sequenceIndex = local.getChild("parameters").sequence.get();
+	script.log(sequenceIndex + "  " + sequence);
+	
 	if(sequence == ""){refreshSequenceEnum();}
-	else{sequencePath.setAttribute("readonly", true);}
+	else{
+		sequencePath.removeOptions();
+		sequencePath.addOption(sequence,0);
+		sequencePath.setAttribute("readonly", true);}
 
 }
 
@@ -87,7 +93,7 @@ function scriptParameterChanged(param){
 		refreshKeysList();
 	}
 
-	else if (param.is(clearSeq)){seq_clearSequence();}
+	
 
 	else {script.log("scriptparamchanged" + param.name);}
 }
@@ -95,15 +101,17 @@ function scriptParameterChanged(param){
 
 
 function update(deltaTime){
-	
-	if(doSync){
-		syncDelta += deltaTime ;
-		// script.log(syncDelta);
-		if (syncDelta >= syncRatems){
-			syncDelta = 0. ;
-			struct_buildValuesFromSeq();
-		}
-	}	
+	if(sequence!=""){
+
+		if(doSync){
+			syncDelta += deltaTime ;
+			// script.log(syncDelta);
+			if (syncDelta >= syncRatems){
+				syncDelta = 0. ;
+				struct_buildValuesFromSeq();
+			}
+		}	
+	}
 }
 
 
@@ -163,11 +171,18 @@ function moduleParameterChanged(param){
 
 	else if (param.is(parametersPath.syncRate)){updateSyncRate();}
 
+	else if (param.is(parametersPath.clearSequence)){seq_clearSequence();}
+
 	else if (param.is(parametersPath.changeSequence)){refreshSequenceEnum();}
 
 	else if (param.is(parametersPath.sequence)){
 		sequence = sequencePath.getKey();
-		script.log("watching "+ sequence);
+		if(sequence!="choose sequence"){
+			script.log("watching "+ sequence);
+			local.parameters.sequence.setAttribute("readonly",true);
+
+		}
+		
 	}
 
 	else{script.log("received module param :" + param.name);}
@@ -189,39 +204,42 @@ function updateSyncRate(){
 function refreshSequenceEnum(){
 	script.log("refresh list of sequences");
 	local.parameters.sequence.setAttribute("readonly",false);
+	
 	if(root.sequences.getItems().length){		
 		local.parameters.sequence.removeOptions();
+		local.parameters.sequence.addOption("", 0);
 		for(var i=0 ; i<root.sequences.getItems().length ; i++ ){
-			local.parameters.sequence.addOption(root.sequences.getItems()[i].name,i);
+			local.parameters.sequence.addOption(root.sequences.getItems()[i].name,i+1);
 		}
 	}
-}
 
-function testSequenceFile(){
-	var file = local.parameters.sequenceFile;
-	//test if a file is declared
-	if( file.getAbsolutePath() != ""){
-		script.log("testing file " + file.getAbsolutePath() );
-		var data = file.readFile(true);
-		// test if expected fields are absent
-		if (data.groups == undefined){
-			script.log("file structure not recognized");
-			refreshSequenceEnum();
-		}
-		//if all is well, let's load in sequence_structure
-		else {
-			script.log("ready to import");
-			return 1;
-			// loadSequenceFile();
-		}
-	}
-	else {
-		script.log("no file to load");
-		refreshSequenceEnum();
-		return 0;
-	}	
 }
 
+// function testSequenceFile(){
+// 	var file = local.parameters.sequenceFile;
+// 	//test if a file is declared
+// 	if( file.getAbsolutePath() != ""){
+// 		script.log("testing file " + file.getAbsolutePath() );
+// 		var data = file.readFile(true);
+// 		// test if expected fields are absent
+// 		if (data.groups == undefined){
+// 			script.log("file structure not recognized");
+// 			refreshSequenceEnum();
+// 		}
+// 		//if all is well, let's load in sequence_structure
+// 		else {
+// 			script.log("ready to import");
+// 			return 1;
+// 			// loadSequenceFile();
+// 		}
+// 	}
+// 	else {
+// 		script.log("no file to load");
+// 		refreshSequenceEnum();
+// 		return 0;
+// 	}	
+// }
+
 function importSequenceFile(){
 	script.log("loading file");
 			sequence_structure = local.parameters.sequenceFile.readFile(true);
@@ -573,7 +591,7 @@ function createNewGroup(){
 	//create a cue and a key in each layer at cursor position in selected sequence
 	var groups = local.getChild("values").groups;
 	var groupsList = util.getObjectProperties(groups, true, false);
-	var index = groupsList.length == undefined ? 0 : groupsList.length;
+	// var index = groupsList.length == undefined ? 0 : groupsList.length;
 	var currentGroup;
 
 	var tl_seq = root.sequences.getItemWithName(sequence);
@@ -610,8 +628,9 @@ function createNewGroup(){
 				// 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());
+				script.log([layers[i].name]);  //local.getChild("values").newGroup.layers.getChild().name
+				newKey.value.set(local.getChild("values").newGroup.layers.getChild(tl_layers[i].name).get());
+				// newKey.value.set(Math.random());
 				keysContainer.addStringParameter(tl_layers[i].name, "",newKey.name );
 				currentGroup.addFloatParameter(tl_layers[i].name,tl_layers[i].name+" value" , newKey.value.get(), 0., 1.);
 				// newKey.addStringParameter("group", "key is part of this group","mongroupe");

+ 6 - 3
module.json

@@ -26,8 +26,11 @@
 			"description": "unlock sequence list  !!!! WILL DESTROY ALL VALUES !!!!"
 		},
 		"Sequence": {
-			"type": "Enum",
-			"options": {"sequence" : "choose sequence"}
+			"type": "Enum"
+		},
+		"Clear sequence": {
+			"type": "Trigger",
+			"description": "Clear all groups, cues and keys"
 		},
 		"Synchronize":{
 			"type": "Boolean",
@@ -35,7 +38,7 @@
 		},
 		"sync rate":{
 			"type": "Integer",
-			"default": 10,
+			"default": 100,
 			"min": 0
 		},
 		"Import&Export":{