123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- var delCue_Trigger = script.addTrigger("clear cues", "clear all cues in the timeline");
- var clearTL_Trigger = script.addTrigger("clear timeline", "clear all cues and keys in the timeline");
- var myFile = script.addFileParameter("textFile", "this is a text file");
- var myTrigger = script.addTrigger("My Trigger", "Trigger description"); //This will add a trigger (button)
- var tl_keyframes = {cues : {}, keys : {}} ; //holds timeline keys, is updated at fixed rate
- var tl_refresh_rate = 0.5;
- var file_keyframes = {groups : 0} ; //holds file keys, used to save and load
- /*
- var myBoolParam = script.addBoolParameter("My Bool Param","Description of my bool param",false); //This will add a boolean parameter (toggle), defaut unchecked
- 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
- 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
- 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"
- 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)
- var myP2DParam = script.addPoint2DParameter("My P2D Param","Description of my p2d param"); //This will add a point 2d parameter
- var myP3DParam = script.addPoint3DParameter("My P3D Param","Description of my p3d param"); //This will add a point 3d parameter
- var myTargetParam = script.addTargetParameter("My Target Param","Description of my target param"); //This will add a target parameter (to reference another parameter)
- var myEnumParam = script.addEnumParameter("My Enum Param","Description of my enum param", //This will add a enum parameter (dropdown with options)
- "Option 1", 1, //Each pair of values after the first 2 arguments define an option and its linked data
- "Option 2", 5, //First argument of an option is the label (string)
- "Option 3", "banana" //Second argument is the value, it can be whatever you want
- );
- */
- //you can also declare custom internal variable
- //var myValue = 5;
- /////////////////////// HELPERS FUNCTIONS ///////////////////////
- function refresh_tl_keys(){
- // tl_keyframes['cues']
- if(root.sequences.keys.cues.items.length){
- for (var i = 0 ; i < root.sequences.keys.cues.items.length ; i++){
- tl_keyframes['cues']['cue'+i] = {index : i};
- tl_keyframes['cues']['cue'+i]['name'] = root.sequences.keys.cues.items[i].name;
- tl_keyframes['cues']['cue'+i]['time'] = root.sequences.keys.cues.items[i].time.get();
- // script.log(tl_keyframes['cues']['cue'+i].time);
- }
- }
- if(root.sequences.keys.layers.items.length){
- for (var i = 0 ; i < root.sequences.keys.layers.items.length ; i++){
- var currentLayer = root.sequences.keys.layers.items[i] ;
- tl_keyframes['keys'][currentLayer.name] = {};
- // script.log(currentLayer.name);
- if(currentLayer.automation.items.length){
- // script.log(currentLayer.automation.items.length);
- for (var j = 0 ; j < currentLayer.automation.items.length ; j++){
- var currentkey = currentLayer.automation.items[j] ;
- tl_keyframes['keys'][currentLayer.name][currentkey.name] = {
- position : currentkey.position.get(),
- value : currentkey.value.get()
- };
- // script.log(tl_keyframes['keys'][currentLayer.name][currentkey.name].value);
- }
- }
- }
- }
- // myFile.writeFile(JSON.stringify(tl_keyframes), 1);
- }
- function clear_tl_cues(){
- if(root.sequences.keys.cues.items.length){
- for (var i = root.sequences.keys.cues.items.length-1 ; i>=0 ; i--){
- root.sequences.keys.cues.removeItem(root.sequences.keys.cues.items[i].name);
- }
- script.log("Cleared all cues");
- }
- else {script.log("no cues to clear");}
- }
- function clear_tl_keys(){
- if(root.sequences.keys.layers.items.length){
- for (var i = root.sequences.keys.layers.items.length-1 ; i >=0 ; i--){
- if(root.sequences.keys.layers.items[i].automation.items.length){
- for (var j = root.sequences.keys.layers.items[i].automation.items.length-1 ; j >= 0 ; j--){
- root.sequences.keys.layers.items[i].automation.removeItem(root.sequences.keys.layers.items[i].automation.items[j].name);
- }
- }
- // root.sequences.keys.cues.removeItem(root.sequences.keys.cues.items[i].name);
- }
- script.log("Cleared all keys");
- }
- else{script.log("no keys to clear");}
- }
- function clear_tl_full(){
- clear_tl_cues();
- clear_tl_keys();
- }
- function create_keyGroup(){
- //creates a cue and a key in each layer with same time position and current layer Values
- var groupIndex = file_keyframes.groups;
- script.log(groupIndex);
- var tempValues = {
- position: root.sequences.keys.currentTime.get() ,
- pan : root.sequences.keys.layers.pan.mapping.outValue.get(),
- tilt : root.sequences.keys.layers.tilt.mapping.outValue.get(),
- zoom : root.sequences.keys.layers.zoom.mapping.outValue.get(),
- dim : root.sequences.keys.layers.dim.mapping.outValue.get(),
- };
- var inCue = root.sequences.keys.cues.addItem();
- inCue.time.set(tempValues.position);
- script.log(inCue.name);
- var outCue = root.sequences.keys.cues.addItem();
- outCue.time.set(tempValues.position+1.);
- script.log(outCue.name);
- var groupKeys = {in:{}, out:{}} ;
- var layers = root.sequences.keys.layers.items ;
- if(layers.length){
- for (var i = 0 ; i<layers.length ; i++){
- tempKey = layers[i].automation.addItem();
- tempKey.position.set(tempValues.position);
- }
- }
- }
- /////////////////////// SCRIPT FUNCTIONS ///////////////////////
- /*
- The init() function will allow you to init everything you want after the script has been checked and loaded
- 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 !
- */
- function init()
- {
- //myFloatParam.set(5); //The .set() function set the parameter to this value.
- //myColorParam.set([1,.5,1,1]); //for a color parameter, you need to pass an array with 3 (RGB) or 4 (RGBA) values.
- //myP2DParam.set([1.5,-5]); // for a Point2D parameter, you need to pass 2 values (XY)
- //myP3DParam.set([1.5,2,-3]); // for a Point3D parameter, you need to pass 3 values (XYZ)
- // tl.cues.cue.time
- // script.log(tl.cues.items[0].name);
- // for (var i = tl.cues.items.length-1 ; i>=0 ; i--){
- // // tl.cues.items[i].name='truc'+i;
- // script.log(tl.cues.items[i].time.get());
- // }
- // root.sequences.sequence.cues.items[0].name.set("moncue");
- }
- /*
- This function will be called each time a parameter of your script has changed
- */
- function scriptParameterChanged(param)
- {
- //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.
- script.log("Parameter changed : "+param.name); //All parameters have "name" property
- 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()
- create_keyGroup();
- // for (var i = tl.cues.items.length-1 ; i>=0 ; i--){
- // script.log(tl.cues.items[i].name);
- // }
- // myFile.writeFile(JSON.stringify(testJSON), 1);
- }
- else if (param.is(delCue_Trigger)){clear_tl_cues();}
- else if (param.is(clearTL_Trigger)){clear_tl_full();}
- 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
- // else script.log("Value is "+param.get()); //All parameters have a get() method that will return their value
- // script.log(myFile.readFile());
- }
- /*
- This function, if you declare it, will launch a timer at 50hz, calling this method on each tick
- */
- var tl_refresh_delta = 0.;
- function update(deltaTime)
- {
- tl_refresh_delta += deltaTime ;
- if (tl_refresh_delta > tl_refresh_rate){
- tl_refresh_delta = 0. ;
- // refresh_tl_keys();
- // 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.
- }
- }
- /* ********** MODULE SPECIFIC SCRIPTING **********************
- The "local" variable refers to the object containing the scripts. In this case, the local variable refers to the module.
- It means that you can access any control inside this module by accessing it through its address.
- For instance, if the module has a float value named "Density", you can access it via local.values.density
- Then you can retrieve its value using local.values.density.get() and change its value using local.values.density.set()
- */
- /*
- 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
- This function only exists because the script is in a module
- */
- function moduleParameterChanged(param)
- {
- if(param.isParameter())
- {
- script.log("Module parameter changed : "+param.name+" > "+param.get());
- }else
- {
- script.log("Module parameter triggered : "+value.name);
- }
- }
- /*
- 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
- This function only exists because the script is in a module
- */
- function moduleValueChanged(value)
- {
- if(value.isParameter())
- {
- script.log("Module value changed : "+value.name+" > "+value.get());
- }else
- {
- script.log("Module value triggered : "+value.name);
- }
- }
- /* ********** OSC MODULE SPECIFIC SCRIPTING ********************* */
- /*
- OSC Modules have specific methods that can be used to send OSC message from Script.
- If you want to send an OSC Message from this script, you can do the following :
- local.send("/myAddress",1,.5f,"cool"); //This will send an OSC Message with address "/myAddress" and 3 arguments <int>, <float> and <string>
- */
- /*
- You can intercept OSC message with the function oscEvent(address, args)
- */
- function oscEvent(address, args)
- {
- //param "address" is the address of the OSC Message
- //param "args" is an array containing all the arguments of the OSC Message
- script.log("OSC Message received "+address+", "+args.length+" arguments");
- for(var i=0; i < args.length; i++)
- {
- script.log(" > "+args[i]);
- }
- }
|