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

Updated Effect schema with enabled flag #1798

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
4 changes: 4 additions & 0 deletions docs/tutorials/otio-serialized-schema-only-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ parameters:

parameters:
- *effect_name*
- *enabled*
- *metadata*
- *name*

Expand All @@ -160,6 +161,7 @@ parameters:

parameters:
- *effect_name*
- *enabled*
- *metadata*
- *name*
- *time_scalar*
Expand Down Expand Up @@ -204,6 +206,7 @@ parameters:

parameters:
- *effect_name*
- *enabled*
- *metadata*
- *name*
- *time_scalar*
Expand Down Expand Up @@ -245,6 +248,7 @@ parameters:

parameters:
- *effect_name*
- *enabled*
- *metadata*
- *name*

Expand Down
4 changes: 4 additions & 0 deletions docs/tutorials/otio-serialized-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ None

parameters:
- *effect_name*:
- *enabled*: If true, the Effect is applied. If false, the Effect is omitted.
- *metadata*:
- *name*:

Expand Down Expand Up @@ -342,6 +343,7 @@ Hold the first frame of the clip for the duration of the clip.

parameters:
- *effect_name*:
- *enabled*: If true, the Effect is applied. If false, the Effect is omitted.
- *metadata*:
- *name*:
- *time_scalar*: Linear time scalar applied to clip. 2.0 means the clip occupies half the time in the parent item, i.e. plays at double speed,
Expand Down Expand Up @@ -500,6 +502,7 @@ A time warp that applies a linear speed up or slow down across the entire clip.

parameters:
- *effect_name*:
- *enabled*: If true, the Effect is applied. If false, the Effect is omitted.
- *metadata*:
- *name*:
- *time_scalar*: Linear time scalar applied to clip. 2.0 means the clip occupies half the time in the parent item, i.e. plays at double speed,
Expand Down Expand Up @@ -607,6 +610,7 @@ Base class for all effects that alter the timing of an item.

parameters:
- *effect_name*:
- *enabled*: If true, the Effect is applied. If false, the Effect is omitted.
- *metadata*:
- *name*:

Expand Down
6 changes: 5 additions & 1 deletion src/opentimelineio/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
Effect::Effect(
std::string const& name,
std::string const& effect_name,
AnyDictionary const& metadata)
AnyDictionary const& metadata,
bool enabled)
: Parent(name, metadata)
, _effect_name(effect_name)
, _enabled(enabled)
{}

Effect::~Effect()
Expand All @@ -21,6 +23,7 @@ bool
Effect::read_from(Reader& reader)
{
return reader.read("effect_name", &_effect_name)
&& reader.read_if_present("enabled", &_enabled)
&& Parent::read_from(reader);
}

Expand All @@ -29,6 +32,7 @@ Effect::write_to(Writer& writer) const
{
Parent::write_to(writer);
writer.write("effect_name", _effect_name);
writer.write("enabled", _enabled);
}

}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
8 changes: 7 additions & 1 deletion src/opentimelineio/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Effect : public SerializableObjectWithMetadata
Effect(
std::string const& name = std::string(),
std::string const& effect_name = std::string(),
AnyDictionary const& metadata = AnyDictionary());
AnyDictionary const& metadata = AnyDictionary(),
bool enabled = true);

std::string effect_name() const noexcept { return _effect_name; }

Expand All @@ -31,6 +32,10 @@ class Effect : public SerializableObjectWithMetadata
_effect_name = effect_name;
}

bool enabled() const { return _enabled; };

void set_enabled(bool enabled) { _enabled = enabled; }

protected:
virtual ~Effect();

Expand All @@ -39,6 +44,7 @@ class Effect : public SerializableObjectWithMetadata

private:
std::string _effect_name;
bool _enabled;
};

}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,15 @@ static void define_effects(py::module m) {
py::class_<Effect, SOWithMetadata, managing_ptr<Effect>>(m, "Effect", py::dynamic_attr())
.def(py::init([](std::string name,
std::string effect_name,
py::object metadata) {
return new Effect(name, effect_name, py_to_any_dictionary(metadata)); }),
py::object metadata,
py::bool_ enabled) {
return new Effect(name, effect_name, py_to_any_dictionary(metadata), enabled); }),
py::arg_v("name"_a = std::string()),
"effect_name"_a = std::string(),
py::arg_v("metadata"_a = py::none()))
.def_property("effect_name", &Effect::effect_name, &Effect::set_effect_name);
py::arg_v("metadata"_a = py::none()),
"enabled"_a = true)
.def_property("effect_name", &Effect::effect_name, &Effect::set_effect_name)
.def_property("enabled", &Effect::enabled, &Effect::set_enabled, "If true, the Effect is applied. If false, the Effect is omitted.");

py::class_<TimeEffect, Effect, managing_ptr<TimeEffect>>(m, "TimeEffect", py::dynamic_attr(), "Base class for all effects that alter the timing of an item.")
.def(py::init([](std::string name,
Expand Down
6 changes: 5 additions & 1 deletion src/py-opentimelineio/opentimelineio/schema/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def __str__(self):
"Effect("
"{}, "
"{}, "
"{}, "
"{}"
")".format(
str(self.name),
str(self.effect_name),
str(self.metadata),
str(self.enabled)
)
)

Expand All @@ -26,10 +28,12 @@ def __repr__(self):
"otio.schema.Effect("
"name={}, "
"effect_name={}, "
"metadata={}"
"metadata={}, "
"enabled={}"
")".format(
repr(self.name),
repr(self.effect_name),
repr(self.metadata),
repr(self.enabled)
)
)
7 changes: 7 additions & 0 deletions tests/baselines/empty_effect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"OTIO_SCHEMA" : "Effect.1",
"name" : "",
"effect_name" : "",
"metadata" : {},
"enabled" : true
}
22 changes: 17 additions & 5 deletions tests/test_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ def test_cons(self):
ef = otio.schema.Effect(
name="blur it",
effect_name="blur",
metadata={"foo": "bar"}
metadata={"foo": "bar"},
enabled=False
)

self.assertEqual(ef.enabled, False)

encoded = otio.adapters.otio_json.write_to_string(ef)
decoded = otio.adapters.otio_json.read_from_string(encoded)
self.assertIsOTIOEquivalentTo(ef, decoded)
self.assertEqual(decoded.name, "blur it")
self.assertEqual(decoded.effect_name, "blur")
self.assertEqual(decoded.metadata['foo'], 'bar')
self.assertEqual(decoded.enabled, False)

def test_eq(self):
ef = otio.schema.Effect(
Expand All @@ -39,26 +44,30 @@ def test_str(self):
ef = otio.schema.Effect(
name="blur it",
effect_name="blur",
metadata={"foo": "bar"}
metadata={"foo": "bar"},
enabled=False
)
self.assertMultiLineEqual(
str(ef),
"Effect({}, {}, {})".format(
"Effect({}, {}, {}, {})".format(
str(ef.name),
str(ef.effect_name),
str(ef.metadata)
str(ef.metadata),
str(ef.enabled)
)
)
self.assertMultiLineEqual(
repr(ef),
"otio.schema.Effect("
"name={}, "
"effect_name={}, "
"metadata={}"
"metadata={}, "
"enabled={}"
")".format(
repr(ef.name),
repr(ef.effect_name),
repr(ef.metadata),
repr(ef.enabled)
)
)

Expand All @@ -71,6 +80,7 @@ def test_setters(self):
self.assertEqual(ef.effect_name, "blur")
ef.effect_name = "flop"
self.assertEqual(ef.effect_name, "flop")
self.assertEqual(ef.enabled, True)


class TestLinearTimeWarp(unittest.TestCase, otio_test_utils.OTIOAssertions):
Expand All @@ -80,6 +90,7 @@ def test_cons(self):
self.assertEqual(ef.name, "Foo")
self.assertEqual(ef.time_scalar, 2.5)
self.assertEqual(ef.metadata, {"foo": "bar"})
self.assertEqual(ef.enabled, True)

def test_serialize(self):
ef = otio.schema.LinearTimeWarp("Foo", 2.5, {'foo': 'bar'})
Expand All @@ -101,6 +112,7 @@ def test_cons(self):
self.assertEqual(ef.name, "Foo")
self.assertEqual(ef.time_scalar, 0)
self.assertEqual(ef.metadata, {"foo": "bar"})
self.assertEqual(ef.enabled, True)


if __name__ == '__main__':
Expand Down
4 changes: 4 additions & 0 deletions tests/test_json_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def test_marker(self):
mr = otio.schema.Marker()
self.check_against_baseline(mr, "empty_marker")

def test_effect(self):
mr = otio.schema.Effect()
self.check_against_baseline(mr, "empty_effect")

def test_transition(self):
trx = otio.schema.Transition()
self.check_against_baseline(trx, "empty_transition")
Expand Down
Loading