Merge 1.0 in.
[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 DCPOMATIC_CONFIG_H
25 #define DCPOMATIC_CONFIG_H
26
27 #include <vector>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/signals2.hpp>
30 #include <libdcp/metadata.h>
31 #include "dci_metadata.h"
32 #include "colour_conversion.h"
33 #include "server.h"
34
35 class ServerDescription;
36 class Scaler;
37 class Filter;
38 class SoundProcessor;
39 class DCPContentType;
40 class Ratio;
41 class Cinema;
42
43 /** @class Config
44  *  @brief A singleton class holding configuration.
45  */
46 class Config : public boost::noncopyable
47 {
48 public:
49
50         /** @return number of threads to use for J2K encoding on the local machine */
51         int num_local_encoding_threads () const {
52                 return _num_local_encoding_threads;
53         }
54
55         std::string default_directory () const {
56                 return _default_directory;
57         }
58
59         std::string default_directory_or (std::string a) const;
60
61         /** @return port to use for J2K encoding servers */
62         int server_port () const {
63                 return _server_port;
64         }
65
66         /** @return J2K encoding servers to use */
67         std::vector<ServerDescription> servers () const {
68                 return _servers;
69         }
70
71         /** @return The IP address of a TMS that we can copy DCPs to */
72         std::string tms_ip () const {
73                 return _tms_ip;
74         }
75
76         /** @return The path on a TMS that we should write DCPs to */
77         std::string tms_path () const {
78                 return _tms_path;
79         }
80
81         /** @return User name to log into the TMS with */
82         std::string tms_user () const {
83                 return _tms_user;
84         }
85
86         /** @return Password to log into the TMS with */
87         std::string tms_password () const {
88                 return _tms_password;
89         }
90
91         /** @return The sound processor that we are using */
92         SoundProcessor const * sound_processor () const {
93                 return _sound_processor;
94         }
95
96         std::list<boost::shared_ptr<Cinema> > cinemas () const {
97                 return _cinemas;
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         int default_still_length () const {
113                 return _default_still_length;
114         }
115
116         Ratio const * default_container () const {
117                 return _default_container;
118         }
119
120         DCPContentType const * default_dcp_content_type () const {
121                 return _default_dcp_content_type;
122         }
123
124         libdcp::XMLMetadata dcp_metadata () const {
125                 return _dcp_metadata;
126         }
127
128         int default_j2k_bandwidth () const {
129                 return _default_j2k_bandwidth;
130         }
131
132         std::vector<PresetColourConversion> colour_conversions () const {
133                 return _colour_conversions;
134         }
135
136         /** @param n New number of local encoding threads */
137         void set_num_local_encoding_threads (int n) {
138                 _num_local_encoding_threads = n;
139         }
140
141         void set_default_directory (std::string d) {
142                 _default_directory = d;
143         }
144
145         /** @param p New server port */
146         void set_server_port (int p) {
147                 _server_port = p;
148         }
149
150         /** @param s New list of servers */
151         void set_servers (std::vector<ServerDescription> s) {
152                 _servers = s;
153         }
154
155         void set_reference_scaler (Scaler const * s) {
156                 _reference_scaler = s;
157         }
158         
159         void set_reference_filters (std::vector<Filter const *> const & f) {
160                 _reference_filters = f;
161         }
162
163         /** @param i IP address of a TMS that we can copy DCPs to */
164         void set_tms_ip (std::string i) {
165                 _tms_ip = i;
166         }
167
168         /** @param p Path on a TMS that we should write DCPs to */
169         void set_tms_path (std::string p) {
170                 _tms_path = p;
171         }
172
173         /** @param u User name to log into the TMS with */
174         void set_tms_user (std::string u) {
175                 _tms_user = u;
176         }
177
178         /** @param p Password to log into the TMS with */
179         void set_tms_password (std::string p) {
180                 _tms_password = p;
181         }
182
183         void add_cinema (boost::shared_ptr<Cinema> c) {
184                 _cinemas.push_back (c);
185         }
186
187         void remove_cinema (boost::shared_ptr<Cinema> c) {
188                 _cinemas.remove (c);
189         }
190
191         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
192                 _allowed_dcp_frame_rates = r;
193         }
194
195         void set_default_dci_metadata (DCIMetadata d) {
196                 _default_dci_metadata = d;
197         }
198
199         void set_language (std::string l) {
200                 _language = l;
201         }
202
203         void unset_language () {
204                 _language = boost::none;
205         }
206
207         void set_default_still_length (int s) {
208                 _default_still_length = s;
209         }
210
211         void set_default_container (Ratio const * c) {
212                 _default_container = c;
213         }
214
215         void set_default_dcp_content_type (DCPContentType const * t) {
216                 _default_dcp_content_type = t;
217         }
218
219         void set_dcp_metadata (libdcp::XMLMetadata m) {
220                 _dcp_metadata = m;
221         }
222
223         void set_default_j2k_bandwidth (int b) {
224                 _default_j2k_bandwidth = b;
225         }
226
227         void set_colour_conversions (std::vector<PresetColourConversion> const & c) {
228                 _colour_conversions = c;
229         }
230         
231         void write () const;
232
233         std::string crypt_chain_directory () const;
234
235         static Config* instance ();
236         static void drop ();
237
238 private:
239         Config ();
240         std::string file (bool) const;
241         void read ();
242         void read_old_metadata ();
243
244         /** number of threads to use for J2K encoding on the local machine */
245         int _num_local_encoding_threads;
246         /** default directory to put new films in */
247         std::string _default_directory;
248         /** port to use for J2K encoding servers */
249         int _server_port;
250
251         /** J2K encoding servers to use */
252         std::vector<ServerDescription> _servers;
253         /** Scaler to use for the "A" part of A/B comparisons */
254         Scaler const * _reference_scaler;
255         /** Filters to use for the "A" part of A/B comparisons */
256         std::vector<Filter const *> _reference_filters;
257         /** The IP address of a TMS that we can copy DCPs to */
258         std::string _tms_ip;
259         /** The path on a TMS that we should write DCPs to */
260         std::string _tms_path;
261         /** User name to log into the TMS with */
262         std::string _tms_user;
263         /** Password to log into the TMS with */
264         std::string _tms_password;
265         /** Our sound processor */
266         SoundProcessor const * _sound_processor;
267         std::list<int> _allowed_dcp_frame_rates;
268         /** Default DCI metadata for newly-created Films */
269         DCIMetadata _default_dci_metadata;
270         boost::optional<std::string> _language;
271         int _default_still_length;
272         Ratio const * _default_container;
273         DCPContentType const * _default_dcp_content_type;
274         libdcp::XMLMetadata _dcp_metadata;
275         int _default_j2k_bandwidth;
276         std::vector<PresetColourConversion> _colour_conversions;
277
278         std::list<boost::shared_ptr<Cinema> > _cinemas;
279
280         /** Singleton instance, or 0 */
281         static Config* _instance;
282 };
283
284 #endif