Skip to content

Commit

Permalink
Remove deprecated each_child and each_clip functions (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston authored Nov 29, 2022
1 parent 33e0d1a commit f7123d0
Show file tree
Hide file tree
Showing 47 changed files with 246 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def validate_metadata(timeline):
all_checks = [__check(timeline, "duration().rate")]
edit_rate = __check(timeline, "duration().rate").value

for child in timeline.each_child():
for child in timeline.find_children():
checks = []
if _is_considered_gap(child):
checks = [
Expand Down Expand Up @@ -227,7 +227,7 @@ def _generate_empty_mobid(clip):

clip_mob_ids = {}

for otio_clip in input_otio.each_clip():
for otio_clip in input_otio.find_clips():
if _is_considered_gap(otio_clip):
continue
for strategy in strategies:
Expand All @@ -249,7 +249,7 @@ def _stackify_nested_groups(timeline):
"""
copied = copy.deepcopy(timeline)
for track in copied.tracks:
for i, child in enumerate(track.each_child()):
for i, child in enumerate(track.find_children()):
is_nested = isinstance(child, otio.schema.Track)
is_parent_in_stack = isinstance(child.parent(), otio.schema.Stack)
if is_nested and not is_parent_in_stack:
Expand Down Expand Up @@ -282,7 +282,7 @@ def __init__(self, root_file_transcriber, otio_track):
self.compositionmob = root_file_transcriber.compositionmob
self.aaf_file = root_file_transcriber.aaf_file
self.otio_track = otio_track
self.edit_rate = next(self.otio_track.each_child()).duration().rate
self.edit_rate = self.otio_track.find_children()[0].duration().rate
self.timeline_mobslot, self.sequence = self._create_timeline_mobslot()
self.timeline_mobslot.name = self.otio_track.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,11 +1208,11 @@ def _attach_markers(collection):
"""
# iterate all timeline objects
for timeline in collection.each_child(descended_from_type=otio.schema.Timeline):
for timeline in collection.find_children(descended_from_type=otio.schema.Timeline):
tracks_map = {}

# build track mapping
for track in timeline.each_child(descended_from_type=otio.schema.Track):
for track in timeline.find_children(descended_from_type=otio.schema.Track):
metadata = track.metadata.get("AAF", {})
slot_id = metadata.get("SlotID")
track_number = metadata.get("PhysicalTrackNumber")
Expand All @@ -1222,7 +1222,8 @@ def _attach_markers(collection):
tracks_map[(int(slot_id), int(track_number))] = track

# iterate all tracks for their markers and attach them to the matching item
for current_track in timeline.each_child(descended_from_type=otio.schema.Track):
for current_track in timeline.find_children(
descended_from_type=otio.schema.Track):
for marker in list(current_track.markers):
metadata = marker.metadata.get("AAF", {})
slot_id = metadata.get("AttachedSlotID")
Expand Down
2 changes: 1 addition & 1 deletion contrib/opentimelineio_contrib/adapters/ale.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def nextline(lines):
def write_to_string(input_otio, columns=None, fps=None, video_format=None):

# Get all the clips we're going to export
clips = list(input_otio.each_clip())
clips = list(input_otio.find_clips())

result = ""

Expand Down
2 changes: 1 addition & 1 deletion contrib/opentimelineio_contrib/adapters/burnins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def build_burnins(input_otio):
key = 'burnins'

burnins = []
for clip in input_otio.each_clip():
for clip in input_otio.find_clips():

# per clip burnin data
burnin_data = clip.media_reference.metadata.get(key)
Expand Down
8 changes: 4 additions & 4 deletions contrib/opentimelineio_contrib/adapters/fcpx_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, otio_timeline):
self.timelines = [self.otio_timeline]
else:
self.timelines = list(
self.otio_timeline.each_child(
self.otio_timeline.find_children(
descended_from_type=otio.schema.Timeline
)
)
Expand Down Expand Up @@ -245,7 +245,7 @@ def _stack_to_sequence(self, stack, compound_clip=False):
return sequence_element

def _track_for_spine(self, track, lane_id, spine, compound):
for child in self._lanable_items(track.each_child()):
for child in self._lanable_items(track.find_children()):
if self._item_in_compound_clip(child) and not compound:
continue
child_element = self._element_for_item(
Expand Down Expand Up @@ -625,12 +625,12 @@ def _add_compound_clip(self, item):
return media_element

def _stacks(self):
return self.otio_timeline.each_child(
return self.otio_timeline.find_children(
descended_from_type=otio.schema.Stack
)

def _clips(self):
return self.otio_timeline.each_child(
return self.otio_timeline.find_children(
descended_from_type=otio.schema.Clip
)

Expand Down
37 changes: 19 additions & 18 deletions contrib/opentimelineio_contrib/adapters/tests/test_aaf_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_aaf_read(self):

self.assertEqual(len(timeline.audio_tracks()), 2)

clips = list(video_track.each_clip())
clips = video_track.find_clips()

self.assertEqual(
[
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_aaf_read_trims(self):
]
)

clips = list(video_track.each_clip())
clips = video_track.find_clips()

self.assertEqual(
[item.name for item in video_track],
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_aaf_read_transitions(self):
video_track = video_tracks[0]
self.assertEqual(len(video_track), 12)

clips = list(video_track.each_clip())
clips = video_track.find_clips()
self.assertEqual(len(clips), 4)

self.assertEqual(
Expand Down Expand Up @@ -631,7 +631,7 @@ def test_aaf_flatten_tracks(self):
t.name = ""
t.metadata.pop("AAF", None)

for c in t.each_child():
for c in t.find_children():
if hasattr(c, "media_reference") and c.media_reference:
mr = c.media_reference
mr.metadata.get("AAF", {}).pop('LastModified', None)
Expand All @@ -642,7 +642,7 @@ def test_aaf_flatten_tracks(self):
meta.pop('StartTime', None)

# We don't care about Gap start times, only their duration matters
for g in t.each_child(descended_from_type=otio.schema.Gap):
for g in t.find_children(descended_from_type=otio.schema.Gap):
dur = g.source_range.duration
rate = g.source_range.start_time.rate
g.source_range = otio.opentime.TimeRange(
Expand Down Expand Up @@ -965,7 +965,7 @@ def test_aaf_sourcemob_usage(self):
# `Usage_SubClip` value
subclip_timeline = otio.adapters.read_from_file(SUBCLIP_PATH)
subclip_usages = {"Subclip.BREATH": "Usage_SubClip"}
for clip in subclip_timeline.each_clip():
for clip in subclip_timeline.find_clips():
self.assertEqual(
clip.metadata.get("AAF", {}).get("SourceMobUsage"),
subclip_usages[clip.name]
Expand All @@ -980,7 +980,7 @@ def test_aaf_sourcemob_usage(self):
"t-hawk (loop)-HD.mp4": "",
"tech.fux (loop)-HD.mp4": ""
}
for clip in simple_timeline.each_clip():
for clip in simple_timeline.find_clips():
self.assertEqual(
clip.metadata.get("AAF", {}).get("SourceMobUsage", ""),
simple_usages[clip.name]
Expand Down Expand Up @@ -1201,9 +1201,9 @@ def test_attach_markers(self):

all_markers = {}
for i, track in enumerate(
timeline.each_child(descended_from_type=otio.schema.Track)
timeline.find_children(descended_from_type=otio.schema.Track)
):
for item in track.each_child():
for item in track.find_children():
markers = [
(
m.name,
Expand All @@ -1220,7 +1220,7 @@ def test_attach_markers(self):
def test_keyframed_properties(self):
def get_expected_dict(timeline):
expected = []
for clip in timeline.each_child(descended_from_type=otio.schema.Clip):
for clip in timeline.find_children(descended_from_type=otio.schema.Clip):
for effect in clip.effects:
props = {}
parameters = effect.metadata.get("AAF", {}).get("Parameters", {})
Expand Down Expand Up @@ -1566,7 +1566,7 @@ def test_aaf_writer_nometadata(self):
def _target_url_fixup(timeline):
# fixes up relative paths to be absolute to this test file
test_dir = os.path.dirname(os.path.abspath(__file__))
for clip in timeline.each_clip():
for clip in timeline.find_clips():
target_url_str = clip.media_reference.target_url
clip.media_reference.target_url = os.path.join(test_dir, target_url_str)

Expand Down Expand Up @@ -1607,7 +1607,7 @@ def test_aaf_roundtrip_first_clip(self):
def _target_url_fixup(timeline):
# fixes up relative paths to be absolute to this test file
test_dir = os.path.dirname(os.path.abspath(__file__))
for clip in timeline.each_clip():
for clip in timeline.find_clips():
target_url_str = clip.media_reference.target_url
clip.media_reference.target_url = os.path.join(test_dir, target_url_str)

Expand All @@ -1621,8 +1621,8 @@ def _target_url_fixup(timeline):
def _verify_first_clip(self, original_timeline, aaf_path):
timeline_from_aaf = otio.adapters.read_from_file(aaf_path)

original_clips = list(original_timeline.each_clip())
aaf_clips = list(timeline_from_aaf.each_clip())
original_clips = original_timeline.find_clips()
aaf_clips = timeline_from_aaf.find_clips()

self.assertTrue(len(original_clips) > 0)
self.assertEqual(len(aaf_clips), len(original_clips))
Expand Down Expand Up @@ -1717,10 +1717,11 @@ def _verify_aaf(self, aaf_path):
sequence = opgroup.segments[0]
self.assertTrue(isinstance(sequence, Sequence))

self.assertEqual(len(list(otio_track.each_child(shallow_search=True))),
len(sequence.components))
self.assertEqual(
len(otio_track.find_children(shallow_search=True)),
len(sequence.components))
for otio_child, aaf_component in zip(
otio_track.each_child(shallow_search=True),
otio_track.find_children(shallow_search=True),
sequence.components):
type_mapping = {
otio.schema.Clip: aaf2.components.SourceClip,
Expand All @@ -1738,7 +1739,7 @@ def _verify_aaf(self, aaf_path):
if isinstance(aaf_component, aaf2.components.OperationGroup):
nested_aaf_segments = aaf_component.segments
for nested_otio_child, nested_aaf_segment in zip(
otio_child.each_child(), nested_aaf_segments):
otio_child.find_children(), nested_aaf_segments):
self._is_otio_aaf_same(nested_otio_child,
nested_aaf_segment)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def __init__(self, *args, **kwargs):

def test_library_roundtrip(self):
container = otio.adapters.read_from_file(SAMPLE_LIBRARY_XML)
timeline = next(
container.each_child(descended_from_type=otio.schema.Timeline)
)
timeline = container.find_children(
descended_from_type=otio.schema.Timeline)[0]

self.assertIsNotNone(timeline)
self.assertEqual(len(timeline.tracks), 4)
Expand Down Expand Up @@ -81,9 +80,8 @@ def test_library_roundtrip(self):

def test_event_roundtrip(self):
container = otio.adapters.read_from_file(SAMPLE_EVENT_XML)
timeline = next(
container.each_child(descended_from_type=otio.schema.Timeline)
)
timeline = container.find_children(
descended_from_type=otio.schema.Timeline)[0]

self.assertIsNotNone(timeline)
self.assertEqual(len(timeline.tracks), 4)
Expand Down
4 changes: 2 additions & 2 deletions examples/conform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int conform_timeline(
int count = 0;

otio::ErrorStatus error_status;
const auto clips = timeline->clip_if(&error_status);
const auto clips = timeline->find_clips(&error_status);
if (otio::is_error(error_status))
{
examples::print_error(error_status);
Expand Down Expand Up @@ -130,7 +130,7 @@ int main(int argc, char** argv)
examples::print_error(error_status);
exit(1);
}
const auto clips = timeline->clip_if(&error_status);
const auto clips = timeline->find_clips(&error_status);
if (otio::is_error(error_status))
{
examples::print_error(error_status);
Expand Down
4 changes: 2 additions & 2 deletions examples/conform.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _conform_timeline(timeline, folder):

count = 0

for clip in timeline.each_clip():
for clip in timeline.find_clips():
# look for a media file that matches the clip's name
new_path = _find_matching_media(clip.name, folder)

Expand Down Expand Up @@ -128,7 +128,7 @@ def main():
print(
"Saved {} with {} clips.".format(
args.output,
len(list(timeline.each_clip()))
len(list(timeline.find_clips()))
)
)

Expand Down
4 changes: 2 additions & 2 deletions examples/summarize_timing.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def _summarize_range(label, time_range):
def _summarize_timeline(timeline):
# Here we iterate over each video track, and then just the top-level
# items in each track. If you want to traverse the whole nested structure
# then you can use: for item in timeline.each_child()
# or just clips via: for clip in timeline.each_clip()
# then you can use: for item in timeline.find_children()
# or just clips via: for clip in timeline.find_clips()
# See also: https://opentimelineio.readthedocs.io/en/latest/tutorials/otio-timeline-structure.html # noqa
for track in timeline.video_tracks():
print(
Expand Down
10 changes: 5 additions & 5 deletions src/opentimelineio/composition.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class Composition : public Item
TimeRange const& search_range,
ErrorStatus* error_status = nullptr) const;

// Return a vector of all objects that match the given template type.
// Find child objects that match the given template type.
//
// An optional search_time may be provided to limit the search.
//
// If shallow_search is false, will recurse into children.
// The search is recursive unless shallow_search is set to true.
template <typename T = Composable>
std::vector<Retainer<T>> children_if(
std::vector<Retainer<T>> find_children(
ErrorStatus* error_status = nullptr,
optional<TimeRange> search_range = nullopt,
bool shallow_search = false) const;
Expand Down Expand Up @@ -171,7 +171,7 @@ class Composition : public Item

template <typename T>
inline std::vector<SerializableObject::Retainer<T>>
Composition::children_if(
Composition::find_children(
ErrorStatus* error_status,
optional<TimeRange> search_range,
bool shallow_search) const
Expand Down Expand Up @@ -217,7 +217,7 @@ Composition::children_if(
}
}

const auto valid_children = composition->children_if<T>(
const auto valid_children = composition->find_children<T>(
error_status,
search_range,
shallow_search);
Expand Down
4 changes: 2 additions & 2 deletions src/opentimelineio/serializableCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ SerializableCollection::write_to(Writer& writer) const
}

std::vector<SerializableObject::Retainer<Clip>>
SerializableCollection::clip_if(
SerializableCollection::find_clips(
ErrorStatus* error_status,
optional<TimeRange> const& search_range,
bool shallow_search) const
{
return children_if<Clip>(error_status, search_range, shallow_search);
return find_children<Clip>(error_status, search_range, shallow_search);
}

}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
Loading

0 comments on commit f7123d0

Please sign in to comment.