2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 /** @file src/config.h
22 * @brief Class holding configuration.
25 #ifndef DCPOMATIC_CONFIG_H
26 #define DCPOMATIC_CONFIG_H
28 #include "isdcf_metadata.h"
30 #include <dcp/name_format.h>
31 #include <dcp/certificate_chain.h>
32 #include <dcp/encrypted_kdm.h>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/signals2.hpp>
35 #include <boost/filesystem.hpp>
38 class CinemaSoundProcessor;
45 * @brief A singleton class holding configuration.
47 class Config : public boost::noncopyable
50 /** @return number of threads to use for J2K encoding on the local machine */
51 int num_local_encoding_threads () const {
52 return _num_local_encoding_threads;
55 boost::optional<boost::filesystem::path> default_directory () const {
56 return _default_directory;
59 boost::optional<boost::filesystem::path> default_kdm_directory () const {
60 return _default_kdm_directory;
63 boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
64 boost::filesystem::path default_kdm_directory_or (boost::filesystem::path a) const;
74 /** @return base port number to use for J2K encoding servers */
75 int server_port_base () const {
76 return _server_port_base;
79 void set_use_any_servers (bool u) {
81 changed (USE_ANY_SERVERS);
84 bool use_any_servers () const {
85 return _use_any_servers;
88 /** @param s New list of servers */
89 void set_servers (std::vector<std::string> s) {
94 /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
95 std::vector<std::string> servers () const {
99 bool only_servers_encode () const {
100 return _only_servers_encode;
103 Protocol tms_protocol () const {
104 return _tms_protocol;
107 /** @return The IP address of a TMS that we can copy DCPs to */
108 std::string tms_ip () const {
112 /** @return The path on a TMS that we should changed DCPs to */
113 std::string tms_path () const {
117 /** @return User name to log into the TMS with */
118 std::string tms_user () const {
122 /** @return Password to log into the TMS with */
123 std::string tms_password () const {
124 return _tms_password;
127 /** @return The cinema sound processor that we are using */
128 CinemaSoundProcessor const * cinema_sound_processor () const {
129 return _cinema_sound_processor;
132 std::list<boost::shared_ptr<Cinema> > cinemas () const {
136 std::list<int> allowed_dcp_frame_rates () const {
137 return _allowed_dcp_frame_rates;
140 bool allow_any_dcp_frame_rate () const {
141 return _allow_any_dcp_frame_rate;
144 ISDCFMetadata default_isdcf_metadata () const {
145 return _default_isdcf_metadata;
148 boost::optional<std::string> language () const {
152 int default_still_length () const {
153 return _default_still_length;
156 Ratio const * default_container () const {
157 return _default_container;
160 DCPContentType const * default_dcp_content_type () const {
161 return _default_dcp_content_type;
164 int default_dcp_audio_channels () const {
165 return _default_dcp_audio_channels;
168 std::string dcp_issuer () const {
172 std::string dcp_creator () const {
176 int default_j2k_bandwidth () const {
177 return _default_j2k_bandwidth;
180 int default_audio_delay () const {
181 return _default_audio_delay;
184 bool default_interop () const {
185 return _default_interop;
188 void set_default_kdm_directory (boost::filesystem::path d) {
189 if (_default_kdm_directory && _default_kdm_directory.get() == d) {
192 _default_kdm_directory = d;
196 std::string mail_server () const {
200 int mail_port () const {
204 std::string mail_user () const {
208 std::string mail_password () const {
209 return _mail_password;
212 std::string kdm_subject () const {
216 std::string kdm_from () const {
220 std::vector<std::string> kdm_cc () const {
224 std::string kdm_bcc () const {
228 std::string kdm_email () const {
232 boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
233 return _signer_chain;
236 boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
237 return _decryption_chain;
240 bool check_for_updates () const {
241 return _check_for_updates;
244 bool check_for_test_updates () const {
245 return _check_for_test_updates;
248 int maximum_j2k_bandwidth () const {
249 return _maximum_j2k_bandwidth;
252 int log_types () const {
256 bool analyse_ebur128 () const {
257 return _analyse_ebur128;
260 bool automatic_audio_analysis () const {
261 return _automatic_audio_analysis;
264 #ifdef DCPOMATIC_WINDOWS
265 bool win32_console () const {
266 return _win32_console;
270 std::vector<boost::filesystem::path> history () const {
274 std::vector<dcp::EncryptedKDM> dkdms () const {
278 boost::filesystem::path cinemas_file () const {
279 return _cinemas_file;
282 bool show_hints_before_make_dcp () const {
283 return _show_hints_before_make_dcp;
286 bool confirm_kdm_email () const {
287 return _confirm_kdm_email;
290 dcp::NameFormat kdm_container_name_format () const {
291 return _kdm_container_name_format;
294 dcp::NameFormat kdm_filename_format () const {
295 return _kdm_filename_format;
298 dcp::NameFormat dcp_metadata_filename_format () const {
299 return _dcp_metadata_filename_format;
302 dcp::NameFormat dcp_asset_filename_format () const {
303 return _dcp_asset_filename_format;
306 bool jump_to_selected () const {
307 return _jump_to_selected;
310 boost::optional<std::string> sound_output () const {
311 return _sound_output;
314 /** @param n New number of local encoding threads */
315 void set_num_local_encoding_threads (int n) {
316 maybe_set (_num_local_encoding_threads, n);
319 void set_default_directory (boost::filesystem::path d) {
320 if (_default_directory && *_default_directory == d) {
323 _default_directory = d;
327 /** @param p New server port */
328 void set_server_port_base (int p) {
329 maybe_set (_server_port_base, p);
332 void set_only_servers_encode (bool o) {
333 maybe_set (_only_servers_encode, o);
336 void set_tms_protocol (Protocol p) {
337 maybe_set (_tms_protocol, p);
340 /** @param i IP address of a TMS that we can copy DCPs to */
341 void set_tms_ip (std::string i) {
342 maybe_set (_tms_ip, i);
345 /** @param p Path on a TMS that we should changed DCPs to */
346 void set_tms_path (std::string p) {
347 maybe_set (_tms_path, p);
350 /** @param u User name to log into the TMS with */
351 void set_tms_user (std::string u) {
352 maybe_set (_tms_user, u);
355 /** @param p Password to log into the TMS with */
356 void set_tms_password (std::string p) {
357 maybe_set (_tms_password, p);
360 void add_cinema (boost::shared_ptr<Cinema> c) {
361 _cinemas.push_back (c);
365 void remove_cinema (boost::shared_ptr<Cinema> c) {
370 void set_allowed_dcp_frame_rates (std::list<int> const & r) {
371 maybe_set (_allowed_dcp_frame_rates, r);
374 void set_allow_any_dcp_frame_rate (bool a) {
375 maybe_set (_allow_any_dcp_frame_rate, a);
378 void set_default_isdcf_metadata (ISDCFMetadata d) {
379 maybe_set (_default_isdcf_metadata, d);
382 void set_language (std::string l) {
383 if (_language && _language.get() == l) {
390 void unset_language () {
395 _language = boost::none;
399 void set_default_still_length (int s) {
400 maybe_set (_default_still_length, s);
403 void set_default_container (Ratio const * c) {
404 maybe_set (_default_container, c);
407 void set_default_dcp_content_type (DCPContentType const * t) {
408 maybe_set (_default_dcp_content_type, t);
411 void set_default_dcp_audio_channels (int c) {
412 maybe_set (_default_dcp_audio_channels, c);
415 void set_dcp_issuer (std::string i) {
416 maybe_set (_dcp_issuer, i);
419 void set_dcp_creator (std::string c) {
420 maybe_set (_dcp_creator, c);
423 void set_default_j2k_bandwidth (int b) {
424 maybe_set (_default_j2k_bandwidth, b);
427 void set_default_audio_delay (int d) {
428 maybe_set (_default_audio_delay, d);
431 void set_default_interop (bool i) {
432 maybe_set (_default_interop, i);
435 void set_mail_server (std::string s) {
436 maybe_set (_mail_server, s);
439 void set_mail_port (int p) {
440 maybe_set (_mail_port, p);
443 void set_mail_user (std::string u) {
444 maybe_set (_mail_user, u);
447 void set_mail_password (std::string p) {
448 maybe_set (_mail_password, p);
451 void set_kdm_subject (std::string s) {
452 maybe_set (_kdm_subject, s);
455 void set_kdm_from (std::string f) {
456 maybe_set (_kdm_from, f);
459 void set_kdm_cc (std::vector<std::string> f) {
460 maybe_set (_kdm_cc, f);
463 void set_kdm_bcc (std::string f) {
464 maybe_set (_kdm_bcc, f);
467 void set_kdm_email (std::string e) {
468 maybe_set (_kdm_email, e);
471 void reset_kdm_email ();
473 void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
474 maybe_set (_signer_chain, s);
477 void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
478 maybe_set (_decryption_chain, c);
481 void set_check_for_updates (bool c) {
482 maybe_set (_check_for_updates, c);
484 set_check_for_test_updates (false);
488 void set_check_for_test_updates (bool c) {
489 maybe_set (_check_for_test_updates, c);
492 void set_maximum_j2k_bandwidth (int b) {
493 maybe_set (_maximum_j2k_bandwidth, b);
496 void set_log_types (int t) {
497 maybe_set (_log_types, t);
500 void set_analyse_ebur128 (bool a) {
501 maybe_set (_analyse_ebur128, a);
504 void set_automatic_audio_analysis (bool a) {
505 maybe_set (_automatic_audio_analysis, a);
508 #ifdef DCPOMATIC_WINDOWS
509 void set_win32_console (bool c) {
510 maybe_set (_win32_console, c);
514 void set_dkdms (std::vector<dcp::EncryptedKDM> dkdms) {
519 void set_cinemas_file (boost::filesystem::path file);
521 void set_show_hints_before_make_dcp (bool s) {
522 maybe_set (_show_hints_before_make_dcp, s);
525 void set_confirm_kdm_email (bool s) {
526 maybe_set (_confirm_kdm_email, s);
529 void set_sound_output (std::string o)
531 maybe_set (_sound_output, o, SOUND_OUTPUT);
534 void unset_sound_output ()
536 if (!_sound_output) {
540 _sound_output = boost::none;
544 void set_kdm_container_name_format (dcp::NameFormat n) {
545 maybe_set (_kdm_container_name_format, n);
548 void set_kdm_filename_format (dcp::NameFormat n) {
549 maybe_set (_kdm_filename_format, n);
552 void set_dcp_metadata_filename_format (dcp::NameFormat n) {
553 maybe_set (_dcp_metadata_filename_format, n);
556 void set_dcp_asset_filename_format (dcp::NameFormat n) {
557 maybe_set (_dcp_asset_filename_format, n);
560 void clear_history () {
565 void add_to_history (boost::filesystem::path p);
567 void set_jump_to_selected (bool j) {
568 maybe_set (_jump_to_selected, j);
571 void changed (Property p = OTHER);
572 boost::signals2::signal<void (Property)> Changed;
573 /** Emitted if read() failed on an existing Config file. There is nothing
574 a listener can do about it: this is just for information.
576 static boost::signals2::signal<void ()> FailedToLoad;
579 void write_config () const;
580 void write_cinemas () const;
582 void save_template (boost::shared_ptr<const Film> film, std::string name) const;
583 bool existing_template (std::string name) const;
584 std::list<std::string> templates () const;
585 boost::filesystem::path template_path (std::string name) const;
586 void rename_template (std::string old_name, std::string new_name) const;
587 void delete_template (std::string name) const;
589 static Config* instance ();
591 static void restore_defaults ();
592 static bool have_existing (std::string);
596 static boost::filesystem::path path (std::string file, bool create_directories = true);
598 void set_defaults ();
599 void set_kdm_email_to_default ();
600 void read_cinemas (cxml::Document const & f);
601 boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
602 boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
605 void maybe_set (T& member, T new_value, Property prop = OTHER) {
606 if (member == new_value) {
614 void maybe_set (boost::optional<T>& member, T new_value, Property prop = OTHER) {
615 if (member && member.get() == new_value) {
622 /** number of threads to use for J2K encoding on the local machine */
623 int _num_local_encoding_threads;
624 /** default directory to put new films in */
625 boost::optional<boost::filesystem::path> _default_directory;
626 /** base port number to use for J2K encoding servers;
627 * this port and the two above it will be used.
629 int _server_port_base;
630 /** true to broadcast on the `any' address to look for servers */
631 bool _use_any_servers;
632 /** J2K encoding servers that should definitely be used */
633 std::vector<std::string> _servers;
634 bool _only_servers_encode;
635 Protocol _tms_protocol;
636 /** The IP address of a TMS that we can copy DCPs to */
638 /** The path on a TMS that we should write DCPs to */
639 std::string _tms_path;
640 /** User name to log into the TMS with */
641 std::string _tms_user;
642 /** Password to log into the TMS with */
643 std::string _tms_password;
644 /** Our cinema sound processor */
645 CinemaSoundProcessor const * _cinema_sound_processor;
646 std::list<int> _allowed_dcp_frame_rates;
647 /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
648 bool _allow_any_dcp_frame_rate;
649 /** Default ISDCF metadata for newly-created Films */
650 ISDCFMetadata _default_isdcf_metadata;
651 boost::optional<std::string> _language;
652 /** Default length of still image content (seconds) */
653 int _default_still_length;
654 Ratio const * _default_container;
655 DCPContentType const * _default_dcp_content_type;
656 int _default_dcp_audio_channels;
657 std::string _dcp_issuer;
658 std::string _dcp_creator;
659 int _default_j2k_bandwidth;
660 int _default_audio_delay;
661 bool _default_interop;
662 /** Default directory to offer to write KDMs to; if it's not set,
663 the home directory will be offered.
665 boost::optional<boost::filesystem::path> _default_kdm_directory;
666 std::list<boost::shared_ptr<Cinema> > _cinemas;
667 std::string _mail_server;
669 std::string _mail_user;
670 std::string _mail_password;
671 std::string _kdm_subject;
672 std::string _kdm_from;
673 std::vector<std::string> _kdm_cc;
674 std::string _kdm_bcc;
675 std::string _kdm_email;
676 boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
677 /** Chain used to decrypt KDMs; the leaf of this chain is the target
678 * certificate for making KDMs given to DCP-o-matic.
680 boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
681 /** true to check for updates on startup */
682 bool _check_for_updates;
683 bool _check_for_test_updates;
684 /** maximum allowed J2K bandwidth in bits per second */
685 int _maximum_j2k_bandwidth;
687 bool _analyse_ebur128;
688 bool _automatic_audio_analysis;
689 #ifdef DCPOMATIC_WINDOWS
692 std::vector<boost::filesystem::path> _history;
693 std::vector<dcp::EncryptedKDM> _dkdms;
694 boost::filesystem::path _cinemas_file;
695 bool _show_hints_before_make_dcp;
696 bool _confirm_kdm_email;
697 dcp::NameFormat _kdm_filename_format;
698 dcp::NameFormat _kdm_container_name_format;
699 dcp::NameFormat _dcp_metadata_filename_format;
700 dcp::NameFormat _dcp_asset_filename_format;
701 bool _jump_to_selected;
702 /** name of a specific sound output stream to use for preview */
703 boost::optional<std::string> _sound_output;
705 /** Singleton instance, or 0 */
706 static Config* _instance;