X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=b3757c5f1be9bd2fefc2a38199215201cde2cf11;hb=8102046b2f29e0c7b234c29bf204b056cb30e64f;hp=3620001251ec688857c172c80c2883f1b8add42a;hpb=d324fc102df00d6dc62614938f78cf983a101dd4;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 362000125..b3757c5f1 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,19 +17,22 @@ */ -#include #include #include +#include #include "audio_mapping.h" +#include "util.h" +#include "md5_digester.h" using std::list; using std::cout; using std::make_pair; using std::pair; using std::string; +using std::min; using boost::shared_ptr; -using boost::lexical_cast; using boost::dynamic_pointer_cast; +using dcp::raw_convert; AudioMapping::AudioMapping () : _content_channels (0) @@ -38,80 +41,106 @@ AudioMapping::AudioMapping () } /** Create a default AudioMapping for a given channel count. - * @param c Number of channels. + * @param channels Number of channels. */ -AudioMapping::AudioMapping (int c) - : _content_channels (c) +AudioMapping::AudioMapping (int channels) { + setup (channels); +} +void +AudioMapping::setup (int c) +{ + _content_channels = c; + + _gain.resize (_content_channels); + for (int i = 0; i < _content_channels; ++i) { + _gain[i].resize (MAX_DCP_AUDIO_CHANNELS); + } } void AudioMapping::make_default () { + for (int i = 0; i < _content_channels; ++i) { + for (int j = 0; j < MAX_DCP_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)); + for (int i = 0; i < min (_content_channels, MAX_DCP_AUDIO_CHANNELS); ++i) { + set (i, static_cast (i), 1); } } } -AudioMapping::AudioMapping (shared_ptr node) +AudioMapping::AudioMapping (cxml::ConstNodePtr 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")), + raw_convert ((*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; + return _gain[c][d]; } -list -AudioMapping::content_to_dcp (int c) const +void +AudioMapping::as_xml (xmlpp::Node* node) 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); + node->add_child ("ContentChannels")->add_child_text (raw_convert (_content_channels)); + + for (int c = 0; c < _content_channels; ++c) { + for (int d = 0; d < MAX_DCP_AUDIO_CHANNELS; ++d) { + xmlpp::Element* t = node->add_child ("Gain"); + t->set_attribute ("Content", raw_convert (c)); + t->set_attribute ("DCP", raw_convert (d)); + t->add_child_text (raw_convert (get (c, static_cast (d)))); } } - - return d; } -void -AudioMapping::as_xml (xmlpp::Node* node) const +/** @return a string which is unique for a given AudioMapping configuration, for + * differentiation between different AudioMappings. + */ +string +AudioMapping::digest () 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)); + MD5Digester digester; + digester.add (_content_channels); + for (int i = 0; i < _content_channels; ++i) { + for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) { + digester.add (_gain[i][j]); + } } + + return digester.get (); }