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