Class Composition

All Implemented Interfaces:
java.lang.AutoCloseable
Direct Known Subclasses:
Stack, Track

public class Composition
extends Item
Base class for an OTIO Item that contains other Items. Should be subclassed (for example by Track and Stack), not used directly.
  • Constructor Details

  • Method Details

    • getCompositionKind

      public java.lang.String getCompositionKind()
      Returns a label specifying the kind of composition.
      Returns:
      the composition kind
    • getChildren

      public java.util.List<Composable> getChildren()
      Returns:
      all the chidlren held by this Composition.
    • clearChildren

      public void clearChildren()
      Remove all children from the composition and clear their parents.
    • setChildren

      public void setChildren​(java.util.List<Composable> children, ErrorStatus errorStatus)
      Set children for this Composition.
      Parameters:
      children - a list of Composables
      errorStatus - errorStatus to report an error if any child cannot be added.
    • insertChild

      public boolean insertChild​(int index, Composable child, ErrorStatus errorStatus)
      Insert a child Composable at an index.
      Parameters:
      index - index at which child is to be inserted.
      child - child Composable to be inserted.
      errorStatus - errorStatus to report an error if child cannot be inserted.
      Returns:
      was the child inserted successfully?
    • setChild

      public boolean setChild​(int index, Composable child, ErrorStatus errorStatus)
      Set the child at a particular index. The needs to exist for the child to be set.
      Parameters:
      index - index to set the child
      child - child Composable to be set
      errorStatus - errorStatus to report an error if child cannot be set.
      Returns:
      was the child set successfully?
    • removeChild

      public boolean removeChild​(int index, ErrorStatus errorStatus)
      Remove the child at any index.
      Parameters:
      index - index from which the child needs to be removed.
      errorStatus - errorStatus to report an error if child cannot be removed.
      Returns:
      was the child removed successfully?
    • appendChild

      public boolean appendChild​(Composable child, ErrorStatus errorStatus)
      Append the child to the end of the Composition.
      Parameters:
      child - child to be appended
      errorStatus - errorStatus to report an error if child cannot be appended.
      Returns:
      was the child appended successfully?
    • isParentOf

      public boolean isParentOf​(Composable composable)
      Parameters:
      composable - Composable to check ancestry of
      Returns:
      true if this is a parent or ancestor of the composable.
    • getHandlesOfChild

      public Pair<RationalTime,​RationalTime> getHandlesOfChild​(Composable child, ErrorStatus errorStatus)
      If media beyond the ends of this child are visible due to adjacent Transitions (only applicable in a Track) then this will return the head and tail offsets as a Pair of RationalTime objects. If no handles are present on either side, then null is returned instead of a RationalTime.
      Parameters:
      child - child Composable to get handles
      errorStatus - errorStatus to report error while fetching handles
      Returns:
      head and tail offsets as a Pair of RationalTime objects
    • getRangeOfChildAtIndex

      public TimeRange getRangeOfChildAtIndex​(int index, ErrorStatus errorStatus)
      Return the range of a child item in the time range of this composition. For example, with a track: [ClipA][ClipB][ClipC] this.getRangeOfChildAtIndex(2, errorStatus) will return: TimeRange(ClipA.duration + ClipB.duration, ClipC.duration)
      Parameters:
      index - index of child whose range is to be fetched
      errorStatus - errorStatus to report error if range cannot be fetched
      Returns:
      range of child at index
    • getTrimmedRangeOfChildAtIndex

      public TimeRange getTrimmedRangeOfChildAtIndex​(int index, ErrorStatus errorStatus)
      Return the trimmed range of the child item at index in the time range of this composition.

      For example, with a track: [ ] [ClipA][ClipB][ClipC] The range of index 2 (ClipC) will be just like getRangeOfChildAtIndex() but trimmed based on this Composition's sourceRange.

      Parameters:
      index - index of child whose trimmed range is to be fetched
      errorStatus - errorStatus to report error if trimmed range cannot be fetched
      Returns:
      trimmed range of child at index
    • getRangeOfChild

      public TimeRange getRangeOfChild​(Composable child, ErrorStatus errorStatus)
      The range of the child not trimmed based on this composition's sourceRange. For example: | [-----] | seq [-----------------] Clip A If ClipA has duration 17, and seq has sourceRange: 5, duration 15, seq.getRangeOfChild(Clip A) will return (0, 17) ignoring the sourceRange of seq.

      To get the range of the child with the sourceRange applied, use the getTrimmedRangeOfChild() method.

      Parameters:
      child - child Composable whose range is to be fetched
      errorStatus - errorStatus to report error if range cannot be fetched
      Returns:
      range of the child not trimmed based on this composition's sourceRange
    • getTrimmedRangeOfChild

      public TimeRange getTrimmedRangeOfChild​(Composable child, ErrorStatus errorStatus)
      Get range of the child, after the sourceRange is applied. Example | [-----] | seq [-----------------] Clip A If ClipA has duration 17, and seq has sourceRange: 5, duration 10, seq.getTrimmedRangeOfChild(Clip A) will return (5, 10) Which is trimming the range according to the sourceRange of seq. To get the range of the child without the sourceRange applied, use the getRangeOfChild() method. Another example | [-----] | seq sourceRange starts on frame 4 and goes to frame 8 [ClipA][ClipB] (each 6 frames long)

      seq.getRangeOfChild(ClipA) = 0, duration 6 seq.getTrimmedRangeOfChild(ClipB) = 4, duration 2

      Parameters:
      child - child Composable whose trimmed range is to be fetched
      errorStatus - errorStatus to report error if range cannot be fetched
      Returns:
      range of the child trimmed based on this composition's sourceRange
    • trimChildRange

      public TimeRange trimChildRange​(TimeRange childRange)
      Trim childRange to this.sourceRange
      Parameters:
      childRange - range to be trimmed
      Returns:
      null if childRange has no intersection with this.sourceRange, else trimmed range
    • hasChild

      public boolean hasChild​(Composable child)
      Parameters:
      child - child to find
      Returns:
      does the composition contain the child?
    • getRangeOfAllChildren

      public java.util.HashMap<Composable,​TimeRange> getRangeOfAllChildren​(ErrorStatus errorStatus)
      Return a HashMap mapping children to their range in this object.
      Parameters:
      errorStatus - errorStatus to report any error while fetching ranges
      Returns:
      a HashMap mapping children to their range in this object
    • getChildAtTime

      public Composable getChildAtTime​(RationalTime searchTime, boolean shallowSearch, ErrorStatus errorStatus)
      Return the child that overlaps with time searchTime. searchTime is in the space of self. If shallowSearch is false, will recurse into compositions.
      Parameters:
      searchTime - the time at which the child is to be fetched
      shallowSearch - should the algorithm recurse into compositions or not?
      errorStatus - errorStatus to report any error while fetching the child
      Returns:
      the child that overlaps with time searchTime
    • getChildAtTime

      public Composable getChildAtTime​(RationalTime searchTime, ErrorStatus errorStatus)
      Return the child that overlaps with time searchTime. searchTime is in the space of self. This function will recurse into compositions.
      Parameters:
      searchTime - the time at which the child is to be fetched
      errorStatus - errorStatus to report any error while fetching the child
      Returns:
      the child that overlaps with time searchTime
    • eachChild

      public <T extends Composable> java.util.stream.Stream<T> eachChild​(TimeRange searchRange, java.lang.Class<T> descendedFrom, boolean shallowSearch, ErrorStatus errorStatus)
      Stream that returns each child of specified type contained in the composition in the order in which it is found.
      Type Parameters:
      T - type of children to fetch
      Parameters:
      searchRange - if not null, only children whose range overlaps with the search range will be in the stream.
      descendedFrom - only children who are a descendent of the descendedFrom type will be in the stream
      shallowSearch - should the algorithm recurse into compositions or not?
      errorStatus - errorStatus to report any error while iterating
      Returns:
      a Stream consisting of all the children of specified type in the composition in the order in which it is found
    • eachChild

      public java.util.stream.Stream<Composable> eachChild​(TimeRange searchRange, boolean shallowSearch, ErrorStatus errorStatus)
      Stream that returns each child contained in the composition in the order in which it is found.
      Parameters:
      searchRange - if not null, only children whose range overlaps with the search range will be in the stream.
      shallowSearch - should the algorithm recurse into compositions or not?
      errorStatus - errorStatus to report any error while iterating
      Returns:
      a Stream consisting of all the children in the composition (in the searchRange) in the order in which it is found
    • eachChild

      public <T extends Composable> java.util.stream.Stream<T> eachChild​(java.lang.Class<T> descendedFrom, ErrorStatus errorStatus)
      Stream that returns each child of specified type contained in the composition in the order in which it is found. This stream will recurse into compositions.
      Type Parameters:
      T - type of children to fetch
      Parameters:
      descendedFrom - only children who are a descendent of the descendedFrom type will be in the stream
      errorStatus - errorStatus to report any error while iterating
      Returns:
      a Stream consisting of all the children of specified type in the composition in the order in which it is found
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class Item