keyframes.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. var delCue_Trigger = script.addTrigger("clear cues", "clear all cues in the timeline");
  2. var clearTL_Trigger = script.addTrigger("clear timeline", "clear all cues and keys in the timeline");
  3. var myFile = script.addFileParameter("textFile", "this is a text file");
  4. var myTrigger = script.addTrigger("My Trigger", "Trigger description"); //This will add a trigger (button)
  5. var tl_keyframes = {cues : {}, keys : {}} ; //holds timeline keys, is updated at fixed rate
  6. var tl_refresh_rate = 0.5;
  7. var file_keyframes = {groups : 0} ; //holds file keys, used to save and load
  8. /*
  9. var myBoolParam = script.addBoolParameter("My Bool Param","Description of my bool param",false); //This will add a boolean parameter (toggle), defaut unchecked
  10. var myFloatParam = script.addFloatParameter("My Float Param","Description of my float param",.1,0,1); //This will add a float number parameter (slider), default value of 0.1, with a range between 0 and 1
  11. var myIntParam = script.addIntParameter("My Int Param","Description of my int param",2,0,10); //This will add an integer number parameter (stepper), default value of 2, with a range between 0 and 10
  12. var myStringParam = script.addStringParameter("My String Param","Description of my string param", "cool"); //This will add a string parameter (text field), default value is "cool"
  13. var myColorParam = script.addColorParameter("My Color Param","Description of my color param",0xff0000ff); //This will add a color parameter (color picker), default value of opaque blue (ARGB)
  14. var myP2DParam = script.addPoint2DParameter("My P2D Param","Description of my p2d param"); //This will add a point 2d parameter
  15. var myP3DParam = script.addPoint3DParameter("My P3D Param","Description of my p3d param"); //This will add a point 3d parameter
  16. var myTargetParam = script.addTargetParameter("My Target Param","Description of my target param"); //This will add a target parameter (to reference another parameter)
  17. var myEnumParam = script.addEnumParameter("My Enum Param","Description of my enum param", //This will add a enum parameter (dropdown with options)
  18. "Option 1", 1, //Each pair of values after the first 2 arguments define an option and its linked data
  19. "Option 2", 5, //First argument of an option is the label (string)
  20. "Option 3", "banana" //Second argument is the value, it can be whatever you want
  21. );
  22. */
  23. //you can also declare custom internal variable
  24. //var myValue = 5;
  25. /////////////////////// HELPERS FUNCTIONS ///////////////////////
  26. function refresh_tl_keys(){
  27. // tl_keyframes['cues']
  28. if(root.sequences.keys.cues.items.length){
  29. for (var i = 0 ; i < root.sequences.keys.cues.items.length ; i++){
  30. tl_keyframes['cues']['cue'+i] = {index : i};
  31. tl_keyframes['cues']['cue'+i]['name'] = root.sequences.keys.cues.items[i].name;
  32. tl_keyframes['cues']['cue'+i]['time'] = root.sequences.keys.cues.items[i].time.get();
  33. // script.log(tl_keyframes['cues']['cue'+i].time);
  34. }
  35. }
  36. if(root.sequences.keys.layers.items.length){
  37. for (var i = 0 ; i < root.sequences.keys.layers.items.length ; i++){
  38. var currentLayer = root.sequences.keys.layers.items[i] ;
  39. tl_keyframes['keys'][currentLayer.name] = {};
  40. // script.log(currentLayer.name);
  41. if(currentLayer.automation.items.length){
  42. // script.log(currentLayer.automation.items.length);
  43. for (var j = 0 ; j < currentLayer.automation.items.length ; j++){
  44. var currentkey = currentLayer.automation.items[j] ;
  45. tl_keyframes['keys'][currentLayer.name][currentkey.name] = {
  46. position : currentkey.position.get(),
  47. value : currentkey.value.get()
  48. };
  49. // script.log(tl_keyframes['keys'][currentLayer.name][currentkey.name].value);
  50. }
  51. }
  52. }
  53. }
  54. // myFile.writeFile(JSON.stringify(tl_keyframes), 1);
  55. }
  56. function clear_tl_cues(){
  57. if(root.sequences.keys.cues.items.length){
  58. for (var i = root.sequences.keys.cues.items.length-1 ; i>=0 ; i--){
  59. root.sequences.keys.cues.removeItem(root.sequences.keys.cues.items[i].name);
  60. }
  61. script.log("Cleared all cues");
  62. }
  63. else {script.log("no cues to clear");}
  64. }
  65. function clear_tl_keys(){
  66. if(root.sequences.keys.layers.items.length){
  67. for (var i = root.sequences.keys.layers.items.length-1 ; i >=0 ; i--){
  68. if(root.sequences.keys.layers.items[i].automation.items.length){
  69. for (var j = root.sequences.keys.layers.items[i].automation.items.length-1 ; j >= 0 ; j--){
  70. root.sequences.keys.layers.items[i].automation.removeItem(root.sequences.keys.layers.items[i].automation.items[j].name);
  71. }
  72. }
  73. // root.sequences.keys.cues.removeItem(root.sequences.keys.cues.items[i].name);
  74. }
  75. script.log("Cleared all keys");
  76. }
  77. else{script.log("no keys to clear");}
  78. }
  79. function clear_tl_full(){
  80. clear_tl_cues();
  81. clear_tl_keys();
  82. }
  83. function create_keyGroup(){
  84. //creates a cue and a key in each layer with same time position and current layer Values
  85. var groupIndex = file_keyframes.groups;
  86. script.log(groupIndex);
  87. var tempValues = {
  88. position: root.sequences.keys.currentTime.get() ,
  89. pan : root.sequences.keys.layers.pan.mapping.outValue.get(),
  90. tilt : root.sequences.keys.layers.tilt.mapping.outValue.get(),
  91. zoom : root.sequences.keys.layers.zoom.mapping.outValue.get(),
  92. dim : root.sequences.keys.layers.dim.mapping.outValue.get(),
  93. };
  94. var inCue = root.sequences.keys.cues.addItem();
  95. inCue.time.set(tempValues.position);
  96. script.log(inCue.name);
  97. var outCue = root.sequences.keys.cues.addItem();
  98. outCue.time.set(tempValues.position+1.);
  99. script.log(outCue.name);
  100. var groupKeys = {in:{}, out:{}} ;
  101. var layers = root.sequences.keys.layers.items ;
  102. if(layers.length){
  103. for (var i = 0 ; i<layers.length ; i++){
  104. tempKey = layers[i].automation.addItem();
  105. tempKey.position.set(tempValues.position);
  106. }
  107. }
  108. }
  109. /////////////////////// SCRIPT FUNCTIONS ///////////////////////
  110. /*
  111. The init() function will allow you to init everything you want after the script has been checked and loaded
  112. WARNING it also means that if you change values of your parameters by hand and set their values inside the init() function, they will be reset to this value each time the script is reloaded !
  113. */
  114. function init()
  115. {
  116. //myFloatParam.set(5); //The .set() function set the parameter to this value.
  117. //myColorParam.set([1,.5,1,1]); //for a color parameter, you need to pass an array with 3 (RGB) or 4 (RGBA) values.
  118. //myP2DParam.set([1.5,-5]); // for a Point2D parameter, you need to pass 2 values (XY)
  119. //myP3DParam.set([1.5,2,-3]); // for a Point3D parameter, you need to pass 3 values (XYZ)
  120. // tl.cues.cue.time
  121. // script.log(tl.cues.items[0].name);
  122. // for (var i = tl.cues.items.length-1 ; i>=0 ; i--){
  123. // // tl.cues.items[i].name='truc'+i;
  124. // script.log(tl.cues.items[i].time.get());
  125. // }
  126. // root.sequences.sequence.cues.items[0].name.set("moncue");
  127. }
  128. /*
  129. This function will be called each time a parameter of your script has changed
  130. */
  131. function scriptParameterChanged(param)
  132. {
  133. //You can use the script.log() function to show an information inside the logger panel. To be able to actuallt see it in the logger panel, you will have to turn on "Log" on this script.
  134. script.log("Parameter changed : "+param.name); //All parameters have "name" property
  135. if(param.is(myTrigger)){
  136. script.log("Trigger !"); //You can check if two variables are the reference to the same parameter or object with the method .is()
  137. create_keyGroup();
  138. // for (var i = tl.cues.items.length-1 ; i>=0 ; i--){
  139. // script.log(tl.cues.items[i].name);
  140. // }
  141. // myFile.writeFile(JSON.stringify(testJSON), 1);
  142. }
  143. else if (param.is(delCue_Trigger)){clear_tl_cues();}
  144. else if (param.is(clearTL_Trigger)){clear_tl_full();}
  145. else if(param.is(myEnumParam)) script.log("Label = "+param.get()+", data = "+param.getData()); //The enum parameter has a special function getData() to get the data associated to the option
  146. // else script.log("Value is "+param.get()); //All parameters have a get() method that will return their value
  147. // script.log(myFile.readFile());
  148. }
  149. /*
  150. This function, if you declare it, will launch a timer at 50hz, calling this method on each tick
  151. */
  152. var tl_refresh_delta = 0.;
  153. function update(deltaTime)
  154. {
  155. tl_refresh_delta += deltaTime ;
  156. if (tl_refresh_delta > tl_refresh_rate){
  157. tl_refresh_delta = 0. ;
  158. // refresh_tl_keys();
  159. // script.log("Update : "+util.getTime()+", delta = "+deltaTime); //deltaTime is the time between now and last update() call, util.getTime() will give you a timestamp relative to either the launch time of the software, or the start of the computer.
  160. }
  161. }
  162. /* ********** MODULE SPECIFIC SCRIPTING **********************
  163. The "local" variable refers to the object containing the scripts. In this case, the local variable refers to the module.
  164. It means that you can access any control inside this module by accessing it through its address.
  165. For instance, if the module has a float value named "Density", you can access it via local.values.density
  166. Then you can retrieve its value using local.values.density.get() and change its value using local.values.density.set()
  167. */
  168. /*
  169. This function will be called each time a parameter of this module has changed, meaning a parameter or trigger inside the "Parameters" panel of this module
  170. This function only exists because the script is in a module
  171. */
  172. function moduleParameterChanged(param)
  173. {
  174. if(param.isParameter())
  175. {
  176. script.log("Module parameter changed : "+param.name+" > "+param.get());
  177. }else
  178. {
  179. script.log("Module parameter triggered : "+value.name);
  180. }
  181. }
  182. /*
  183. This function will be called each time a value of this module has changed, meaning a parameter or trigger inside the "Values" panel of this module
  184. This function only exists because the script is in a module
  185. */
  186. function moduleValueChanged(value)
  187. {
  188. if(value.isParameter())
  189. {
  190. script.log("Module value changed : "+value.name+" > "+value.get());
  191. }else
  192. {
  193. script.log("Module value triggered : "+value.name);
  194. }
  195. }
  196. /* ********** OSC MODULE SPECIFIC SCRIPTING ********************* */
  197. /*
  198. OSC Modules have specific methods that can be used to send OSC message from Script.
  199. If you want to send an OSC Message from this script, you can do the following :
  200. local.send("/myAddress",1,.5f,"cool"); //This will send an OSC Message with address "/myAddress" and 3 arguments <int>, <float> and <string>
  201. */
  202. /*
  203. You can intercept OSC message with the function oscEvent(address, args)
  204. */
  205. function oscEvent(address, args)
  206. {
  207. //param "address" is the address of the OSC Message
  208. //param "args" is an array containing all the arguments of the OSC Message
  209. script.log("OSC Message received "+address+", "+args.length+" arguments");
  210. for(var i=0; i < args.length; i++)
  211. {
  212. script.log(" > "+args[i]);
  213. }
  214. }