X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=e86e2e2ac6820499cd551ddaed17ffe8e7f30019;hb=5dc2dbdb6639f8d617a40209ad603d2a38f9df2a;hp=301d44fa665f0840f60cdd30956352ec3f1d76b0;hpb=5eacf5f4805181617e486805ab5d07ccf5e21cde;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 301d44fa6..e86e2e2ac 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,11 +17,12 @@ */ -#include #include #include +#include #include "audio_mapping.h" #include "util.h" +#include "md5_digester.h" using std::list; using std::cout; @@ -30,8 +31,8 @@ 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) @@ -39,12 +40,12 @@ AudioMapping::AudioMapping () } -/** Create a default AudioMapping for a given channel count. - * @param c Number of channels. +/** Create an empty AudioMapping for a given channel count. + * @param channels Number of channels. */ -AudioMapping::AudioMapping (int c) +AudioMapping::AudioMapping (int channels) { - setup (c); + setup (channels); } void @@ -69,16 +70,16 @@ AudioMapping::make_default () if (_content_channels == 1) { /* Mono -> Centre */ - set (0, libdcp::CENTRE, 1); + set (0, dcp::CENTRE, 1); } else { /* 1:1 mapping */ for (int i = 0; i < min (_content_channels, MAX_DCP_AUDIO_CHANNELS); ++i) { - set (i, static_cast (i), 1); + set (i, static_cast (i), 1); } } } -AudioMapping::AudioMapping (shared_ptr node, int state_version) +AudioMapping::AudioMapping (cxml::ConstNodePtr node, int state_version) { setup (node->number_child ("ContentChannels")); @@ -86,28 +87,28 @@ AudioMapping::AudioMapping (shared_ptr node, int state_version /* 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); + 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 ()) + static_cast ((*i)->number_attribute ("DCP")), + raw_convert ((*i)->content ()) ); } } } void -AudioMapping::set (int c, libdcp::Channel d, float g) +AudioMapping::set (int c, dcp::Channel d, float g) { _gain[c][d] = g; } float -AudioMapping::get (int c, libdcp::Channel d) const +AudioMapping::get (int c, dcp::Channel d) const { return _gain[c][d]; } @@ -115,14 +116,31 @@ AudioMapping::get (int c, libdcp::Channel d) const void AudioMapping::as_xml (xmlpp::Node* node) const { - node->add_child ("ContentChannels")->add_child_text (lexical_cast (_content_channels)); + 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", lexical_cast (c)); - t->set_attribute ("DCP", lexical_cast (d)); - t->add_child_text (lexical_cast (get (c, static_cast (d)))); + 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 a string which is unique for a given AudioMapping configuration, for + * differentiation between different AudioMappings. + */ +string +AudioMapping::digest () const +{ + 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 (); +}