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

  1. /***************************************************************
  2. ADOBE SYSTEMS INCORPORATED 
  3. Copyright 2002 Adobe Systems Incorporated 
  4. All Rights Reserved 
  5.  
  6. NOTICE:  Adobe permits you to use, modify, and distribute this 
  7. file in accordance with the terms of the Adobe license agreement 
  8. accompanying it.  If you have received this file from a source 
  9. other than Adobe, then your use, modification, or distribution
  10. of it requires the prior written permission of Adobe. 
  11. ***************************************************************/
  12. /***************************************************************
  13. Author: Mary Obelnicki
  14. ***************************************************************/
  15.  
  16. /***************************************************************
  17. alignEndToEnd is a utility that allow the user to align the lifetimes 
  18. of a selection of objects.  
  19.  
  20. When aligning the lifetimes there are a number of options.  The user can
  21. control if the key frames are moved with the lifetimes or left in place,
  22. if the first lifetime is aligned to the CTI, if the original start order
  23. of the lifetimes is maintained in the stagger, if the original order is
  24. not maintained, if the objects should be staggered from top down, or
  25. bottom up, the amount of overlap between the lifetimes and the type of
  26. transition between the lifetimes. 
  27.  
  28. alignEndToEnd(arrayObjs, moveKeyFrames, alignToCTI, maintainStartOrder, topDown, overlap, transition);
  29.  
  30. Arguments:
  31.     arrayObjs (array) - the array of LMObjects to align the lifetimes of
  32.     moveKeyFrames (boolean) - True: move the key frames with the lifetime. 
  33.         False: the key frames in place.
  34.     alignToCTI (boolean) - True: place the first object's lifetime at the current 
  35.         position of the CTI. False: the start frame of the first object will be set to 0.
  36.     maintainStartOrder (boolean) - True: maintain the order of start key frames. 
  37.         False: the start order will be automatically sorted as determined by topDown.
  38.     topDown (boolean) - True: the order of sorting will be dependent upon the LMObject's
  39.         z-order. The object at the top will start first. False: start order will
  40.         be from the bottom up.
  41.     overlap (integer) - number of frames of overlap between lifetimes
  42.     transition (integer) - transition style in frames of overlap
  43.         0: no style
  44.         1: fade in
  45.         2: fade out
  46.         3: fade in and out
  47.  
  48. Example:
  49.     alignEndToEnd(application.currentComposition.selection,true,false,false,true,3,2);
  50.  
  51. ***************************************************************/
  52.  
  53.  
  54. /***************************************************************
  55. DO NOT EDIT BELOW THIS LINE
  56. ***************************************************************/
  57.  
  58. #include "shellSort.js"
  59.  
  60. function alignEndToEnd(theObjects, moveKeyFrames, alignToCTI, maintainStartOrder, topDown, overlap, transitionStyle)
  61. {
  62.     //turn all lifetimes explicit otherwise this function doesn't 
  63.     //really make sense
  64.     var i; 
  65.     for(i = 0; i<theObjects.length; i++)
  66.         theObjects[i].explicitLifetime = true; 
  67.  
  68.     if(maintainStartOrder)
  69.         shellSort(theObjects, "startFrame"); 
  70.     else if(!topDown)
  71.         theObjects.reverse();
  72.  
  73.     if(alignToCTI)
  74.     {
  75.         var cti = theObjects[0].currentFrame; 
  76.  
  77.         if(moveKeyFrames)
  78.             theObjects[0].moveLifetimeTo(cti);
  79.         else
  80.         {
  81.             var lifetimeLength = theObjects[0].endFrame - theObjects[0].startFrame; 
  82.             theObjects[0].startFrame = cti; 
  83.             theObjects[0].endFrame = cti + lifetimeLength; 
  84.         }
  85.     }
  86.  
  87.     //align the lifetimes
  88.     for(i = 1; i<theObjects.length; i++)
  89.     {
  90.         var curO = theObjects[i]; 
  91.         var prevO = theObjects[i-1]; 
  92.         var actualOverlap = Math.min(overlap, (curO.endFrame - curO.startFrame + 1) ); 
  93.         if(moveKeyFrames)
  94.         {
  95.             curO.moveLifetimeTo(Math.max((prevO.endFrame + 1 - actualOverlap), prevO.startFrame) );
  96.         }
  97.         else
  98.         {
  99.             var lifetimeLength = curO.endFrame  - curO.startFrame; 
  100.             curO.startFrame = Math.max((prevO.endFrame + 1 - actualOverlap), prevO.startFrame); 
  101.             curO.endFrame = curO.startFrame + lifetimeLength; 
  102.         }
  103.     }
  104.   
  105.     if(overlap > 0)
  106.     {
  107.         for (i = 0; i<theObjects.length; i++)
  108.         {
  109.             applyTransition(transitionStyle, overlap, theObjects[i]);  
  110.         }
  111.     }
  112. }
  113.  
  114. function applyTransition(style, frames, theObj)
  115.     var lifetimeFrames = theObj.endFrame - theObj.startFrame + 1;
  116.     var offset; 
  117.     if(style == 3)
  118.         offset = Math.min(frames, Math.ceil(lifetimeFrames/2)) - 1; 
  119.     else
  120.         offset = Math.min(frames, lifetimeFrames) - 1; 
  121.  
  122.     theObj.currentFrame = theObj.startFrame; 
  123.     var oriOpacity = theObj.opacity; 
  124.     
  125.     if((style == 1) || (style == 3)) // fade in
  126.     {
  127.         theObj.stopwatch.opacity = true; 
  128.         theObj.currentFrame = theObj.startFrame + offset; 
  129.         theObj.opacity = oriOpacity * offset/(frames-1); 
  130.         theObj.currentFrame = theObj.startFrame; 
  131.         theObj.opacity = 0; 
  132.     }
  133.     if((style == 2) || (style == 3)) // fade out
  134.     {
  135.         theObj.stopwatch.opacity = true; 
  136.         theObj.currentFrame = theObj.endFrame - offset; 
  137.         theObj.opacity = oriOpacity * offset/(frames-1);  
  138.         theObj.currentFrame = theObj.endFrame; 
  139.         theObj.opacity = 0; 
  140.  
  141.     }
  142. }
  143.