Browse Source

first commit

basic file management
eLandon 4 years ago
commit
18d07b2218
2 changed files with 345 additions and 0 deletions
  1. 266 0
      SequenceMgr.js
  2. 79 0
      module.json

+ 266 - 0
SequenceMgr.js

@@ -0,0 +1,266 @@
+/*
+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
+
+*/
+
+// var parameterPath = local.parameters;
+// var valuesPath = local.values;
+
+var newKey = script.addTrigger("newKey", "adds a key at current cursor position" );
+var refreshKeys = script.addTrigger("refresh keys", "truc");
+var printKeys = script.addTrigger("printKeys","truc");
+var moveKey = script.addTrigger("moveKey","truc");
+
+
+var sequence_structure = {	params: {}, 
+							groups:{},
+							keys:{
+								cues:{},
+								layers:{}
+							}
+						};
+						 //WAS tl_groups
+	/*group0 : { inCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"},
+							 							outCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"}
+													}*/
+								
+
+
+function init() {
+	script.log("LOADED SEQUENCE GROUPING MANAGEMENT MODULE ");
+	// script.log();
+	testSequenceFile();
+	
+	// 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();
+	//	
+}
+
+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
+	//
+	}
+}
+
+function moduleValueChanged(value){
+
+
+	//
+	// if (value.name == "addGroup"){
+	// 	script.log("in values");
+	//
+	// 	var meth = util.getObjectProperties(key);
+	// 	if(meth.length){
+	// 		for(var i=0; i< meth.length; i++){
+	// 			script.log(meth[i]);
+	// 		}
+	// 	}
+	// }
+}
+
+function scriptParameterChanged(param){
+	script.log("paramchanged" + 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(newKey)){
+		var key = root.sequences.sequence.layers.mapping.automation.addItem();
+		key.position.set(root.sequences.sequence.currentTime.get());
+		key.value.set(Math.random());
+		root.sequences.sequence.layers.mapping.automation.reorderItems();
+	}
+
+	if (param.is(refreshKeys)){
+		script.log("refreshKeys");
+		refreshKeysList();
+	}
+	if (param.is(moveKey)){
+		root.sequences.sequence.layers.mapping.automation.key2.position.set(10.);
+	}
+
+}
+
+
+
+
+///////////////////////////		HELPERS		/////////////////////////////////
+
+function printMethodsAndProperties(obj){
+	script.log(" ");
+	script.log("  METHODS OF " + obj.getControlAddress());
+	var methods = util.getObjectMethods(obj);
+	for(var i=0 ; i<methods.length ; i++){
+		script.log("  "+ methods[i]);
+	}
+	script.log("  PARAMETERS OF " + obj.getControlAddress());
+	var props = util.getObjectProperties(obj, true, false);
+	for(var i=0 ; i<props.length ; i++){
+		script.log("  "+ props[i]);
+	}
+	script.log("  OBJECTS OF " + obj.getControlAddress());
+	var props = util.getObjectProperties(obj, false, true);
+	for(var i=0 ; i<props.length ; i++){
+		script.log("  "+ props[i]);
+	}
+}
+
+
+
+//refresh Enum
+function refreshSequenceEnum(){
+	script.log("refresh list of sequences");
+	local.parameters.sequence.setAttribute("readonly",false);
+	if(root.sequences.getItems().length){		
+		local.parameters.sequence.removeOptions();
+		for(var i=0 ; i<root.sequences.getItems().length ; i++ ){
+			local.parameters.sequence.addOption(root.sequences.getItems()[i].name,i);
+		}
+	}
+}
+
+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");
+			// loadSequenceFile();
+		}
+	}
+	else {
+		script.log("no file to load");
+		refreshSequenceEnum();
+	}	
+}
+
+function loadSequenceFile(){
+	script.log("loading file");
+			sequence_structure = data;
+			//lock enum with curent sequence name
+			var sequenceList = local.parameters.sequence;
+			sequenceList.removeOptions();
+			sequenceList.addOption(data.params.sequence, 0);
+			local.parameters.sequence.setAttribute("readonly",true);
+}
+
+function exportSequenceFile(){
+	script.log("exporting file");
+	local.parameters.sequenceFile.writeFile(JSON.stringify(sequence_structure), true);
+}
+
+
+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 hold all keys, presented in group containers
+a nogroup container shows keys that are not grouped
+*/
+
+function clearValues(){
+	var values = local.values.getItems();
+
+}
+
+
+///////////////////////		TIMELINE FUNCTIONS		///////////////////////
+
+function refreshKeysList(){
+
+	var sequence = root.sequences.getItemWithName(local.parameters.sequence.getKey(0));
+	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()
+																				};
+					// script.log(tl_keyframes['keys'][currentLayer.name][currentkey.name].value);
+				}
+			}
+		}
+	}
+
+	// myFile.writeFile(JSON.stringify(tl_keyframes), 1);
+}

+ 79 - 0
module.json

@@ -0,0 +1,79 @@
+{
+	"name": "keysMgr",
+	"type": "Serial",
+	"path": "LIEN",
+	"version": "0.0.1",
+	"description": "augment control over sequence keys, with saving/recalling mecanism, grouping ",
+	"url": "",
+	"downloadURL": "",
+	"hasInput": false,
+	"hasOutput": false,
+	"hideDefaultCommands": true,
+	"hideDefaultParameters": [
+		"protocol",
+		"autoAdd",
+		"messageStructure",
+		"firstValueIsTheName",
+		"port",
+		"baudRate",
+		"isConnected",
+		"pass_through"
+	],
+	"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": {
+			"type": "Trigger",
+			"description": "export group structure and key values to json file"
+		},
+		"Sequence": {
+			"type": "Enum"
+		},
+		"Refresh list": {
+			"type": "Trigger",
+			"description": "refresh sequence list"
+		}
+	},
+	"scripts": [
+		"keysMgr.js"
+	],
+	"values": {
+		"addGroup": {
+			"type": "Trigger",
+			"description": "create a new key group"
+		},
+		"groups": {
+			"type": "Container",
+			"collapsed": false
+		}
+	},
+	"commands": {
+		"ZoomAbsolute": {
+			"menu": "",
+			"callback": "setZoom",
+			"parameters": {
+				"ID": {
+					"type": "Integer",
+					"default": 1,
+					"min": 1,
+					"max": 255,
+					"useForMapping": true
+				},
+				"Position": {
+					"type": "Float",
+					"default":0,
+					"min": 0,
+					"max": 1,
+					"useForMapping": true
+				}
+			}
+		}
+	}
+}