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