Merge master.
[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
33 class ServerDescription;
34 class Scaler;
35 class Filter;
36 class SoundProcessor;
37 class Format;
38 class DCPContentType;
39
40 /** @class Config
41  *  @brief A singleton class holding configuration.
42  */
43 class Config
44 {
45 public:
46
47         /** @return number of threads to use for J2K encoding on the local machine */
48         int num_local_encoding_threads () const {
49                 return _num_local_encoding_threads;
50         }
51
52         std::string default_directory () const {
53                 return _default_directory;
54         }
55
56         std::string default_directory_or (std::string a) const;
57
58         /** @return port to use for J2K encoding servers */
59         int server_port () const {
60                 return _server_port;
61         }
62
63         /** @return J2K encoding servers to use */
64         std::vector<ServerDescription*> servers () const {
65                 return _servers;
66         }
67
68         Scaler const * reference_scaler () const {
69                 return _reference_scaler;
70         }
71
72         std::vector<Filter const *> reference_filters () const {
73                 return _reference_filters;
74         }
75
76         /** @return The IP address of a TMS that we can copy DCPs to */
77         std::string tms_ip () const {
78                 return _tms_ip;
79         }
80
81         /** @return The path on a TMS that we should write DCPs to */
82         std::string tms_path () const {
83                 return _tms_path;
84         }
85
86         /** @return User name to log into the TMS with */
87         std::string tms_user () const {
88                 return _tms_user;
89         }
90
91         /** @return Password to log into the TMS with */
92         std::string tms_password () const {
93                 return _tms_password;
94         }
95
96         /** @return The sound processor that we are using */
97         SoundProcessor const * sound_processor () const {
98                 return _sound_processor;
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         Format const * default_format () const {
118                 return _default_format;
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         /** @param n New number of local encoding threads */
130         void set_num_local_encoding_threads (int n) {
131                 _num_local_encoding_threads = n;
132         }
133
134         void set_default_directory (std::string d) {
135                 _default_directory = d;
136         }
137
138         /** @param p New server port */
139         void set_server_port (int p) {
140                 _server_port = p;
141         }
142
143         /** @param s New list of servers */
144         void set_servers (std::vector<ServerDescription*> s) {
145                 _servers = s;
146         }
147
148         void set_reference_scaler (Scaler const * s) {
149                 _reference_scaler = s;
150         }
151         
152         void set_reference_filters (std::vector<Filter const *> const & f) {
153                 _reference_filters = f;
154         }
155
156         /** @param i IP address of a TMS that we can copy DCPs to */
157         void set_tms_ip (std::string i) {
158                 _tms_ip = i;
159         }
160
161         /** @param p Path on a TMS that we should write DCPs to */
162         void set_tms_path (std::string p) {
163                 _tms_path = p;
164         }
165
166         /** @param u User name to log into the TMS with */
167         void set_tms_user (std::string u) {
168                 _tms_user = u;
169         }
170
171         /** @param p Password to log into the TMS with */
172         void set_tms_password (std::string p) {
173                 _tms_password = p;
174         }
175
176         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
177                 _allowed_dcp_frame_rates = r;
178         }
179
180         void set_default_dci_metadata (DCIMetadata d) {
181                 _default_dci_metadata = d;
182         }
183
184         void set_language (std::string l) {
185                 _language = l;
186         }
187
188         void unset_language () {
189                 _language = boost::none;
190         }
191
192         void set_default_still_length (int s) {
193                 _default_still_length = s;
194         }
195
196         void set_default_format (Format const * f) {
197                 _default_format = f;
198         }
199
200         void set_default_dcp_content_type (DCPContentType const * t) {
201                 _default_dcp_content_type = t;
202         }
203
204         void set_dcp_metadata (libdcp::XMLMetadata m) {
205                 _dcp_metadata = m;
206         }
207         
208         void write () const;
209
210         static Config* instance ();
211         static void drop ();
212
213 private:
214         Config ();
215         std::string file (bool) const;
216         void read_old_metadata ();
217
218         /** number of threads to use for J2K encoding on the local machine */
219         int _num_local_encoding_threads;
220         /** default directory to put new films in */
221         std::string _default_directory;
222         /** port to use for J2K encoding servers */
223         int _server_port;
224
225         /** J2K encoding servers to use */
226         std::vector<ServerDescription *> _servers;
227         /** Scaler to use for the "A" part of A/B comparisons */
228         Scaler const * _reference_scaler;
229         /** Filters to use for the "A" part of A/B comparisons */
230         std::vector<Filter const *> _reference_filters;
231         /** The IP address of a TMS that we can copy DCPs to */
232         std::string _tms_ip;
233         /** The path on a TMS that we should write DCPs to */
234         std::string _tms_path;
235         /** User name to log into the TMS with */
236         std::string _tms_user;
237         /** Password to log into the TMS with */
238         std::string _tms_password;
239         /** Our sound processor */
240         SoundProcessor const * _sound_processor;
241         std::list<int> _allowed_dcp_frame_rates;
242         /** Default DCI metadata for newly-created Films */
243         DCIMetadata _default_dci_metadata;
244         boost::optional<std::string> _language;
245         int _default_still_length;
246         Format const * _default_format;
247         DCPContentType const * _default_dcp_content_type;
248         libdcp::XMLMetadata _dcp_metadata;
249
250         /** Singleton instance, or 0 */
251         static Config* _instance;
252 };
253
254 #endif