Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/opentimelineio/composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ Composition::trimmed_range_of_child(
result_range = TimeRange(
result_range->start_time() + parent_range.start_time(),
result_range->duration());
current = parent;
}

if (!source_range())
Expand Down
23 changes: 23 additions & 0 deletions tests/test_composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <opentimelineio/clip.h>
#include <opentimelineio/composition.h>
#include <opentimelineio/gap.h>
#include <opentimelineio/item.h>
#include <opentimelineio/stack.h>
#include <opentimelineio/track.h>
Expand Down Expand Up @@ -54,6 +55,28 @@ main(int argc, char** argv)
assertEqual(items[0].value, clip.value);
});

tests.add_test("test_trimmed_range_of_nested_child", [] {
SerializableObject::Retainer<Stack> root = new Stack;
SerializableObject::Retainer<Track> track = new Track;
SerializableObject::Retainer<Stack> stack = new Stack;
SerializableObject::Retainer<Clip> clip = new Clip;

clip->set_source_range(
TimeRange(RationalTime(100, 24), RationalTime(50, 24)));
root->append_child(track);
track->append_child(new Gap(RationalTime(10, 24)));
track->append_child(stack);
stack->append_child(clip);

OTIO_NS::ErrorStatus err;
auto range = root->trimmed_range_of_child(clip, &err);
assertFalse(is_error(err));
assertTrue(range.has_value());
assertEqual(
*range,
TimeRange(RationalTime(10, 24), RationalTime(50, 24)));
});

tests.run(argc, argv);
return 0;
}
35 changes: 35 additions & 0 deletions tests/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,41 @@

class CompositionTests(unittest.TestCase, otio_test_utils.OTIOAssertions):

def test_trimmed_range_of_nested_child(self):
rt = otio.opentime.RationalTime
tr = otio.opentime.TimeRange
clip = otio.schema.Clip(source_range=tr(rt(100, 24), rt(50, 24)))
track = otio.schema.Track(children=[
otio.schema.Gap(duration=rt(10, 24)), clip
])
stack = otio.schema.Stack(children=[track])
outer_track = otio.schema.Track(children=[
otio.schema.Gap(duration=rt(20, 24)), stack
])
timeline = otio.schema.Timeline(tracks=[outer_track])

for ancestor, start in (
(track, 10),
(stack, 10),
(outer_track, 30),
(timeline.tracks, 30),
):
with self.subTest(ancestor=type(ancestor).__name__, start=start):
self.assertEqual(
ancestor.trimmed_range_of_child(clip),
tr(rt(start, 24), rt(50, 24)),
)

# A source range on the outermost stack still clips the result.
timeline.tracks.source_range = tr(rt(0, 24), rt(40, 24))
self.assertEqual(
timeline.tracks.trimmed_range_of_child(clip),
tr(rt(30, 24), rt(10, 24)),
)

timeline.tracks.source_range = tr(rt(0, 24), rt(20, 24))
self.assertIsNone(timeline.tracks.trimmed_range_of_child(clip))

def test_cons(self):
it = otio.core.Item()
co = otio.core.Composition(name="test", children=[it])
Expand Down
Loading