+ 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; ++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));
+ t->add_child_text (raw_convert<string> (get (c, d)));
+ }
+ }
+}
+
+
+/** @return a string which is unique for a given AudioMapping configuration, for
+ * differentiation between different AudioMappings.
+ */
+string
+AudioMapping::digest () const
+{
+ Digester digester;
+ digester.add(input_channels());
+ digester.add(output_channels());
+ for (auto const& input: _gain) {
+ for (auto output: input) {
+ digester.add(output);
+ }
+ }
+
+ return digester.get ();
+}
+
+
+list<int>
+AudioMapping::mapped_output_channels () const
+{
+ static float const minus_96_db = 0.000015849;
+
+ list<int> mapped;
+
+ for (auto const& i: _gain) {
+ for (auto j: dcp::used_audio_channels()) {
+ if (abs(i[static_cast<int>(j)]) > minus_96_db) {
+ mapped.push_back (static_cast<int>(j));
+ }
+ }
+ }
+
+ mapped.sort ();
+ mapped.unique ();
+
+ return mapped;
+}
+
+
+void
+AudioMapping::unmap_all ()
+{
+ for (auto& i: _gain) {
+ for (auto& j: i) {
+ j = 0;
+ }
+ }
+}
+
+
+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());