123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- /*
- SEQUENCE GROUPING MANAGEMENT MODULE
- 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 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"}
- }*/
-
- ///////////////////// SCRIPT FUNCTIONS //////////////////////////////
- function init() {
- script.log("LOADED SEQUENCE GROUPING MANAGEMENT MODULE ");
-
- //adapt update rate
- updateSyncRate();
-
- //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 scriptParameterChanged(param){
-
- if (param.is(printKeys) ){printKeys();}
- else if(param.is(rebuildValues)){rebuildValuesStructure();}
- else if (param.is(refreshKeys)){
- script.log("refreshKeys");
- refreshKeysList();
- }
- 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();
- }
- }
- }
- /////////////////////////// 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]);
- }
- }
- 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(){
- 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);
- }
- /////////////////////// VALUES FUNCTIONS ///////////////////////
- /* Values hold all keys, presented in group containers
- a nogroup container shows keys that are not grouped
- */
- // 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");
- //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++){
- //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 seq_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();
- }
- }
- }
- //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);
- 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(),
- 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);
- }
- }
- }
- }
- // 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();
- }
|