Skip to content

Commit 7c58de1

Browse files
authored
moved find_clips function to superclass and added test case (#1902)
* moved find_clips function to superclass and added test case Signed-off-by: Yingjie Wang <[email protected]>
1 parent bacf095 commit 7c58de1

File tree

9 files changed

+92
-50
lines changed

9 files changed

+92
-50
lines changed

src/opentimelineio/composition.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,4 +709,13 @@ Composition::has_clips() const
709709
return false;
710710
}
711711

712+
std::vector<SerializableObject::Retainer<Clip>>
713+
Composition::find_clips(
714+
ErrorStatus* error_status,
715+
std::optional<TimeRange> const& search_range,
716+
bool shallow_search) const
717+
{
718+
return find_children<Clip>(error_status, search_range, shallow_search);
719+
}
720+
712721
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION

src/opentimelineio/composition.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
1111

12+
class Clip;
13+
1214
/// @brief Base class for an Item that contains Composables.
1315
///
1416
/// Should be subclassed (for example by Track Stack), not used directly.
@@ -157,6 +159,17 @@ class Composition : public Item
157159
ErrorStatus* error_status = nullptr,
158160
std::optional<TimeRange> search_range = std::nullopt,
159161
bool shallow_search = false) const;
162+
163+
/// @brief Find child clips.
164+
///
165+
/// @param error_status The return status.
166+
/// @param search_range An optional range to limit the search.
167+
/// @param shallow_search The search is recursive unless shallow_search is
168+
/// set to true.
169+
std::vector<Retainer<Clip>> find_clips(
170+
ErrorStatus* error_status = nullptr,
171+
std::optional<TimeRange> const& search_range = std::nullopt,
172+
bool shallow_search = false) const;
160173

161174
protected:
162175
virtual ~Composition();

src/opentimelineio/stack.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ Stack::available_range(ErrorStatus* error_status) const
133133
return TimeRange(RationalTime(0, duration.rate()), duration);
134134
}
135135

136-
std::vector<SerializableObject::Retainer<Clip>>
137-
Stack::find_clips(
138-
ErrorStatus* error_status,
139-
std::optional<TimeRange> const& search_range,
140-
bool shallow_search) const
141-
{
142-
return find_children<Clip>(error_status, search_range, shallow_search);
143-
}
144-
145136
std::optional<IMATH_NAMESPACE::Box2d>
146137
Stack::available_image_bounds(ErrorStatus* error_status) const
147138
{

src/opentimelineio/stack.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ class Stack : public Composition
5858
std::optional<IMATH_NAMESPACE::Box2d>
5959
available_image_bounds(ErrorStatus* error_status) const override;
6060

61-
/// @brief Find child clips.
62-
///
63-
/// @param error_status The return status.
64-
/// @param search_range An optional range to limit the search.
65-
/// @param shallow_search The search is recursive unless shallow_search is
66-
/// set to true.
67-
std::vector<Retainer<Clip>> find_clips(
68-
ErrorStatus* error_status = nullptr,
69-
std::optional<TimeRange> const& search_range = std::nullopt,
70-
bool shallow_search = false) const;
71-
7261
protected:
7362
virtual ~Stack();
7463

src/opentimelineio/track.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,6 @@ Track::range_of_all_children(ErrorStatus* error_status) const
263263
return result;
264264
}
265265

266-
std::vector<SerializableObject::Retainer<Clip>>
267-
Track::find_clips(
268-
ErrorStatus* error_status,
269-
std::optional<TimeRange> const& search_range,
270-
bool shallow_search) const
271-
{
272-
return find_children<Clip>(error_status, search_range, shallow_search);
273-
}
274-
275266
std::optional<IMATH_NAMESPACE::Box2d>
276267
Track::available_image_bounds(ErrorStatus* error_status) const
277268
{

src/opentimelineio/track.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ class Track : public Composition
8181
std::optional<IMATH_NAMESPACE::Box2d>
8282
available_image_bounds(ErrorStatus* error_status) const override;
8383

84-
/// @brief Find child clips.
85-
///
86-
/// @param error_status The return status.
87-
/// @param search_range An optional range to limit the search.
88-
/// @param shallow_search The search is recursive unless shallow_search is
89-
/// set to true.
90-
std::vector<Retainer<Clip>> find_clips(
91-
ErrorStatus* error_status = nullptr,
92-
std::optional<TimeRange> const& search_range = std::nullopt,
93-
bool shallow_search = false) const;
94-
9584
protected:
9685
virtual ~Track();
9786

src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
513513
.def("find_children", [](Composition* c, py::object descended_from_type, std::optional<TimeRange> const& search_range, bool shallow_search) {
514514
return find_children(c, descended_from_type, search_range, shallow_search);
515515
}, "descended_from_type"_a = py::none(), "search_range"_a = std::nullopt, "shallow_search"_a = false)
516+
.def("find_clips", [](Composition* c, std::optional<TimeRange> const& search_range, bool shallow_search) {
517+
return find_clips(c, search_range, shallow_search);
518+
}, "search_range"_a = std::nullopt, "shallow_search"_a = false)
516519
.def("handles_of_child", [](Composition* c, Composable* child) {
517520
auto result = c->handles_of_child(child, ErrorStatusHandler());
518521
return py::make_tuple(py::cast(result.first), py::cast(result.second));
@@ -586,16 +589,12 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
586589
.def("neighbors_of", [](Track* t, Composable* item, Track::NeighborGapPolicy policy) {
587590
auto result = t->neighbors_of(item, ErrorStatusHandler(), policy);
588591
return py::make_tuple(py::cast(result.first.take_value()), py::cast(result.second.take_value()));
589-
}, "item"_a, "policy"_a = Track::NeighborGapPolicy::never)
590-
.def("find_clips", [](Track* t, std::optional<TimeRange> const& search_range, bool shallow_search) {
591-
return find_clips(t, search_range, shallow_search);
592-
}, "search_range"_a = std::nullopt, "shallow_search"_a = false);
592+
}, "item"_a, "policy"_a = Track::NeighborGapPolicy::never);
593593

594594
py::class_<Track::Kind>(track_class, "Kind")
595595
.def_property_readonly_static("Audio", [](py::object /* self */) { return Track::Kind::audio; })
596596
.def_property_readonly_static("Video", [](py::object /* self */) { return Track::Kind::video; });
597597

598-
599598
py::class_<Stack, Composition, managing_ptr<Stack>>(m, "Stack", py::dynamic_attr())
600599
.def(py::init([](std::string name,
601600
std::optional<std::vector<Composable*>> children,
@@ -621,10 +620,7 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
621620
"source_range"_a = std::nullopt,
622621
"markers"_a = py::none(),
623622
"effects"_a = py::none(),
624-
py::arg_v("metadata"_a = py::none()))
625-
.def("find_clips", [](Stack* s, std::optional<TimeRange> const& search_range, bool shallow_search) {
626-
return find_clips(s, search_range, shallow_search);
627-
}, "search_range"_a = std::nullopt, "shallow_search"_a = false);
623+
py::arg_v("metadata"_a = py::none()));
628624

629625
py::class_<Timeline, SerializableObjectWithMetadata, managing_ptr<Timeline>>(m, "Timeline", py::dynamic_attr())
630626
.def(py::init([](std::string name,

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ foreach(test ${tests_opentime})
1515
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1616
endforeach()
1717

18-
list(APPEND tests_opentimelineio test_clip test_serialization test_serializableCollection test_stack_algo test_timeline test_track test_editAlgorithm)
18+
list(APPEND tests_opentimelineio test_clip test_serialization test_serializableCollection test_stack_algo test_timeline test_track test_editAlgorithm test_composition)
1919
foreach(test ${tests_opentimelineio})
2020
add_executable(${test} utils.h utils.cpp ${test}.cpp)
2121

tests/test_composition.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the OpenTimelineIO project
3+
4+
#include "utils.h"
5+
6+
#include <opentimelineio/composition.h>
7+
#include <opentimelineio/item.h>
8+
#include <opentimelineio/clip.h>
9+
#include <opentimelineio/stack.h>
10+
#include <opentimelineio/track.h>
11+
#include <opentimelineio/transition.h>
12+
13+
#include <iostream>
14+
15+
namespace otime = opentime::OPENTIME_VERSION;
16+
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION;
17+
18+
int
19+
main(int argc, char** argv)
20+
{
21+
Tests tests;
22+
23+
// test a basic case of find_children
24+
tests.add_test(
25+
"test_find_children", [] {
26+
using namespace otio;
27+
SerializableObject::Retainer<Composition> comp = new Composition;
28+
SerializableObject::Retainer<Item> item = new Item;
29+
30+
comp->append_child(item);
31+
opentimelineio::v1_0::ErrorStatus err;
32+
auto result = comp->find_children<>(&err);
33+
assertEqual(result.size(), 1);
34+
assertEqual(result[0].value, item.value);
35+
});
36+
37+
// test stack and track correctly calls find_clips from composition parent class
38+
tests.add_test(
39+
"test_find_clips", [] {
40+
using namespace otio;
41+
SerializableObject::Retainer<Stack> stack = new Stack();
42+
SerializableObject::Retainer<Track> track = new Track;
43+
SerializableObject::Retainer<Clip> clip = new Clip;
44+
SerializableObject::Retainer<Transition> transition = new Transition;
45+
46+
stack->append_child(track);
47+
track->append_child(transition);
48+
track->append_child(clip);
49+
50+
opentimelineio::v1_0::ErrorStatus err;
51+
auto items = stack->find_clips(&err);
52+
assertFalse(is_error(err));
53+
assertEqual(items.size(), 1);
54+
assertEqual(items[0].value, clip.value);
55+
56+
items = track->find_clips(&err);
57+
assertFalse(is_error(err));
58+
assertEqual(items.size(), 1);
59+
assertEqual(items[0].value, clip.value);
60+
});
61+
62+
tests.run(argc, argv);
63+
return 0;
64+
}

0 commit comments

Comments
 (0)