Allow 96kHz audio as an advanced option (#1789).
[dcpomatic.git] / src / lib / config.h
1 /*
2     Copyright (C) 2012-2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file src/config.h
22  *  @brief Class holding configuration.
23  */
24
25
26 #ifndef DCPOMATIC_CONFIG_H
27 #define DCPOMATIC_CONFIG_H
28
29
30 #include "audio_mapping.h"
31 #include "state.h"
32 #include "types.h"
33 #include <dcp/name_format.h>
34 #include <dcp/certificate_chain.h>
35 #include <dcp/encrypted_kdm.h>
36 #include <dcp/language_tag.h>
37 #include <boost/signals2.hpp>
38 #include <boost/filesystem.hpp>
39 #include <vector>
40
41
42 class Cinema;
43 class CinemaSoundProcessor;
44 class DCPContentType;
45 class DKDMGroup;
46 class DKDMRecipient;
47 class Film;
48 class Ratio;
49
50
51 extern void save_all_config_as_zip (boost::filesystem::path zip_file);
52
53
54 /** @class Config
55  *  @brief A singleton class holding configuration.
56  */
57 class Config : public State
58 {
59 public:
60         /** @return number of threads which a master DoM should use for J2K encoding on the local machine */
61         int master_encoding_threads () const {
62                 return _master_encoding_threads;
63         }
64
65         /** @return number of threads which a server should use for J2K encoding on the local machine */
66         int server_encoding_threads () const {
67                 return _server_encoding_threads;
68         }
69
70         boost::optional<boost::filesystem::path> default_directory () const {
71                 return _default_directory;
72         }
73
74         boost::optional<boost::filesystem::path> default_kdm_directory () const {
75                 return _default_kdm_directory;
76         }
77
78         boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
79         boost::filesystem::path default_kdm_directory_or (boost::filesystem::path a) const;
80
81         enum Property {
82                 USE_ANY_SERVERS,
83                 SERVERS,
84                 CINEMAS,
85                 DKDM_RECIPIENTS,
86                 SOUND,
87                 SOUND_OUTPUT,
88                 PLAYER_CONTENT_DIRECTORY,
89                 PLAYER_PLAYLIST_DIRECTORY,
90                 PLAYER_DEBUG_LOG,
91                 HISTORY,
92                 SHOW_EXPERIMENTAL_AUDIO_PROCESSORS,
93                 AUDIO_MAPPING,
94                 OTHER
95         };
96
97         /** @return base port number to use for J2K encoding servers */
98         int server_port_base () const {
99                 return _server_port_base;
100         }
101
102         void set_use_any_servers (bool u) {
103                 _use_any_servers = u;
104                 changed (USE_ANY_SERVERS);
105         }
106
107         bool use_any_servers () const {
108                 return _use_any_servers;
109         }
110
111         /** @param s New list of servers */
112         void set_servers (std::vector<std::string> s) {
113                 _servers = s;
114                 changed (SERVERS);
115         }
116
117         /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
118         std::vector<std::string> servers () const {
119                 return _servers;
120         }
121
122         bool only_servers_encode () const {
123                 return _only_servers_encode;
124         }
125
126         FileTransferProtocol tms_protocol () const {
127                 return _tms_protocol;
128         }
129
130         /** @return The IP address of a TMS that we can copy DCPs to */
131         std::string tms_ip () const {
132                 return _tms_ip;
133         }
134
135         /** @return The path on a TMS that we should changed DCPs to */
136         std::string tms_path () const {
137                 return _tms_path;
138         }
139
140         /** @return User name to log into the TMS with */
141         std::string tms_user () const {
142                 return _tms_user;
143         }
144
145         /** @return Password to log into the TMS with */
146         std::string tms_password () const {
147                 return _tms_password;
148         }
149
150         std::list<std::shared_ptr<Cinema>> cinemas () const {
151                 return _cinemas;
152         }
153
154         std::list<std::shared_ptr<DKDMRecipient>> dkdm_recipients () const {
155                 return _dkdm_recipients;
156         }
157
158         std::list<int> allowed_dcp_frame_rates () const {
159                 return _allowed_dcp_frame_rates;
160         }
161
162         bool allow_any_dcp_frame_rate () const {
163                 return _allow_any_dcp_frame_rate;
164         }
165
166         bool allow_any_container () const {
167                 return _allow_any_container;
168         }
169
170         bool allow_96khz_audio () const {
171                 return _allow_96khz_audio;
172         }
173
174         bool show_experimental_audio_processors () const {
175                 return _show_experimental_audio_processors;
176         }
177
178         boost::optional<std::string> language () const {
179                 return _language;
180         }
181
182         int default_still_length () const {
183                 return _default_still_length;
184         }
185
186         Ratio const * default_container () const {
187                 return _default_container;
188         }
189
190         DCPContentType const * default_dcp_content_type () const {
191                 return _default_dcp_content_type;
192         }
193
194         int default_dcp_audio_channels () const {
195                 return _default_dcp_audio_channels;
196         }
197
198         std::string dcp_issuer () const {
199                 return _dcp_issuer;
200         }
201
202         std::string dcp_creator () const {
203                 return _dcp_creator;
204         }
205
206         std::string dcp_company_name () const {
207                 return _dcp_company_name;
208         }
209
210         std::string dcp_product_name () const {
211                 return _dcp_product_name;
212         }
213
214         std::string dcp_product_version () const {
215                 return _dcp_product_version;
216         }
217
218         std::string dcp_j2k_comment () const {
219                 return _dcp_j2k_comment;
220         }
221
222         int default_j2k_bandwidth () const {
223                 return _default_j2k_bandwidth;
224         }
225
226         int default_audio_delay () const {
227                 return _default_audio_delay;
228         }
229
230         bool default_interop () const {
231                 return _default_interop;
232         }
233
234         std::map<std::string, std::string> default_metadata () const {
235                 return _default_metadata;
236         }
237
238         bool upload_after_make_dcp () {
239                 return _upload_after_make_dcp;
240         }
241
242         void set_default_kdm_directory (boost::filesystem::path d) {
243                 if (_default_kdm_directory && _default_kdm_directory.get() == d) {
244                         return;
245                 }
246                 _default_kdm_directory = d;
247                 changed ();
248         }
249
250         std::string mail_server () const {
251                 return _mail_server;
252         }
253
254         int mail_port () const {
255                 return _mail_port;
256         }
257
258         EmailProtocol mail_protocol () const {
259                 return _mail_protocol;
260         }
261
262         std::string mail_user () const {
263                 return _mail_user;
264         }
265
266         std::string mail_password () const {
267                 return _mail_password;
268         }
269
270         std::string kdm_subject () const {
271                 return _kdm_subject;
272         }
273
274         std::string kdm_from () const {
275                 return _kdm_from;
276         }
277
278         std::vector<std::string> kdm_cc () const {
279                 return _kdm_cc;
280         }
281
282         std::string kdm_bcc () const {
283                 return _kdm_bcc;
284         }
285
286         std::string kdm_email () const {
287                 return _kdm_email;
288         }
289
290         std::string notification_subject () const {
291                 return _notification_subject;
292         }
293
294         std::string notification_from () const {
295                 return _notification_from;
296         }
297
298         std::string notification_to () const {
299                 return _notification_to;
300         }
301
302         std::vector<std::string> notification_cc () const {
303                 return _notification_cc;
304         }
305
306         std::string notification_bcc () const {
307                 return _notification_bcc;
308         }
309
310         std::string notification_email () const {
311                 return _notification_email;
312         }
313
314         std::shared_ptr<const dcp::CertificateChain> signer_chain () const {
315                 return _signer_chain;
316         }
317
318         std::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
319                 return _decryption_chain;
320         }
321
322         bool check_for_updates () const {
323                 return _check_for_updates;
324         }
325
326         bool check_for_test_updates () const {
327                 return _check_for_test_updates;
328         }
329
330         int maximum_j2k_bandwidth () const {
331                 return _maximum_j2k_bandwidth;
332         }
333
334         int log_types () const {
335                 return _log_types;
336         }
337
338         bool analyse_ebur128 () const {
339                 return _analyse_ebur128;
340         }
341
342         bool automatic_audio_analysis () const {
343                 return _automatic_audio_analysis;
344         }
345
346 #ifdef DCPOMATIC_WINDOWS
347         bool win32_console () const {
348                 return _win32_console;
349         }
350 #endif
351
352         std::vector<boost::filesystem::path> history () const {
353                 return _history;
354         }
355
356         std::vector<boost::filesystem::path> player_history () const {
357                 return _player_history;
358         }
359
360         std::shared_ptr<DKDMGroup> dkdms () const {
361                 return _dkdms;
362         }
363
364         boost::filesystem::path cinemas_file () const {
365                 return _cinemas_file;
366         }
367
368         boost::filesystem::path dkdm_recipients_file () const {
369                 return _dkdm_recipients_file;
370         }
371
372         bool show_hints_before_make_dcp () const {
373                 return _show_hints_before_make_dcp;
374         }
375
376         bool confirm_kdm_email () const {
377                 return _confirm_kdm_email;
378         }
379
380         dcp::NameFormat kdm_container_name_format () const {
381                 return _kdm_container_name_format;
382         }
383
384         dcp::NameFormat kdm_filename_format () const {
385                 return _kdm_filename_format;
386         }
387
388         dcp::NameFormat dkdm_filename_format () const {
389                 return _dkdm_filename_format;
390         }
391
392         dcp::NameFormat dcp_metadata_filename_format () const {
393                 return _dcp_metadata_filename_format;
394         }
395
396         dcp::NameFormat dcp_asset_filename_format () const {
397                 return _dcp_asset_filename_format;
398         }
399
400         bool jump_to_selected () const {
401                 return _jump_to_selected;
402         }
403
404         /* This could be an enum class but we use the enum a lot to index _nagged
405          * so it means a lot of casts.
406          */
407         enum Nag {
408                 NAG_DKDM_CONFIG,
409                 NAG_ENCRYPTED_METADATA,
410                 NAG_ALTER_DECRYPTION_CHAIN,
411                 NAG_BAD_SIGNER_CHAIN_UTF8,
412                 NAG_IMPORT_DECRYPTION_CHAIN,
413                 NAG_DELETE_DKDM,
414                 NAG_32_ON_64,
415                 NAG_TOO_MANY_DROPPED_FRAMES,
416                 NAG_BAD_SIGNER_CHAIN_VALIDITY,
417                 NAG_COUNT
418         };
419
420         bool nagged (Nag nag) const {
421                 return _nagged[nag];
422         }
423
424         bool sound () const {
425                 return _sound;
426         }
427
428         std::string cover_sheet () const {
429                 return _cover_sheet;
430         }
431
432         boost::optional<std::string> sound_output () const {
433                 return _sound_output;
434         }
435
436         boost::optional<boost::filesystem::path> last_player_load_directory () const {
437                 return _last_player_load_directory;
438         }
439
440         enum KDMWriteType {
441                 KDM_WRITE_FLAT,
442                 KDM_WRITE_FOLDER,
443                 KDM_WRITE_ZIP
444         };
445
446         boost::optional<KDMWriteType> last_kdm_write_type () const {
447                 return _last_kdm_write_type;
448         }
449
450         enum DKDMWriteType {
451                 DKDM_WRITE_INTERNAL,
452                 DKDM_WRITE_FILE
453         };
454
455         boost::optional<DKDMWriteType> last_dkdm_write_type () const {
456                 return _last_dkdm_write_type;
457         }
458
459         int frames_in_memory_multiplier () const {
460                 return _frames_in_memory_multiplier;
461         }
462
463         boost::optional<int> decode_reduction () const {
464                 return _decode_reduction;
465         }
466
467         bool default_notify () const {
468                 return _default_notify;
469         }
470
471         enum Notification {
472                 MESSAGE_BOX,
473                 EMAIL,
474                 NOTIFICATION_COUNT
475         };
476
477         bool notification (Notification n) const {
478                 return _notification[n];
479         }
480
481         boost::optional<std::string> barco_username () const {
482                 return _barco_username;
483         }
484
485         boost::optional<std::string> barco_password () const {
486                 return _barco_password;
487         }
488
489         boost::optional<std::string> christie_username () const {
490                 return _christie_username;
491         }
492
493         boost::optional<std::string> christie_password () const {
494                 return _christie_password;
495         }
496
497         boost::optional<std::string> gdc_username () const {
498                 return _gdc_username;
499         }
500
501         boost::optional<std::string> gdc_password () const {
502                 return _gdc_password;
503         }
504
505         enum PlayerMode {
506                 PLAYER_MODE_WINDOW, ///< one window containing image and controls
507                 PLAYER_MODE_FULL,   ///< just the image filling the screen
508                 PLAYER_MODE_DUAL    ///< image on one monitor and extended controls on the other
509         };
510
511         PlayerMode player_mode () const {
512                 return _player_mode;
513         }
514
515         int image_display () const {
516                 return _image_display;
517         }
518
519         enum VideoViewType {
520                 VIDEO_VIEW_SIMPLE,
521                 VIDEO_VIEW_OPENGL
522         };
523
524         VideoViewType video_view_type () const {
525                 return _video_view_type;
526         }
527
528         bool respect_kdm_validity_periods () const {
529                 return _respect_kdm_validity_periods;
530         }
531
532         boost::optional<boost::filesystem::path> player_debug_log_file () const {
533                 return _player_debug_log_file;
534         }
535
536         boost::optional<boost::filesystem::path> player_content_directory () const {
537                 return _player_content_directory;
538         }
539
540         boost::optional<boost::filesystem::path> player_playlist_directory () const {
541                 return _player_playlist_directory;
542         }
543
544         boost::optional<boost::filesystem::path> player_kdm_directory () const {
545                 return _player_kdm_directory;
546         }
547
548         AudioMapping audio_mapping (int output_channels);
549
550         std::vector<dcp::LanguageTag> custom_languages () const {
551                 return _custom_languages;
552         }
553
554         boost::optional<boost::filesystem::path> add_files_path () const {
555                 return _add_files_path;
556         }
557
558         bool use_isdcf_name_by_default () const {
559                 return _use_isdcf_name_by_default;
560         }
561
562         bool write_kdms_to_disk () const {
563                 return _write_kdms_to_disk;
564         }
565
566         bool email_kdms () const {
567                 return _email_kdms;
568         }
569
570         dcp::Formulation default_kdm_type () const {
571                 return _default_kdm_type;
572         }
573
574
575         /* SET (mostly) */
576
577         void set_master_encoding_threads (int n) {
578                 maybe_set (_master_encoding_threads, n);
579         }
580
581         void set_server_encoding_threads (int n) {
582                 maybe_set (_server_encoding_threads, n);
583         }
584
585         void set_default_directory (boost::filesystem::path d) {
586                 if (_default_directory && *_default_directory == d) {
587                         return;
588                 }
589                 _default_directory = d;
590                 changed ();
591         }
592
593         /** @param p New server port */
594         void set_server_port_base (int p) {
595                 maybe_set (_server_port_base, p);
596         }
597
598         void set_only_servers_encode (bool o) {
599                 maybe_set (_only_servers_encode, o);
600         }
601
602         void set_tms_protocol (FileTransferProtocol p) {
603                 maybe_set (_tms_protocol, p);
604         }
605
606         /** @param i IP address of a TMS that we can copy DCPs to */
607         void set_tms_ip (std::string i) {
608                 maybe_set (_tms_ip, i);
609         }
610
611         /** @param p Path on a TMS that we should changed DCPs to */
612         void set_tms_path (std::string p) {
613                 maybe_set (_tms_path, p);
614         }
615
616         /** @param u User name to log into the TMS with */
617         void set_tms_user (std::string u) {
618                 maybe_set (_tms_user, u);
619         }
620
621         /** @param p Password to log into the TMS with */
622         void set_tms_password (std::string p) {
623                 maybe_set (_tms_password, p);
624         }
625
626         void add_cinema (std::shared_ptr<Cinema> c) {
627                 _cinemas.push_back (c);
628                 changed (CINEMAS);
629         }
630
631         void remove_cinema (std::shared_ptr<Cinema> c) {
632                 _cinemas.remove (c);
633                 changed (CINEMAS);
634         }
635
636         void add_dkdm_recipient (std::shared_ptr<DKDMRecipient> c) {
637                 _dkdm_recipients.push_back (c);
638                 changed (DKDM_RECIPIENTS);
639         }
640
641         void remove_dkdm_recipient (std::shared_ptr<DKDMRecipient> c) {
642                 _dkdm_recipients.remove (c);
643                 changed (DKDM_RECIPIENTS);
644         }
645
646         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
647                 maybe_set (_allowed_dcp_frame_rates, r);
648         }
649
650         void set_allow_any_dcp_frame_rate (bool a) {
651                 maybe_set (_allow_any_dcp_frame_rate, a);
652         }
653
654         void set_allow_any_container (bool a) {
655                 maybe_set (_allow_any_container, a);
656         }
657
658         void set_allow_96hhz_audio (bool a) {
659                 maybe_set (_allow_96khz_audio, a);
660         }
661
662         void set_show_experimental_audio_processors (bool e) {
663                 maybe_set (_show_experimental_audio_processors, e, SHOW_EXPERIMENTAL_AUDIO_PROCESSORS);
664         }
665
666         void set_language (std::string l) {
667                 if (_language && _language.get() == l) {
668                         return;
669                 }
670                 _language = l;
671                 changed ();
672         }
673
674         void unset_language () {
675                 if (!_language) {
676                         return;
677                 }
678
679                 _language = boost::none;
680                 changed ();
681         }
682
683         void set_default_still_length (int s) {
684                 maybe_set (_default_still_length, s);
685         }
686
687         void set_default_container (Ratio const * c) {
688                 maybe_set (_default_container, c);
689         }
690
691         void set_default_dcp_content_type (DCPContentType const * t) {
692                 maybe_set (_default_dcp_content_type, t);
693         }
694
695         void set_default_dcp_audio_channels (int c) {
696                 maybe_set (_default_dcp_audio_channels, c);
697         }
698
699         void set_dcp_issuer (std::string i) {
700                 maybe_set (_dcp_issuer, i);
701         }
702
703         void set_dcp_creator (std::string c) {
704                 maybe_set (_dcp_creator, c);
705         }
706
707         void set_dcp_company_name (std::string c) {
708                 maybe_set (_dcp_company_name, c);
709         }
710
711         void set_dcp_product_name (std::string c) {
712                 maybe_set (_dcp_product_name, c);
713         }
714
715         void set_dcp_product_version (std::string c) {
716                 maybe_set (_dcp_product_version, c);
717         }
718
719         void set_dcp_j2k_comment (std::string c) {
720                 maybe_set (_dcp_j2k_comment, c);
721         }
722
723         void set_default_j2k_bandwidth (int b) {
724                 maybe_set (_default_j2k_bandwidth, b);
725         }
726
727         void set_default_audio_delay (int d) {
728                 maybe_set (_default_audio_delay, d);
729         }
730
731         void set_default_interop (bool i) {
732                 maybe_set (_default_interop, i);
733         }
734
735         void set_default_metadata (std::map<std::string, std::string> const& metadata) {
736                 maybe_set (_default_metadata, metadata);
737         }
738
739         void set_upload_after_make_dcp (bool u) {
740                 maybe_set (_upload_after_make_dcp, u);
741         }
742
743         void set_mail_server (std::string s) {
744                 maybe_set (_mail_server, s);
745         }
746
747         void set_mail_port (int p) {
748                 maybe_set (_mail_port, p);
749         }
750
751         void set_mail_protocol (EmailProtocol p) {
752                 maybe_set (_mail_protocol, p);
753         }
754
755         void set_mail_user (std::string u) {
756                 maybe_set (_mail_user, u);
757         }
758
759         void set_mail_password (std::string p) {
760                 maybe_set (_mail_password, p);
761         }
762
763         void set_kdm_subject (std::string s) {
764                 maybe_set (_kdm_subject, s);
765         }
766
767         void set_kdm_from (std::string f) {
768                 maybe_set (_kdm_from, f);
769         }
770
771         void set_kdm_cc (std::vector<std::string> f) {
772                 maybe_set (_kdm_cc, f);
773         }
774
775         void set_kdm_bcc (std::string f) {
776                 maybe_set (_kdm_bcc, f);
777         }
778
779         void set_kdm_email (std::string e) {
780                 maybe_set (_kdm_email, e);
781         }
782
783         void reset_kdm_email ();
784
785         void set_notification_subject (std::string s) {
786                 maybe_set (_notification_subject, s);
787         }
788
789         void set_notification_from (std::string f) {
790                 maybe_set (_notification_from, f);
791         }
792
793         void set_notification_to (std::string t) {
794                 maybe_set (_notification_to, t);
795         }
796
797         void set_notification_cc (std::vector<std::string> f) {
798                 maybe_set (_notification_cc, f);
799         }
800
801         void set_notification_bcc (std::string f) {
802                 maybe_set (_notification_bcc, f);
803         }
804
805         void set_notification_email (std::string e) {
806                 maybe_set (_notification_email, e);
807         }
808
809         void reset_notification_email ();
810
811         void set_signer_chain (std::shared_ptr<const dcp::CertificateChain> s) {
812                 maybe_set (_signer_chain, s);
813         }
814
815         void set_decryption_chain (std::shared_ptr<const dcp::CertificateChain> c) {
816                 maybe_set (_decryption_chain, c);
817         }
818
819         void set_check_for_updates (bool c) {
820                 maybe_set (_check_for_updates, c);
821                 if (!c) {
822                         set_check_for_test_updates (false);
823                 }
824         }
825
826         void set_check_for_test_updates (bool c) {
827                 maybe_set (_check_for_test_updates, c);
828         }
829
830         void set_maximum_j2k_bandwidth (int b) {
831                 maybe_set (_maximum_j2k_bandwidth, b);
832         }
833
834         void set_log_types (int t) {
835                 maybe_set (_log_types, t);
836         }
837
838         void set_analyse_ebur128 (bool a) {
839                 maybe_set (_analyse_ebur128, a);
840         }
841
842         void set_automatic_audio_analysis (bool a) {
843                 maybe_set (_automatic_audio_analysis, a);
844         }
845
846 #ifdef DCPOMATIC_WINDOWS
847         void set_win32_console (bool c) {
848                 maybe_set (_win32_console, c);
849         }
850 #endif
851
852         void set_dkdms (std::shared_ptr<DKDMGroup> dkdms) {
853                 _dkdms = dkdms;
854                 changed ();
855         }
856
857         void set_cinemas_file (boost::filesystem::path file);
858
859         void set_show_hints_before_make_dcp (bool s) {
860                 maybe_set (_show_hints_before_make_dcp, s);
861         }
862
863         void set_confirm_kdm_email (bool s) {
864                 maybe_set (_confirm_kdm_email, s);
865         }
866
867         void set_sound (bool s) {
868                 maybe_set (_sound, s, SOUND);
869         }
870
871         void set_sound_output (std::string o) {
872                 maybe_set (_sound_output, o, SOUND_OUTPUT);
873         }
874
875         void set_last_player_load_directory (boost::filesystem::path d) {
876                 maybe_set (_last_player_load_directory, d);
877         }
878
879         void set_last_kdm_write_type (KDMWriteType t) {
880                 maybe_set (_last_kdm_write_type, t);
881         }
882
883         void set_last_dkdm_write_type (DKDMWriteType t) {
884                 maybe_set (_last_dkdm_write_type, t);
885         }
886
887         void unset_sound_output () {
888                 if (!_sound_output) {
889                         return;
890                 }
891
892                 _sound_output = boost::none;
893                 changed ();
894         }
895
896         void set_kdm_container_name_format (dcp::NameFormat n) {
897                 maybe_set (_kdm_container_name_format, n);
898         }
899
900         void set_kdm_filename_format (dcp::NameFormat n) {
901                 maybe_set (_kdm_filename_format, n);
902         }
903
904         void set_dkdm_filename_format (dcp::NameFormat n) {
905                 maybe_set (_dkdm_filename_format, n);
906         }
907
908         void set_dcp_metadata_filename_format (dcp::NameFormat n) {
909                 maybe_set (_dcp_metadata_filename_format, n);
910         }
911
912         void set_dcp_asset_filename_format (dcp::NameFormat n) {
913                 maybe_set (_dcp_asset_filename_format, n);
914         }
915
916         void set_frames_in_memory_multiplier (int m) {
917                 maybe_set (_frames_in_memory_multiplier, m);
918         }
919
920         void set_decode_reduction (boost::optional<int> r) {
921                 maybe_set (_decode_reduction, r);
922         }
923
924         void set_default_notify (bool n) {
925                 maybe_set (_default_notify, n);
926         }
927
928         void clear_history () {
929                 _history.clear ();
930                 changed ();
931         }
932
933         void clear_player_history () {
934                 _player_history.clear ();
935                 changed ();
936         }
937
938         void add_to_history (boost::filesystem::path p);
939         void clean_history ();
940         void add_to_player_history (boost::filesystem::path p);
941         void clean_player_history ();
942
943         void set_jump_to_selected (bool j) {
944                 maybe_set (_jump_to_selected, j);
945         }
946
947         void set_nagged (Nag nag, bool nagged) {
948                 maybe_set (_nagged[nag], nagged);
949         }
950
951         void set_cover_sheet (std::string s) {
952                 maybe_set (_cover_sheet, s);
953         }
954
955         void reset_cover_sheet ();
956
957         void set_notification (Notification n, bool v) {
958                 maybe_set (_notification[n], v);
959         }
960
961         void set_barco_username (std::string u) {
962                 maybe_set (_barco_username, u);
963         }
964
965         void unset_barco_username () {
966                 maybe_set (_barco_username, boost::optional<std::string>());
967         }
968
969         void set_barco_password (std::string p) {
970                 maybe_set (_barco_password, p);
971         }
972
973         void unset_barco_password () {
974                 maybe_set (_barco_password, boost::optional<std::string>());
975         }
976
977         void set_christie_username (std::string u) {
978                 maybe_set (_christie_username, u);
979         }
980
981         void unset_christie_username () {
982                 maybe_set (_christie_username, boost::optional<std::string>());
983         }
984
985         void set_christie_password (std::string p) {
986                 maybe_set (_christie_password, p);
987         }
988
989         void unset_christie_password () {
990                 maybe_set (_christie_password, boost::optional<std::string>());
991         }
992
993         void set_gdc_username (std::string u) {
994                 maybe_set (_gdc_username, u);
995         }
996
997         void unset_gdc_username () {
998                 maybe_set (_gdc_username, boost::optional<std::string>());
999         }
1000
1001         void set_gdc_password (std::string p) {
1002                 maybe_set (_gdc_password, p);
1003         }
1004
1005         void unset_gdc_password () {
1006                 maybe_set (_gdc_password, boost::optional<std::string>());
1007         }
1008
1009         void set_player_mode (PlayerMode m) {
1010                 maybe_set (_player_mode, m);
1011         }
1012
1013         void set_image_display (int n) {
1014                 maybe_set (_image_display, n);
1015         }
1016
1017         void set_video_view_type (VideoViewType v) {
1018                 maybe_set (_video_view_type, v);
1019         }
1020
1021         void set_respect_kdm_validity_periods (bool r) {
1022                 maybe_set (_respect_kdm_validity_periods, r);
1023         }
1024
1025         void set_player_debug_log_file (boost::filesystem::path p) {
1026                 maybe_set (_player_debug_log_file, p, PLAYER_DEBUG_LOG);
1027         }
1028
1029         void unset_player_debug_log_file () {
1030                 if (!_player_debug_log_file) {
1031                         return;
1032                 }
1033                 _player_debug_log_file = boost::none;
1034                 changed (PLAYER_DEBUG_LOG);
1035         }
1036
1037         void set_player_content_directory (boost::filesystem::path p) {
1038                 maybe_set (_player_content_directory, p, PLAYER_CONTENT_DIRECTORY);
1039         }
1040
1041         void unset_player_content_directory () {
1042                 if (!_player_content_directory) {
1043                         return;
1044                 }
1045                 _player_content_directory = boost::none;
1046                 changed (PLAYER_CONTENT_DIRECTORY);
1047         }
1048
1049         void set_player_playlist_directory (boost::filesystem::path p) {
1050                 maybe_set (_player_playlist_directory, p, PLAYER_PLAYLIST_DIRECTORY);
1051         }
1052
1053         void unset_player_playlist_directory () {
1054                 if (!_player_playlist_directory) {
1055                         return;
1056                 }
1057                 _player_playlist_directory = boost::none;
1058                 changed (PLAYER_PLAYLIST_DIRECTORY);
1059         }
1060
1061         void set_player_kdm_directory (boost::filesystem::path p) {
1062                 maybe_set (_player_kdm_directory, p);
1063         }
1064
1065         void unset_player_kdm_directory () {
1066                 if (!_player_kdm_directory) {
1067                         return;
1068                 }
1069                 _player_kdm_directory = boost::none;
1070                 changed ();
1071         }
1072
1073         void set_audio_mapping (AudioMapping m);
1074         void set_audio_mapping_to_default ();
1075
1076         void add_custom_language (dcp::LanguageTag tag);
1077
1078         void set_add_files_path (boost::filesystem::path p) {
1079                 _add_files_path = p;
1080                 changed ();
1081         }
1082
1083         void set_use_isdcf_name_by_default (bool use) {
1084                 maybe_set (_use_isdcf_name_by_default, use);
1085         }
1086
1087         void set_write_kdms_to_disk (bool write) {
1088                 maybe_set (_write_kdms_to_disk, write);
1089         }
1090
1091         void set_email_kdms (bool email) {
1092                 maybe_set (_email_kdms, email);
1093         }
1094
1095         void set_default_kdm_type (dcp::Formulation type) {
1096                 maybe_set (_default_kdm_type, type);
1097         }
1098
1099         void changed (Property p = OTHER);
1100         boost::signals2::signal<void (Property)> Changed;
1101         /** Emitted if read() failed on an existing Config file.  There is nothing
1102             a listener can do about it: this is just for information.
1103         */
1104         static boost::signals2::signal<void ()> FailedToLoad;
1105         /** Emitted if read() issued a warning which the user might want to know about */
1106         static boost::signals2::signal<void (std::string)> Warning;
1107         /** Emitted if there is a something wrong the contents of our config.  Handler can call
1108          *  true to ask Config to solve the problem (by discarding and recreating the bad thing)
1109          */
1110         enum BadReason {
1111                 BAD_SIGNER_UTF8_STRINGS,      ///< signer chain contains UTF-8 strings (not PRINTABLESTRING)
1112                 BAD_SIGNER_INCONSISTENT,      ///< signer chain is somehow inconsistent
1113                 BAD_DECRYPTION_INCONSISTENT,  ///< KDM decryption chain is somehow inconsistent
1114                 BAD_SIGNER_VALIDITY_TOO_LONG, ///< signer certificate validity periods are >10 years
1115         };
1116
1117         static boost::signals2::signal<bool (BadReason)> Bad;
1118
1119         void write () const override;
1120         void write_config () const;
1121         void write_cinemas () const;
1122         void write_dkdm_recipients () const;
1123         void link (boost::filesystem::path new_file) const;
1124         void copy_and_link (boost::filesystem::path new_file) const;
1125         bool have_write_permission () const;
1126
1127         void save_template (std::shared_ptr<const Film> film, std::string name) const;
1128         bool existing_template (std::string name) const;
1129         std::list<std::string> templates () const;
1130         boost::filesystem::path template_read_path (std::string name) const;
1131         boost::filesystem::path template_write_path (std::string name) const;
1132         void rename_template (std::string old_name, std::string new_name) const;
1133         void delete_template (std::string name) const;
1134
1135         boost::optional<BadReason> check_certificates () const;
1136
1137         static Config* instance ();
1138         static void drop ();
1139         static void restore_defaults ();
1140         static bool have_existing (std::string);
1141         static boost::filesystem::path config_read_file ();
1142         static boost::filesystem::path config_write_file ();
1143
1144 private:
1145         Config ();
1146         void read () override;
1147         void set_defaults ();
1148         void set_kdm_email_to_default ();
1149         void set_notification_email_to_default ();
1150         void set_cover_sheet_to_default ();
1151         void read_cinemas (cxml::Document const & f);
1152         void read_dkdm_recipients (cxml::Document const & f);
1153         std::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
1154         boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
1155         void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
1156         void clean_history_internal (std::vector<boost::filesystem::path>& h);
1157         void backup ();
1158
1159         template <class T>
1160         void maybe_set (T& member, T new_value, Property prop = OTHER) {
1161                 if (member == new_value) {
1162                         return;
1163                 }
1164                 member = new_value;
1165                 changed (prop);
1166         }
1167
1168         template <class T>
1169         void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
1170                 if (member && member.get() == new_value) {
1171                         return;
1172                 }
1173                 member = new_value;
1174                 changed (prop);
1175         }
1176
1177         /** number of threads which a master DoM should use for J2K encoding on the local machine */
1178         int _master_encoding_threads;
1179         /** number of threads which a server should use for J2K encoding on the local machine */
1180         int _server_encoding_threads;
1181         /** default directory to put new films in */
1182         boost::optional<boost::filesystem::path> _default_directory;
1183         /** base port number to use for J2K encoding servers;
1184          *  this port and the two above it will be used.
1185          */
1186         int _server_port_base;
1187         /** true to broadcast on the `any' address to look for servers */
1188         bool _use_any_servers;
1189         /** J2K encoding servers that should definitely be used */
1190         std::vector<std::string> _servers;
1191         bool _only_servers_encode;
1192         FileTransferProtocol _tms_protocol;
1193         /** The IP address of a TMS that we can copy DCPs to */
1194         std::string _tms_ip;
1195         /** The path on a TMS that we should write DCPs to */
1196         std::string _tms_path;
1197         /** User name to log into the TMS with */
1198         std::string _tms_user;
1199         /** Password to log into the TMS with */
1200         std::string _tms_password;
1201         /** The list of possible DCP frame rates that DCP-o-matic will use */
1202         std::list<int> _allowed_dcp_frame_rates;
1203         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
1204         bool _allow_any_dcp_frame_rate;
1205         /** Allow any container ratio, not just the standard ones.  GDC SX-2001 will not play Flat
1206             DCPs at 25fps but will play 16:9, so this is very useful for some users.
1207             https://www.dcpomatic.com/forum/viewtopic.php?f=2&t=1119&p=4468
1208         */
1209         bool _allow_any_container;
1210         bool _allow_96khz_audio;
1211         /** Offer the upmixers in the audio processor settings */
1212         bool _show_experimental_audio_processors;
1213         boost::optional<std::string> _language;
1214         /** Default length of still image content (seconds) */
1215         int _default_still_length;
1216         Ratio const * _default_container;
1217         DCPContentType const * _default_dcp_content_type;
1218         int _default_dcp_audio_channels;
1219         std::string _dcp_issuer;
1220         std::string _dcp_creator;
1221         std::string _dcp_company_name;
1222         std::string _dcp_product_name;
1223         std::string _dcp_product_version;
1224         std::string _dcp_j2k_comment;
1225         int _default_j2k_bandwidth;
1226         int _default_audio_delay;
1227         bool _default_interop;
1228         std::map<std::string, std::string> _default_metadata;
1229         /** Default directory to offer to write KDMs to; if it's not set,
1230             the home directory will be offered.
1231         */
1232         boost::optional<boost::filesystem::path> _default_kdm_directory;
1233         bool _upload_after_make_dcp;
1234         std::list<std::shared_ptr<Cinema>> _cinemas;
1235         std::list<std::shared_ptr<DKDMRecipient>> _dkdm_recipients;
1236         std::string _mail_server;
1237         int _mail_port;
1238         EmailProtocol _mail_protocol;
1239         std::string _mail_user;
1240         std::string _mail_password;
1241         std::string _kdm_subject;
1242         std::string _kdm_from;
1243         std::vector<std::string> _kdm_cc;
1244         std::string _kdm_bcc;
1245         std::string _kdm_email;
1246         std::string _notification_subject;
1247         std::string _notification_from;
1248         std::string _notification_to;
1249         std::vector<std::string> _notification_cc;
1250         std::string _notification_bcc;
1251         std::string _notification_email;
1252         std::shared_ptr<const dcp::CertificateChain> _signer_chain;
1253         /** Chain used to decrypt KDMs; the leaf of this chain is the target
1254          *  certificate for making KDMs given to DCP-o-matic.
1255          */
1256         std::shared_ptr<const dcp::CertificateChain> _decryption_chain;
1257         /** true to check for updates on startup */
1258         bool _check_for_updates;
1259         bool _check_for_test_updates;
1260         /** maximum allowed J2K bandwidth in bits per second */
1261         int _maximum_j2k_bandwidth;
1262         int _log_types;
1263         bool _analyse_ebur128;
1264         bool _automatic_audio_analysis;
1265 #ifdef DCPOMATIC_WINDOWS
1266         bool _win32_console;
1267 #endif
1268         std::vector<boost::filesystem::path> _history;
1269         std::vector<boost::filesystem::path> _player_history;
1270         std::shared_ptr<DKDMGroup> _dkdms;
1271         boost::filesystem::path _cinemas_file;
1272         boost::filesystem::path _dkdm_recipients_file;
1273         bool _show_hints_before_make_dcp;
1274         bool _confirm_kdm_email;
1275         dcp::NameFormat _kdm_filename_format;
1276         dcp::NameFormat _dkdm_filename_format;
1277         dcp::NameFormat _kdm_container_name_format;
1278         dcp::NameFormat _dcp_metadata_filename_format;
1279         dcp::NameFormat _dcp_asset_filename_format;
1280         bool _jump_to_selected;
1281         bool _nagged[NAG_COUNT];
1282         bool _sound;
1283         /** name of a specific sound output stream to use, or empty to use the default */
1284         boost::optional<std::string> _sound_output;
1285         std::string _cover_sheet;
1286         boost::optional<boost::filesystem::path> _last_player_load_directory;
1287         boost::optional<KDMWriteType> _last_kdm_write_type;
1288         boost::optional<DKDMWriteType> _last_dkdm_write_type;
1289         int _frames_in_memory_multiplier;
1290         boost::optional<int> _decode_reduction;
1291         bool _default_notify;
1292         bool _notification[NOTIFICATION_COUNT];
1293         boost::optional<std::string> _barco_username;
1294         boost::optional<std::string> _barco_password;
1295         boost::optional<std::string> _christie_username;
1296         boost::optional<std::string> _christie_password;
1297         boost::optional<std::string> _gdc_username;
1298         boost::optional<std::string> _gdc_password;
1299         PlayerMode _player_mode;
1300         int _image_display;
1301         VideoViewType _video_view_type;
1302         bool _respect_kdm_validity_periods;
1303         /** Log file containing debug information for the player */
1304         boost::optional<boost::filesystem::path> _player_debug_log_file;
1305         /** A directory containing DCPs whose contents are presented to the user
1306             in the dual-screen player mode.  DCPs on the list can be loaded
1307             for playback.
1308         */
1309         boost::optional<boost::filesystem::path> _player_content_directory;
1310         boost::optional<boost::filesystem::path> _player_playlist_directory;
1311         boost::optional<boost::filesystem::path> _player_kdm_directory;
1312         boost::optional<AudioMapping> _audio_mapping;
1313         std::vector<dcp::LanguageTag> _custom_languages;
1314         boost::optional<boost::filesystem::path> _add_files_path;
1315         bool _use_isdcf_name_by_default;
1316         bool _write_kdms_to_disk;
1317         bool _email_kdms;
1318         dcp::Formulation _default_kdm_type;
1319
1320         static int const _current_version;
1321
1322         /** Singleton instance, or 0 */
1323         static Config* _instance;
1324 };
1325
1326 #endif