Various work on audio channel mapping.
[dcpomatic.git] / src / lib / audio_mapping.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "audio_mapping.h"
21
22 using std::list;
23 using std::cout;
24 using std::make_pair;
25 using std::pair;
26 using boost::shared_ptr;
27
28 void
29 AudioMapping::add (Channel c, libdcp::Channel d)
30 {
31         _content_to_dcp.push_back (make_pair (c, d));
32 }
33
34 /* XXX: this is grotty */
35 int
36 AudioMapping::dcp_channels () const
37 {
38         for (list<pair<Channel, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
39                 if (((int) i->second) > 2) {
40                         return 6;
41                 }
42         }
43
44         return 2;
45 }
46
47 list<AudioMapping::Channel>
48 AudioMapping::dcp_to_content (libdcp::Channel d) const
49 {
50         list<AudioMapping::Channel> c;
51         for (list<pair<Channel, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
52                 if (i->second == d) {
53                         c.push_back (i->first);
54                 }
55         }
56
57         return c;
58 }
59
60 list<AudioMapping::Channel>
61 AudioMapping::content_channels () const
62 {
63         list<AudioMapping::Channel> c;
64         for (list<pair<Channel, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
65                 if (find (c.begin(), c.end(), i->first) == c.end ()) {
66                         c.push_back (i->first);
67                 }
68         }
69
70         return c;
71 }
72
73 list<libdcp::Channel>
74 AudioMapping::content_to_dcp (Channel c) const
75 {
76         list<libdcp::Channel> d;
77         for (list<pair<Channel, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
78                 if (i->first == c) {
79                         d.push_back (i->second);
80                 }
81         }
82
83         return d;
84 }
85
86 bool
87 operator== (AudioMapping::Channel const & a, AudioMapping::Channel const & b)
88 {
89         shared_ptr<const AudioContent> sa = a.content.lock ();
90         shared_ptr<const AudioContent> sb = b.content.lock ();
91         return sa == sb && a.index == b.index;
92 }
93
94         
95