SequenceMgr.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 newKey = script.addTrigger("newKey", "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. testSequenceFile();
  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. //
  68. // if (value.name == "addGroup"){
  69. // script.log("in values");
  70. //
  71. // var meth = util.getObjectProperties(key);
  72. // if(meth.length){
  73. // for(var i=0; i< meth.length; i++){
  74. // script.log(meth[i]);
  75. // }
  76. // }
  77. // }
  78. }
  79. function scriptParameterChanged(param){
  80. script.log("paramchanged" + param.name);
  81. // if (param.name == "printKeys" ){printKeys();}
  82. // if(param.name == "newKey"){
  83. // var key = root.sequences.sequence.layers.mapping.automation.addItem();
  84. // key.position.set(root.sequences.sequence.currentTime.get());
  85. // key.value.set(Math.random());
  86. // }
  87. //
  88. // if (param.name == "reorder"){
  89. // root.sequences.sequence.layers.mapping.automation.reorderItems();
  90. // }
  91. // if (param.name == "moveKey"){
  92. // root.sequences.sequence.layers.mapping.automation.key2.position.set(10.);
  93. // }
  94. if (param.is(printKeys) ){printKeys();}
  95. if(param.is(newKey)){
  96. var key = root.sequences.sequence.layers.mapping.automation.addItem();
  97. key.position.set(root.sequences.sequence.currentTime.get());
  98. key.value.set(Math.random());
  99. root.sequences.sequence.layers.mapping.automation.reorderItems();
  100. }
  101. if (param.is(refreshKeys)){
  102. script.log("refreshKeys");
  103. refreshKeysList();
  104. }
  105. if (param.is(moveKey)){
  106. root.sequences.sequence.layers.mapping.automation.key2.position.set(10.);
  107. }
  108. }
  109. /////////////////////////// HELPERS /////////////////////////////////
  110. function printMethodsAndProperties(obj){
  111. script.log(" ");
  112. script.log(" METHODS OF " + obj.getControlAddress());
  113. var methods = util.getObjectMethods(obj);
  114. for(var i=0 ; i<methods.length ; i++){
  115. script.log(" "+ methods[i]);
  116. }
  117. script.log(" PARAMETERS OF " + obj.getControlAddress());
  118. var props = util.getObjectProperties(obj, true, false);
  119. for(var i=0 ; i<props.length ; i++){
  120. script.log(" "+ props[i]);
  121. }
  122. script.log(" OBJECTS OF " + obj.getControlAddress());
  123. var props = util.getObjectProperties(obj, false, true);
  124. for(var i=0 ; i<props.length ; i++){
  125. script.log(" "+ props[i]);
  126. }
  127. }
  128. //refresh Enum
  129. function refreshSequenceEnum(){
  130. script.log("refresh list of sequences");
  131. local.parameters.sequence.setAttribute("readonly",false);
  132. if(root.sequences.getItems().length){
  133. local.parameters.sequence.removeOptions();
  134. for(var i=0 ; i<root.sequences.getItems().length ; i++ ){
  135. local.parameters.sequence.addOption(root.sequences.getItems()[i].name,i);
  136. }
  137. }
  138. }
  139. function testSequenceFile(){
  140. var file = local.parameters.sequenceFile;
  141. //test if a file is declared
  142. if( file.getAbsolutePath() != ""){
  143. script.log("testing file " + file.getAbsolutePath() );
  144. var data = file.readFile(true);
  145. // test if expected fields are absent
  146. if (data.groups == undefined){
  147. script.log("file structure not recognized");
  148. refreshSequenceEnum();
  149. }
  150. //if all is well, let's load in sequence_structure
  151. else {
  152. script.log("ready to import");
  153. // loadSequenceFile();
  154. }
  155. }
  156. else {
  157. script.log("no file to load");
  158. refreshSequenceEnum();
  159. }
  160. }
  161. function loadSequenceFile(){
  162. script.log("loading file");
  163. sequence_structure = data;
  164. //lock enum with curent sequence name
  165. var sequenceList = local.parameters.sequence;
  166. sequenceList.removeOptions();
  167. sequenceList.addOption(data.params.sequence, 0);
  168. local.parameters.sequence.setAttribute("readonly",true);
  169. }
  170. function exportSequenceFile(){
  171. script.log("exporting file");
  172. local.parameters.sequenceFile.writeFile(JSON.stringify(sequence_structure), true);
  173. }
  174. function printKeys(){
  175. var seq = root.sequences.sequence.layers.mapping.automation.getItems() ;
  176. if(seq.length){
  177. for(var i=0; i<seq.length; i++){
  178. script.log (">> "+seq[i].name + " " + seq[i].position.get() + " " + seq[i].listSize.get() );
  179. }
  180. }
  181. else{script.log("nothing to print");}
  182. }
  183. /////////////////////// VALUES FUNCTIONS ///////////////////////
  184. /* Values hold all keys, presented in group containers
  185. a nogroup container shows keys that are not grouped
  186. */
  187. function clearValues(){
  188. var values = local.values.getItems();
  189. }
  190. /////////////////////// TIMELINE FUNCTIONS ///////////////////////
  191. function refreshKeysList(){
  192. var sequence = root.sequences.getItemWithName(local.parameters.sequence.getKey(0));
  193. var cues = sequence.cues.getItems();
  194. sequence_structure.keys.cues = {};
  195. if(cues.length){
  196. for (var i = 0 ; i < cues.length ; i++){
  197. sequence_structure.keys.cues['cue'+i] = {index : i};
  198. sequence_structure.keys['cues']['cue'+i]['name'] = cues[i].name;
  199. sequence_structure.keys['cues']['cue'+i]['niceName'] = cues[i].niceName;
  200. sequence_structure.keys['cues']['cue'+i]['time'] = cues[i].time.get();
  201. // script.log(tl_keyframes['cues']['cue'+i].time);
  202. }
  203. }
  204. var layers = sequence.layers.getItems();
  205. sequence_structure.keys.layers={};
  206. if(layers.length){
  207. for (var i = 0 ; i < layers.length ; i++){
  208. sequence_structure['keys']['layers'][layers[i].name] = {};
  209. // script.log(currentLayer.name);
  210. if(layers[i].automation.getItems().length){
  211. // script.log(currentLayer.automation.items.length);
  212. for (var j = 0 ; j < layers[i].automation.getItems().length ; j++){
  213. var currentkey = layers[i].automation.getItems()[j] ;
  214. sequence_structure['keys']['layers'][layers[i].name][currentkey.name] = {
  215. position : currentkey.position.get(),
  216. value : currentkey.value.get()
  217. };
  218. // script.log(tl_keyframes['keys'][currentLayer.name][currentkey.name].value);
  219. }
  220. }
  221. }
  222. }
  223. // myFile.writeFile(JSON.stringify(tl_keyframes), 1);
  224. }