SequenceMgr.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. SEQUENCE GROUPING MANAGEMENT MODULE
  3. this module builds a representation of a sequence in values using containers
  4. It allows to create groups of keys, a group being a cue and one key per layer.
  5. In a group, all keys sync their time on cue's time, only value can be modified
  6. The sequence with grouping can then be exported and reloaded.
  7. The module checks periodicaly if timeline sequence structure (cues, layers and keys) and
  8. module values structure are in sync. If out of sync, you may either rebuild values structure
  9. from sequence or rebuild sequence from values
  10. */
  11. var syncRatems = 100;
  12. var syncDelta = 0.;
  13. var doSync = false ;
  14. var inibValuesChanged = false ;
  15. var saveFile = script.addFileParameter("auto save sequence","");
  16. var saveRatems = 30;
  17. var saveDelta = 0.;
  18. var debug = true;
  19. var debugFile;
  20. var parametersPath = local.parameters ;
  21. var sequence = '' ;
  22. var sequencePath = local.getChild("parameters").sequence ;
  23. var file ;
  24. var filePath = local.parameters.sequenceFile ;
  25. var newGroupLayers = local.values.newGroup.layers ;
  26. // var groups = local.getChild("values").groups ;
  27. var cues = local.getChild("values").keys.cues ;
  28. // var cuesList = []; //holds cues containers reference
  29. var layers = local.getChild("values").keys.layers ;
  30. // var layerList = {}; //holds layer container as object with reference and an array of keys containers references
  31. var rebuildValues = script.addTrigger("rebuild values", "adds a key at current cursor position" );
  32. var refreshKeys = script.addTrigger("refresh keys", "truc");
  33. var printKeys = script.addTrigger("printKeys","truc");
  34. var clearSeq = script.addTrigger("clear Sequence","truc");
  35. var sequence_structure = { params: {},
  36. groups:{},
  37. keys:{
  38. cues:{},
  39. layers:{}
  40. }
  41. };
  42. //WAS tl_groups
  43. /*group0 : { inCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"},
  44. outCue : {pan : "key", tilt : "key", zoom : "key", dim : "key", focus : "key"}
  45. }*/
  46. ///////////////////// SCRIPT FUNCTIONS //////////////////////////////
  47. function init() {
  48. script.log("LOADED SEQUENCE GROUPING MANAGEMENT MODULE ");
  49. //adapt update rate
  50. updateSyncRate();
  51. updateSynchronize();
  52. saveFile.set("sequence_autosave.json");
  53. saveFile.setAttribute("readonly", true);
  54. importSequenceFile(saveFile);
  55. // layers = local.getChild("values").keys.layers ;
  56. // printMethodsAndProperties(local.getChild("values").groups.group0.cue.get());
  57. // script.log(local.getChild("values").groups.group0.cue.get());
  58. //test if a sequence is already choosen else refresh and unlock sequence enum
  59. sequence = local.getChild("parameters").sequence.getKey();
  60. // var sequenceIndex = local.getChild("parameters").sequence.get();
  61. // script.log(sequenceIndex + " " + sequence);
  62. if(sequence == ""){refreshSequenceEnum();}
  63. else{
  64. sequencePath.removeOptions();
  65. sequencePath.addOption(sequence,0);
  66. sequencePath.setAttribute("readonly", true);}
  67. }
  68. function scriptParameterChanged(param){
  69. if (param.is(printKeys) ){printKeys();}
  70. else if(param.is(rebuildValues)){struct_buildValuesFromSeq();}
  71. else if (param.is(refreshKeys)){
  72. script.log("refreshKeys");
  73. refreshKeysList();
  74. }
  75. else {script.log("scriptparamchanged" + param.name);}
  76. }
  77. function update(deltaTime){
  78. if(sequence!=""){
  79. if(doSync){
  80. syncDelta += deltaTime ;
  81. // script.log(syncDelta);
  82. if (syncDelta >= syncRatems){
  83. syncDelta = 0. ;
  84. var autosave = struct_buildValuesFromSeq();
  85. if(autosave){exportSequenceFile(saveFile);}
  86. }
  87. }
  88. saveDelta += deltaTime ;
  89. if (saveDelta >= saveRatems){
  90. saveDelta = 0. ;
  91. exportSequenceFile(saveFile);
  92. script.log("sequence autosave");
  93. }
  94. }
  95. }
  96. /////////////////////////// HELPERS /////////////////////////////////
  97. function printMethodsAndProperties(obj){
  98. script.log(" ");
  99. var name = obj.getControlAddress() == undefined ? "object" : obj.getControlAddress();
  100. // var name = "object";
  101. script.log(" METHODS OF " + name);
  102. var methods = util.getObjectMethods(obj);
  103. for(var i=0 ; i<methods.length ; i++){
  104. script.log(" "+ methods[i]);
  105. }
  106. script.log(" PARAMETERS OF " + name);
  107. var props = util.getObjectProperties(obj, true, false);
  108. for(var i=0 ; i<props.length ; i++){
  109. script.log(" "+ props[i]);
  110. }
  111. script.log(" OBJECTS OF " + name);
  112. var props = util.getObjectProperties(obj, false, true);
  113. for(var i=0 ; i<props.length ; i++){
  114. script.log(" "+ props[i]);
  115. }
  116. }
  117. function printKeys(){
  118. var seq = root.sequences.sequence.layers.mapping.automation.getItems() ;
  119. if(seq.length){
  120. for(var i=0; i<seq.length; i++){
  121. script.log (">> "+seq[i].name + " " + seq[i].position.get() + " " + seq[i].listSize.get() );
  122. }
  123. }
  124. else{script.log("nothing to print");}
  125. }
  126. /////////////////////// PARAMETERS FUNCTIONS ///////////////////////
  127. // Module callback
  128. function moduleParameterChanged(param){
  129. if (param.is(parametersPath.importExport.sequenceFile)) {}
  130. else if (param.is(parametersPath.importExport.importSequence)){importSequenceFile(parametersPath.importExport.sequenceFile);}
  131. else if (param.is(parametersPath.importExport.exportSequence)) {
  132. exportSequenceFile(parametersPath.importExport.sequenceFile);
  133. exportSequenceFile(saveFile);
  134. }
  135. else if (param.is(parametersPath.synchronize)){updateSynchronize();}
  136. else if (param.is(parametersPath.syncRate)){updateSyncRate();}
  137. else if (param.is(parametersPath.clearSequence)){seq_clearSequence();}
  138. else if (param.is(parametersPath.reorderSequence)){seq_reorderSequence();}
  139. else if (param.is(parametersPath.changeSequence)){refreshSequenceEnum();}
  140. else if (param.is(parametersPath.sequence)){
  141. sequence = sequencePath.getKey();
  142. if(sequence!=""){
  143. script.log("watching "+ sequence);
  144. local.parameters.sequence.setAttribute("readonly",true);
  145. }
  146. }
  147. else{script.log("received module param :" + param.name);}
  148. }
  149. function updateSynchronize(){
  150. doSync = parametersPath.synchronize.get();
  151. script.log(doSync ? "sync ON" : "sync OFF" );
  152. }
  153. function updateSyncRate(){
  154. syncRatems = parametersPath.syncRate.get() / 1000.;
  155. script.log("new sync rate : " + syncRatems);
  156. // script.setUpdateRate(syncRatems);
  157. }
  158. //refresh Enum
  159. function refreshSequenceEnum(){
  160. script.log("refresh list of sequences");
  161. local.parameters.sequence.setAttribute("readonly",false);
  162. if(root.sequences.getItems().length){
  163. local.parameters.sequence.removeOptions();
  164. local.parameters.sequence.addOption("", 0);
  165. for(var i=0 ; i<root.sequences.getItems().length ; i++ ){
  166. local.parameters.sequence.addOption(root.sequences.getItems()[i].name,i+1);
  167. }
  168. }
  169. }
  170. function importSequenceFile(loadFile){
  171. doSync = false ;
  172. script.log("loading file");
  173. loadData = loadFile.readFile(true);
  174. //load parameters
  175. var parameters = local.getChild("parameters");
  176. parameters.syncRate.set(loadData.parameters.SyncRate);
  177. parameters.synchronize.set(loadData.parameters.Synchronize);
  178. sequence = loadData.parameters.Sequence;
  179. parameters.sequence.removeOptions();
  180. parameters.sequence.addOption(sequence,0);
  181. parameters.sequence.setAttribute("readonly", true);
  182. // script.log(parameters.synchronize.get());
  183. //
  184. //check if Sequence already exists in sequences manager, else create it
  185. var tl_sequence = root.sequences.getItemWithName(sequence) ;
  186. if(tl_sequence == undefined){
  187. tl_sequence = root.sequences.addItem();
  188. tl_sequence.setName(sequence);
  189. }
  190. //recreate cues
  191. tl_sequence.cues.removeAll();
  192. var cuesList = util.getObjectProperties(loadData.values.keys.cues, true, false);
  193. if(cuesList.length){
  194. for(var i=0; i<cuesList.length; i++){
  195. var cue = tl_sequence.cues.addItem();
  196. cue.setName(cuesList[i]);
  197. cue.time.set(loadData.values.keys.cues[cuesList[i]].time);
  198. }
  199. }
  200. //recreate layers and keys
  201. tl_sequence.layers.removeAll();
  202. var layersList = util.getObjectProperties(loadData.values.keys.layers, true, false);
  203. if(layersList.length){
  204. for(var i=0; i<layersList.length; i++ ){
  205. var layer = tl_sequence.layers.addItem("Mapping");
  206. layer.setName(layersList[i]);
  207. var keysList = util.getObjectProperties(loadData.values.keys.layers[layersList[i]], true, false);
  208. if(keysList.length){
  209. for(var j=0; j<keysList.length; j++){
  210. var key = layer.automation.addItem();
  211. key.setName(keysList[j]);
  212. key.value.set(loadData.values.keys.layers[layersList[i]][keysList[j]].value);
  213. key.position.set(loadData.values.keys.layers[layersList[i]][keysList[j]].time);
  214. }
  215. }
  216. layer.automation.reorderItems();
  217. }
  218. }
  219. //recreate groups
  220. var groupList = util.getObjectProperties(loadData.values.groups, true, false);
  221. if(groupList.length){
  222. for(var i=0; i<groupList.length; i++){
  223. var group = local.getChild("Values").groups.addContainer(groupList[i]);
  224. var groupLayers = util.getObjectProperties(loadData.values.groups[groupList[i]], true, false);
  225. group.addFloatParameter("cue", "", 0., 0.);
  226. cue.setName(cuesList[i]);
  227. cue.time.set(loadData.values.keys.cues[cuesList[i]].time);
  228. var groupKeysList = util.getObjectProperties(loadData.values.groups[groupList[i]].groupKeys, true, false);
  229. if (groupKeysList.length){
  230. var keysContainer = group.addContainer("keys");
  231. keysContainer.setCollapsed(true);
  232. for (var j=0; j<groupKeysList.length; j++){
  233. group.addFloatParameter(groupKeysList[j], "", 0., 0., 1.);
  234. keysContainer.addStringParameter(groupKeysList[j], "", loadData.values.groups[groupList[i]]['groupKeys'][groupKeysList[j]]['key']);
  235. }
  236. }
  237. }
  238. }
  239. // script.log(layersList[0]);
  240. doSync = true;
  241. // updateSynchronize() ;
  242. }
  243. function exportSequenceFile(fileObj){
  244. script.log("exporting file");
  245. var exportData = {parameters:{}, values:{groups:{}, keys:{cues:{}, layers:{}}}};
  246. //collect parameters
  247. var parameters = local.getChild("parameters");
  248. exportData.parameters["Sequence"] = parameters.sequence.getKey();
  249. exportData.parameters["Synchronize"] = parameters.synchronize.get();
  250. exportData.parameters["Sync Rate"] = parameters.syncRate.get();
  251. //collect values
  252. var values = local.getChild("values");
  253. var groups = values.groups;
  254. var groupsList=util.getObjectProperties(groups, true, false);
  255. if(groupsList.length){
  256. for(var i=0; i<groupsList.length; i++){
  257. var exportGroup = exportData.values.groups[groupsList[i]] = {cue:"", time:0., groupKeys:{}};
  258. var currentGroup = groups.getChild(groupsList[i]);
  259. exportGroup.cue = currentGroup.cue.name;
  260. exportGroup.time = currentGroup.cue.get();
  261. var currentGroupLayers = util.getObjectProperties(currentGroup.keys, true, false);
  262. if (currentGroupLayers.length){
  263. for(var j=0; j<currentGroupLayers.length; j++){
  264. // script.log(groupsList[i]+ " "+ currentGroupLayers[j]);
  265. exportGroup.groupKeys[currentGroupLayers[j]] = {key:"", value:0};
  266. exportGroup.groupKeys[currentGroupLayers[j]].value = currentGroup.getChild(currentGroupLayers[j]).get();
  267. exportGroup.groupKeys[currentGroupLayers[j]].key = currentGroup.keys.getChild(currentGroupLayers[j]).get();
  268. }
  269. }
  270. }
  271. }
  272. var cues = values.keys.cues;
  273. var cuesList=util.getObjectProperties(cues, true, false);
  274. if(cuesList.length){
  275. for(var i=0; i<cuesList.length; i++){
  276. var exportCue = exportData.values.keys.cues[cuesList[i]] = {cue:"", time:0.};
  277. exportCue.cue = cuesList[i];
  278. exportCue.time = cues.getChild(cuesList[i]).time.get();
  279. }
  280. }
  281. var layers = values.keys.layers;
  282. var layersList=util.getObjectProperties(layers, true, false);
  283. if(layersList.length){
  284. for(var i=0; i<layersList.length; i++){
  285. var exportLayer = exportData.values.keys.layers[layersList[i]] = {};
  286. var currentLayer = layers.getChild(layersList[i]);
  287. var currentLayersKeys = util.getObjectProperties(currentLayer, true, false);
  288. if (currentLayersKeys.length){
  289. for(var j=0; j<currentLayersKeys.length; j++){
  290. // script.log(groupsList[i]+ " "+ currentGroupLayers[j]);
  291. exportLayer[currentLayersKeys[j]] = {key:"", value:0., time:0.};
  292. exportLayer[currentLayersKeys[j]].value = currentLayer.getChild(currentLayersKeys[j]).value.get();
  293. exportLayer[currentLayersKeys[j]].key = currentLayer.getChild(currentLayersKeys[j]).name;
  294. exportLayer[currentLayersKeys[j]].time = currentLayer.getChild(currentLayersKeys[j]).time.get();
  295. }
  296. }
  297. }
  298. }
  299. // exportData.groups
  300. fileObj.writeFile(JSON.stringify(exportData), true);
  301. }
  302. /////////////////////// VALUES FUNCTIONS ///////////////////////
  303. /* Values hold all keys, presented in group containers
  304. a nogroup container shows keys that are not grouped
  305. */
  306. // Value callback
  307. function moduleValueChanged(value){
  308. if(!inibValuesChanged){
  309. doSync = false;
  310. script.log(value.getParent().name);
  311. doSync = true;
  312. }
  313. if (value.is(local.values.newGroup.create)){createNewGroup();}
  314. // script.log(value.getParent().name);
  315. // if(value.getParent().name = "cue"){script.log("changed");}
  316. if (value.name == "addGroup"){createNewGroup();}
  317. }
  318. //rebuild values.keys structure from sequence
  319. function struct_buildValuesFromSeq(){
  320. inibValuesChanged = true;
  321. var hasUpdated = false ;
  322. var tl_seq = root.sequences.getItemWithName(sequence);
  323. if(tl_sequence!=undefined){
  324. //build cues if needed
  325. var tl_cues = tl_seq.cues.getItems();
  326. cues = local.getChild("values").keys.cues ;
  327. var cuesList = util.getObjectProperties(cues, true, false);
  328. // script.log("cueList : " +cuesList.length);
  329. // script.log("tl List : " +tl_cues.length);
  330. if (cuesList.length != tl_cues.length){
  331. var delta = cuesList.length-tl_cues.length;
  332. var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
  333. delta = Math.abs(delta);
  334. script.log("cues "+ delta + (addRemove ? " up" : " down"));
  335. for(var i=0; i<delta; i++){
  336. // script.log(i);
  337. if(addRemove){
  338. var newCue = cues.addContainer("newCue"+i);
  339. newCue.addFloatParameter("time", "position in time", 0., 0.);
  340. newCue.setCollapsed(true);
  341. }
  342. else {
  343. script.log(util.getObjectProperties(cues, true, false)[0]);
  344. cues.removeContainer(util.getObjectProperties(cues, true, false)[0]);
  345. }
  346. // cuesList = ;
  347. }
  348. hasUpdated = true;
  349. }
  350. //update cues
  351. cues = local.getChild("values").keys.cues ;
  352. var cuesList = util.getObjectProperties(cues, true, false);
  353. if(tl_cues.length){
  354. for (var i=0; i<tl_cues.length; i++){
  355. var currentCue = cues.getChild(cuesList[i]);
  356. currentCue.setName(tl_cues[i].name);
  357. currentCue.time.set(tl_cues[i].time.get());
  358. }
  359. }
  360. //build layers if needed
  361. var layersChanged = false ;
  362. var tl_layers = tl_seq.layers.getItems();
  363. layers = local.getChild("values").keys.layers ;
  364. var layersList = util.getObjectProperties(layers, true, false);
  365. if (layersList.length != tl_layers.length){
  366. layersChanged = true ;
  367. var delta = layersList.length-tl_layers.length;
  368. var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
  369. delta = Math.abs(delta);
  370. script.log("layers "+ delta + (addRemove ? " up" : " down"));
  371. for(var i=0; i<delta; i++){
  372. // script.log(i);
  373. if(addRemove){
  374. var newLayer = layers.addContainer("newLayer"+i);
  375. // newLayer.addFloatParameter("time", "position in time", 0., 0.);
  376. newLayer.setCollapsed(true);
  377. local.getChild("values").newGroup.layers.addFloatParameter("newLayer"+i, "value for this layer at group creation", 0., 0., 1.);
  378. }
  379. else {
  380. script.log(util.getObjectProperties(layers, true, false)[0]);
  381. layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
  382. local.getChild("values").newGroup.layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
  383. }
  384. // cuesList = ;
  385. }
  386. hasUpdated = true;
  387. }
  388. //update layers value if there was a change in structure
  389. if(layersChanged){
  390. layers = local.getChild("values").keys.layers ;
  391. var layerList = util.getObjectProperties(layers, true, false);
  392. var template = local.getChild("values").newGroup.layers;
  393. var layerTemplate = util.getObjectProperties(template, true, false);
  394. if(tl_layers.length){
  395. for (var i=0; i<tl_layers.length; i++){
  396. var currentLayer = layers.getChild(layerList[i]);
  397. currentLayer.setName(tl_layers[i].name);
  398. var currentTemplate = template.getChild(layerTemplate[i]) ;
  399. currentTemplate.setName(tl_layers[i].name);
  400. }
  401. }
  402. }
  403. //build keys if needed
  404. layers = local.getChild("values").keys.layers ;
  405. layersList = util.getObjectProperties(layers, true, false);
  406. if(layersList.length){
  407. for(var layerIndex=0; layerIndex<layersList.length; layerIndex++){
  408. var currentLayer = layers.getChild(layersList[layerIndex]);
  409. var keyList = util.getObjectProperties(currentLayer, true, false);
  410. var tl_lay = tl_seq.layers.getItemWithName(layersList[layerIndex]);
  411. var tl_keys;
  412. if(tl_lay.automation!=undefined){tl_keys = tl_lay.automation.getItems();}
  413. //rebuild key structure for currentLayer
  414. if (keyList.length != tl_keys.length){
  415. var delta = keyList.length-tl_keys.length;
  416. var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
  417. delta = Math.abs(delta);
  418. script.log("keys "+ delta + (addRemove ? " up" : " down"));
  419. for(var i=0; i<delta; i++){
  420. // script.log(i);
  421. if(addRemove){
  422. var newKey = currentLayer.addContainer("newkey"+i);
  423. newKey.addFloatParameter("time", "position in time", 0., 0.);
  424. newKey.addFloatParameter("value", "vertical value", 0., 0.);
  425. newKey.setCollapsed(true);
  426. }
  427. else {
  428. script.log(util.getObjectProperties(currentLayer, true, false)[0]);
  429. currentLayer.removeContainer(util.getObjectProperties(currentLayer, true, false)[0]);
  430. }
  431. }
  432. hasUpdated = true;
  433. }
  434. currentLayer = layers.getChild(layersList[layerIndex]);
  435. keyList = util.getObjectProperties(currentLayer, true, false);
  436. //update values for currentLayer
  437. if(tl_keys.length){
  438. for(var i=0; i<tl_keys.length; i++){
  439. var currentKey = currentLayer.getChild(keyList[i]);
  440. currentKey.setName(tl_keys[i].name);
  441. currentKey.time.set(tl_keys[i].position.get());
  442. currentKey.value.set(tl_keys[i].value.get());
  443. }
  444. }
  445. }
  446. }
  447. //Groups
  448. tl_seq = root.sequences.getItemWithName(sequence);
  449. var groups = local.getChild("values").groups ;
  450. var groupList = util.getObjectProperties(groups, true, false);
  451. // printMethodsAndProperties(tl_seq.cues.getItemWithName("group0"));
  452. if(groupList.length){
  453. for (var i = 0; i<groupList.length; i++){
  454. //check if cue exist, else remove group
  455. // script.log(groupList[i]);
  456. var groupCue = tl_seq.cues.getItemWithName(groupList[i]);
  457. if(groupCue.name==undefined){
  458. script.log("cue " + groupList[i] + "not found, removing group (keys survive this)");
  459. groups.removeContainer(groupList[i]);
  460. hasUpdated = true;
  461. break;
  462. }
  463. //else check at key level
  464. else {
  465. groups = local.getChild("values").groups ;
  466. groupList = util.getObjectProperties(groups, true, false);
  467. var currentGroup = groups.getChild(groupList[i]);
  468. var currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
  469. //update cue time
  470. var groupTime = groupCue.time.get();
  471. currentGroup.cue.set(groupTime);
  472. if (currentGroupLayers.length){
  473. // script.log(currentGroupLayers.length);
  474. for(var j=0; j<currentGroupLayers.length; j++){
  475. // script.log("in loop" + j);
  476. groups = local.getChild("values").groups ;
  477. groupList = util.getObjectProperties(groups, true, false);
  478. currentGroup = groups.getChild(groupList[i]);
  479. currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
  480. var tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
  481. var keyName = currentGroup.keys.getChild(tl_layer.name).get();
  482. // script.log(tl_layer.name + " " +tl_layer.automation.getItemWithName(keyName).name);
  483. //if key dosn't exist anymore, remove it from group
  484. if(tl_layer.automation.getItemWithName(keyName).name == undefined){
  485. groups = local.getChild("values").groups ;
  486. groupList = util.getObjectProperties(groups, true, false);
  487. currentGroup = groups.getChild(groupList[i]);
  488. currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
  489. tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
  490. keyName = currentGroup.keys.getChild(tl_layer.name).get();
  491. script.log("should remove" + currentGroup.name + " " + currentGroupLayers[j]);
  492. currentGroup.keys.removeParameter(currentGroupLayers[j]);
  493. currentGroup.removeParameter(currentGroupLayers[j]);
  494. currentGroup.setCollapsed(true);
  495. currentGroup.setCollapsed(false);
  496. hasUpdated = true;
  497. }
  498. //if key exists, update value from tl and update time from group cue
  499. else{
  500. //apply groupTime
  501. var tl_key = tl_layer.automation.getItemWithName(keyName);
  502. tl_key.position.set(groupTime);
  503. //get tl value
  504. var keyValue = tl_key.value.get();
  505. var currentKey = currentGroup.getChild(tl_layer.name);
  506. // script.log(tl_layer.name + " " +keyName+" " + keyValue);
  507. // script.log(currentKey.name + " " +keyName+" " + keyValue);
  508. currentKey.set(keyValue);
  509. // script.log(currentKey.get());
  510. }
  511. }
  512. }
  513. // //if cue doesn't exist, remove whole group
  514. // if(tl_layers.length){
  515. // for (var j=0; j<tl_layers.length; j++){
  516. // if(!tl_layers[j].automation.getItemWithName(groupList[i])){
  517. // script.log("key " + groupList[i] + "not found, removing group (keys survive this)");
  518. // groups.removeContainer(groupList[i]);}
  519. // hasUpdated = true;
  520. // }
  521. // }
  522. //update group values
  523. }
  524. }
  525. }
  526. inibValuesChanged = false;
  527. return hasUpdated;
  528. }
  529. }
  530. function struct_rebuildGroupsFromSeq(){
  531. }
  532. // function rebuildValuesStructure() {
  533. // script.log("updating values structure");
  534. // //empty current structure
  535. // // local.values.removeAll();
  536. // local.getChild("Values").removeContainer("newGroup");
  537. // local.getChild("Values").removeContainer("groups");
  538. // local.getChild("Values").removeContainer("ungrouped");
  539. // //rebuild containers
  540. // var ng_cont = local.values.addContainer("New group");
  541. // var g_cont = local.values.addContainer("groups");
  542. // var ug_cont = local.values.addContainer("ungrouped");
  543. // // rebuild new group
  544. // ng_cont.addTrigger("add group", "adds a new group at cursor time with below values");
  545. // ng_cont.addFloatParameter("group time", "time position where the group will be created ", 0., 0.);
  546. // var layer_cont = ng_cont.addContainer("layers values");
  547. // var layers = util.getObjectProperties(sequence_structure.keys.layers) ;
  548. // for (var i=0; i<layers.length; i++){
  549. // //add a float value in each layer for group creation
  550. // layer_cont.addFloatParameter(layers[i], "", 0., 0., 1.);
  551. // ug_cont.addContainer(layers[i]);
  552. // }
  553. // //rebuild keys grouped/ungrouped
  554. // //first create group containers in groups
  555. // // //then create layer containers in ungrouped
  556. // // var layer_cont = ug_cont.addContainer("layers values");
  557. // }
  558. /////////////////////// TIMELINE FUNCTIONS ///////////////////////
  559. function seq_clearSequence(){
  560. var seq = root.sequences.getItemWithName(sequence) ;
  561. script.log("clearing all keys and cues of sequence : "+seq.name);
  562. seq.cues.removeAll();
  563. var layers = seq.layers.getItems();
  564. if(layers.length){
  565. for (var i = 0; i<layers.length; i++){
  566. if(layers[i].automation){layers[i].automation.removeAll();}
  567. }
  568. }
  569. //clear all groups
  570. var groups = local.getChild("values").groups;
  571. var groupsList = util.getObjectProperties(groups, true, false);
  572. if (groupsList.length){
  573. for(var i=0; i<groupsList.length; i++){
  574. groups.removeContainer(groupsList[i]);
  575. }
  576. }
  577. }
  578. //use Values structure to rebuild the sequence
  579. function seq_buildSeqFromValues(){}
  580. //use file to rebuild sequence
  581. function seq_buildSeqFromFile(){}
  582. function createNewGroup(){
  583. script.log("create new group");
  584. //create a cue and a key in each layer at cursor position in selected sequence
  585. var groups = local.getChild("values").groups;
  586. var groupsList = util.getObjectProperties(groups, true, false);
  587. // var index = groupsList.length == undefined ? 0 : groupsList.length;
  588. var currentGroup;
  589. var tl_seq = root.sequences.getItemWithName(sequence);
  590. var tl_layers = tl_seq.layers.getItems();
  591. script.log(groupList.length);
  592. //Get current sequence time position and create cue at this position, with group name
  593. var currentTime = tl_seq.currentTime.get() ;
  594. // var currentTime = local.values.newGroup.groupTime.get();
  595. script.log(currentTime);
  596. newCue = tl_seq.cues.addItem();
  597. newCue.time.set(currentTime);
  598. //test for holes in the sequence to rename the cue
  599. for (var i=0; i<=groupsList.length+1; i++){
  600. if(tl_seq.cues.getChild("group"+i)==undefined){
  601. newCue.setName("group"+i);
  602. currentGroup = groups.addContainer("group"+i);
  603. script.log("create new group: group"+i);
  604. break;
  605. }
  606. }
  607. currentGroup.addFloatParameter(newCue.name, "cue of the group", currentTime, 0.);
  608. var keysContainer = currentGroup.addContainer("keys");
  609. keysContainer.setCollapsed(true);
  610. // var struc_layers = util.getObjectProperties(sequence_structure.keys.layers);
  611. if(tl_layers.length){
  612. for(var i=0;i<tl_layers.length; i++ ){
  613. if(tl_layers[i].automation!=undefined){//only for mapping layers
  614. // script.log(sequence_structure.keys.layers[layers[i].name]);
  615. var newKey = tl_layers[i].automation.addItem();
  616. newKey.position.set(currentTime);
  617. script.log([layers[i].name]); //local.getChild("values").newGroup.layers.getChild().name
  618. newKey.value.set(local.getChild("values").newGroup.layers.getChild(tl_layers[i].name).get());
  619. // newKey.value.set(Math.random());
  620. keysContainer.addStringParameter(tl_layers[i].name, "",newKey.name );
  621. currentGroup.addFloatParameter(tl_layers[i].name,tl_layers[i].name+" value" , newKey.value.get(), 0., 1.);
  622. // newKey.addStringParameter("group", "key is part of this group","mongroupe");
  623. tl_layers[i].automation.reorderItems();
  624. }
  625. }
  626. }
  627. // seq = seq.getItems();
  628. }