Add option to analyse audio automatically when content is added (#673).
[dcpomatic.git] / src / lib / config.h
1 /*
2     Copyright (C) 2012-2015 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 "isdcf_metadata.h"
28 #include "types.h"
29 #include <dcp/certificate_chain.h>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/signals2.hpp>
32 #include <boost/filesystem.hpp>
33 #include <vector>
34
35 class CinemaSoundProcessor;
36 class DCPContentType;
37 class Ratio;
38 class Cinema;
39
40 /** @class Config
41  *  @brief A singleton class holding configuration.
42  */
43 class Config : public boost::noncopyable
44 {
45 public:
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         boost::filesystem::path default_directory () const {
52                 return _default_directory;
53         }
54
55         boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
56
57         enum Property {
58                 USE_ANY_SERVERS,
59                 SERVERS,
60                 OTHER
61         };
62
63         /** @return base port number to use for J2K encoding servers */
64         int server_port_base () const {
65                 return _server_port_base;
66         }
67
68         void set_use_any_servers (bool u) {
69                 _use_any_servers = u;
70                 changed (USE_ANY_SERVERS);
71         }
72
73         bool use_any_servers () const {
74                 return _use_any_servers;
75         }
76
77         /** @param s New list of servers */
78         void set_servers (std::vector<std::string> s) {
79                 _servers = s;
80                 changed (SERVERS);
81         }
82
83         /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
84         std::vector<std::string> servers () const {
85                 return _servers;
86         }
87
88         bool only_servers_encode () const {
89                 return _only_servers_encode;
90         }
91
92         Protocol tms_protocol () const {
93                 return _tms_protocol;
94         }
95
96         /** @return The IP address of a TMS that we can copy DCPs to */
97         std::string tms_ip () const {
98                 return _tms_ip;
99         }
100
101         /** @return The path on a TMS that we should changed DCPs to */
102         std::string tms_path () const {
103                 return _tms_path;
104         }
105
106         /** @return User name to log into the TMS with */
107         std::string tms_user () const {
108                 return _tms_user;
109         }
110
111         /** @return Password to log into the TMS with */
112         std::string tms_password () const {
113                 return _tms_password;
114         }
115
116         /** @return The cinema sound processor that we are using */
117         CinemaSoundProcessor const * cinema_sound_processor () const {
118                 return _cinema_sound_processor;
119         }
120
121         std::list<boost::shared_ptr<Cinema> > cinemas () const {
122                 return _cinemas;
123         }
124
125         std::list<int> allowed_dcp_frame_rates () const {
126                 return _allowed_dcp_frame_rates;
127         }
128
129         bool allow_any_dcp_frame_rate () const {
130                 return _allow_any_dcp_frame_rate;
131         }
132
133         ISDCFMetadata default_isdcf_metadata () const {
134                 return _default_isdcf_metadata;
135         }
136
137         boost::optional<std::string> language () const {
138                 return _language;
139         }
140
141         int default_still_length () const {
142                 return _default_still_length;
143         }
144
145         Ratio const * default_container () const {
146                 return _default_container;
147         }
148
149         DCPContentType const * default_dcp_content_type () const {
150                 return _default_dcp_content_type;
151         }
152
153         std::string dcp_issuer () const {
154                 return _dcp_issuer;
155         }
156
157         std::string dcp_creator () const {
158                 return _dcp_creator;
159         }
160
161         int default_j2k_bandwidth () const {
162                 return _default_j2k_bandwidth;
163         }
164
165         int default_audio_delay () const {
166                 return _default_audio_delay;
167         }
168
169         std::string mail_server () const {
170                 return _mail_server;
171         }
172
173         int mail_port () const {
174                 return _mail_port;
175         }
176
177         std::string mail_user () const {
178                 return _mail_user;
179         }
180
181         std::string mail_password () const {
182                 return _mail_password;
183         }
184
185         std::string kdm_subject () const {
186                 return _kdm_subject;
187         }
188
189         std::string kdm_from () const {
190                 return _kdm_from;
191         }
192
193         std::string kdm_cc () const {
194                 return _kdm_cc;
195         }
196
197         std::string kdm_bcc () const {
198                 return _kdm_bcc;
199         }
200
201         std::string kdm_email () const {
202                 return _kdm_email;
203         }
204
205         boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
206                 return _signer_chain;
207         }
208
209         boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
210                 return _decryption_chain;
211         }
212
213         bool check_for_updates () const {
214                 return _check_for_updates;
215         }
216
217         bool check_for_test_updates () const {
218                 return _check_for_test_updates;
219         }
220
221         int maximum_j2k_bandwidth () const {
222                 return _maximum_j2k_bandwidth;
223         }
224
225         int log_types () const {
226                 return _log_types;
227         }
228
229         bool automatic_audio_analysis () const {
230                 return _automatic_audio_analysis;
231         }
232
233 #ifdef DCPOMATIC_WINDOWS
234         bool win32_console () const {
235                 return _win32_console;
236         }
237 #endif
238
239         std::vector<boost::filesystem::path> history () const {
240                 return _history;
241         }
242
243         /** @param n New number of local encoding threads */
244         void set_num_local_encoding_threads (int n) {
245                 maybe_set (_num_local_encoding_threads, n);
246         }
247
248         void set_default_directory (boost::filesystem::path d) {
249                 maybe_set (_default_directory, d);
250         }
251
252         /** @param p New server port */
253         void set_server_port_base (int p) {
254                 maybe_set (_server_port_base, p);
255         }
256
257         void set_only_servers_encode (bool o) {
258                 maybe_set (_only_servers_encode, o);
259         }
260
261         void set_tms_protocol (Protocol p) {
262                 maybe_set (_tms_protocol, p);
263         }
264
265         /** @param i IP address of a TMS that we can copy DCPs to */
266         void set_tms_ip (std::string i) {
267                 maybe_set (_tms_ip, i);
268         }
269
270         /** @param p Path on a TMS that we should changed DCPs to */
271         void set_tms_path (std::string p) {
272                 maybe_set (_tms_path, p);
273         }
274
275         /** @param u User name to log into the TMS with */
276         void set_tms_user (std::string u) {
277                 maybe_set (_tms_user, u);
278         }
279
280         /** @param p Password to log into the TMS with */
281         void set_tms_password (std::string p) {
282                 maybe_set (_tms_password, p);
283         }
284
285         void add_cinema (boost::shared_ptr<Cinema> c) {
286                 _cinemas.push_back (c);
287                 changed ();
288         }
289
290         void remove_cinema (boost::shared_ptr<Cinema> c) {
291                 _cinemas.remove (c);
292                 changed ();
293         }
294
295         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
296                 maybe_set (_allowed_dcp_frame_rates, r);
297         }
298
299         void set_allow_any_dcp_frame_rate (bool a) {
300                 maybe_set (_allow_any_dcp_frame_rate, a);
301         }
302
303         void set_default_isdcf_metadata (ISDCFMetadata d) {
304                 maybe_set (_default_isdcf_metadata, d);
305         }
306
307         void set_language (std::string l) {
308                 if (_language && _language.get() == l) {
309                         return;
310                 }
311                 _language = l;
312                 changed ();
313         }
314
315         void unset_language () {
316                 if (!_language) {
317                         return;
318                 }
319
320                 _language = boost::none;
321                 changed ();
322         }
323
324         void set_default_still_length (int s) {
325                 maybe_set (_default_still_length, s);
326         }
327
328         void set_default_container (Ratio const * c) {
329                 maybe_set (_default_container, c);
330         }
331
332         void set_default_dcp_content_type (DCPContentType const * t) {
333                 maybe_set (_default_dcp_content_type, t);
334         }
335
336         void set_dcp_issuer (std::string i) {
337                 maybe_set (_dcp_issuer, i);
338         }
339
340         void set_dcp_creator (std::string c) {
341                 maybe_set (_dcp_creator, c);
342         }
343
344         void set_default_j2k_bandwidth (int b) {
345                 maybe_set (_default_j2k_bandwidth, b);
346         }
347
348         void set_default_audio_delay (int d) {
349                 maybe_set (_default_audio_delay, d);
350         }
351
352         void set_mail_server (std::string s) {
353                 maybe_set (_mail_server, s);
354         }
355
356         void set_mail_port (int p) {
357                 maybe_set (_mail_port, p);
358         }
359
360         void set_mail_user (std::string u) {
361                 maybe_set (_mail_user, u);
362         }
363
364         void set_mail_password (std::string p) {
365                 maybe_set (_mail_password, p);
366         }
367
368         void set_kdm_subject (std::string s) {
369                 maybe_set (_kdm_subject, s);
370         }
371
372         void set_kdm_from (std::string f) {
373                 maybe_set (_kdm_from, f);
374         }
375
376         void set_kdm_cc (std::string f) {
377                 maybe_set (_kdm_cc, f);
378         }
379
380         void set_kdm_bcc (std::string f) {
381                 maybe_set (_kdm_bcc, f);
382         }
383
384         void set_kdm_email (std::string e) {
385                 maybe_set (_kdm_email, e);
386         }
387
388         void reset_kdm_email ();
389
390         void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
391                 maybe_set (_signer_chain, s);
392         }
393
394         void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
395                 maybe_set (_decryption_chain, c);
396         }
397
398         void set_check_for_updates (bool c) {
399                 maybe_set (_check_for_updates, c);
400         }
401
402         void set_check_for_test_updates (bool c) {
403                 maybe_set (_check_for_test_updates, c);
404         }
405
406         void set_maximum_j2k_bandwidth (int b) {
407                 maybe_set (_maximum_j2k_bandwidth, b);
408         }
409
410         void set_log_types (int t) {
411                 maybe_set (_log_types, t);
412         }
413
414         void set_automatic_audio_analysis (bool a) {
415                 maybe_set (_automatic_audio_analysis, a);
416         }
417
418 #ifdef DCPOMATIC_WINDOWS
419         void set_win32_console (bool c) {
420                 maybe_set (_win32_console, c);
421         }
422 #endif
423
424         void clear_history () {
425                 _history.clear ();
426                 changed ();
427         }
428
429         void add_to_history (boost::filesystem::path p);
430
431         void changed (Property p = OTHER);
432         boost::signals2::signal<void (Property)> Changed;
433
434         void write () const;
435
436         static Config* instance ();
437         static void drop ();
438         static void restore_defaults ();
439         static bool have_existing ();
440
441 private:
442         Config ();
443         static boost::filesystem::path file (bool create_directories = true);
444         void read ();
445         void set_defaults ();
446         void set_kdm_email_to_default ();
447
448         template <class T>
449         void maybe_set (T& member, T new_value) {
450                 if (member == new_value) {
451                         return;
452                 }
453                 member = new_value;
454                 changed ();
455         }
456
457         /** number of threads to use for J2K encoding on the local machine */
458         int _num_local_encoding_threads;
459         /** default directory to put new films in */
460         boost::filesystem::path _default_directory;
461         /** base port number to use for J2K encoding servers;
462          *  this port and the one above it will be used.
463          */
464         int _server_port_base;
465         /** true to broadcast on the `any' address to look for servers */
466         bool _use_any_servers;
467         /** J2K encoding servers that should definitely be used */
468         std::vector<std::string> _servers;
469         bool _only_servers_encode;
470         Protocol _tms_protocol;
471         /** The IP address of a TMS that we can copy DCPs to */
472         std::string _tms_ip;
473         /** The path on a TMS that we should write DCPs to */
474         std::string _tms_path;
475         /** User name to log into the TMS with */
476         std::string _tms_user;
477         /** Password to log into the TMS with */
478         std::string _tms_password;
479         /** Our cinema sound processor */
480         CinemaSoundProcessor const * _cinema_sound_processor;
481         std::list<int> _allowed_dcp_frame_rates;
482         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
483         bool _allow_any_dcp_frame_rate;
484         /** Default ISDCF metadata for newly-created Films */
485         ISDCFMetadata _default_isdcf_metadata;
486         boost::optional<std::string> _language;
487         /** Default length of still image content (seconds) */
488         int _default_still_length;
489         Ratio const * _default_container;
490         DCPContentType const * _default_dcp_content_type;
491         std::string _dcp_issuer;
492         std::string _dcp_creator;
493         int _default_j2k_bandwidth;
494         int _default_audio_delay;
495         std::list<boost::shared_ptr<Cinema> > _cinemas;
496         std::string _mail_server;
497         int _mail_port;
498         std::string _mail_user;
499         std::string _mail_password;
500         std::string _kdm_subject;
501         std::string _kdm_from;
502         std::string _kdm_cc;
503         std::string _kdm_bcc;
504         std::string _kdm_email;
505         boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
506         /** Chain used to decrypt KDMs; the leaf of this chain is the target
507          *  certificate for making KDMs given to DCP-o-matic.
508          */
509         boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
510         /** true to check for updates on startup */
511         bool _check_for_updates;
512         bool _check_for_test_updates;
513         /** maximum allowed J2K bandwidth in bits per second */
514         int _maximum_j2k_bandwidth;
515         int _log_types;
516         bool _automatic_audio_analysis;
517 #ifdef DCPOMATIC_WINDOWS
518         bool _win32_console;
519 #endif
520         std::vector<boost::filesystem::path> _history;
521
522         /** Singleton instance, or 0 */
523         static Config* _instance;
524 };
525
526 #endif