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