123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- /*
- 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 rebuildValues = script.addTrigger("rebuild values", "adds a key at current cursor position" );
- var refreshKeys = script.addTrigger("refresh keys", "truc");
- var printKeys = script.addTrigger("printKeys","truc");
- var clearSeq = script.addTrigger("clear Sequence","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();
- 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();
- //
- }
- 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"){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)){
- script.log("refreshKeys");
- refreshKeysList();
- }
- if (param.is(clearSeq)){clearSequence();}
- }
- /////////////////////////// HELPERS /////////////////////////////////
- function printMethodsAndProperties(obj){
- script.log(" ");
- // var name = obj.getControlAddress() == undefined ? "object" : obj.getControlAddress();
- var name = "object";
- script.log(" METHODS OF " + name);
- var methods = util.getObjectMethods(obj);
- for(var i=0 ; i<methods.length ; i++){
- script.log(" "+ methods[i]);
- }
- script.log(" PARAMETERS OF " + name);
- var props = util.getObjectProperties(obj, true, false);
- for(var i=0 ; i<props.length ; i++){
- script.log(" "+ props[i]);
- }
- script.log(" OBJECTS OF " + name);
- 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");
- return 1;
- // loadSequenceFile();
- }
- }
- else {
- script.log("no file to load");
- refreshSequenceEnum();
- return 0;
- }
- }
- function loadSequenceFile(){
- script.log("loading file");
- sequence_structure = local.parameters.sequenceFile.readFile(true);
- //lock enum with curent sequence name
- var sequenceList = local.parameters.sequence;
- sequenceList.removeOptions();
- sequenceList.addOption(sequence_structure.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();
- // }
- function rebuildValuesStructure() {
- script.log("updating values structure");
- //empty current structure
- 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 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++){
- layer_cont.addFloatParameter(layers[i], "", 0., 0., 1.);
- }
-
- }
- /////////////////////// TIMELINE FUNCTIONS ///////////////////////
- function clearSequence(){
-
- var sequence = root.sequences.getItemWithName(sequence_structure.params.sequence) ;
- script.log("clearing all keys and cues of sequence : "+sequence.name);
- sequence.cues.removeAll();
- var layers = sequence.layers.getItems();
- if(layers.length){
- for (var i = 0; i<layers.length; i++){
- layers[i].automation.removeAll();
- }
- }
- }
- 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(),
- // group : currentkey.group.get()
- };
- // 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){
- //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() ;
- // var currentTime = local.values.newGroup.groupTime.get();
- script.log(currentTime);
- newCue = seq.cues.addItem();
- newCue.time.set(currentTime);
- var layers = seq.layers.getItems();
- script.log(layers.length);
- // 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();
- }
- }
- // seq = seq.getItems();
- }
|