Missed update to private test repo version.
[dcpomatic.git] / src / lib / cinema_sound_processor.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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.
10
11     DCP-o-matic 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.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file src/sound_processor.cc
22  *  @brief CinemaSoundProcessor class.
23  */
24
25 #include "cinema_sound_processor.h"
26 #include "dolby_cp750.h"
27 #include "dcpomatic_assert.h"
28 #include <iostream>
29 #include <cassert>
30
31 using namespace std;
32
33 vector<CinemaSoundProcessor const *> CinemaSoundProcessor::_cinema_sound_processors;
34
35 /** @param i Our id.
36  *  @param n User-visible name.
37  */
38 CinemaSoundProcessor::CinemaSoundProcessor (string i, string n)
39         : _id (i)
40         , _name (n)
41 {
42
43 }
44
45 /** @return All available sound processors */
46 vector<CinemaSoundProcessor const *>
47 CinemaSoundProcessor::all ()
48 {
49         return _cinema_sound_processors;
50 }
51
52 /** Set up the static _sound_processors vector; must be called before from_*
53  *  methods are used.
54  */
55 void
56 CinemaSoundProcessor::setup_cinema_sound_processors ()
57 {
58         _cinema_sound_processors.push_back (new DolbyCP750);
59 }
60
61 /** @param id One of our ids.
62  *  @return Corresponding sound processor, or 0.
63  */
64 CinemaSoundProcessor const *
65 CinemaSoundProcessor::from_id (string id)
66 {
67         vector<CinemaSoundProcessor const *>::iterator i = _cinema_sound_processors.begin ();
68         while (i != _cinema_sound_processors.end() && (*i)->id() != id) {
69                 ++i;
70         }
71
72         if (i == _cinema_sound_processors.end ()) {
73                 return 0;
74         }
75
76         return *i;
77 }
78
79 /** @param s A sound processor from our static list.
80  *  @return Index of the sound processor with the list, or -1.
81  */
82 int
83 CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s)
84 {
85         vector<CinemaSoundProcessor*>::size_type i = 0;
86         while (i < _cinema_sound_processors.size() && _cinema_sound_processors[i] != s) {
87                 ++i;
88         }
89
90         if (i == _cinema_sound_processors.size ()) {
91                 return -1;
92         }
93
94         return i;
95 }
96
97 /** @param i An index returned from as_index().
98  *  @return Corresponding sound processor.
99  */
100 CinemaSoundProcessor const *
101 CinemaSoundProcessor::from_index (int i)
102 {
103         DCPOMATIC_ASSERT (i <= int(_cinema_sound_processors.size ()));
104         return _cinema_sound_processors[i];
105 }