1 /* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
4 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <boost/lexical_cast.hpp>
23 #include <libxml++/libxml++.h>
24 #include <libcxml/cxml.h>
25 #include "audio_mapping.h"
32 using boost::shared_ptr;
33 using boost::lexical_cast;
34 using boost::dynamic_pointer_cast;
36 AudioMapping::AudioMapping ()
41 /** Create a default AudioMapping for a given channel count.
42 * @param c Number of channels.
44 AudioMapping::AudioMapping (int c)
48 add (0, libdcp::CENTRE);
51 for (int i = 0; i < c; ++i) {
52 add (i, static_cast<libdcp::Channel> (i));
57 AudioMapping::AudioMapping (shared_ptr<const cxml::Node> node)
59 list<shared_ptr<cxml::Node> > const c = node->node_children ("Map");
60 for (list<shared_ptr<cxml::Node> >::const_iterator i = c.begin(); i != c.end(); ++i) {
61 add ((*i)->number_child<int> ("ContentIndex"), static_cast<libdcp::Channel> ((*i)->number_child<int> ("DCP")));
66 AudioMapping::add (int c, libdcp::Channel d)
68 _content_to_dcp.push_back (make_pair (c, d));
72 AudioMapping::dcp_to_content (libdcp::Channel d) const
75 for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
77 c.push_back (i->first);
85 AudioMapping::content_channels () const
88 for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
89 if (find (c.begin(), c.end(), i->first) == c.end ()) {
90 c.push_back (i->first);
98 AudioMapping::content_to_dcp (int c) const
100 list<libdcp::Channel> d;
101 for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
103 d.push_back (i->second);
111 AudioMapping::as_xml (xmlpp::Node* node) const
113 for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
114 xmlpp::Node* t = node->add_child ("Map");
115 t->add_child ("ContentIndex")->add_child_text (lexical_cast<string> (i->first));
116 t->add_child ("DCP")->add_child_text (lexical_cast<string> (i->second));