X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=496300b48a746931f419748231f24f70364f4493;hb=308488324dbc4d8b709d3fb1dc9fee0479346c21;hp=48cc23307504457f1e94a7724635e852ba0d052d;hpb=c921cfe23b593d7c367ad76094308c5f08037374;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 48cc23307..496300b48 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,79 +17,112 @@ */ +#include +#include +#include #include "audio_mapping.h" +#include "util.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::dynamic_pointer_cast; +using dcp::raw_convert; -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 channels Number of channels. + */ +AudioMapping::AudioMapping (int channels) { - 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 (channels); } -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_DCP_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_DCP_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 < min (_content_channels, MAX_DCP_AUDIO_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")), + raw_convert ((*i)->content ()) + ); } } +} - return d; +void +AudioMapping::set (int c, dcp::Channel d, float g) +{ + _gain[c][d] = g; } -bool -operator== (AudioMapping::Channel const & a, AudioMapping::Channel const & b) +float +AudioMapping::get (int c, dcp::Channel d) const { - shared_ptr sa = a.content.lock (); - shared_ptr sb = b.content.lock (); - return sa == sb && a.index == b.index; + return _gain[c][d]; } - - +void +AudioMapping::as_xml (xmlpp::Node* node) const +{ + 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)))); + } + } +}