diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-12-20 14:21:13 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-03 11:59:16 +0200 |
| commit | f0189cc11f08d67dfeb45b41a5b970a5856cb42d (patch) | |
| tree | ef17e46cb51c8013d1faed5855b90c1eb4f24914 /src | |
| parent | 4effe4c3dc2d4b6a700e5c20e9e0104f023bd9f9 (diff) | |
Use helpers for serialising times to/from XML.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/audio_analysis.cc | 6 | ||||
| -rw-r--r-- | src/lib/audio_content.cc | 8 | ||||
| -rw-r--r-- | src/lib/content.cc | 12 | ||||
| -rw-r--r-- | src/lib/dcp_content.cc | 8 | ||||
| -rw-r--r-- | src/lib/dcp_subtitle_content.cc | 4 | ||||
| -rw-r--r-- | src/lib/dcpomatic_time.h | 8 | ||||
| -rw-r--r-- | src/lib/ffmpeg_audio_stream.cc | 7 | ||||
| -rw-r--r-- | src/lib/ffmpeg_content.cc | 8 | ||||
| -rw-r--r-- | src/lib/film.cc | 8 | ||||
| -rw-r--r-- | src/lib/remembered_asset.cc | 8 | ||||
| -rw-r--r-- | src/lib/string_text_file_content.cc | 4 | ||||
| -rw-r--r-- | src/lib/text_content.cc | 20 |
12 files changed, 43 insertions, 58 deletions
diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc index 8375ae770..771734a7b 100644 --- a/src/lib/audio_analysis.cc +++ b/src/lib/audio_analysis.cc @@ -85,8 +85,8 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename) } for (auto i: f.node_children ("SamplePeak")) { - auto const time = number_attribute<Frame>(i, "Time", "time"); - _sample_peak.push_back(PeakTime(dcp::raw_convert<float>(i->content()), DCPTime(time))); + auto time = DCPTime::from_attributes(i); + _sample_peak.push_back(PeakTime(dcp::raw_convert<float>(i->content()), time)); } for (auto i: f.node_children("TruePeak")) { @@ -153,7 +153,7 @@ AudioAnalysis::write (boost::filesystem::path filename) for (size_t i = 0; i < _sample_peak.size(); ++i) { auto n = cxml::add_child(root, "SamplePeak"); n->add_child_text(fmt::to_string(_sample_peak[i].peak)); - n->set_attribute("time", fmt::to_string(_sample_peak[i].time.get())); + _sample_peak[i].time.add_as_attributes(n); } for (auto i: _true_peak) { diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 142dc0855..71fb35d5b 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -84,8 +84,8 @@ AudioContent::AudioContent (Content* parent, cxml::ConstNodePtr node) { _gain = node->number_child<double> ("AudioGain"); _delay = node->number_child<int> ("AudioDelay"); - _fade_in = ContentTime(node->optional_number_child<ContentTime::Type>("AudioFadeIn").get_value_or(0)); - _fade_out = ContentTime(node->optional_number_child<ContentTime::Type>("AudioFadeOut").get_value_or(0)); + _fade_in = ContentTime::from_node(node->optional_node_child("AudioFadeIn")); + _fade_out = ContentTime::from_node(node->optional_node_child("AudioFadeOut")); _use_same_fades_as_video = node->optional_bool_child("AudioUseSameFadesAsVideo").get_value_or(false); } @@ -118,8 +118,8 @@ AudioContent::as_xml(xmlpp::Element* element) const boost::mutex::scoped_lock lm (_mutex); cxml::add_text_child(element, "AudioGain", fmt::to_string(_gain)); cxml::add_text_child(element, "AudioDelay", fmt::to_string(_delay)); - cxml::add_text_child(element, "AudioFadeIn", fmt::to_string(_fade_in.get())); - cxml::add_text_child(element, "AudioFadeOut", fmt::to_string(_fade_out.get())); + _fade_in.add_as_node(element, "AudioFadeIn"); + _fade_out.add_as_node(element, "AudioFadeOut"); cxml::add_text_child(element, "AudioUseSameFadesAsVideo", _use_same_fades_as_video ? "1" : "0"); } diff --git a/src/lib/content.cc b/src/lib/content.cc index c62522105..960e23967 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -87,9 +87,9 @@ Content::Content(cxml::ConstNodePtr node, boost::optional<boost::filesystem::pat } } _digest = node->optional_string_child("Digest").get_value_or("X"); - _position = DCPTime(node->number_child<DCPTime::Type>("Position")); - _trim_start = ContentTime(node->number_child<ContentTime::Type>("TrimStart")); - _trim_end = ContentTime(node->number_child<ContentTime::Type>("TrimEnd")); + _position = DCPTime::from_node(node->node_child("Position")); + _trim_start = ContentTime::from_node(node->node_child("TrimStart")); + _trim_end = ContentTime::from_node(node->node_child("TrimEnd")); _video_frame_rate = node->optional_number_child<double>("VideoFrameRate"); } @@ -146,9 +146,9 @@ Content::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_beh } } cxml::add_text_child(element, "Digest", _digest); - cxml::add_text_child(element, "Position", fmt::to_string(_position.get())); - cxml::add_text_child(element, "TrimStart", fmt::to_string(_trim_start.get())); - cxml::add_text_child(element, "TrimEnd", fmt::to_string(_trim_end.get())); + _position.add_as_node(element, "Position"); + _trim_start.add_as_node(element, "TrimStart"); + _trim_end.add_as_node(element, "TrimEnd"); if (_video_frame_rate) { cxml::add_text_child(element, "VideoFrameRate", fmt::to_string(_video_frame_rate.get())); } diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 3e50005b3..8e18756de 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -145,7 +145,7 @@ DCPContent::DCPContent(cxml::ConstNodePtr node, boost::optional<boost::filesyste } for (auto i: node->node_children("Marker")) { - _markers[dcp::marker_from_string(i->string_attribute("type"))] = ContentTime(raw_convert<int64_t>(i->content())); + _markers[dcp::marker_from_string(i->string_attribute("type"))] = ContentTime::from_attributes(i); } for (auto i: node->node_children("Rating")) { @@ -324,7 +324,7 @@ DCPContent::examine(shared_ptr<const Film> film, shared_ptr<Job> job, bool toler _cpl = examiner->cpl (); _reel_lengths = examiner->reel_lengths (); for (auto const& i: examiner->markers()) { - _markers[i.first] = ContentTime(i.second.as_editable_units_ceil(DCPTime::HZ)); + _markers[i.first] = ContentTime(i.second.as_editable_units_ceil(96000), 96000); } _ratings = examiner->ratings (); _content_versions = examiner->content_versions (); @@ -433,9 +433,9 @@ DCPContent::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_ } for (auto const& i: _markers) { - auto marker = cxml::add_child(element, "Marker"); + auto marker = i.second.add_as_node(element, "Marker"); marker->set_attribute("type", dcp::marker_to_string(i.first)); - marker->add_child_text(fmt::to_string(i.second.get())); + i.second.add_as_attributes(marker); } for (auto i: _ratings) { diff --git a/src/lib/dcp_subtitle_content.cc b/src/lib/dcp_subtitle_content.cc index 21159fcac..1a28c9952 100644 --- a/src/lib/dcp_subtitle_content.cc +++ b/src/lib/dcp_subtitle_content.cc @@ -50,7 +50,7 @@ DCPSubtitleContent::DCPSubtitleContent (boost::filesystem::path path) DCPSubtitleContent::DCPSubtitleContent(cxml::ConstNodePtr node, boost::optional<boost::filesystem::path> film_directory, int version) : Content (node, film_directory) - , _length (node->number_child<ContentTime::Type> ("Length")) + , _length(ContentTime::from_node(node->node_child("Length"))) { list<string> notes; text = TextContent::from_xml (this, node, version, notes); @@ -149,5 +149,5 @@ DCPSubtitleContent::as_xml(xmlpp::Element* element, bool with_paths, PathBehavio only_text()->as_xml(element); } - cxml::add_text_child(element, "Length", fmt::to_string(_length.get())); + _length.add_as_node(element, "Length"); } diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index b77c961d9..cb7b58253 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -294,8 +294,8 @@ public: 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)); + child->add_child_text(fmt::to_string(_t)); + child->set_attribute("timebase", fmt::to_string(HZ)); return child; } @@ -306,8 +306,8 @@ public: } 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)); + element->set_attribute("time", fmt::to_string(_t)); + element->set_attribute("timebase", fmt::to_string(HZ)); } static Time<S, O> delta () { diff --git a/src/lib/ffmpeg_audio_stream.cc b/src/lib/ffmpeg_audio_stream.cc index e0da3a22d..ed1ef3791 100644 --- a/src/lib/ffmpeg_audio_stream.cc +++ b/src/lib/ffmpeg_audio_stream.cc @@ -42,10 +42,7 @@ FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version) node->optional_number_child<int>("BitDepth") ) { - optional<ContentTime::Type> const f = node->optional_number_child<ContentTime::Type>("FirstAudio"); - if (f) { - first_audio = ContentTime(f.get()); - } + first_audio = ContentTime::from_node(node->optional_node_child("FirstAudio")); codec_name = node->optional_string_child("CodecName"); } @@ -58,7 +55,7 @@ FFmpegAudioStream::as_xml(xmlpp::Element* root) const cxml::add_text_child(root, "Length", fmt::to_string(length())); mapping().as_xml(cxml::add_child(root, "Mapping")); if (first_audio) { - cxml::add_text_child(root, "FirstAudio", fmt::to_string(first_audio.get().get())); + first_audio->add_as_node(root, "FirstAudio"); } if (codec_name) { cxml::add_text_child(root, "CodecName", codec_name.get()); diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 6261c4003..6d70336a5 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -115,11 +115,7 @@ FFmpegContent::FFmpegContent(cxml::ConstNodePtr node, boost::optional<boost::fil } } - auto const f = node->optional_number_child<ContentTime::Type> ("FirstVideo"); - if (f) { - _first_video = ContentTime (f.get ()); - } - + _first_video = ContentTime::from_node(node->optional_node_child("FirstVideo")); _color_primaries = get_optional_enum<AVColorPrimaries>(node, "ColorPrimaries"); _color_trc = get_optional_enum<AVColorTransferCharacteristic>(node, "ColorTransferCharacteristic"); _colorspace = get_optional_enum<AVColorSpace>(node, "Colorspace"); @@ -228,7 +224,7 @@ FFmpegContent::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour pa } if (_first_video) { - cxml::add_text_child(element, "FirstVideo", fmt::to_string(_first_video.get().get())); + _first_video->add_as_node(element, "FirstVideo"); } if (_color_range) { diff --git a/src/lib/film.cc b/src/lib/film.cc index 21d69d233..754c7c850 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -421,14 +421,14 @@ Film::metadata(bool with_content_paths) const cxml::add_text_child(root, "ReelType", fmt::to_string(static_cast<int>(_reel_type))); cxml::add_text_child(root, "ReelLength", fmt::to_string(_reel_length)); for (auto boundary: _custom_reel_boundaries) { - cxml::add_text_child(root, "CustomReelBoundary", fmt::to_string(boundary.get())); + boundary.add_as_node(root, "CustomReelBoundary"); } cxml::add_text_child(root, "ReencodeJ2K", _reencode_j2k ? "1" : "0"); cxml::add_text_child(root, "UserExplicitVideoFrameRate", _user_explicit_video_frame_rate ? "1" : "0"); for (auto const& marker: _markers) { auto m = cxml::add_child(root, "Marker"); m->set_attribute("type", dcp::marker_to_string(marker.first)); - m->add_child_text(fmt::to_string(marker.second.get())); + marker.second.add_as_attributes(m); } for (auto i: _ratings) { i.as_xml(cxml::add_child(root, "Rating")); @@ -629,7 +629,7 @@ Film::read_metadata(optional<boost::filesystem::path> path) _reel_type = static_cast<ReelType>(f.optional_number_child<int>("ReelType").get_value_or(static_cast<int>(ReelType::SINGLE))); _reel_length = f.optional_number_child<int64_t>("ReelLength").get_value_or(2000000000); for (auto boundary: f.node_children("CustomReelBoundary")) { - _custom_reel_boundaries.push_back(DCPTime(raw_convert<int64_t>(boundary->content()))); + _custom_reel_boundaries.push_back(DCPTime::from_node(boundary)); } _reencode_j2k = f.optional_bool_child("ReencodeJ2K").get_value_or(false); _user_explicit_video_frame_rate = f.optional_bool_child("UserExplicitVideoFrameRate").get_value_or(false); @@ -639,7 +639,7 @@ Film::read_metadata(optional<boost::filesystem::path> path) if (!type) { type = i->string_attribute("type"); } - _markers[dcp::marker_from_string(*type)] = DCPTime(dcp::raw_convert<DCPTime::Type>(i->content())); + _markers[dcp::marker_from_string(*type)] = DCPTime::from_attributes(i); } for (auto i: f.node_children("Rating")) { diff --git a/src/lib/remembered_asset.cc b/src/lib/remembered_asset.cc index dfe0917c5..5eb574974 100644 --- a/src/lib/remembered_asset.cc +++ b/src/lib/remembered_asset.cc @@ -40,8 +40,8 @@ RememberedAsset::RememberedAsset(cxml::ConstNodePtr node) DCPOMATIC_ASSERT(period_node); _period = { - dcpomatic::DCPTime(period_node->number_child<int64_t>("From")), - dcpomatic::DCPTime(period_node->number_child<int64_t>("To")) + dcpomatic::DCPTime::from_node(period_node->node_child("From")), + dcpomatic::DCPTime::from_node(period_node->node_child("To")) }; _identifier = node->string_child("Identifier"); @@ -53,8 +53,8 @@ RememberedAsset::as_xml(xmlpp::Element* parent) const { cxml::add_text_child(parent, "Filename", _filename.string()); auto period_node = cxml::add_child(parent, "Period"); - cxml::add_text_child(period_node, "From", fmt::to_string(_period.from.get())); - cxml::add_text_child(period_node, "To", fmt::to_string(_period.to.get())); + _period.from.add_as_node(period_node, "From"); + _period.to.add_as_node(period_node, "To"); cxml::add_text_child(parent, "Identifier", _identifier); } diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index 5ecf50a12..4e06cbf08 100644 --- a/src/lib/string_text_file_content.cc +++ b/src/lib/string_text_file_content.cc @@ -53,7 +53,7 @@ StringTextFileContent::StringTextFileContent (boost::filesystem::path path) StringTextFileContent::StringTextFileContent(cxml::ConstNodePtr node, boost::optional<boost::filesystem::path> film_directory, int version, list<string>& notes) : Content (node, film_directory) - , _length (node->number_child<ContentTime::Type>("Length")) + , _length(ContentTime::from_node(node->node_child("Length"))) { text = TextContent::from_xml (this, node, version, notes); } @@ -130,7 +130,7 @@ StringTextFileContent::as_xml(xmlpp::Element* element, bool with_paths, PathBeha only_text()->as_xml(element); } - cxml::add_text_child(element, "Length", fmt::to_string(_length.get())); + _length.add_as_node(element, "Length"); } diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc index a83facd68..17d8b832f 100644 --- a/src/lib/text_content.cc +++ b/src/lib/text_content.cc @@ -173,24 +173,16 @@ TextContent::TextContent(Content* parent, cxml::ConstNodePtr node, int version, ); } - optional<Frame> fi; if (version >= 37) { - fi = node->optional_number_child<Frame>("FadeIn"); + _fade_in = ContentTime::from_node(node->optional_node_child("FadeIn")); } else { - fi = node->optional_number_child<Frame>("SubtitleFadeIn"); - } - if (fi) { - _fade_in = ContentTime(*fi); + _fade_in = ContentTime::from_node(node->optional_node_child("SubtitleFadeIn")); } - optional<Frame> fo; if (version >= 37) { - fo = node->optional_number_child<Frame>("FadeOut"); + _fade_out = ContentTime::from_node(node->optional_node_child("FadeOut")); } else { - fo = node->optional_number_child<Frame>("SubtitleFadeOut"); - } - if (fo) { - _fade_out = ContentTime(*fo); + _fade_out = ContentTime::from_node(node->optional_node_child("SubtitleFadeOut")); } for (auto i: node->node_children("Font")) { @@ -373,10 +365,10 @@ TextContent::as_xml(xmlpp::Element* root) const } cxml::add_text_child(text, "LineSpacing", fmt::to_string(_line_spacing)); if (_fade_in) { - cxml::add_text_child(text, "FadeIn", fmt::to_string(_fade_in->get())); + _fade_in->add_as_node(text, "FadeIn"); } if (_fade_out) { - cxml::add_text_child(text, "FadeOut", fmt::to_string(_fade_out->get())); + _fade_out->add_as_node(text, "FadeOut"); } cxml::add_text_child(text, "OutlineWidth", fmt::to_string(_outline_width)); |
