Explorar o código

values-centric reorganisation

make value structure represent sequence and store group logic
allow import/export from/to file
eLandon %!s(int64=4) %!d(string=hai) anos
pai
achega
4845831e18
Modificáronse 3 ficheiros con 198 adicións e 96 borrados
  1. 156 80
      SequenceMgr.js
  2. 41 15
      module.json
  3. 1 1
      testSequenceMgr.noisette

+ 156 - 80
SequenceMgr.js

@@ -1,15 +1,37 @@
 /*
 SEQUENCE GROUPING MANAGEMENT MODULE
-allows to define a template of layers, then create groups of keys using that template
-groups are composed of one key per layer and a cue
-cue is used to define the time position of the keys
-values of each key can be changed
-keys are grouped by name, and groups can be saved/loaded to a file
+
+this module builds a representation of a sequence in values using containers
+It allows to create groups of keys, a group being a cue and one key per layer.
+In a group, all keys sync their time on cue's time, only value can be modified
+
+The sequence with grouping can then be exported and reloaded.
+
+The module checks periodicaly if timeline sequence structure (cues, layers and keys) and
+module values structure are in sync. If out of sync, you may either rebuild values structure 
+from sequence or rebuild sequence from values
 
 */
+var syncRate = 10;
+var synchronize = false ;
+
+var debug = true;
+var debugFile;
+
+var parametersPath = local.parameters ;
+
+var sequence ;
+var sequencePath = local.parameters.sequence ;
+var file ;
+var filePath = local.parameters.sequenceFile ;
+
+
+var newGroup = local.values.newGroup ;
+var groups = local.value.groups ;
+var cues = local.keys.cues ;
+var layers = local.keys.layers ;
+
 
-// var parameterPath = local.parameters;
-// var valuesPath = local.values;
 
 var rebuildValues = script.addTrigger("rebuild values", "adds a key at current cursor position" );
 var refreshKeys = script.addTrigger("refresh keys", "truc");
@@ -29,79 +51,55 @@ var sequence_structure = {	params: {},
 							 							outCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"}
 													}*/
 								
+/////////////////////		SCRIPT FUNCTIONS	//////////////////////////////
 
 
 function init() {
 	script.log("LOADED SEQUENCE GROUPING MANAGEMENT MODULE ");
-	// script.log();
-	if(testSequenceFile()){loadSequenceFile();}
 	
-	// printMethodsAndProperties(local.parameters.sequenceFile);
-
-	//test if a file is already defined,
-	//if yes load it, if no refresh sequences enum
-	// if(local.parameters.sequenceFile.getAbsolutePath() != ""){
-	// 	script.log("file ok");
-	// 	loadSequenceFile();
-	// }
-	// else{
-	// 	local.parameters.sequence.setAttribute("readonly",false);
-	// 	refreshSequenceEnum();
-	//	
-}
+	//adapt update rate
+	updateSyncRate();
+	
 
-function moduleParameterChanged(param){
-	script.log("received " + param.name);
-	if (param.name == "sequenceFile") {}
-	else if (param.name == "loadSequence"){loadSequenceFile();}
-	else if (param.name == "exportSequence") { exportSequenceFile();}
-	else if (param.name == "refreshList"){refreshSequenceEnum();}
-	else if (param.name == "sequence"){
-		var seq = root.sequences.getItems()[local.parameters.sequence.get()];
-		sequence_structure.params.sequence = seq.name ;
-		script.log(seq.name);
-	// 	local.parameters.removeContainer("groupTemplate");
-	// 	seqCont = local.parameters.addContainer("groupTemplate");
-	// 	if (seq.layers.getItems().length){
-	// 		for(var j=0 ; j<seq.layers.getItems().length ; j++){
-	// 			seqCont.addBoolParameter(seq.layers.getItems()[j].name, "is part of group template", true);
-	// 		}
-	// 		script.log("in layers");
-		// }
-	// 	else{script.log("no layers");}
-	//
-	// 	//refresh layers list
-	//
-	}
-}
+	//test if a sequence is already choosen else refresh and unlock sequence enum
+	sequence = sequencePath.getKey();
+	if(sequence == ""){refreshSequenceEnum();}
+	else{sequencePath.setAttribute("readonly", true);}
 
-function moduleValueChanged(value){
-	if (value.name == "addGroup"){createNewGroup(sequence_structure.params.sequence);}
 }
 
 function scriptParameterChanged(param){
-	script.log("scriptparamchanged" + param.name);
-	// if (param.name == "printKeys" ){printKeys();}
-	// if(param.name == "newKey"){
-	// 	var key = root.sequences.sequence.layers.mapping.automation.addItem();
-	// 	key.position.set(root.sequences.sequence.currentTime.get());
-	// 	key.value.set(Math.random());
-	// }
-	//
-	// if (param.name == "reorder"){
-	// 	root.sequences.sequence.layers.mapping.automation.reorderItems();
-	// }
-	// if (param.name == "moveKey"){
-	// 	root.sequences.sequence.layers.mapping.automation.key2.position.set(10.);
-	// }
+	
 	if (param.is(printKeys) ){printKeys();}
-	if(param.is(rebuildValues)){rebuildValuesStructure();}
-	if (param.is(refreshKeys)){
+
+	else if(param.is(rebuildValues)){rebuildValuesStructure();}
+
+	else if (param.is(refreshKeys)){
 		script.log("refreshKeys");
 		refreshKeysList();
 	}
-	if (param.is(clearSeq)){clearSequence();}
 
+	else if (param.is(clearSeq)){seq_clearSequence();}
+
+	else {script.log("scriptparamchanged" + param.name);}
+}
+
+var syncDelta = 0.;
+
+function update(deltaTime){
+
+	if(synchronize){
+		syncDelta += deltaTime ;
+		if (syncDelta > syncRate){
+			syncDelta = 0. ;
+			// if (debug ){
+			// 	// script.log(debugFile.getAbsolutePath());
+			// 	debugFile.writeFile(JSON.stringify(sequence_structure), true);
+			// }
+			// refreshKeysList();
+			struct_buildValuesFromSeq();
+		}
+	}	
 }
 
 
@@ -131,6 +129,52 @@ function printMethodsAndProperties(obj){
 }
 
 
+function printKeys(){
+
+	var seq = root.sequences.sequence.layers.mapping.automation.getItems() ;
+	if(seq.length){
+		for(var i=0; i<seq.length; i++){
+			script.log (">> "+seq[i].name + "  " + seq[i].position.get() + "  " + seq[i].listSize.get() );
+		}
+	}
+	else{script.log("nothing to print");}
+}
+
+
+
+
+///////////////////////		 PARAMETERS FUNCTIONS	///////////////////////
+
+// Module callback
+function moduleParameterChanged(param){
+	
+
+	if (param.is(parametersPath.importExport.sequenceFile)) {}
+
+	else if (param.is(parametersPath.importExport.loadSequence)){loadSequenceFile();}
+	
+	else if (param.is(parametersPath.importExport.exportSequence)) { exportSequenceFile();}
+
+	else if (param.is(parametersPath.synchronize)){}
+
+	else if (param.is(parametersPath.syncRate)){updateSyncRate();}
+
+	else if (param.is(parametersPath.changeSequence)){refreshSequenceEnum();}
+
+	else if (param.is(parametersPath.sequence)){
+		sequence = sequencePath.getKey();
+		script.log("watching "+ sequence);
+	}
+
+	else{script.log("received module param :" + param.name);}
+}
+
+function updateSyncRate(){
+	syncRate = parametersPath.syncRate.get();
+	script.log("new sync rate : " + syncRate);
+	script.setUpdateRate(syncRate);
+
+}
 
 //refresh Enum
 function refreshSequenceEnum(){
@@ -185,29 +229,42 @@ function exportSequenceFile(){
 }
 
 
-function printKeys(){
 
-	var seq = root.sequences.sequence.layers.mapping.automation.getItems() ;
-	if(seq.length){
-		for(var i=0; i<seq.length; i++){
-			script.log (">> "+seq[i].name + "  " + seq[i].position.get() + "  " + seq[i].listSize.get() );
-		}
-	}
-	else{script.log("nothing to print");}
-}
 
-///////////////////////		VALUES FUNCTIONS		///////////////////////
+///////////////////////		 VALUES FUNCTIONS		///////////////////////
 /* Values hold all keys, presented in group containers
 a nogroup container shows keys that are not grouped
 */
 
-// function clearValues(){
-	// var values = local.values.getItems();
-// }
+// Value callback
+function moduleValueChanged(value){
+	if (value.name == "addGroup"){createNewGroup(sequence_structure.params.sequence);}
+}
+
+//check if sequence and value structures are in sync (same cues, layers, and keys)
+function struct_checkSync(){
+
+}
+
+//rebuild values.keys structure from sequence
+function struct_buildValuesFromSeq(){
+	
+	//build cues
+
+	//build layers
+
+	//build keys in layers
+
+}
+
+
+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");
@@ -223,13 +280,22 @@ function rebuildValuesStructure() {
 	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		///////////////////////
-function clearSequence(){
+
+function seq_clearSequence(){
 	
 	var sequence = root.sequences.getItemWithName(sequence_structure.params.sequence) ;
 	script.log("clearing all keys and cues of sequence : "+sequence.name);
@@ -243,6 +309,12 @@ function clearSequence(){
 
 }
 
+//use Values structure to rebuild the sequence
+function seq_buildSeqFromValues(){}
+
+//use file to rebuild sequence
+function seq_buildSeqFromFile(){}
+
 function refreshKeysList(){
 
 	var sequence = root.sequences.getItemWithName(sequence_structure.params.sequence);
@@ -273,7 +345,11 @@ function refreshKeysList(){
 					sequence_structure['keys']['layers'][layers[i].name][currentkey.name] = {
 																				position : currentkey.position.get(),
 																				value : currentkey.value.get(),
-																				// group : currentkey.group.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);
 				}

+ 41 - 15
module.json

@@ -21,25 +21,39 @@
 	],
 	"defaults": {},
 	"parameters": {
-		"Sequence File": {
-			"type": "File",
-			"description": "Select json file with sequence structure."
-		},
-		"Load Sequence": {
-			"type": "Trigger",
-			"description": "Rebuilds all keys and groups in current sequence"
-		},
-		"Export Sequence": {
+		"Change sequence": {
 			"type": "Trigger",
-			"description": "export group structure and key values to json file"
+			"description": "unlock sequence list  !!!! WILL DESTROY ALL VALUES !!!!"
 		},
 		"Sequence": {
-			"type": "Enum"
+			"type": "Enum",
+			"options": {"sequence" : "choose sequence"}
 		},
-		"Refresh list": {
-			"type": "Trigger",
-			"description": "refresh sequence list"
-		}
+		"Synchronize":{
+			"type": "Boolean",
+			"default": true
+		},
+		"sync rate":{
+			"type": "Integer",
+			"default": 10,
+			"min": 0
+		},
+		"Import&Export":{
+			"type": "Container",
+			"collapsed": true,
+			"Sequence File": {
+				"type": "File",
+				"description": "Select json file with sequence structure."
+			},
+			"Load Sequence": {
+				"type": "Trigger",
+				"description": "Rebuilds all keys and groups in current sequence"
+			},
+			"Export Sequence": {
+				"type": "Trigger",
+				"description": "export group structure and key values to json file"
+			}
+		}		
 	},
 	"scripts": [
 		"SequenceMgr.js"
@@ -56,6 +70,18 @@
 		"groups": {
 			"type": "Container",
 			"collapsed": false
+		},
+		"keys": {
+			"type": "Container",
+			"collapsed": false,
+			"cues": {
+				"type": "Container",
+				"collapsed": false
+			},
+			"layers": {
+				"type": "Container",
+				"collapsed": false
+			}
 		}
 	},
 	"commands": {

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
testSequenceMgr.noisette