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