camAutomationTrigger.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* ********** GENERAL SCRIPTING **********************
  2. This templates shows what you can do in this is module script
  3. All the code outside functions will be executed each time this script is loaded, meaning at file load, when hitting the "reload" button or when saving this file
  4. */
  5. // You can add custom parameters to use in your script here, they will be replaced each time this script is saved
  6. 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
  7. //Here are all the type of parameters you can create
  8. /*
  9. var myTrigger = script.addTrigger("My Trigger", "Trigger description"); //This will add a trigger (button)
  10. var myBoolParam = script.addBoolParameter("My Bool Param","Description of my bool param",false); //This will add a boolean parameter (toggle), defaut unchecked
  11. 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
  12. 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
  13. 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"
  14. 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)
  15. var myP2DParam = script.addPoint2DParameter("My P2D Param","Description of my p2d param"); //This will add a point 2d parameter
  16. var myP3DParam = script.addPoint3DParameter("My P3D Param","Description of my p3d param"); //This will add a point 3d parameter
  17. var myTargetParam = script.addTargetParameter("My Target Param","Description of my target param"); //This will add a target parameter (to reference another parameter)
  18. var myEnumParam = script.addEnumParameter("My Enum Param","Description of my enum param", //This will add a enum parameter (dropdown with options)
  19. "Option 1", 1, //Each pair of values after the first 2 arguments define an option and its linked data
  20. "Option 2", 5, //First argument of an option is the label (string)
  21. "Option 3", "banana" //Second argument is the value, it can be whatever you want
  22. );
  23. */
  24. //you can also declare custom internal variable
  25. //var myValue = 5;
  26. /*
  27. The init() function will allow you to init everything you want after the script has been checked and loaded
  28. 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 !
  29. */
  30. function init()
  31. {
  32. //myFloatParam.set(5); //The .set() function set the parameter to this value.
  33. //myColorParam.set([1,.5,1,1]); //for a color parameter, you need to pass an array with 3 (RGB) or 4 (RGBA) values.
  34. //myP2DParam.set([1.5,-5]); // for a Point2D parameter, you need to pass 2 values (XY)
  35. //myP3DParam.set([1.5,2,-3]); // for a Point3D parameter, you need to pass 3 values (XYZ)
  36. }
  37. /*
  38. This function will be called each time a parameter of your script has changed
  39. */
  40. function scriptParameterChanged(param)
  41. {
  42. //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.
  43. script.log("Parameter changed : "+param.name); //All parameters have "name" property
  44. if(param.is(myTrigger)) script.log("Trigger !"); //You can check if two variables are the reference to the same parameter or object with the method .is()
  45. else if(param.is(myEnumParam)) script.log("Key = "+param.getKey()+", data = "+param.get()); //The enum parameter has a special function getKey() to get the key associated to the option. .get() will give you the data associated
  46. else script.log("Value is "+param.get()); //All parameters have a get() method that will return their value
  47. }
  48. /*
  49. This function, if you declare it, will launch a timer at 50hz, calling this method on each tick
  50. */
  51. /*
  52. function update(deltaTime)
  53. {
  54. 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.
  55. }
  56. */
  57. /* ********** COMMAND SPECIFIC SCRIPTING ********************** */
  58. /*
  59. If this script is in a mapping, then this will be called whenever the value from the mapping is updated
  60. */
  61. function setValue(value)
  62. {
  63. script.log("Set value "+value);
  64. }
  65. /*
  66. This will be called either when the consequence is triggered if it is in an Action, or just after setValue() if it is in a Mapping
  67. */
  68. function trigger()
  69. {
  70. var sequence = root.sequences.keys;
  71. var layer = sequence.layers.camZoom;
  72. var time = sequence.currentTime.get() ;
  73. myFloatParam.set(layer.automation.getValueAtPosition(time+10.));
  74. var currentKey = layer.automation.getKeyAtPosition(time);
  75. var nextKey = layer.automation.getItemAfter(currentKey);
  76. if(nextKey!=undefined){
  77. var duration = nextKey.position.get() - time;
  78. var value = nextKey.value.get();
  79. root.customVariables.camAutomation.variables.value.value.set(value);
  80. root.customVariables.camAutomation.variables.time.time.set(duration);
  81. }
  82. }