Cleanup: make a temporary for the content list.
[dcpomatic.git] / src / lib / film.cc
index 37720025b8ca5568e8d6f8e157be952d354a7b26..0ce56a4362821a7316ee91e38a089c9d8c995c86 100644 (file)
@@ -32,6 +32,7 @@
 #include "cinema.h"
 #include "compose.hpp"
 #include "config.h"
+#include "constants.h"
 #include "cross.h"
 #include "dcp_content.h"
 #include "dcp_content_type.h"
@@ -56,7 +57,6 @@
 #include "text_content.h"
 #include "transcode_job.h"
 #include "upload_job.h"
-#include "util.h"
 #include "video_content.h"
 #include "version.h"
 #include <libcxml/cxml.h>
@@ -156,7 +156,7 @@ Film::Film (optional<boost::filesystem::path> dir)
        : _playlist (new Playlist)
        , _use_isdcf_name (Config::instance()->use_isdcf_name_by_default())
        , _dcp_content_type (Config::instance()->default_dcp_content_type ())
-       , _container (Config::instance()->default_container ())
+       , _container(Ratio::from_id("185"))
        , _resolution (Resolution::TWO_K)
        , _encrypted (false)
        , _context_id (dcp::make_uuid ())
@@ -174,8 +174,10 @@ Film::Film (optional<boost::filesystem::path> dir)
        , _user_explicit_container (false)
        , _user_explicit_resolution (false)
        , _name_language (dcp::LanguageTag("en-US"))
+       , _release_territory(Config::instance()->default_territory())
        , _version_number (1)
        , _status (dcp::Status::FINAL)
+       , _audio_language(Config::instance()->default_audio_language())
        , _state_version (current_state_version)
        , _dirty (false)
        , _tolerant (false)
@@ -630,7 +632,7 @@ Film::read_metadata (optional<boost::filesystem::path> path)
                _sign_language_video_language = dcp::LanguageTag(*sign_language_video_language);
        }
 
-       _version_number = f.optional_number_child<int>("VersionNumber").get_value_or(0);
+       _version_number = f.optional_number_child<int>("VersionNumber").get_value_or(1);
 
        auto status = f.optional_string_child("Status");
        if (status) {
@@ -803,10 +805,15 @@ Film::subtitle_languages () const
 string
 Film::isdcf_name (bool if_created_now) const
 {
-       string d;
+       string isdcf_name;
 
        auto raw_name = name ();
 
+       auto to_upper = [](string s) {
+               transform(s.begin(), s.end(), s.begin(), ::toupper);
+               return s;
+       };
+
        /* Split the raw name up into words */
        vector<string> words;
        split (words, raw_name, is_any_of (" _-"));
@@ -842,14 +849,12 @@ Film::isdcf_name (bool if_created_now) const
                }
        }
 
-       if (fixed_name.length() > 14) {
-               fixed_name = fixed_name.substr (0, 14);
-       }
+       fixed_name = fixed_name.substr(0, 14);
 
-       d += fixed_name;
+       isdcf_name += fixed_name;
 
        if (dcp_content_type()) {
-               d += "_" + dcp_content_type()->isdcf_name();
+               isdcf_name += "_" + dcp_content_type()->isdcf_name();
                string version = "1";
                if (_interop) {
                        if (!_content_versions.empty()) {
@@ -861,59 +866,60 @@ Film::isdcf_name (bool if_created_now) const
                } else {
                        version = dcp::raw_convert<string>(_version_number);
                }
-               d += "-" + version;
+               isdcf_name += "-" + version;
        }
 
        if (_temp_version) {
-               d += "-Temp";
+               isdcf_name += "-Temp";
        }
 
        if (_pre_release) {
-               d += "-Pre";
+               isdcf_name += "-Pre";
        }
 
        if (_red_band) {
-               d += "-RedBand";
+               isdcf_name += "-RedBand";
        }
 
        if (_chain && !_chain->empty()) {
-               d += "-" + *_chain;
+               isdcf_name += "-" + *_chain;
        }
 
        if (three_d ()) {
-               d += "-3D";
+               isdcf_name += "-3D";
        }
 
        if (_two_d_version_of_three_d) {
-               d += "-2D";
+               isdcf_name += "-2D";
        }
 
        if (_luminance) {
                auto fl = _luminance->value_in_foot_lamberts();
                char buffer[64];
                snprintf (buffer, sizeof(buffer), "%.1f", fl);
-               d += String::compose("-%1fl", buffer);
+               isdcf_name += String::compose("-%1fl", buffer);
        }
 
        if (video_frame_rate() != 24) {
-               d += "-" + raw_convert<string>(video_frame_rate());
+               isdcf_name += "-" + raw_convert<string>(video_frame_rate());
        }
 
        if (container()) {
-               d += "_" + container()->isdcf_name();
+               isdcf_name += "_" + container()->isdcf_name();
        }
 
+       auto content_list = content();
+
        /* XXX: this uses the first bit of content only */
 
        /* Interior aspect ratio.  The standard says we don't do this for trailers, for some strange reason */
        if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::ContentKind::TRAILER) {
-               auto cl = content();
-               auto first_video = std::find_if(cl.begin(), cl.end(), [](shared_ptr<Content> c) { return static_cast<bool>(c->video); });
-               if (first_video != cl.end()) {
+               auto first_video = std::find_if(content_list.begin(), content_list.end(), [](shared_ptr<Content> c) { return static_cast<bool>(c->video); });
+               if (first_video != content_list.end()) {
                        auto first_ratio = lrintf((*first_video)->video->scaled_size(frame_size()).ratio() * 100);
                        auto container_ratio = lrintf(container()->ratio() * 100);
                        if (first_ratio != container_ratio) {
-                               d += "-" + dcp::raw_convert<string>(first_ratio);
+                               isdcf_name += "-" + dcp::raw_convert<string>(first_ratio);
                        }
                }
        }
@@ -931,7 +937,7 @@ Film::isdcf_name (bool if_created_now) const
 
        auto audio_language = _audio_language ? entry_for_language(*_audio_language) : "XX";
 
-       d += "_" + to_upper (audio_language);
+       isdcf_name += "_" + to_upper (audio_language);
 
        /* I'm not clear on the precise details of the convention for CCAP labelling;
           for now I'm just appending -CCAP if we have any closed captions.
@@ -939,7 +945,7 @@ Film::isdcf_name (bool if_created_now) const
 
        auto burnt_in = true;
        auto ccap = false;
-       for (auto i: content()) {
+       for (auto i: content_list) {
                for (auto j: i->text) {
                        if (j->type() == TextType::OPEN_SUBTITLE && j->use() && !j->burn()) {
                                burnt_in = false;
@@ -958,22 +964,23 @@ Film::isdcf_name (bool if_created_now) const
                        lang = to_upper (lang);
                }
 
-               d += "-" + lang;
+               isdcf_name += "-" + lang;
                if (ccap) {
-                       d += "-CCAP";
+                       isdcf_name += "-CCAP";
                }
        } else {
                /* No subtitles */
-               d += "-XX";
+               isdcf_name += "-XX";
        }
 
        if (_release_territory) {
                auto territory = _release_territory->subtag();
-               d += "_" + to_upper (territory);
-               if (_ratings.empty ()) {
-                       d += "-NR";
-               } else {
-                       d += "-" + _ratings[0].label;
+               isdcf_name += "_" + to_upper (territory);
+               if (!_ratings.empty()) {
+                       auto label = _ratings[0].label;
+                       boost::erase_all(label, "+");
+                       boost::erase_all(label, "-");
+                       isdcf_name += "-" + label;
                }
        }
 
@@ -983,46 +990,46 @@ Film::isdcf_name (bool if_created_now) const
 
        auto ch = audio_channel_types (mapped, audio_channels());
        if (!ch.first && !ch.second) {
-               d += "_MOS";
+               isdcf_name += "_MOS";
        } else if (ch.first) {
-               d += String::compose("_%1%2", ch.first, ch.second);
+               isdcf_name += String::compose("_%1%2", ch.first, ch.second);
        }
 
        if (audio_channels() > static_cast<int>(dcp::Channel::HI) && find(mapped.begin(), mapped.end(), static_cast<int>(dcp::Channel::HI)) != mapped.end()) {
-               d += "-HI";
+               isdcf_name += "-HI";
        }
        if (audio_channels() > static_cast<int>(dcp::Channel::VI) && find(mapped.begin(), mapped.end(), static_cast<int>(dcp::Channel::VI)) != mapped.end()) {
-               d += "-VI";
+               isdcf_name += "-VI";
        }
 
-       d += "_" + resolution_to_string (_resolution);
+       isdcf_name += "_" + resolution_to_string (_resolution);
 
        if (_studio && _studio->length() >= 2) {
-               d += "_" + to_upper (_studio->substr(0, 4));
+               isdcf_name += "_" + to_upper (_studio->substr(0, 4));
        }
 
        if (if_created_now) {
-               d += "_" + boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
+               isdcf_name += "_" + boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
        } else {
-               d += "_" + boost::gregorian::to_iso_string (_isdcf_date);
+               isdcf_name += "_" + boost::gregorian::to_iso_string (_isdcf_date);
        }
 
        if (_facility && _facility->length() >= 3) {
-               d += "_" + to_upper(_facility->substr(0, 3));
+               isdcf_name += "_" + to_upper(_facility->substr(0, 3));
        }
 
        if (_interop) {
-               d += "_IOP";
+               isdcf_name += "_IOP";
        } else {
-               d += "_SMPTE";
+               isdcf_name += "_SMPTE";
        }
 
        if (three_d ()) {
-               d += "-3D";
+               isdcf_name += "-3D";
        }
 
        auto vf = false;
-       for (auto i: content()) {
+       for (auto i: content_list) {
                auto dc = dynamic_pointer_cast<const DCPContent>(i);
                if (!dc) {
                        continue;
@@ -1040,12 +1047,12 @@ Film::isdcf_name (bool if_created_now) const
        }
 
        if (vf) {
-               d += "_VF";
+               isdcf_name += "_VF";
        } else {
-               d += "_OV";
+               isdcf_name += "_OV";
        }
 
-       return d;
+       return isdcf_name;
 }
 
 /** @return name to give the DCP */