SequenceMgr.js 27 KB

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