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 optional comment field to Marker #1698

Merged
merged 3 commits into from
Feb 15, 2024
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
1 change: 1 addition & 0 deletions docs/tutorials/otio-serialized-schema-only-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ parameters:

parameters:
- *color*
- *comment*
- *marked_range*
- *metadata*
- *name*
Expand Down
1 change: 1 addition & 0 deletions docs/tutorials/otio-serialized-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*:
Expand Down
6 changes: 5 additions & 1 deletion src/opentimelineio/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}

Expand All @@ -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
8 changes: 7 additions & 1 deletion src/opentimelineio/marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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();

Expand All @@ -60,6 +65,7 @@ class Marker : public SerializableObjectWithMetadata
private:
std::string _color;
TimeRange _marked_range;
std::string _comment;
};

}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -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::Color>(marker_class, "Color")
.def_property_readonly_static("PINK", [](py::object /* self */) { return Marker::Color::pink; })
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/empty_marker.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"metadata" : {},
"name" : "",
"color" : "RED",
"comment" : "",
"marked_range" : {
"FROM_TEST_FILE" : "empty_timerange.json"
}
Expand Down
41 changes: 41 additions & 0 deletions tests/test_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading