X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=1db827046946a8008d54bff21597d4fd1d201bff;hb=854f2e5bbb7ffb9758b823af87034033033f3cb8;hp=b85ea731402046347a58738be6d5bb550df7fdd3;hpb=d62877ae6c4e316e43f4052e4b9ba673610012cf;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index b85ea7314..1db827046 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -18,8 +18,10 @@ */ #include +#include #include #include "audio_mapping.h" +#include "util.h" using std::list; using std::cout; @@ -30,102 +32,96 @@ using boost::shared_ptr; using boost::lexical_cast; using boost::dynamic_pointer_cast; -void -AudioMapping::add (Channel c, libdcp::Channel d) +AudioMapping::AudioMapping () + : _content_channels (0) { - _content_to_dcp.push_back (make_pair (c, d)); + } -/* XXX: this is grotty */ -int -AudioMapping::dcp_channels () const +/** Create a default AudioMapping for a given channel count. + * @param c Number of channels. + */ +AudioMapping::AudioMapping (int c) { - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - if (((int) i->second) > 2) { - return 6; - } - } - - return 2; + setup (c); } -list -AudioMapping::dcp_to_content (libdcp::Channel d) const +void +AudioMapping::setup (int c) { - 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); - } + _content_channels = c; + + _gain.resize (_content_channels); + for (int i = 0; i < _content_channels; ++i) { + _gain[i].resize (MAX_AUDIO_CHANNELS); } - - return c; } -list -AudioMapping::content_channels () const +void +AudioMapping::make_default () { - list c; - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - if (find (c.begin(), c.end(), i->first) == c.end ()) { - c.push_back (i->first); + for (int i = 0; i < _content_channels; ++i) { + for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) { + _gain[i][j] = 0; } } - return c; + if (_content_channels == 1) { + /* Mono -> Centre */ + set (0, dcp::CENTRE, 1); + } else { + /* 1:1 mapping */ + for (int i = 0; i < _content_channels; ++i) { + set (i, static_cast (i), 1); + } + } } -list -AudioMapping::content_to_dcp (Channel c) const +AudioMapping::AudioMapping (shared_ptr node, int state_version) { - 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); + 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 ()) + ); } } - - return d; } void -AudioMapping::as_xml (xmlpp::Node* node) const +AudioMapping::set (int c, dcp::Channel d, float g) { - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { - xmlpp::Node* t = node->add_child ("Map"); - shared_ptr c = i->first.content.lock (); - t->add_child ("Content")->add_child_text (c->file().string ()); - t->add_child ("ContentIndex")->add_child_text (lexical_cast (i->first.index)); - t->add_child ("DCP")->add_child_text (lexical_cast (i->second)); - } + _gain[c][d] = g; } -void -AudioMapping::set_from_xml (ContentList const & content, shared_ptr node) +float +AudioMapping::get (int c, dcp::Channel d) const { - list > const c = node->node_children ("Map"); - for (list >::const_iterator i = c.begin(); i != c.end(); ++i) { - string const c = (*i)->string_child ("Content"); - ContentList::const_iterator j = content.begin (); - while (j != content.end() && (*j)->file().string() != c) { - ++j; - } - - if (j == content.end ()) { - continue; - } - - shared_ptr ac = dynamic_pointer_cast (*j); - assert (ac); - - add (AudioMapping::Channel (ac, (*i)->number_child ("ContentIndex")), static_cast ((*i)->number_child ("DCP"))); - } + return _gain[c][d]; } -bool -operator== (AudioMapping::Channel const & a, AudioMapping::Channel const & b) +void +AudioMapping::as_xml (xmlpp::Node* node) const { - shared_ptr sa = a.content.lock (); - shared_ptr sb = b.content.lock (); - return sa == sb && a.index == b.index; + node->add_child ("ContentChannels")->add_child_text (lexical_cast (_content_channels)); + + 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)))); + } + } }