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