Cleanup: extract some stuff to a method in CreateCLI.
authorCarl Hetherington <cth@carlh.net>
Sat, 30 Sep 2023 09:29:42 +0000 (11:29 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 30 Sep 2023 09:29:42 +0000 (11:29 +0200)
src/lib/create_cli.cc
src/lib/create_cli.h
src/tools/dcpomatic_create.cc

index 81e35389383383c870ef1cc529a05425f15a7b41..03a1992586809b2cb4c3bb4fdc2c666f527d15f3 100644 (file)
 #include "config.h"
 #include "create_cli.h"
 #include "dcp_content_type.h"
+#include "dcpomatic_log.h"
+#include "film.h"
 #include "ratio.h"
 #include <dcp/raw_convert.h>
 #include <iostream>
 #include <string>
 
 
-using std::string;
 using std::cout;
+using std::make_shared;
+using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::optional;
 
 
@@ -307,3 +312,49 @@ CreateCLI::CreateCLI (int argc, char* argv[])
                return;
        }
 }
+
+
+shared_ptr<Film>
+CreateCLI::make_film() const
+{
+       auto film = std::make_shared<Film>(output_dir);
+       dcpomatic_log = film->log();
+       dcpomatic_log->set_types(Config::instance()->log_types());
+       if (template_name) {
+               film->use_template(template_name.get());
+       }
+       film->set_name(name);
+
+       if (container_ratio) {
+               film->set_container(container_ratio);
+       }
+       film->set_dcp_content_type(dcp_content_type);
+       film->set_interop(standard == dcp::Standard::INTEROP);
+       film->set_use_isdcf_name(!no_use_isdcf_name);
+       film->set_encrypted(encrypt);
+       film->set_three_d(threed);
+       if (twok) {
+               film->set_resolution(Resolution::TWO_K);
+       }
+       if (fourk) {
+               film->set_resolution(Resolution::FOUR_K);
+       }
+       if (j2k_bandwidth) {
+               film->set_j2k_bandwidth(*j2k_bandwidth);
+       }
+
+       int channels = 6;
+       for (auto cli_content: content) {
+               if (cli_content.channel) {
+                       channels = std::max(channels, static_cast<int>(*cli_content.channel) + 1);
+               }
+       }
+       if (channels % 1) {
+               ++channels;
+       }
+
+       film->set_audio_channels(channels);
+
+       return film;
+}
+
index 58f7cf20c151f1bcf6ebcdacb126f8b56c7cc56e..f6fe1860bce812763e02b7252f756cad922a02b2 100644 (file)
@@ -27,6 +27,7 @@
 
 
 class DCPContentType;
+class Film;
 class Ratio;
 
 
@@ -63,6 +64,8 @@ public:
        bool fourk;
        boost::optional<int> j2k_bandwidth;
 
+       std::shared_ptr<Film> make_film() const;
+
 private:
        static std::string _help;
 };
index caaba6b3808ba90b8a0ab7ad49633828b8e5459e..63889a5977f7f9ff6bccdb4662b3926cfc031d2b 100644 (file)
@@ -25,7 +25,6 @@
 #include "lib/cross.h"
 #include "lib/dcp_content.h"
 #include "lib/dcp_content_type.h"
-#include "lib/dcpomatic_log.h"
 #include "lib/film.h"
 #include "lib/image_content.h"
 #include "lib/job.h"
@@ -92,43 +91,7 @@ main (int argc, char* argv[])
        auto jm = JobManager::instance ();
 
        try {
-               auto film = std::make_shared<Film>(cc.output_dir);
-               dcpomatic_log = film->log ();
-               dcpomatic_log->set_types (Config::instance()->log_types());
-               if (cc.template_name) {
-                       film->use_template (cc.template_name.get());
-               }
-               film->set_name (cc.name);
-
-               if (cc.container_ratio) {
-                       film->set_container (cc.container_ratio);
-               }
-               film->set_dcp_content_type (cc.dcp_content_type);
-               film->set_interop (cc.standard == dcp::Standard::INTEROP);
-               film->set_use_isdcf_name (!cc.no_use_isdcf_name);
-               film->set_encrypted (cc.encrypt);
-               film->set_three_d (cc.threed);
-               if (cc.twok) {
-                       film->set_resolution (Resolution::TWO_K);
-               }
-               if (cc.fourk) {
-                       film->set_resolution (Resolution::FOUR_K);
-               }
-               if (cc.j2k_bandwidth) {
-                       film->set_j2k_bandwidth (*cc.j2k_bandwidth);
-               }
-
-               int channels = 6;
-               for (auto cli_content: cc.content) {
-                       if (cli_content.channel) {
-                               channels = std::max(channels, static_cast<int>(*cli_content.channel) + 1);
-                       }
-               }
-               if (channels % 1) {
-                       ++channels;
-               }
-
-               film->set_audio_channels(channels);
+               auto film = cc.make_film();
 
                for (auto cli_content: cc.content) {
                        auto const can = boost::filesystem::canonical (cli_content.path);