Logging improvements to allow prettier displays in the server GUI.
[dcpomatic.git] / src / lib / cinema_sound_processor.cc
1 /*
2     Copyright (C) 2012-2014 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 /** @file src/sound_processor.cc
21  *  @brief CinemaSoundProcessor class.
22  */
23
24 #include "cinema_sound_processor.h"
25 #include "dolby_cp750.h"
26 #include "dcpomatic_assert.h"
27 #include <iostream>
28 #include <cassert>
29
30 using namespace std;
31
32 vector<CinemaSoundProcessor const *> CinemaSoundProcessor::_cinema_sound_processors;
33
34 /** @param i Our id.
35  *  @param n User-visible name.
36  */
37 CinemaSoundProcessor::CinemaSoundProcessor (string i, string n)
38         : _id (i)
39         , _name (n)
40 {
41
42 }
43
44 /** @return All available sound processors */
45 vector<CinemaSoundProcessor const *>
46 CinemaSoundProcessor::all ()
47 {
48         return _cinema_sound_processors;
49 }
50
51 /** Set up the static _sound_processors vector; must be called before from_*
52  *  methods are used.
53  */
54 void
55 CinemaSoundProcessor::setup_cinema_sound_processors ()
56 {
57         _cinema_sound_processors.push_back (new DolbyCP750);
58 }
59
60 /** @param id One of our ids.
61  *  @return Corresponding sound processor, or 0.
62  */
63 CinemaSoundProcessor const *
64 CinemaSoundProcessor::from_id (string id)
65 {
66         vector<CinemaSoundProcessor const *>::iterator i = _cinema_sound_processors.begin ();
67         while (i != _cinema_sound_processors.end() && (*i)->id() != id) {
68                 ++i;
69         }
70
71         if (i == _cinema_sound_processors.end ()) {
72                 return 0;
73         }
74
75         return *i;
76 }
77
78 /** @param s A sound processor from our static list.
79  *  @return Index of the sound processor with the list, or -1.
80  */
81 int
82 CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s)
83 {
84         vector<CinemaSoundProcessor*>::size_type i = 0;
85         while (i < _cinema_sound_processors.size() && _cinema_sound_processors[i] != s) {
86                 ++i;
87         }
88
89         if (i == _cinema_sound_processors.size ()) {
90                 return -1;
91         }
92
93         return i;
94 }
95
96 /** @param i An index returned from as_index().
97  *  @return Corresponding sound processor.
98  */
99 CinemaSoundProcessor const *
100 CinemaSoundProcessor::from_index (int i)
101 {
102         DCPOMATIC_ASSERT (i <= int(_cinema_sound_processors.size ()));
103         return _cinema_sound_processors[i];
104 }