2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "audio_mapping.h"
23 using boost::optional;
25 AutomaticAudioMapping::AutomaticAudioMapping (int c)
26 : _source_channels (c)
31 optional<libdcp::Channel>
32 AutomaticAudioMapping::source_to_dcp (int c) const
34 if (c >= _source_channels) {
35 return optional<libdcp::Channel> ();
38 if (_source_channels == 1) {
39 /* mono sources to centre */
40 return libdcp::CENTRE;
43 return static_cast<libdcp::Channel> (c);
47 AutomaticAudioMapping::dcp_to_source (libdcp::Channel c) const
49 if (_source_channels == 1) {
50 if (c == libdcp::CENTRE) {
53 return optional<int> ();
57 if (static_cast<int> (c) >= _source_channels) {
58 return optional<int> ();
61 return static_cast<int> (c);
65 AutomaticAudioMapping::dcp_channels () const
67 if (_source_channels == 1) {
68 /* The source is mono, so to put the mono channel into
69 the centre we need to generate a 5.1 soundtrack.
74 return _source_channels;
78 ConfiguredAudioMapping::dcp_to_source (libdcp::Channel c) const
80 map<int, libdcp::Channel>::const_iterator i = _source_to_dcp.begin ();
81 while (i != _source_to_dcp.end() && i->second != c) {
85 if (i == _source_to_dcp.end ()) {
92 optional<libdcp::Channel>
93 ConfiguredAudioMapping::source_to_dcp (int c) const
95 map<int, libdcp::Channel>::const_iterator i = _source_to_dcp.find (c);
96 if (i == _source_to_dcp.end ()) {