home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Include / TimeFrameTools.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  10.6 KB  |  560 lines

  1. /***************************************************************
  2.  
  3. ADOBE SYSTEMS INCORPORATED 
  4.  
  5. Copyright 2002 Adobe Systems Incorporated 
  6.  
  7. All Rights Reserved 
  8.  
  9.  
  10.  
  11. NOTICE:  Adobe permits you to use, modify, and distribute this 
  12.  
  13. file in accordance with the terms of the Adobe license agreement 
  14.  
  15. accompanying it.  If you have received this file from a source 
  16.  
  17. other than Adobe, then your use, modification, or distribution
  18.  
  19. of it requires the prior written permission of Adobe. 
  20.  
  21. ***************************************************************/
  22.  
  23. /***************************************************************
  24.  
  25. Author: Mary Obelnicki
  26.  
  27. ***************************************************************/
  28.  
  29.  
  30.  
  31. /***************************************************************
  32.  
  33.  
  34.  
  35. There are four types of functions that compose this include.  Each of these
  36.  
  37. function affect the distribution of start/end frames of an array of LMObjects.
  38.  
  39.  
  40.  
  41. alignStartFrames(arrayObjs, moveKeyFrames, alignToCTI)
  42.  
  43. alignEndFrames(arrayObjs, moveKeyFrames, alignToCTI)
  44.  
  45.     This utility will take an array of objects and align their 
  46.  
  47.     start/end frames depending on the set parameters.
  48.  
  49.  
  50.  
  51. Arguments:
  52.  
  53.     arrayObjs (array) - the array of LMObjects to align the lifetimes of
  54.  
  55.     moveKeyFrames (boolean) - If set to true, move the key frames with 
  56.  
  57.         the lifetime. If set to false, the key frames in place.
  58.  
  59.     alignToCTI (boolean) - If set to true, place the first object's 
  60.  
  61.         start/end frame at the current position of the CTI. If set to false, 
  62.  
  63.         the start/end frame of the first object will be left in place.
  64.  
  65.  
  66.  
  67. Example: 
  68.  
  69.     alignStartFrames(application.currentComposition.selection, true, true); 
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. distributeStartFrames(arrayObjs, moveKeyFrames, alignToCTI, maintainOrder, topDown)
  78.  
  79. distributeEndFrames(arrayObjs, moveKeyFrames, alignToCTI, maintainOrder, topDown)
  80.  
  81.     This utility will take an array of objects and distribute their start/end times 
  82.  
  83.     across the timeline.  This will not affect the lifetime of the objects.
  84.  
  85.  
  86.  
  87. Arguments:
  88.  
  89.     arrayObjs (array) - the array of LMObjects to align the lifetimes of
  90.  
  91.     moveKeyFrames (boolean) - True: move the key frames with the lifetime. 
  92.  
  93.         False: the key frames in place.
  94.  
  95.     alignToCTI (boolean) - If set to true, place the first object's 
  96.  
  97.         start/end frame at the current position of the CTI. If set to false, 
  98.  
  99.         the start/end frame of the first object will be left in place.
  100.  
  101.     maintainOrder (boolean) - True: maintain the order of start/end key frames. 
  102.  
  103.         False: the start/end order will be automatically sorted as determined by topDown.
  104.  
  105.     topDown (boolean) - True: the order of sorting will be dependent upon the LMObject's
  106.  
  107.         position in the array. The stagger order will be from the first object
  108.  
  109.         in the array to the last object in the array.  False: the stagger order will be 
  110.  
  111.         from the last object in the array to the first object in the array
  112.  
  113. .
  114.  
  115.  
  116.  
  117. Example:
  118.  
  119.     distributeEndFrames(application.currentComposition.selection, true, false, false, false); 
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. staggerStartFrames(arrayObjs, moveKeyFrames, alignToCTI, stagger, maintainOrder, topDown)
  128.  
  129. staggerEndFrames(arrayObjs, moveKeyFrames, alignToCTI, stagger, maintainOrder, topDown)
  130.  
  131.     This utility will take an array of objects and distribute their start/end frames
  132.  
  133.     by staggering each successive one a preset amount as set by the programmer.
  134.  
  135.  
  136.  
  137. Arguments:
  138.  
  139.     arrayObjs (array) - the array of LMObjects to align the lifetimes of
  140.  
  141.     moveKeyFrames (boolean) - True: move the key frames with the lifetime. 
  142.  
  143.         False: the key frames in place.
  144.  
  145.     alignToCTI (boolean) - If set to true, place the first object's 
  146.  
  147.         start/end frame at the current position of the CTI. If set to false, 
  148.  
  149.         the start/end frame of the first object will be left in place.
  150.  
  151.     stagger (integer) - the number of frames between each LMObject's start frame        
  152.  
  153.     maintainOrder (boolean) - True: maintain the order of start/end key frames. 
  154.  
  155.         False: the start/end order will be automatically sorted as determined by topDown.
  156.  
  157.     topDown (boolean) - True: the order of sorting will be dependent upon the LMObject's
  158.  
  159.         position in the array. The stagger order will be from the first object
  160.  
  161.         in the array to the last object in the array.  False: the stagger order will be 
  162.  
  163.         from the last object in the array to the first object in the array
  164.  
  165.  
  166.  
  167. Example: 
  168.  
  169.     staggerStartFrames(application.currentComposition.selection, true, true, 3, true, false); 
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. startFrameHelper(arrayObjs, moveKeyFrames, first, stagger, maintainStartOrder, topDown)
  178.  
  179. endFrameHelper(arrayObjs, moveKeyFrames, first, stagger, maintainStartOrder, topDown)
  180.  
  181.     These utilities are the main engine behind all of the above functions. 
  182.  
  183.     Depending upon the parameters, these functions can stagger an array
  184.  
  185.     of LMObjects' start/end frames.
  186.  
  187.  
  188.  
  189. Arguments:
  190.  
  191.     arrayObjs (array) - the array of LMObjects to align the lifetimes of
  192.  
  193.     moveKeyFrames (boolean) - True: move the key frames with the lifetime. 
  194.  
  195.         False: the key frames in place.
  196.  
  197.     first (integer) - the frame number where the first start/end frame will
  198.  
  199.         be placed.
  200.  
  201.     stagger (integer) - the number of frames between each LMObject's start/end frame        
  202.  
  203.     maintainOrder (boolean) - True: maintain the order of start/end key frames. 
  204.  
  205.         False: the start/end order will be automatically sorted as determined by topDown.
  206.  
  207.     topDown (boolean) - True: the order of sorting will be dependent upon the LMObject's
  208.  
  209.         position in the array. The stagger order will be from the first object
  210.  
  211.         in the array to the last object in the array.  False: the stagger order will be 
  212.  
  213.         from the last object in the array to the first object in the array
  214.  
  215.  
  216.  
  217.  
  218.  
  219. ***************************************************************/
  220.  
  221.  
  222.  
  223. /***************************************************************
  224.  
  225. DO NOT EDIT BELOW THIS LINE
  226.  
  227. ***************************************************************/
  228.  
  229.  
  230.  
  231. #include "shellSort.js"
  232.  
  233.  
  234.  
  235. function startFrameHelper(theObjects, moveKeyFrames, firstStart, stagger, maintainStartOrder, topDown)
  236.  
  237. {
  238.  
  239.     var setStart = firstStart; 
  240.  
  241.     var i;
  242.  
  243.  
  244.  
  245.     if(stagger != 0)
  246.  
  247.     {
  248.  
  249.     if(maintainStartOrder)
  250.  
  251.         shellSort(theObjects, "startFrame"); 
  252.  
  253.     else if(!topDown)
  254.  
  255.         theObjects.reverse();
  256.  
  257.     }
  258.  
  259.  
  260.  
  261.     if(moveKeyFrames)
  262.  
  263.     for(i = 0; i < theObjects.length; i++)
  264.  
  265.         theObjects[i].moveLifetimeTo(setStart + Math.round(i*stagger)); 
  266.  
  267.     else
  268.  
  269.     for(i = 0; i < theObjects.length; i++)
  270.  
  271.         theObjects[i].startFrame = setStart + Math.round(i*stagger); 
  272.  
  273.  
  274.  
  275. }
  276.  
  277.  
  278.  
  279. function endFrameHelper(theObjects, moveKeyFrames, firstEnd, stagger, maintainEndOrder, topDown)
  280.  
  281. {
  282.  
  283.     var setEnd = firstEnd; 
  284.  
  285.     var i;
  286.  
  287.  
  288.  
  289.     // make the lifetimes explicit
  290.  
  291.     for(i = 0; i < theObjects.length; i++)
  292.  
  293.     theObjects[i].explicitLifetime = true; 
  294.  
  295.  
  296.  
  297.     if(stagger != 0)
  298.  
  299.     {
  300.  
  301.     if(maintainEndOrder)
  302.  
  303.         shellSort(theObjects, "endFrame"); 
  304.  
  305.     else if(!topDown)
  306.  
  307.         theObjects.reverse();
  308.  
  309.     }
  310.  
  311.  
  312.  
  313.     if(moveKeyFrames)
  314.  
  315.     for(i = 0; i < theObjects.length; i++)
  316.  
  317.     {
  318.  
  319.         var lifetimeLength = theObjects[i].endFrame - theObjects[i].startFrame; 
  320.  
  321.         theObjects[i].moveLifetimeTo(setEnd + Math.round(i*stagger)- lifetimeLength);
  322.  
  323.     }
  324.  
  325.     else
  326.  
  327.     for(i = 0; i < theObjects.length; i++)
  328.  
  329.         theObjects[i].endFrame = setEnd + Math.round(i*stagger); 
  330.  
  331.  
  332.  
  333. }
  334.  
  335.  
  336.  
  337. function staggerStartFrames(theObjects, moveKeyFrames, alignToCTI, stagger, maintainStartOrder, topDown)
  338.  
  339. {
  340.  
  341.     var firstStart; 
  342.  
  343.     var i; 
  344.  
  345.     if(alignToCTI)
  346.  
  347.     firstStart = theObjects[0].currentFrame; 
  348.  
  349.     else
  350.  
  351.     {
  352.  
  353.     //find first startFrame;  
  354.  
  355.     firstStart = theObjects[0].startFrame;
  356.  
  357.     for(i = 1; i < theObjects.length; i++)
  358.  
  359.     {
  360.  
  361.         var testStart = theObjects[i].startFrame; 
  362.  
  363.         if(testStart < firstStart)
  364.  
  365.         firstStart = testStart; 
  366.  
  367.     }
  368.  
  369.     }
  370.  
  371.     
  372.  
  373.     startFrameHelper(theObjects, moveKeyFrames, firstStart, stagger, maintainStartOrder, topDown); 
  374.  
  375. }
  376.  
  377.  
  378.  
  379. function staggerEndFrames(theObjects, moveKeyFrames, alignToCTI, stagger, maintainEndOrder, topDown)
  380.  
  381. {
  382.  
  383.     var firstEnd; 
  384.  
  385.     var i; 
  386.  
  387.     if(alignToCTI)
  388.  
  389.     firstEnd = theObjects[0].currentFrame; 
  390.  
  391.     else
  392.  
  393.     {
  394.  
  395.     firstEnd = theObjects[0].endFrame;
  396.  
  397.     for(i = 1; i < theObjects.length; i++)
  398.  
  399.     {
  400.  
  401.         var testEnd = theObjects[i].endFrame; 
  402.  
  403.         if(testEnd < firstEnd)
  404.  
  405.         firstEnd = testEnd; 
  406.  
  407.     }
  408.  
  409.     }
  410.  
  411.     
  412.  
  413.     endFrameHelper(theObjects, moveKeyFrames, firstEnd, stagger, maintainEndOrder, topDown); 
  414.  
  415. }
  416.  
  417.  
  418.  
  419. function distributeStartFrames(theObjects, moveKeyFrames, alignToCTI, maintainStartOrder, topDown)
  420.  
  421. {
  422.  
  423.     var firstStart; 
  424.  
  425.     var lastStart; 
  426.  
  427.     var i; 
  428.  
  429.     
  430.  
  431.     //find first and last startFrame;  
  432.  
  433.     firstStart = theObjects[0].startFrame;
  434.  
  435.     lastStart = theObjects[0].startFrame; 
  436.  
  437.     for(i = 1; i < theObjects.length; i++)
  438.  
  439.     {
  440.  
  441.     var testStart = theObjects[i].startFrame; 
  442.  
  443.     if(testStart < firstStart)
  444.  
  445.         firstStart = testStart; 
  446.  
  447.     else if(testStart > lastStart)
  448.  
  449.         lastStart = testStart; 
  450.  
  451.     }
  452.  
  453.  
  454.  
  455.     if(alignToCTI)
  456.  
  457.     firstStart = theObjects[0].currentFrame; 
  458.  
  459.     
  460.  
  461.     startFrameHelper(theObjects, moveKeyFrames, firstStart, (lastStart-firstStart)/(theObjects.length-1), maintainStartOrder, topDown); 
  462.  
  463. }
  464.  
  465.  
  466.  
  467. function distributeEndFrames(theObjects, moveKeyFrames, alignToCTI, maintainEndOrder, topDown)
  468.  
  469. {
  470.  
  471.     var firstEnd; 
  472.  
  473.     var lastEnd; 
  474.  
  475.     var i; 
  476.  
  477.     
  478.  
  479.     firstEnd = theObjects[0].endFrame;
  480.  
  481.     lastEnd = theObjects[0].endFrame; 
  482.  
  483.     for(i = 1; i < theObjects.length; i++)
  484.  
  485.     {
  486.  
  487.     var testEnd = theObjects[i].endFrame;  
  488.  
  489.     if(testEnd < firstEnd)
  490.  
  491.         firstEnd = testEnd; 
  492.  
  493.     else if(testEnd > lastEnd)
  494.  
  495.         lastEnd = testEnd; 
  496.  
  497.     }
  498.  
  499.  
  500.  
  501.     if(alignToCTI)
  502.  
  503.     firstEnd = theObjects[0].currentFrame; 
  504.  
  505.     
  506.  
  507.     endFrameHelper(theObjects, moveKeyFrames, firstEnd, (lastEnd-firstEnd)/(theObjects.length-1), maintainEndOrder, topDown); 
  508.  
  509. }
  510.  
  511.  
  512.  
  513. function alignStartFrames(theObjects, moveKeyFrames, alignToCTI)
  514.  
  515. {
  516.  
  517.     staggerStartFrames(theObjects, moveKeyFrames, alignToCTI, 0, false, true); 
  518.  
  519. }
  520.  
  521.  
  522.  
  523. function alignEndFrames(theObjects, moveKeyFrames, alignToCTI)
  524.  
  525. {
  526.  
  527.     var lastEnd; 
  528.  
  529.     var i; 
  530.  
  531.     if(alignToCTI)
  532.  
  533.     lastEnd = theObjects[0].currentFrame; 
  534.  
  535.     else
  536.  
  537.     {
  538.  
  539.     lastEnd = theObjects[0].endFrame; 
  540.  
  541.     for(i = 1; i < theObjects.length; i++)
  542.  
  543.     {
  544.  
  545.         var testEnd = theObjects[i].endFrame;  
  546.  
  547.         if(testEnd > lastEnd)
  548.  
  549.         lastEnd = testEnd; 
  550.  
  551.     }
  552.  
  553.     }
  554.  
  555.  
  556.  
  557.     endFrameHelper(theObjects, moveKeyFrames, lastEnd, 0, false, true); 
  558.  
  559. }
  560.