diff --git a/docs/tutorials/otio-serialized-schema-only-fields.md b/docs/tutorials/otio-serialized-schema-only-fields.md index bbabcc5380..b9496d9d99 100644 --- a/docs/tutorials/otio-serialized-schema-only-fields.md +++ b/docs/tutorials/otio-serialized-schema-only-fields.md @@ -144,6 +144,7 @@ parameters: parameters: - *effect_name* +- *enabled* - *metadata* - *name* @@ -160,6 +161,7 @@ parameters: parameters: - *effect_name* +- *enabled* - *metadata* - *name* - *time_scalar* @@ -204,6 +206,7 @@ parameters: parameters: - *effect_name* +- *enabled* - *metadata* - *name* - *time_scalar* @@ -245,6 +248,7 @@ parameters: parameters: - *effect_name* +- *enabled* - *metadata* - *name* diff --git a/docs/tutorials/otio-serialized-schema.md b/docs/tutorials/otio-serialized-schema.md index d36e1d482d..6c966f1396 100644 --- a/docs/tutorials/otio-serialized-schema.md +++ b/docs/tutorials/otio-serialized-schema.md @@ -310,6 +310,7 @@ None parameters: - *effect_name*: +- *enabled*: If true, the Effect is applied. If false, the Effect is omitted. - *metadata*: - *name*: @@ -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, @@ -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, @@ -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*: diff --git a/src/opentimelineio/effect.cpp b/src/opentimelineio/effect.cpp index e1e4f75f77..e6daf05257 100644 --- a/src/opentimelineio/effect.cpp +++ b/src/opentimelineio/effect.cpp @@ -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() @@ -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); } @@ -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 diff --git a/src/opentimelineio/effect.h b/src/opentimelineio/effect.h index 9c3908588a..5d27ba24d1 100644 --- a/src/opentimelineio/effect.h +++ b/src/opentimelineio/effect.h @@ -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; } @@ -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(); @@ -39,6 +44,7 @@ class Effect : public SerializableObjectWithMetadata private: std::string _effect_name; + bool _enabled; }; }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp b/src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp index 5a99ed8b8a..b8361d0942 100644 --- a/src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp +++ b/src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp @@ -657,12 +657,15 @@ static void define_effects(py::module m) { py::class_>(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_>(m, "TimeEffect", py::dynamic_attr(), "Base class for all effects that alter the timing of an item.") .def(py::init([](std::string name, diff --git a/src/py-opentimelineio/opentimelineio/schema/effect.py b/src/py-opentimelineio/opentimelineio/schema/effect.py index 3fc575ce35..2db4cae937 100644 --- a/src/py-opentimelineio/opentimelineio/schema/effect.py +++ b/src/py-opentimelineio/opentimelineio/schema/effect.py @@ -11,11 +11,13 @@ def __str__(self): "Effect(" "{}, " "{}, " + "{}, " "{}" ")".format( str(self.name), str(self.effect_name), str(self.metadata), + str(self.enabled) ) ) @@ -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) ) ) diff --git a/tests/baselines/empty_effect.json b/tests/baselines/empty_effect.json new file mode 100644 index 0000000000..7046ab4e5c --- /dev/null +++ b/tests/baselines/empty_effect.json @@ -0,0 +1,7 @@ +{ + "OTIO_SCHEMA" : "Effect.1", + "name" : "", + "effect_name" : "", + "metadata" : {}, + "enabled" : true +} diff --git a/tests/test_effect.py b/tests/test_effect.py index 9e615695b4..8bc366ab95 100644 --- a/tests/test_effect.py +++ b/tests/test_effect.py @@ -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( @@ -39,14 +44,16 @@ 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( @@ -54,11 +61,13 @@ def test_str(self): "otio.schema.Effect(" "name={}, " "effect_name={}, " - "metadata={}" + "metadata={}, " + "enabled={}" ")".format( repr(ef.name), repr(ef.effect_name), repr(ef.metadata), + repr(ef.enabled) ) ) @@ -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): @@ -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'}) @@ -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__': diff --git a/tests/test_json_backend.py b/tests/test_json_backend.py index f649f4b1c1..da61274d5f 100755 --- a/tests/test_json_backend.py +++ b/tests/test_json_backend.py @@ -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")