Updated cs_CZ translation from Tomáš Begeni.
[dcpomatic.git] / src / lib / audio_mapping.cc
index 8b9f102a56fdae460987cac010ee87ab89098178..b8aa6249f5faf11697331bb15ff6236a1e0b61c9 100644 (file)
 
 #include "audio_mapping.h"
 #include "audio_processor.h"
+#include "constants.h"
+#include "dcpomatic_assert.h"
 #include "digester.h"
-#include "util.h"
-#include "warnings.h"
 #include <dcp/raw_convert.h>
+#include <dcp/warnings.h>
 #include <libcxml/cxml.h>
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
 #include <libxml++/libxml++.h>
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #include <boost/regex.hpp>
 #include <iostream>
 
@@ -60,12 +61,9 @@ AudioMapping::AudioMapping (int input_channels, int output_channels)
 void
 AudioMapping::setup (int input_channels, int output_channels)
 {
-       _input_channels = input_channels;
-       _output_channels = output_channels;
-
-       _gain.resize (_input_channels);
-       for (int i = 0; i < _input_channels; ++i) {
-               _gain[i].resize (_output_channels);
+       _gain.resize(input_channels);
+       for (int i = 0; i < input_channels; ++i) {
+               _gain[i].resize(output_channels);
        }
 
        make_zero ();
@@ -75,9 +73,9 @@ AudioMapping::setup (int input_channels, int output_channels)
 void
 AudioMapping::make_zero ()
 {
-       for (int i = 0; i < _input_channels; ++i) {
-               for (int j = 0; j < _output_channels; ++j) {
-                       _gain[i][j] = 0;
+       for (auto& input: _gain) {
+               for (auto& output: input) {
+                       output = 0;
                }
        }
 }
@@ -106,9 +104,11 @@ AudioMapping::make_default (AudioProcessor const * processor, optional<boost::fi
                ChannelRegex(".*[\\._-]LFE[\\._-].*", 3),
                ChannelRegex(".*[\\._-]Lss[\\._-].*", 4),
                ChannelRegex(".*[\\._-]Lsr[\\._-].*", 6),
+               ChannelRegex(".*[\\._-]Lrs[\\._-].*", 6),
                ChannelRegex(".*[\\._-]Ls[\\._-].*", 4),
                ChannelRegex(".*[\\._-]Rss[\\._-].*", 5),
                ChannelRegex(".*[\\._-]Rsr[\\._-].*", 7),
+               ChannelRegex(".*[\\._-]Rrs[\\._-].*", 7),
                ChannelRegex(".*[\\._-]Rs[\\._-].*", 5),
        };
 
@@ -125,7 +125,7 @@ AudioMapping::make_default (AudioProcessor const * processor, optional<boost::fi
                        if (filename) {
                                for (int i = 0; i < regexes; ++i) {
                                        boost::regex e (regex[i].regex, boost::regex::icase);
-                                       if (boost::regex_match(filename->string(), e) && regex[i].channel < output_channels()) {
+                                       if (boost::regex_match(filename->filename().string(), e) && regex[i].channel < output_channels()) {
                                                set (0, regex[i].channel, 1);
                                                guessed = true;
                                        }
@@ -221,11 +221,14 @@ AudioMapping::get (int input_channel, int output_channel) const
 void
 AudioMapping::as_xml (xmlpp::Node* node) const
 {
-       node->add_child ("InputChannels")->add_child_text (raw_convert<string> (_input_channels));
-       node->add_child ("OutputChannels")->add_child_text (raw_convert<string> (_output_channels));
+       auto const input = input_channels();
+       auto const output = output_channels();
+
+       node->add_child("InputChannels")->add_child_text(raw_convert<string>(input));
+       node->add_child("OutputChannels")->add_child_text(raw_convert<string>(output));
 
-       for (int c = 0; c < _input_channels; ++c) {
-               for (int d = 0; d < _output_channels; ++d) {
+       for (int c = 0; c < input; ++c) {
+               for (int d = 0; d < output; ++d) {
                        auto t = node->add_child ("Gain");
                        t->set_attribute ("Input", raw_convert<string> (c));
                        t->set_attribute ("Output", raw_convert<string> (d));
@@ -242,11 +245,11 @@ string
 AudioMapping::digest () const
 {
        Digester digester;
-       digester.add (_input_channels);
-       digester.add (_output_channels);
-       for (int i = 0; i < _input_channels; ++i) {
-               for (int j = 0; j < _output_channels; ++j) {
-                       digester.add (_gain[i][j]);
+       digester.add(input_channels());
+       digester.add(output_channels());
+       for (auto const& input: _gain) {
+               for (auto output: input) {
+                       digester.add(output);
                }
        }
 
@@ -285,3 +288,18 @@ AudioMapping::unmap_all ()
                }
        }
 }
+
+
+void
+AudioMapping::take_from(AudioMapping const& other)
+{
+       auto input = std::min(input_channels(), other.input_channels());
+       auto output = std::min(output_channels(), other.output_channels());
+
+       for (auto i = 0; i < input; ++i) {
+               for (auto o = 0; o < output; ++o) {
+                       set(i, o, other.get(i, o));
+               }
+       }
+}
+