Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add effect and marker initialization to Clip #1808

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/opentimelineio/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Clip::Clip(
MediaReference* media_reference,
std::optional<TimeRange> const& source_range,
AnyDictionary const& metadata,
std::vector<Effect*> const& effects,
std::vector<Marker*> const& markers,
std::string const& active_media_reference_key)
: Parent{ name, source_range, metadata }
: Parent{ name, source_range, metadata, effects, markers }
, _active_media_reference_key(active_media_reference_key)
{
set_media_reference(media_reference);
Expand Down
2 changes: 2 additions & 0 deletions src/opentimelineio/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Clip : public Item
MediaReference* media_reference = nullptr,
std::optional<TimeRange> const& source_range = std::nullopt,
AnyDictionary const& metadata = AnyDictionary(),
std::vector<Effect*> const& effects = std::vector<Effect*>(),
std::vector<Marker*> const& markers = std::vector<Marker*>(),
std::string const& active_media_reference_key = default_media_key);

void set_media_reference(MediaReference* media_reference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,20 @@ Contains a :class:`.MediaReference` and a trim on that media reference.
)docstring")
.def(py::init([](std::string name, MediaReference* media_reference,
std::optional<TimeRange> source_range, py::object metadata,
std::optional<std::vector<Effect*>> effects,
std::optional<std::vector<Marker*>> markers,
const std::string& active_media_reference) {
return new Clip(name, media_reference, source_range, py_to_any_dictionary(metadata), active_media_reference);
return new Clip(name, media_reference, source_range, py_to_any_dictionary(metadata),
vector_or_default<Effect>(effects),
vector_or_default<Marker>(markers),
active_media_reference);
}),
py::arg_v("name"_a = std::string()),
"media_reference"_a = nullptr,
"source_range"_a = std::nullopt,
py::arg_v("metadata"_a = py::none()),
"effects"_a = py::none(),
"markers"_a = py::none(),
"active_media_reference"_a = std::string(Clip::default_media_key))
.def_property_readonly_static("DEFAULT_MEDIA_KEY",[](py::object /* self */) {
return Clip::default_media_key;
Expand Down
12 changes: 9 additions & 3 deletions src/py-opentimelineio/opentimelineio/schema/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

@add_method(_otio.Clip)
def __str__(self):
return 'Clip("{}", {}, {}, {})'.format(
return 'Clip("{}", {}, {}, {}, {}, {})'.format(
self.name,
self.media_reference,
self.source_range,
self.metadata
self.metadata,
self.effects,
self.markers
)


Expand All @@ -22,12 +24,16 @@ def __repr__(self):
'name={}, '
'media_reference={}, '
'source_range={}, '
'metadata={}'
'metadata={}, '
'effects={}, '
'markers={}'
peter-targett marked this conversation as resolved.
Show resolved Hide resolved
')'.format(
repr(self.name),
repr(self.media_reference),
repr(self.source_range),
repr(self.metadata),
repr(self.effects),
repr(self.markers)
)
)

Expand Down
33 changes: 33 additions & 0 deletions tests/test_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <opentimelineio/missingReference.h>
#include <opentimelineio/serializableCollection.h>
#include <opentimelineio/timeline.h>
#include <opentimelineio/freezeFrame.h>
#include <opentimelineio/linearTimeWarp.h>
#include <opentimelineio/marker.h>

#include <iostream>

Expand Down Expand Up @@ -150,6 +153,22 @@ main(int argc, char** argv)
tests.add_test("test_clip_media_representation", [] {
using namespace otio;

static constexpr auto time_scalar = 1.5;

SerializableObject::Retainer<LinearTimeWarp> ltw(new LinearTimeWarp(
LinearTimeWarp::Schema::name,
LinearTimeWarp::Schema::name,
time_scalar));
std::vector<Effect*> effects = { ltw };

static constexpr auto red = Marker::Color::red;

SerializableObject::Retainer<Marker> m(new Marker(
LinearTimeWarp::Schema::name,
TimeRange(),
red));
std::vector<Marker*> markers = { m };

static constexpr auto high_quality = "high_quality";
static constexpr auto proxy_quality = "proxy_quality";

Expand All @@ -161,6 +180,8 @@ main(int argc, char** argv)
media,
std::nullopt,
AnyDictionary(),
effects,
markers,
high_quality));

assertEqual(clip->active_media_reference_key().c_str(), high_quality);
Expand Down Expand Up @@ -225,6 +246,18 @@ main(int argc, char** argv)
// should work
clip->set_media_references({ { "cloud", ref4 } }, "cloud");
assertEqual(clip->media_reference(), ref4.value);

// basic test for an effect
assertEqual(clip->effects().size(), effects.size());
auto effect = dynamic_cast<OTIO_NS::LinearTimeWarp*>(
clip->effects().front().value);
assertEqual(effect->time_scalar(), time_scalar);

// basic test for a marker
assertEqual(clip->markers().size(), markers.size());
auto marker = dynamic_cast<OTIO_NS::Marker*>(
clip->markers().front().value);
assertEqual(marker->color().c_str(), red);
});

tests.run(argc, argv);
Expand Down
18 changes: 18 additions & 0 deletions tests/test_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,35 @@ def test_cons(self):
target_url="/var/tmp/test.mov"
)

ltw = otio.schema.LinearTimeWarp(
name="linear_time_warp",
time_scalar=1.5)
effects = []
effects.append(ltw)

red = otio.schema.MarkerColor.RED
m = otio.schema.Marker(
name="red_marker", color=red)
markers = []
markers.append(m)

cl = otio.schema.Clip(
name=name,
media_reference=mr,
source_range=tr,
effects=effects,
markers=markers,
# transition_in
# transition_out
)
self.assertEqual(cl.name, name)
self.assertEqual(cl.source_range, tr)
self.assertIsOTIOEquivalentTo(cl.media_reference, mr)

self.assertTrue(isinstance(cl.effects[0], otio.schema.LinearTimeWarp))

self.assertEqual(cl.markers[0].color, red)

encoded = otio.adapters.otio_json.write_to_string(cl)
decoded = otio.adapters.otio_json.read_from_string(encoded)
self.assertIsOTIOEquivalentTo(cl, decoded)
Expand Down
Loading