X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=1db827046946a8008d54bff21597d4fd1d201bff;hb=1f8b45c7fd49714628009f5ed2161fbaa2b4d729;hp=3fc423e101a891074eada7261bff77d622311cba;hpb=8750efb9e072cf3b42e6c3c29521c7031c0b5dfd;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 3fc423e10..1db827046 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -17,87 +17,111 @@ */ +#include +#include +#include #include "audio_mapping.h" - -using std::map; -using boost::optional; - -AutomaticAudioMapping::AutomaticAudioMapping (int c) - : _source_channels (c) +#include "util.h" + +using std::list; +using std::cout; +using std::make_pair; +using std::pair; +using std::string; +using boost::shared_ptr; +using boost::lexical_cast; +using boost::dynamic_pointer_cast; + +AudioMapping::AudioMapping () + : _content_channels (0) { } -optional -AutomaticAudioMapping::source_to_dcp (int c) const +/** Create a default AudioMapping for a given channel count. + * @param c Number of channels. + */ +AudioMapping::AudioMapping (int c) { - if (c >= _source_channels) { - return optional (); - } + setup (c); +} - if (_source_channels == 1) { - /* mono sources to centre */ - return libdcp::CENTRE; - } +void +AudioMapping::setup (int c) +{ + _content_channels = c; - return static_cast (c); + _gain.resize (_content_channels); + for (int i = 0; i < _content_channels; ++i) { + _gain[i].resize (MAX_AUDIO_CHANNELS); + } } -optional -AutomaticAudioMapping::dcp_to_source (libdcp::Channel c) const +void +AudioMapping::make_default () { - if (_source_channels == 1) { - if (c == libdcp::CENTRE) { - return 0; - } else { - return optional (); + for (int i = 0; i < _content_channels; ++i) { + for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) { + _gain[i][j] = 0; } } - if (static_cast (c) >= _source_channels) { - return optional (); + 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); + } } - - return static_cast (c); } -int -AutomaticAudioMapping::dcp_channels () const +AudioMapping::AudioMapping (shared_ptr node, int state_version) { - if (_source_channels == 1) { - /* The source is mono, so to put the mono channel into - the centre we need to generate a 5.1 soundtrack. - */ - return 6; - } + setup (node->number_child ("ContentChannels")); - return _source_channels; + 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 ()) + ); + } + } } -optional -ConfiguredAudioMapping::dcp_to_source (libdcp::Channel c) const +void +AudioMapping::set (int c, dcp::Channel d, float g) { - map::const_iterator i = _source_to_dcp.begin (); - while (i != _source_to_dcp.end() && i->second != c) { - ++i; - } - - if (i == _source_to_dcp.end ()) { - return boost::none; - } + _gain[c][d] = g; +} - return i->first; +float +AudioMapping::get (int c, dcp::Channel d) const +{ + return _gain[c][d]; } -optional -ConfiguredAudioMapping::source_to_dcp (int c) const +void +AudioMapping::as_xml (xmlpp::Node* node) const { - map::const_iterator i = _source_to_dcp.find (c); - if (i == _source_to_dcp.end ()) { - return boost::none; + 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)))); + } } - - return i->second; } - -