From 4eeed2f88a418c0ab374f5fc9e53a1fb645298e2 Mon Sep 17 00:00:00 2001 From: Nicholas Bui LeTourneau <225737+nickblt@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:20:40 -0800 Subject: [PATCH 1/3] add optional comment field to Marker Signed-off-by: Nicholas Bui LeTourneau <225737+nickblt@users.noreply.github.com> --- src/opentimelineio/marker.cpp | 6 ++- src/opentimelineio/marker.h | 8 +++- .../otio_serializableObjects.cpp | 12 ++++-- tests/test_marker.py | 41 +++++++++++++++++++ 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/opentimelineio/marker.cpp b/src/opentimelineio/marker.cpp index 0c6b748b1..aa3e6445b 100644 --- a/src/opentimelineio/marker.cpp +++ b/src/opentimelineio/marker.cpp @@ -10,10 +10,12 @@ Marker::Marker( std::string const& name, TimeRange const& marked_range, std::string const& color, - AnyDictionary const& metadata) + AnyDictionary const& metadata, + std::string const& comment) : Parent(name, metadata) , _color(color) , _marked_range(marked_range) + , _comment(comment) {} Marker::~Marker() @@ -24,6 +26,7 @@ Marker::read_from(Reader& reader) { return reader.read_if_present("color", &_color) && reader.read("marked_range", &_marked_range) + && reader.read_if_present("comment", &_comment) && Parent::read_from(reader); } @@ -33,6 +36,7 @@ Marker::write_to(Writer& writer) const Parent::write_to(writer); writer.write("color", _color); writer.write("marked_range", _marked_range); + writer.write("comment", _comment); } }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/marker.h b/src/opentimelineio/marker.h index 927e9d647..625bb42fc 100644 --- a/src/opentimelineio/marker.h +++ b/src/opentimelineio/marker.h @@ -38,7 +38,8 @@ class Marker : public SerializableObjectWithMetadata std::string const& name = std::string(), TimeRange const& marked_range = TimeRange(), std::string const& color = Color::green, - AnyDictionary const& metadata = AnyDictionary()); + AnyDictionary const& metadata = AnyDictionary(), + std::string const& comment = std::string()); std::string color() const noexcept { return _color; } @@ -51,6 +52,10 @@ class Marker : public SerializableObjectWithMetadata _marked_range = marked_range; } + std::string comment() const noexcept { return _comment; } + + void set_comment(std::string const& comment) { _comment = comment; } + protected: virtual ~Marker(); @@ -60,6 +65,7 @@ class Marker : public SerializableObjectWithMetadata private: std::string _color; TimeRange _marked_range; + std::string _comment; }; }} // 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 e3ac4b4e2..d5d0c768f 100644 --- a/src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp +++ b/src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp @@ -214,19 +214,23 @@ The marked range may have a zero duration. The marked range is in the owning ite std::string name, TimeRange marked_range, std::string const& color, - py::object metadata) { + py::object metadata, + std::string const& comment) { return new Marker( name, marked_range, color, - py_to_any_dictionary(metadata)); + py_to_any_dictionary(metadata), + comment); }), py::arg_v("name"_a = std::string()), "marked_range"_a = TimeRange(), "color"_a = std::string(Marker::Color::red), - py::arg_v("metadata"_a = py::none())) + py::arg_v("metadata"_a = py::none()), + "comment"_a = std::string()) .def_property("color", &Marker::color, &Marker::set_color, "Color string for this marker (for example: 'RED'), based on the :class:`~Color` enum.") - .def_property("marked_range", &Marker::marked_range, &Marker::set_marked_range, "Range this marker applies to, relative to the :class:`.Item` this marker is attached to (e.g. the :class:`.Clip` or :class:`.Track` that owns this marker)."); + .def_property("marked_range", &Marker::marked_range, &Marker::set_marked_range, "Range this marker applies to, relative to the :class:`.Item` this marker is attached to (e.g. the :class:`.Clip` or :class:`.Track` that owns this marker).") + .def_property("comment", &Marker::comment, &Marker::set_comment, "Optional comment for this marker."); py::class_(marker_class, "Color") .def_property_readonly_static("PINK", [](py::object /* self */) { return Marker::Color::pink; }) diff --git a/tests/test_marker.py b/tests/test_marker.py index f05936b20..c5c256dfa 100755 --- a/tests/test_marker.py +++ b/tests/test_marker.py @@ -88,6 +88,47 @@ def test_repr(self): self.assertEqual(repr(m), expected) + def test_comment(self): + src = """ + { + "OTIO_SCHEMA" : "Marker.1", + "metadata" : {}, + "name" : null, + "comment": "foo bar", + "range" : { + "OTIO_SCHEMA" : "TimeRange.1", + "start_time" : { + "OTIO_SCHEMA" : "RationalTime.1", + "rate" : 5, + "value" : 0 + }, + "duration" : { + "OTIO_SCHEMA" : "RationalTime.1", + "rate" : 5, + "value" : 0 + } + } + + } + """ + marker = otio.adapters.read_from_string(src, "otio_json") + self.assertEqual(marker.comment, "foo bar") + + tr = otio.opentime.TimeRange( + otio.opentime.RationalTime(5, 24), + otio.opentime.RationalTime(10, 24) + ) + m = otio.schema.Marker( + name="marker_1", + marked_range=tr, + metadata={'foo': 'bar'}, + comment="foo bar2") + self.assertEqual(m.comment, "foo bar2") + + encoded = otio.adapters.otio_json.write_to_string(m) + decoded = otio.adapters.otio_json.read_from_string(encoded) + self.assertEqual(decoded.comment, "foo bar2") + def test_str(self): tr = otio.opentime.TimeRange( otio.opentime.RationalTime(5, 24), From 09dd254fca5e53c311fc363cedf78f25e6af51ee Mon Sep 17 00:00:00 2001 From: Nicholas Bui LeTourneau <225737+nickblt@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:30:35 -0800 Subject: [PATCH 2/3] Update docs because of shema change Signed-off-by: Nicholas Bui LeTourneau <225737+nickblt@users.noreply.github.com> --- docs/tutorials/otio-serialized-schema-only-fields.md | 1 + docs/tutorials/otio-serialized-schema.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/tutorials/otio-serialized-schema-only-fields.md b/docs/tutorials/otio-serialized-schema-only-fields.md index 6c70a0bf0..bbabcc538 100644 --- a/docs/tutorials/otio-serialized-schema-only-fields.md +++ b/docs/tutorials/otio-serialized-schema-only-fields.md @@ -212,6 +212,7 @@ parameters: parameters: - *color* +- *comment* - *marked_range* - *metadata* - *name* diff --git a/docs/tutorials/otio-serialized-schema.md b/docs/tutorials/otio-serialized-schema.md index d109d14fd..d36e1d482 100644 --- a/docs/tutorials/otio-serialized-schema.md +++ b/docs/tutorials/otio-serialized-schema.md @@ -526,6 +526,7 @@ system. parameters: - *color*: Color string for this marker (for example: 'RED'), based on the :class:`~Color` enum. +- *comment*: Optional comment for this marker. - *marked_range*: Range this marker applies to, relative to the :class:`.Item` this marker is attached to (e.g. the :class:`.Clip` or :class:`.Track` that owns this marker). - *metadata*: - *name*: From 74dd686275e9215f25670ff2c8ffc07d1352e1fb Mon Sep 17 00:00:00 2001 From: Nicholas Bui LeTourneau <225737+nickblt@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:39:31 -0800 Subject: [PATCH 3/3] add empty comment to marker baseline Signed-off-by: Nicholas Bui LeTourneau <225737+nickblt@users.noreply.github.com> --- tests/baselines/empty_marker.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/baselines/empty_marker.json b/tests/baselines/empty_marker.json index f54afeed9..cfee65e75 100644 --- a/tests/baselines/empty_marker.json +++ b/tests/baselines/empty_marker.json @@ -3,6 +3,7 @@ "metadata" : {}, "name" : "", "color" : "RED", + "comment" : "", "marked_range" : { "FROM_TEST_FILE" : "empty_timerange.json" }