X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=4630f17c16eeb9058c93384389a061531a9e2e9e;hb=e16c8ed02a0cb1f733a990d75a9de1bf50cf89bd;hp=b85ea731402046347a58738be6d5bb550df7fdd3;hpb=9bdd8cc51942a13e360dde4efc04b3ca417c8b94;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index b85ea7314..4630f17c1 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -18,6 +18,7 @@ */ #include +#include #include #include "audio_mapping.h" @@ -30,30 +31,46 @@ using boost::shared_ptr; using boost::lexical_cast; using boost::dynamic_pointer_cast; -void -AudioMapping::add (Channel c, libdcp::Channel d) +AudioMapping::AudioMapping () { - _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; + if (c == 1) { + /* Mono -> Centre */ + add (0, libdcp::CENTRE); + } else { + /* 1:1 mapping */ + for (int i = 0; i < c; ++i) { + add (i, static_cast (i)); } } +} + +AudioMapping::AudioMapping (shared_ptr node) +{ + 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"))); + } +} - return 2; +void +AudioMapping::add (int c, libdcp::Channel d) +{ + _content_to_dcp.push_back (make_pair (c, d)); } -list +list AudioMapping::dcp_to_content (libdcp::Channel d) const { - list c; - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { + 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); } @@ -62,11 +79,11 @@ AudioMapping::dcp_to_content (libdcp::Channel d) const return c; } -list +list AudioMapping::content_channels () const { - list c; - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { + 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); } @@ -76,10 +93,10 @@ AudioMapping::content_channels () const } list -AudioMapping::content_to_dcp (Channel c) const +AudioMapping::content_to_dcp (int c) const { list d; - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { + for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { if (i->first == c) { d.push_back (i->second); } @@ -91,41 +108,9 @@ AudioMapping::content_to_dcp (Channel c) const void AudioMapping::as_xml (xmlpp::Node* node) const { - for (list >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) { + 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 ("ContentIndex")->add_child_text (lexical_cast (i->first)); t->add_child ("DCP")->add_child_text (lexical_cast (i->second)); } } - -void -AudioMapping::set_from_xml (ContentList const & content, shared_ptr node) -{ - 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"))); - } -} - -bool -operator== (AudioMapping::Channel const & a, AudioMapping::Channel const & b) -{ - shared_ptr sa = a.content.lock (); - shared_ptr sb = b.content.lock (); - return sa == sb && a.index == b.index; -}