SequenceMgr.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. SEQUENCE GROUPING MANAGEMENT MODULE
  3. allows to define a template of layers, then create groups of keys using that template
  4. groups are composed of one key per layer and a cue
  5. cue is used to define the time position of the keys
  6. values of each key can be changed
  7. keys are grouped by name, and groups can be saved/loaded to a file
  8. */
  9. // var parameterPath = local.parameters;
  10. // var valuesPath = local.values;
  11. var rebuildValues = script.addTrigger("rebuild values", "adds a key at current cursor position" );
  12. var refreshKeys = script.addTrigger("refresh keys", "truc");
  13. var printKeys = script.addTrigger("printKeys","truc");
  14. var moveKey = script.addTrigger("moveKey","truc");
  15. var sequence_structure = { params: {},
  16. groups:{},
  17. keys:{
  18. cues:{},
  19. layers:{}
  20. }
  21. };
  22. //WAS tl_groups
  23. /*group0 : { inCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"},
  24. outCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"}
  25. }*/
  26. function init() {
  27. script.log("LOADED SEQUENCE GROUPING MANAGEMENT MODULE ");
  28. // script.log();
  29. if(testSequenceFile()){loadSequenceFile();}
  30. // printMethodsAndProperties(local.parameters.sequenceFile);
  31. //test if a file is already defined,
  32. //if yes load it, if no refresh sequences enum
  33. // if(local.parameters.sequenceFile.getAbsolutePath() != ""){
  34. // script.log("file ok");
  35. // loadSequenceFile();
  36. // }
  37. // else{
  38. // local.parameters.sequence.setAttribute("readonly",false);
  39. // refreshSequenceEnum();
  40. //
  41. }
  42. function moduleParameterChanged(param){
  43. script.log("received " + param.name);
  44. if (param.name == "sequenceFile") {}
  45. else if (param.name == "loadSequence"){loadSequenceFile();}
  46. else if (param.name == "exportSequence") { exportSequenceFile();}
  47. else if (param.name == "refreshList"){refreshSequenceEnum();}
  48. else if (param.name == "sequence"){
  49. var seq = root.sequences.getItems()[local.parameters.sequence.get()];
  50. sequence_structure.params.sequence = seq.name ;
  51. script.log(seq.name);
  52. // local.parameters.removeContainer("groupTemplate");
  53. // seqCont = local.parameters.addContainer("groupTemplate");
  54. // if (seq.layers.getItems().length){
  55. // for(var j=0 ; j<seq.layers.getItems().length ; j++){
  56. // seqCont.addBoolParameter(seq.layers.getItems()[j].name, "is part of group template", true);
  57. // }
  58. // script.log("in layers");
  59. // }
  60. // else{script.log("no layers");}
  61. //
  62. // //refresh layers list
  63. //
  64. }
  65. }
  66. function moduleValueChanged(value){
  67. if (value.name == "addGroup"){createNewGroup(sequence_structure.params.sequence);}
  68. }
  69. function scriptParameterChanged(param){
  70. script.log("paramchanged" + param.name);
  71. // if (param.name == "printKeys" ){printKeys();}
  72. // if(param.name == "newKey"){
  73. // var key = root.sequences.sequence.layers.mapping.automation.addItem();
  74. // key.position.set(root.sequences.sequence.currentTime.get());
  75. // key.value.set(Math.random());
  76. // }
  77. //
  78. // if (param.name == "reorder"){
  79. // root.sequences.sequence.layers.mapping.automation.reorderItems();
  80. // }
  81. // if (param.name == "moveKey"){
  82. // root.sequences.sequence.layers.mapping.automation.key2.position.set(10.);
  83. // }
  84. if (param.is(printKeys) ){printKeys();}
  85. if(param.is(rebuildValues)){rebuildValuesStructure(); }
  86. if (param.is(refreshKeys)){
  87. script.log("refreshKeys");
  88. refreshKeysList();
  89. }
  90. if (param.is(moveKey)){
  91. root.sequences.sequence.layers.mapping.automation.key2.position.set(10.);
  92. }
  93. }
  94. /////////////////////////// HELPERS /////////////////////////////////
  95. function printMethodsAndProperties(obj){
  96. script.log(" ");
  97. script.log(" METHODS OF " + obj.getControlAddress());
  98. var methods = util.getObjectMethods(obj);
  99. for(var i=0 ; i<methods.length ; i++){
  100. script.log(" "+ methods[i]);
  101. }
  102. script.log(" PARAMETERS OF " + obj.getControlAddress());
  103. var props = util.getObjectProperties(obj, true, false);
  104. for(var i=0 ; i<props.length ; i++){
  105. script.log(" "+ props[i]);
  106. }
  107. script.log(" OBJECTS OF " + obj.getControlAddress());
  108. var props = util.getObjectProperties(obj, false, true);
  109. for(var i=0 ; i<props.length ; i++){
  110. script.log(" "+ props[i]);
  111. }
  112. }
  113. //refresh Enum
  114. function refreshSequenceEnum(){
  115. script.log("refresh list of sequences");
  116. local.parameters.sequence.setAttribute("readonly",false);
  117. if(root.sequences.getItems().length){
  118. local.parameters.sequence.removeOptions();
  119. for(var i=0 ; i<root.sequences.getItems().length ; i++ ){
  120. local.parameters.sequence.addOption(root.sequences.getItems()[i].name,i);
  121. }
  122. }
  123. }
  124. function testSequenceFile(){
  125. var file = local.parameters.sequenceFile;
  126. //test if a file is declared
  127. if( file.getAbsolutePath() != ""){
  128. script.log("testing file " + file.getAbsolutePath() );
  129. var data = file.readFile(true);
  130. // test if expected fields are absent
  131. if (data.groups == undefined){
  132. script.log("file structure not recognized");
  133. refreshSequenceEnum();
  134. }
  135. //if all is well, let's load in sequence_structure
  136. else {
  137. script.log("ready to import");
  138. return 1;
  139. // loadSequenceFile();
  140. }
  141. }
  142. else {
  143. script.log("no file to load");
  144. refreshSequenceEnum();
  145. return 0;
  146. }
  147. }
  148. function loadSequenceFile(){
  149. script.log("loading file");
  150. sequence_structure = local.parameters.sequenceFile.readFile(true);
  151. //lock enum with curent sequence name
  152. var sequenceList = local.parameters.sequence;
  153. sequenceList.removeOptions();
  154. sequenceList.addOption(sequence_structure.params.sequence, 0);
  155. local.parameters.sequence.setAttribute("readonly",true);
  156. }
  157. function exportSequenceFile(){
  158. script.log("exporting file");
  159. local.parameters.sequenceFile.writeFile(JSON.stringify(sequence_structure), true);
  160. }
  161. function printKeys(){
  162. var seq = root.sequences.sequence.layers.mapping.automation.getItems() ;
  163. if(seq.length){
  164. for(var i=0; i<seq.length; i++){
  165. script.log (">> "+seq[i].name + " " + seq[i].position.get() + " " + seq[i].listSize.get() );
  166. }
  167. }
  168. else{script.log("nothing to print");}
  169. }
  170. /////////////////////// VALUES FUNCTIONS ///////////////////////
  171. /* Values hold all keys, presented in group containers
  172. a nogroup container shows keys that are not grouped
  173. */
  174. // function clearValues(){
  175. // var values = local.values.getItems();
  176. // }
  177. function rebuildValuesStructure() {
  178. script.log("updating values structure");
  179. //empty current structure
  180. local.getChild("Values").removeContainer("newGroup");
  181. local.getChild("Values").removeContainer("groups");
  182. local.getChild("Values").removeContainer("ungrouped");
  183. //rebuild containers
  184. var ng_cont = local.values.addContainer("New group");
  185. var g_cont = local.values.addContainer("groups");
  186. var ug_cont = local.values.addContainer("ungrouped");
  187. // rebuild new group
  188. ng_cont.addTrigger("add group", "adds a new group at cursor time with below values");
  189. ng_cont.addFloatParameter("group time", "time position where the group will be created ", 0., 0.);
  190. var layer_cont = ng_cont.addContainer("layers values");
  191. var layers = util.getObjectProperties(sequence_structure.keys.layers) ;
  192. for (var i=0; i<layers.length; i++){
  193. layer_cont.addFloatParameter(layers[i], "", 0., 0., 1.);
  194. }
  195. }
  196. /////////////////////// TIMELINE FUNCTIONS ///////////////////////
  197. function refreshKeysList(){
  198. var sequence = root.sequences.getItemWithName(local.parameters.sequence.getKey(0));
  199. var cues = sequence.cues.getItems();
  200. sequence_structure.keys.cues = {};
  201. if(cues.length){
  202. for (var i = 0 ; i < cues.length ; i++){
  203. sequence_structure.keys.cues['cue'+i] = {index : i};
  204. sequence_structure.keys['cues']['cue'+i]['name'] = cues[i].name;
  205. sequence_structure.keys['cues']['cue'+i]['niceName'] = cues[i].niceName;
  206. sequence_structure.keys['cues']['cue'+i]['time'] = cues[i].time.get();
  207. // script.log(tl_keyframes['cues']['cue'+i].time);
  208. }
  209. }
  210. var layers = sequence.layers.getItems();
  211. sequence_structure.keys.layers={};
  212. if(layers.length){
  213. for (var i = 0 ; i < layers.length ; i++){
  214. sequence_structure['keys']['layers'][layers[i].name] = {};
  215. // script.log(currentLayer.name);
  216. if(layers[i].automation.getItems().length){
  217. // script.log(currentLayer.automation.items.length);
  218. for (var j = 0 ; j < layers[i].automation.getItems().length ; j++){
  219. var currentkey = layers[i].automation.getItems()[j] ;
  220. sequence_structure['keys']['layers'][layers[i].name][currentkey.name] = {
  221. position : currentkey.position.get(),
  222. value : currentkey.value.get()
  223. };
  224. // script.log(tl_keyframes['keys'][currentLayer.name][currentkey.name].value);
  225. }
  226. }
  227. }
  228. }
  229. // myFile.writeFile(JSON.stringify(tl_keyframes), 1);
  230. }
  231. function createNewGroup(seqName){
  232. //create a cue and a key in each layer at cursor position in selected sequence
  233. var seq = root.sequences.getItemWithName(seqName);
  234. var currentTime = seq.currentTime.get() ;
  235. // var currentTime = local.values.newGroup.groupTime.get();
  236. script.log(currentTime);
  237. newCue = seq.cues.addItem();
  238. newCue.time.set(currentTime);
  239. var layers = seq.layers.getItems();
  240. script.log(layers.length);
  241. // var struc_layers = util.getObjectProperties(sequence_structure.keys.layers);
  242. if(layers.length){
  243. for(var i=0;i<layers.length; i++ ){
  244. // script.log(sequence_structure.keys.layers[layers[i].name]);
  245. newKey = layers[i].automation.addItem();
  246. newKey.position.set(currentTime);
  247. script.log(local.values.newGroup.layersValues[layers[i].name].get());
  248. newKey.value.set(local.values.newGroup.layersValues[layers[i].name].get());
  249. layers[i].automation.reorderItems();
  250. }
  251. }
  252. // seq = seq.getItems();
  253. }