summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-12-20 14:19:47 +0100
committerCarl Hetherington <cth@carlh.net>2025-09-03 10:53:29 +0200
commit4effe4c3dc2d4b6a700e5c20e9e0104f023bd9f9 (patch)
treec447dc29e31b0075701c9043083d3332f944ea7a /src/lib
parenta55f7fa11991d222251a2a50f9349d8dbeed5ed7 (diff)
Add helpers for serialising times to XML with timebase.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcpomatic_time.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h
index a26b21a9c..b77c961d9 100644
--- a/src/lib/dcpomatic_time.h
+++ b/src/lib/dcpomatic_time.h
@@ -30,6 +30,12 @@
#include "dcpomatic_assert.h"
#include "frame_rate_change.h"
+#include "xml_util.h"
+#include <libcxml/cxml.h>
+#include <dcp/raw_convert.h>
+LIBDCP_DISABLE_WARNINGS
+#include <libxml++/libxml++.h>
+LIBDCP_ENABLE_WARNINGS
#include <boost/optional.hpp>
#include <cmath>
#include <cstdio>
@@ -278,6 +284,32 @@ public:
return Time<S, O> (f * HZ / r);
}
+ static Time<S, O> from_node(std::shared_ptr<const cxml::Node> node) {
+ if (!node) {
+ return {};
+ }
+
+ return Time<S, O>(dcp::raw_convert<Type>(node->content()), node->optional_number_attribute<Type>("timebase").get_value_or(96000));
+ }
+
+ xmlpp::Element* add_as_node(xmlpp::Element* parent, std::string name) const {
+ auto child = cxml::add_child(parent, name);
+ child->add_child_text(dcp::raw_convert<std::string>(_t));
+ child->set_attribute("timebase", dcp::raw_convert<std::string>(HZ));
+ return child;
+ }
+
+ static Time<S, O> from_attributes(std::shared_ptr<const cxml::Node> node) {
+ auto time = number_attribute<Type>(node, "Time", "time");
+ auto timebase = node->optional_number_attribute<Type>("timebase").get_value_or(96000);
+ return Time<S, O>(time, timebase);
+ }
+
+ void add_as_attributes(xmlpp::Element* element) const {
+ element->set_attribute("time", dcp::raw_convert<std::string>(_t));
+ element->set_attribute("timebase", dcp::raw_convert<std::string>(HZ));
+ }
+
static Time<S, O> delta () {
return Time<S, O> (1);
}