6041045cfc8e176f2290371e043c3d5d9c563c30
[dcpomatic.git] / src / lib / config.h
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/config.h
21  *  @brief Class holding configuration.
22  */
23
24 #ifndef DVDOMATIC_CONFIG_H
25 #define DVDOMATIC_CONFIG_H
26
27 #include <vector>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/signals2.hpp>
30 #include "dci_metadata.h"
31
32 class ServerDescription;
33 class Scaler;
34 class Filter;
35 class SoundProcessor;
36 class Format;
37 class DCPContentType;
38
39 /** @class Config
40  *  @brief A singleton class holding configuration.
41  */
42 class Config
43 {
44 public:
45
46         /** @return number of threads to use for J2K encoding on the local machine */
47         int num_local_encoding_threads () const {
48                 return _num_local_encoding_threads;
49         }
50
51         std::string default_directory () const {
52                 return _default_directory;
53         }
54
55         std::string default_directory_or (std::string a) const;
56
57         /** @return port to use for J2K encoding servers */
58         int server_port () const {
59                 return _server_port;
60         }
61
62         /** @return J2K encoding servers to use */
63         std::vector<ServerDescription*> servers () const {
64                 return _servers;
65         }
66
67         Scaler const * reference_scaler () const {
68                 return _reference_scaler;
69         }
70
71         std::vector<Filter const *> reference_filters () const {
72                 return _reference_filters;
73         }
74
75         /** @return The IP address of a TMS that we can copy DCPs to */
76         std::string tms_ip () const {
77                 return _tms_ip;
78         }
79
80         /** @return The path on a TMS that we should write DCPs to */
81         std::string tms_path () const {
82                 return _tms_path;
83         }
84
85         /** @return User name to log into the TMS with */
86         std::string tms_user () const {
87                 return _tms_user;
88         }
89
90         /** @return Password to log into the TMS with */
91         std::string tms_password () const {
92                 return _tms_password;
93         }
94
95         /** @return The sound processor that we are using */
96         SoundProcessor const * sound_processor () const {
97                 return _sound_processor;
98         }
99
100         std::list<int> allowed_dcp_frame_rates () const {
101                 return _allowed_dcp_frame_rates;
102         }
103         
104         DCIMetadata default_dci_metadata () const {
105                 return _default_dci_metadata;
106         }
107
108         boost::optional<std::string> language () const {
109                 return _language;
110         }
111
112         Format const * default_format () const {
113                 return _default_format;
114         }
115
116         DCPContentType const * default_dcp_content_type () const {
117                 return _default_dcp_content_type;
118         }
119
120         /** @param n New number of local encoding threads */
121         void set_num_local_encoding_threads (int n) {
122                 _num_local_encoding_threads = n;
123         }
124
125         void set_default_directory (std::string d) {
126                 _default_directory = d;
127         }
128
129         /** @param p New server port */
130         void set_server_port (int p) {
131                 _server_port = p;
132         }
133
134         /** @param s New list of servers */
135         void set_servers (std::vector<ServerDescription*> s) {
136                 _servers = s;
137         }
138
139         void set_reference_scaler (Scaler const * s) {
140                 _reference_scaler = s;
141         }
142         
143         void set_reference_filters (std::vector<Filter const *> const & f) {
144                 _reference_filters = f;
145         }
146
147         /** @param i IP address of a TMS that we can copy DCPs to */
148         void set_tms_ip (std::string i) {
149                 _tms_ip = i;
150         }
151
152         /** @param p Path on a TMS that we should write DCPs to */
153         void set_tms_path (std::string p) {
154                 _tms_path = p;
155         }
156
157         /** @param u User name to log into the TMS with */
158         void set_tms_user (std::string u) {
159                 _tms_user = u;
160         }
161
162         /** @param p Password to log into the TMS with */
163         void set_tms_password (std::string p) {
164                 _tms_password = p;
165         }
166
167         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
168                 _allowed_dcp_frame_rates = r;
169         }
170
171         void set_default_dci_metadata (DCIMetadata d) {
172                 _default_dci_metadata = d;
173         }
174
175         void set_language (std::string l) {
176                 _language = l;
177         }
178
179         void unset_language () {
180                 _language = boost::none;
181         }
182
183         void set_default_format (Format const * f) {
184                 _default_format = f;
185         }
186
187         void set_default_dcp_content_type (DCPContentType const * t) {
188                 _default_dcp_content_type = t;
189         }
190         
191         void write () const;
192
193         static Config* instance ();
194         static void drop ();
195
196 private:
197         Config ();
198         std::string file () const;
199
200         /** number of threads to use for J2K encoding on the local machine */
201         int _num_local_encoding_threads;
202         /** default directory to put new films in */
203         std::string _default_directory;
204         /** port to use for J2K encoding servers */
205         int _server_port;
206
207         /** J2K encoding servers to use */
208         std::vector<ServerDescription *> _servers;
209         /** Scaler to use for the "A" part of A/B comparisons */
210         Scaler const * _reference_scaler;
211         /** Filters to use for the "A" part of A/B comparisons */
212         std::vector<Filter const *> _reference_filters;
213         /** The IP address of a TMS that we can copy DCPs to */
214         std::string _tms_ip;
215         /** The path on a TMS that we should write DCPs to */
216         std::string _tms_path;
217         /** User name to log into the TMS with */
218         std::string _tms_user;
219         /** Password to log into the TMS with */
220         std::string _tms_password;
221         /** Our sound processor */
222         SoundProcessor const * _sound_processor;
223         std::list<int> _allowed_dcp_frame_rates;
224         /** Default DCI metadata for newly-created Films */
225         DCIMetadata _default_dci_metadata;
226         boost::optional<std::string> _language;
227         Format const * _default_format;
228         DCPContentType const * _default_dcp_content_type;
229
230         /** Singleton instance, or 0 */
231         static Config* _instance;
232 };
233
234 #endif