Cleanup: make some variables private.
[dcpomatic.git] / src / lib / create_cli.cc
index 2cbff6e85bc2900ec6342cccb72e7d6371d00905..0ad728fafb926cf69e660d0f97302b6385814480 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;
 
 
@@ -119,15 +124,6 @@ argument_option (
 
 CreateCLI::CreateCLI (int argc, char* argv[])
        : version (false)
-       , encrypt (false)
-       , threed (false)
-       , dcp_content_type (nullptr)
-       , container_ratio (nullptr)
-       , still_length (10)
-       , standard (dcp::Standard::SMPTE)
-       , no_use_isdcf_name (false)
-       , twok (false)
-       , fourk (false)
 {
        string dcp_content_type_string = "TST";
        string container_ratio_string;
@@ -184,12 +180,20 @@ CreateCLI::CreateCLI (int argc, char* argv[])
                        return boost::filesystem::path(s);
                };
 
+               std::function<optional<int> (string s)> string_to_nonzero_int = [](string s) {
+                       auto const value = dcp::raw_convert<int>(s);
+                       if (value == 0) {
+                               return boost::optional<int>();
+                       }
+                       return boost::optional<int>(value);
+               };
+
                argument_option(i, argc, argv, "-n", "--name",             &claimed, &error, &name);
                argument_option(i, argc, argv, "-t", "--template",         &claimed, &error, &template_name_string);
                argument_option(i, argc, argv, "-c", "--dcp-content-type", &claimed, &error, &dcp_content_type_string);
                argument_option(i, argc, argv, "-f", "--dcp-frame-rate",   &claimed, &error, &dcp_frame_rate_int);
                argument_option(i, argc, argv, "",   "--container-ratio",  &claimed, &error, &container_ratio_string);
-               argument_option(i, argc, argv, "-s", "--still-length",     &claimed, &error, &still_length);
+               argument_option(i, argc, argv, "-s", "--still-length",     &claimed, &error, &still_length, string_to_nonzero_int);
                argument_option(i, argc, argv, "",   "--standard",         &claimed, &error, &standard_string);
                argument_option(i, argc, argv, "",   "--config",           &claimed, &error, &config_dir, string_to_path);
                argument_option(i, argc, argv, "-o", "--output",           &claimed, &error, &output_dir, string_to_path);
@@ -300,3 +304,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;
+}
+