SequenceMgr.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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. if(sequence!="undefined"){
  180. parameters.sequence.removeOptions();
  181. parameters.sequence.addOption(sequence,0);
  182. parameters.sequence.setAttribute("readonly", true);
  183. // script.log(parameters.synchronize.get());
  184. //
  185. //check if Sequence already exists in sequences manager, else create it
  186. var tl_sequence = root.sequences.getItemWithName(sequence) ;
  187. if(tl_sequence == undefined){
  188. tl_sequence = root.sequences.addItem();
  189. tl_sequence.setName(sequence);
  190. }
  191. //recreate cues
  192. tl_sequence.cues.removeAll();
  193. var cuesList = util.getObjectProperties(loadData.values.keys.cues, true, false);
  194. if(cuesList.length){
  195. for(var i=0; i<cuesList.length; i++){
  196. var cue = tl_sequence.cues.addItem();
  197. cue.setName(cuesList[i]);
  198. cue.time.set(loadData.values.keys.cues[cuesList[i]].time);
  199. }
  200. }
  201. //recreate layers and keys
  202. tl_sequence.layers.removeAll();
  203. var layersList = util.getObjectProperties(loadData.values.keys.layers, true, false);
  204. if(layersList.length){
  205. for(var i=0; i<layersList.length; i++ ){
  206. var layer = tl_sequence.layers.addItem("Mapping");
  207. layer.setName(layersList[i]);
  208. var keysList = util.getObjectProperties(loadData.values.keys.layers[layersList[i]], true, false);
  209. if(keysList.length){
  210. for(var j=0; j<keysList.length; j++){
  211. var key = layer.automation.addItem();
  212. key.setName(keysList[j]);
  213. key.value.set(loadData.values.keys.layers[layersList[i]][keysList[j]].value);
  214. key.position.set(loadData.values.keys.layers[layersList[i]][keysList[j]].time);
  215. }
  216. }
  217. layer.automation.reorderItems();
  218. }
  219. }
  220. //recreate groups
  221. var groupList = util.getObjectProperties(loadData.values.groups, true, false);
  222. if(groupList.length){
  223. for(var i=0; i<groupList.length; i++){
  224. var group = local.getChild("Values").groups.addContainer(groupList[i]);
  225. var groupLayers = util.getObjectProperties(loadData.values.groups[groupList[i]], true, false);
  226. var cue = group.addFloatParameter("cue", "", 0., 0.);
  227. group.setName(groupList[i]);
  228. cue.set(loadData.values.groups[groupList[i]].time);
  229. var groupKeysList = util.getObjectProperties(loadData.values.groups[groupList[i]].groupKeys, true, false);
  230. if (groupKeysList.length){
  231. var keysContainer = group.addContainer("keys");
  232. keysContainer.setCollapsed(true);
  233. for (var j=0; j<groupKeysList.length; j++){
  234. group.addFloatParameter(groupKeysList[j], "", 0., 0., 1.);
  235. keysContainer.addStringParameter(groupKeysList[j], "", loadData.values.groups[groupList[i]]['groupKeys'][groupKeysList[j]]['key']);
  236. }
  237. }
  238. }
  239. }
  240. // script.log(layersList[0]);
  241. doSync = true;
  242. // updateSynchronize() ;
  243. }
  244. }
  245. function exportSequenceFile(fileObj){
  246. script.log("exporting file");
  247. var exportData = {parameters:{}, values:{groups:{}, keys:{cues:{}, layers:{}}}};
  248. //collect parameters
  249. var parameters = local.getChild("parameters");
  250. exportData.parameters["Sequence"] = parameters.sequence.getKey();
  251. exportData.parameters["Synchronize"] = parameters.synchronize.get();
  252. exportData.parameters["Sync Rate"] = parameters.syncRate.get();
  253. //collect values
  254. var values = local.getChild("values");
  255. var groups = values.groups;
  256. var groupsList=util.getObjectProperties(groups, true, false);
  257. if(groupsList.length){
  258. for(var i=0; i<groupsList.length; i++){
  259. var exportGroup = exportData.values.groups[groupsList[i]] = {cue:"", time:0., groupKeys:{}};
  260. var currentGroup = groups.getChild(groupsList[i]);
  261. exportGroup.cue = currentGroup.cue.name;
  262. exportGroup.time = currentGroup.cue.get();
  263. var currentGroupLayers = util.getObjectProperties(currentGroup.keys, true, false);
  264. if (currentGroupLayers.length){
  265. for(var j=0; j<currentGroupLayers.length; j++){
  266. // script.log(groupsList[i]+ " "+ currentGroupLayers[j]);
  267. exportGroup.groupKeys[currentGroupLayers[j]] = {key:"", value:0};
  268. exportGroup.groupKeys[currentGroupLayers[j]].value = currentGroup.getChild(currentGroupLayers[j]).get();
  269. exportGroup.groupKeys[currentGroupLayers[j]].key = currentGroup.keys.getChild(currentGroupLayers[j]).get();
  270. }
  271. }
  272. }
  273. }
  274. var cues = values.keys.cues;
  275. var cuesList=util.getObjectProperties(cues, true, false);
  276. if(cuesList.length){
  277. for(var i=0; i<cuesList.length; i++){
  278. var exportCue = exportData.values.keys.cues[cuesList[i]] = {cue:"", time:0.};
  279. exportCue.cue = cuesList[i];
  280. exportCue.time = cues.getChild(cuesList[i]).time.get();
  281. }
  282. }
  283. var layers = values.keys.layers;
  284. var layersList=util.getObjectProperties(layers, true, false);
  285. if(layersList.length){
  286. for(var i=0; i<layersList.length; i++){
  287. var exportLayer = exportData.values.keys.layers[layersList[i]] = {};
  288. var currentLayer = layers.getChild(layersList[i]);
  289. var currentLayersKeys = util.getObjectProperties(currentLayer, true, false);
  290. if (currentLayersKeys.length){
  291. for(var j=0; j<currentLayersKeys.length; j++){
  292. // script.log(groupsList[i]+ " "+ currentGroupLayers[j]);
  293. exportLayer[currentLayersKeys[j]] = {key:"", value:0., time:0.};
  294. exportLayer[currentLayersKeys[j]].value = currentLayer.getChild(currentLayersKeys[j]).value.get();
  295. exportLayer[currentLayersKeys[j]].key = currentLayer.getChild(currentLayersKeys[j]).name;
  296. exportLayer[currentLayersKeys[j]].time = currentLayer.getChild(currentLayersKeys[j]).time.get();
  297. }
  298. }
  299. }
  300. }
  301. // exportData.groups
  302. fileObj.writeFile(JSON.stringify(exportData), true);
  303. }
  304. /////////////////////// VALUES FUNCTIONS ///////////////////////
  305. /* Values hold all keys, presented in group containers
  306. a nogroup container shows keys that are not grouped
  307. */
  308. // Value callback
  309. function moduleValueChanged(value){
  310. if(!inibValuesChanged){
  311. doSync = false;
  312. script.log(value.getParent().name);
  313. doSync = true;
  314. }
  315. if (value.is(local.values.newGroup.create)){createNewGroup();}
  316. // script.log(value.getParent().name);
  317. // if(value.getParent().name = "cue"){script.log("changed");}
  318. if (value.name == "addGroup"){createNewGroup();}
  319. }
  320. //rebuild values.keys structure from sequence
  321. function struct_buildValuesFromSeq(){
  322. inibValuesChanged = true;
  323. var hasUpdated = false ;
  324. var tl_seq = root.sequences.getItemWithName(sequence);
  325. if(tl_sequence!=undefined){
  326. //build cues if needed
  327. var tl_cues = tl_seq.cues.getItems();
  328. cues = local.getChild("values").keys.cues ;
  329. var cuesList = util.getObjectProperties(cues, true, false);
  330. // script.log("cueList : " +cuesList.length);
  331. // script.log("tl List : " +tl_cues.length);
  332. if (cuesList.length != tl_cues.length){
  333. var delta = cuesList.length-tl_cues.length;
  334. var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
  335. delta = Math.abs(delta);
  336. script.log("cues "+ delta + (addRemove ? " up" : " down"));
  337. for(var i=0; i<delta; i++){
  338. // script.log(i);
  339. if(addRemove){
  340. var newCue = cues.addContainer("newCue"+i);
  341. newCue.addFloatParameter("time", "position in time", 0., 0.);
  342. newCue.setCollapsed(true);
  343. }
  344. else {
  345. script.log(util.getObjectProperties(cues, true, false)[0]);
  346. cues.removeContainer(util.getObjectProperties(cues, true, false)[0]);
  347. }
  348. // cuesList = ;
  349. }
  350. hasUpdated = true;
  351. }
  352. //update cues
  353. cues = local.getChild("values").keys.cues ;
  354. var cuesList = util.getObjectProperties(cues, true, false);
  355. if(tl_cues.length){
  356. for (var i=0; i<tl_cues.length; i++){
  357. var currentCue = cues.getChild(cuesList[i]);
  358. currentCue.setName(tl_cues[i].name);
  359. currentCue.time.set(tl_cues[i].time.get());
  360. }
  361. }
  362. //build layers if needed
  363. var layersChanged = false ;
  364. var tl_layers = tl_seq.layers.getItems();
  365. layers = local.getChild("values").keys.layers ;
  366. var layersList = util.getObjectProperties(layers, true, false);
  367. if (layersList.length != tl_layers.length){
  368. layersChanged = true ;
  369. var delta = layersList.length-tl_layers.length;
  370. var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
  371. delta = Math.abs(delta);
  372. script.log("layers "+ delta + (addRemove ? " up" : " down"));
  373. for(var i=0; i<delta; i++){
  374. // script.log(i);
  375. if(addRemove){
  376. var newLayer = layers.addContainer("newLayer"+i);
  377. // newLayer.addFloatParameter("time", "position in time", 0., 0.);
  378. newLayer.setCollapsed(true);
  379. local.getChild("values").newGroup.layers.addFloatParameter("newLayer"+i, "value for this layer at group creation", 0., 0., 1.);
  380. }
  381. else {
  382. script.log(util.getObjectProperties(layers, true, false)[0]);
  383. layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
  384. local.getChild("values").newGroup.layers.removeContainer(util.getObjectProperties(layers, true, false)[0]);
  385. }
  386. // cuesList = ;
  387. }
  388. hasUpdated = true;
  389. }
  390. //update layers value if there was a change in structure
  391. if(layersChanged){
  392. layers = local.getChild("values").keys.layers ;
  393. var layerList = util.getObjectProperties(layers, true, false);
  394. var template = local.getChild("values").newGroup.layers;
  395. var layerTemplate = util.getObjectProperties(template, true, false);
  396. if(tl_layers.length){
  397. for (var i=0; i<tl_layers.length; i++){
  398. var currentLayer = layers.getChild(layerList[i]);
  399. currentLayer.setName(tl_layers[i].name);
  400. var currentTemplate = template.getChild(layerTemplate[i]) ;
  401. currentTemplate.setName(tl_layers[i].name);
  402. }
  403. }
  404. }
  405. //build keys if needed
  406. layers = local.getChild("values").keys.layers ;
  407. layersList = util.getObjectProperties(layers, true, false);
  408. if(layersList.length){
  409. for(var layerIndex=0; layerIndex<layersList.length; layerIndex++){
  410. var currentLayer = layers.getChild(layersList[layerIndex]);
  411. var keyList = util.getObjectProperties(currentLayer, true, false);
  412. var tl_lay = tl_seq.layers.getItemWithName(layersList[layerIndex]);
  413. var tl_keys;
  414. if(tl_lay.automation!=undefined){tl_keys = tl_lay.automation.getItems();}
  415. //rebuild key structure for currentLayer
  416. if (keyList.length != tl_keys.length){
  417. var delta = keyList.length-tl_keys.length;
  418. var addRemove = delta > 0 ? false : true ; //0 to remove, 1 to add
  419. delta = Math.abs(delta);
  420. script.log("keys "+ delta + (addRemove ? " up" : " down"));
  421. for(var i=0; i<delta; i++){
  422. // script.log(i);
  423. if(addRemove){
  424. var newKey = currentLayer.addContainer("newkey"+i);
  425. newKey.addFloatParameter("time", "position in time", 0., 0.);
  426. newKey.addFloatParameter("value", "vertical value", 0., 0.);
  427. newKey.setCollapsed(true);
  428. }
  429. else {
  430. script.log(util.getObjectProperties(currentLayer, true, false)[0]);
  431. currentLayer.removeContainer(util.getObjectProperties(currentLayer, true, false)[0]);
  432. }
  433. }
  434. hasUpdated = true;
  435. }
  436. currentLayer = layers.getChild(layersList[layerIndex]);
  437. keyList = util.getObjectProperties(currentLayer, true, false);
  438. //update values for currentLayer
  439. if(tl_keys.length){
  440. for(var i=0; i<tl_keys.length; i++){
  441. var currentKey = currentLayer.getChild(keyList[i]);
  442. currentKey.setName(tl_keys[i].name);
  443. currentKey.time.set(tl_keys[i].position.get());
  444. currentKey.value.set(tl_keys[i].value.get());
  445. }
  446. }
  447. }
  448. }
  449. //Groups
  450. tl_seq = root.sequences.getItemWithName(sequence);
  451. var groups = local.getChild("values").groups ;
  452. var groupList = util.getObjectProperties(groups, true, false);
  453. // printMethodsAndProperties(tl_seq.cues.getItemWithName("group0"));
  454. if(groupList.length){
  455. for (var i = 0; i<groupList.length; i++){
  456. //check if cue exist, else remove group
  457. // script.log(groupList[i]);
  458. var groupCue = tl_seq.cues.getItemWithName(groupList[i]);
  459. if(groupCue.name==undefined){
  460. script.log("cue " + groupList[i] + "not found, removing group (keys survive this)");
  461. groups.removeContainer(groupList[i]);
  462. hasUpdated = true;
  463. break;
  464. }
  465. //else check at key level
  466. else {
  467. groups = local.getChild("values").groups ;
  468. groupList = util.getObjectProperties(groups, true, false);
  469. var currentGroup = groups.getChild(groupList[i]);
  470. var currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
  471. //update cue time
  472. var groupTime = groupCue.time.get();
  473. currentGroup.cue.set(groupTime);
  474. if (currentGroupLayers.length){
  475. // script.log(currentGroupLayers.length);
  476. for(var j=0; j<currentGroupLayers.length; j++){
  477. // script.log("in loop" + j);
  478. groups = local.getChild("values").groups ;
  479. groupList = util.getObjectProperties(groups, true, false);
  480. currentGroup = groups.getChild(groupList[i]);
  481. currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
  482. var tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
  483. var keyName = currentGroup.keys.getChild(tl_layer.name).get();
  484. // script.log(tl_layer.name + " " +tl_layer.automation.getItemWithName(keyName).name);
  485. //if key dosn't exist anymore, remove it from group
  486. if(tl_layer.automation.getItemWithName(keyName).name == undefined){
  487. groups = local.getChild("values").groups ;
  488. groupList = util.getObjectProperties(groups, true, false);
  489. currentGroup = groups.getChild(groupList[i]);
  490. currentGroupLayers = util.getObjectProperties (currentGroup.keys, true, false);
  491. tl_layer = tl_seq.layers.getItemWithName(currentGroupLayers[j]);
  492. keyName = currentGroup.keys.getChild(tl_layer.name).get();
  493. script.log("should remove" + currentGroup.name + " " + currentGroupLayers[j]);
  494. currentGroup.keys.removeParameter(currentGroupLayers[j]);
  495. currentGroup.removeParameter(currentGroupLayers[j]);
  496. currentGroup.setCollapsed(true);
  497. currentGroup.setCollapsed(false);
  498. hasUpdated = true;
  499. }
  500. //if key exists, update value from tl and update time from group cue
  501. else{
  502. //apply groupTime
  503. var tl_key = tl_layer.automation.getItemWithName(keyName);
  504. tl_key.position.set(groupTime);
  505. //get tl value
  506. var keyValue = tl_key.value.get();
  507. var currentKey = currentGroup.getChild(tl_layer.name);
  508. // script.log(tl_layer.name + " " +keyName+" " + keyValue);
  509. // script.log(currentKey.name + " " +keyName+" " + keyValue);
  510. currentKey.set(keyValue);
  511. // script.log(currentKey.get());
  512. }
  513. }
  514. }
  515. // //if cue doesn't exist, remove whole group
  516. // if(tl_layers.length){
  517. // for (var j=0; j<tl_layers.length; j++){
  518. // if(!tl_layers[j].automation.getItemWithName(groupList[i])){
  519. // script.log("key " + groupList[i] + "not found, removing group (keys survive this)");
  520. // groups.removeContainer(groupList[i]);}
  521. // hasUpdated = true;
  522. // }
  523. // }
  524. //update group values
  525. }
  526. }
  527. }
  528. inibValuesChanged = false;
  529. return hasUpdated;
  530. }
  531. }
  532. function struct_rebuildGroupsFromSeq(){
  533. }
  534. // function rebuildValuesStructure() {
  535. // script.log("updating values structure");
  536. // //empty current structure
  537. // // local.values.removeAll();
  538. // local.getChild("Values").removeContainer("newGroup");
  539. // local.getChild("Values").removeContainer("groups");
  540. // local.getChild("Values").removeContainer("ungrouped");
  541. // //rebuild containers
  542. // var ng_cont = local.values.addContainer("New group");
  543. // var g_cont = local.values.addContainer("groups");
  544. // var ug_cont = local.values.addContainer("ungrouped");
  545. // // rebuild new group
  546. // ng_cont.addTrigger("add group", "adds a new group at cursor time with below values");
  547. // ng_cont.addFloatParameter("group time", "time position where the group will be created ", 0., 0.);
  548. // var layer_cont = ng_cont.addContainer("layers values");
  549. // var layers = util.getObjectProperties(sequence_structure.keys.layers) ;
  550. // for (var i=0; i<layers.length; i++){
  551. // //add a float value in each layer for group creation
  552. // layer_cont.addFloatParameter(layers[i], "", 0., 0., 1.);
  553. // ug_cont.addContainer(layers[i]);
  554. // }
  555. // //rebuild keys grouped/ungrouped
  556. // //first create group containers in groups
  557. // // //then create layer containers in ungrouped
  558. // // var layer_cont = ug_cont.addContainer("layers values");
  559. // }
  560. /////////////////////// TIMELINE FUNCTIONS ///////////////////////
  561. function seq_clearSequence(){
  562. var seq = root.sequences.getItemWithName(sequence) ;
  563. script.log("clearing all keys and cues of sequence : "+seq.name);
  564. seq.cues.removeAll();
  565. var layers = seq.layers.getItems();
  566. if(layers.length){
  567. for (var i = 0; i<layers.length; i++){
  568. if(layers[i].automation){layers[i].automation.removeAll();}
  569. }
  570. }
  571. //clear all groups
  572. var groups = local.getChild("values").groups;
  573. var groupsList = util.getObjectProperties(groups, true, false);
  574. if (groupsList.length){
  575. for(var i=0; i<groupsList.length; i++){
  576. groups.removeContainer(groupsList[i]);
  577. }
  578. }
  579. }
  580. //use Values structure to rebuild the sequence
  581. function seq_buildSeqFromValues(){}
  582. //use file to rebuild sequence
  583. function seq_buildSeqFromFile(){}
  584. function createNewGroup(){
  585. script.log("create new group");
  586. //create a cue and a key in each layer at cursor position in selected sequence
  587. var groups = local.getChild("values").groups;
  588. var groupsList = util.getObjectProperties(groups, true, false);
  589. // var index = groupsList.length == undefined ? 0 : groupsList.length;
  590. var currentGroup;
  591. var tl_seq = root.sequences.getItemWithName(sequence);
  592. var tl_layers = tl_seq.layers.getItems();
  593. script.log(groupList.length);
  594. //Get current sequence time position and create cue at this position, with group name
  595. var currentTime = tl_seq.currentTime.get() ;
  596. // var currentTime = local.values.newGroup.groupTime.get();
  597. script.log(currentTime);
  598. newCue = tl_seq.cues.addItem();
  599. newCue.time.set(currentTime);
  600. //test for holes in the sequence to rename the cue
  601. for (var i=0; i<=groupsList.length+1; i++){
  602. if(tl_seq.cues.getChild("group"+i)==undefined){
  603. newCue.setName("group"+i);
  604. currentGroup = groups.addContainer("group"+i);
  605. script.log("create new group: group"+i);
  606. break;
  607. }
  608. }
  609. currentGroup.addFloatParameter(newCue.name, "cue of the group", currentTime, 0.);
  610. var keysContainer = currentGroup.addContainer("keys");
  611. keysContainer.setCollapsed(true);
  612. // var struc_layers = util.getObjectProperties(sequence_structure.keys.layers);
  613. if(tl_layers.length){
  614. for(var i=0;i<tl_layers.length; i++ ){
  615. if(tl_layers[i].automation!=undefined){//only for mapping layers
  616. // script.log(sequence_structure.keys.layers[layers[i].name]);
  617. var newKey = tl_layers[i].automation.addItem();
  618. newKey.position.set(currentTime);
  619. script.log([layers[i].name]); //local.getChild("values").newGroup.layers.getChild().name
  620. newKey.value.set(local.getChild("values").newGroup.layers.getChild(tl_layers[i].name).get());
  621. // newKey.value.set(Math.random());
  622. keysContainer.addStringParameter(tl_layers[i].name, "",newKey.name );
  623. currentGroup.addFloatParameter(tl_layers[i].name,tl_layers[i].name+" value" , newKey.value.get(), 0., 1.);
  624. // newKey.addStringParameter("group", "key is part of this group","mongroupe");
  625. tl_layers[i].automation.reorderItems();
  626. }
  627. }
  628. }
  629. // seq = seq.getItems();
  630. }