From b03cf7c1e6f9799fd7570d4cc6fcf7bc69b614ee Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 May 2023 23:01:34 +0200 Subject: [PATCH] Cleanup: rearrange how overlap checking is done in can_reference(). --- src/lib/dcp_content.cc | 73 +++++++++++++++++++++++------------------- src/lib/dcp_content.h | 8 ++--- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 2d441353a..f50ae9800 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -612,7 +612,7 @@ DCPContent::reel_split_points (shared_ptr film) const } bool -DCPContent::can_reference (shared_ptr film, function)> part, string overlapping, string& why_not) const +DCPContent::can_reference(shared_ptr film, string& why_not) const { /* We must be using the same standard as the film */ if (_standard) { @@ -658,15 +658,16 @@ DCPContent::can_reference (shared_ptr film, functioncontent(), part, position(), end(film)); - if (a.size() != 1 || a.front().get() != this) { - why_not = overlapping; - return false; - } - return true; } +bool +DCPContent::overlaps(shared_ptr film, function)> part) const +{ + auto const a = dcpomatic::overlaps(film, film->content(), part, position(), end(film)); + return a.size() != 1 || a.front().get() != this; +} + bool DCPContent::can_reference_video (shared_ptr film, string& why_not) const @@ -691,15 +692,17 @@ DCPContent::can_reference_video (shared_ptr film, string& why_not) c return false; } - /// TRANSLATORS: this string will follow "Cannot reference this DCP: " - return can_reference( - film, - [](shared_ptr c) { - return static_cast(c->video) && c->video->use(); - }, - _("it overlaps other video content; remove the other content."), - why_not - ); + auto part = [](shared_ptr c) { + return static_cast(c->video) && c->video->use(); + }; + + if (overlaps(film, part)) { + /// TRANSLATORS: this string will follow "Cannot reference this DCP: " + why_not = _("it overlaps other video content; remove the other content."); + return false; + } + + return can_reference(film, why_not); } @@ -728,14 +731,17 @@ DCPContent::can_reference_audio (shared_ptr film, string& why_not) c } } - /// TRANSLATORS: this string will follow "Cannot reference this DCP: " - return can_reference( - film, [](shared_ptr c) { - return static_cast(c->audio) && !c->audio->mapping().mapped_output_channels().empty(); - }, - _("it overlaps other audio content; remove the other content."), - why_not - ); + auto part = [](shared_ptr c) { + return static_cast(c->audio) && !c->audio->mapping().mapped_output_channels().empty(); + }; + + if (overlaps(film, part)) { + /// TRANSLATORS: this string will follow "Cannot reference this DCP: " + why_not = _("it overlaps other audio content; remove the other content."); + return true; + } + + return can_reference(film, why_not); } @@ -787,15 +793,16 @@ DCPContent::can_reference_text (shared_ptr film, TextType type, stri return false; } - /// TRANSLATORS: this string will follow "Cannot reference this DCP: " - return can_reference( - film, - [type](shared_ptr c) { - return std::find_if(c->text.begin(), c->text.end(), [type](shared_ptr t) { return t->type() == type; }) != c->text.end(); - }, - _("they overlap other text content; remove the other content."), - why_not - ); + auto part = [type](shared_ptr c) { + return std::find_if(c->text.begin(), c->text.end(), [type](shared_ptr t) { return t->type() == type; }) != c->text.end(); + }; + + if (overlaps(film, part)) { + /// TRANSLATORS: this string will follow "Cannot reference this DCP: " + why_not = _("it overlaps other text content; remove the other content."); + } + + return can_reference(film, why_not); } void diff --git a/src/lib/dcp_content.h b/src/lib/dcp_content.h index 3753740a2..c0445899e 100644 --- a/src/lib/dcp_content.h +++ b/src/lib/dcp_content.h @@ -186,12 +186,8 @@ private: void read_directory (boost::filesystem::path); void read_sub_directory (boost::filesystem::path); std::list reels (std::shared_ptr film) const; - bool can_reference ( - std::shared_ptr film, - std::function )>, - std::string overlapping, - std::string& why_not - ) const; + bool can_reference(std::shared_ptr film, std::string& why_not) const; + bool overlaps(std::shared_ptr film, std::function)> part) const; std::string _name; /** true if our DCP is encrypted */ -- 2.30.2