X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=1db827046946a8008d54bff21597d4fd1d201bff;hb=854f2e5bbb7ffb9758b823af87034033033f3cb8;hp=7a5da7d2a4571445fd8d253393d7043d2f89a790;hpb=5778f4c92793a7950f02206e735a00731c87b090;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 7a5da7d2a..1db827046 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -21,6 +21,7 @@ #include #include #include "audio_mapping.h" +#include "util.h" using std::list; using std::cout; @@ -41,77 +42,86 @@ AudioMapping::AudioMapping () * @param c Number of channels. */ AudioMapping::AudioMapping (int c) - : _content_channels (c) { + setup (c); +} +void +AudioMapping::setup (int c) +{ + _content_channels = c; + + _gain.resize (_content_channels); + for (int i = 0; i < _content_channels; ++i) { + _gain[i].resize (MAX_AUDIO_CHANNELS); + } } void AudioMapping::make_default () { + for (int i = 0; i < _content_channels; ++i) { + for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) { + _gain[i][j] = 0; + } + } + if (_content_channels == 1) { /* Mono -> Centre */ - add (0, libdcp::CENTRE); + set (0, dcp::CENTRE, 1); } else { /* 1:1 mapping */ for (int i = 0; i < _content_channels; ++i) { - add (i, static_cast (i)); + set (i, static_cast (i), 1); } } } -AudioMapping::AudioMapping (shared_ptr node) +AudioMapping::AudioMapping (shared_ptr node, int state_version) { - _content_channels = node->number_child ("ContentChannels"); - - list > const c = node->node_children ("Map"); - for (list >::const_iterator i = c.begin(); i != c.end(); ++i) { - add ((*i)->number_child ("ContentIndex"), static_cast ((*i)->number_child ("DCP"))); + setup (node->number_child ("ContentChannels")); + + if (state_version <= 5) { + /* Old-style: on/off mapping */ + list const c = node->node_children ("Map"); + for (list::const_iterator i = c.begin(); i != c.end(); ++i) { + set ((*i)->number_child ("ContentIndex"), static_cast ((*i)->number_child ("DCP")), 1); + } + } else { + list const c = node->node_children ("Gain"); + for (list::const_iterator i = c.begin(); i != c.end(); ++i) { + set ( + (*i)->number_attribute ("Content"), + static_cast ((*i)->number_attribute ("DCP")), + lexical_cast ((*i)->content ()) + ); + } } } void -AudioMapping::add (int c, libdcp::Channel d) +AudioMapping::set (int c, dcp::Channel d, float g) { - _content_to_dcp.push_back (make_pair (c, d)); + _gain[c][d] = g; } -list -AudioMapping::dcp_to_content (libdcp::Channel d) const +float +AudioMapping::get (int c, dcp::Channel d) const { - list c; - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - if (i->second == d) { - c.push_back (i->first); - } - } - - return c; -} - -list -AudioMapping::content_to_dcp (int c) const -{ - assert (c < _content_channels); - - list d; - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - if (i->first == c) { - d.push_back (i->second); - } - } - - return d; + return _gain[c][d]; } void AudioMapping::as_xml (xmlpp::Node* node) const { node->add_child ("ContentChannels")->add_child_text (lexical_cast (_content_channels)); - - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - xmlpp::Node* t = node->add_child ("Map"); - t->add_child ("ContentIndex")->add_child_text (lexical_cast (i->first)); - t->add_child ("DCP")->add_child_text (lexical_cast (i->second)); + + for (int c = 0; c < _content_channels; ++c) { + for (int d = 0; d < MAX_AUDIO_CHANNELS; ++d) { + xmlpp::Element* t = node->add_child ("Gain"); + t->set_attribute ("Content", lexical_cast (c)); + t->set_attribute ("DCP", lexical_cast (d)); + t->add_child_text (lexical_cast (get (c, static_cast (d)))); + } } }