Add --gain option to dcpomatic_create.
authorCarl Hetherington <cth@carlh.net>
Sun, 28 Nov 2021 19:00:09 +0000 (20:00 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 29 Nov 2021 00:10:16 +0000 (01:10 +0100)
src/lib/create_cli.cc
src/lib/create_cli.h
src/tools/dcpomatic_create.cc
test/create_cli_test.cc

index 8d7c5928758720e50e2ce491aa4638617e08c860..9453cc1671964614c70d6d51eb096a355ff6c74a 100644 (file)
@@ -55,7 +55,8 @@ string CreateCLI::_help =
        "      --j2k-bandwidth <Mbit/s>  J2K bandwidth in Mbit/s\n"
        "      --left-eye                next piece of content is for the left eye\n"
        "      --right-eye               next piece of content is for the right eye\n"
-       "      --channel <channel>       next piece of content should be mapped to audio channel L, R, C, Lfe, Ls or Rs\n";
+       "      --channel <channel>       next piece of content should be mapped to audio channel L, R, C, Lfe, Ls or Rs\n"
+       "      --gain                    next piece of content should have the given audio gain (in dB)\n";
 
 
 template <class T>
@@ -133,6 +134,7 @@ CreateCLI::CreateCLI (int argc, char* argv[])
        int j2k_bandwidth_int = 0;
        auto next_frame_type = VideoFrameType::TWO_D;
        optional<dcp::Channel> channel;
+       optional<float> gain;
 
        int i = 1;
        while (i < argc) {
@@ -200,6 +202,7 @@ CreateCLI::CreateCLI (int argc, char* argv[])
                };
 
                argument_option(i, argc, argv, "", "--channel", &claimed, &error, &channel, convert_channel);
+               argument_option(i, argc, argv, "", "--gain", &claimed, &error, &gain);
 
                if (!claimed) {
                        if (a.length() > 2 && a.substr(0, 2) == "--") {
@@ -210,9 +213,11 @@ CreateCLI::CreateCLI (int argc, char* argv[])
                                c.path = a;
                                c.frame_type = next_frame_type;
                                c.channel = channel;
+                               c.gain = gain;
                                content.push_back (c);
                                next_frame_type = VideoFrameType::TWO_D;
                                channel = {};
+                               gain = {};
                        }
                }
 
index 9cd7905368a7bdb66092af9470845a6c8372da7a..ed42e669ca81ce9f6d1565ee5124942ddd2b5a15 100644 (file)
@@ -39,6 +39,7 @@ public:
                boost::filesystem::path path;
                VideoFrameType frame_type;
                boost::optional<dcp::Channel> channel;
+               boost::optional<float> gain;
        };
 
        bool version;
index d78aef3df117ac346552c0e10386b92f314aac25..e6c948d2d509895986db5efdae1a08262d526416 100644 (file)
@@ -146,6 +146,9 @@ main (int argc, char* argv[])
                                                stream->set_mapping (mapping);
                                        }
                                }
+                               if (j->audio && i.gain) {
+                                       j->audio->set_gain (*i.gain);
+                               }
                        }
                }
 
index dff10a11c2fed9203329a8360b3c770d190d9bdc..acc3f64b0eb6eb31de56de6c40ff632578b395ea 100644 (file)
@@ -171,4 +171,13 @@ BOOST_AUTO_TEST_CASE (create_cli_test)
        cc = run ("dcpomatic2_create --channel foo fred.wav");
        BOOST_REQUIRE (cc.error);
        BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: foo is not valid for --channel"));
+
+       cc = run ("dcpomatic2_create fred.wav --gain -6 jim.wav --gain 2 sheila.wav");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
+       BOOST_CHECK_EQUAL (cc.content[0].path, "fred.wav");
+       BOOST_CHECK (!cc.content[0].gain);
+       BOOST_CHECK_EQUAL (cc.content[1].path, "jim.wav");
+       BOOST_CHECK_CLOSE (*cc.content[1].gain, -6, 0.001);
+       BOOST_CHECK_EQUAL (cc.content[2].path, "sheila.wav");
+       BOOST_CHECK_CLOSE (*cc.content[2].gain, 2, 0.001);
 }