Allow configuration of default audio delay (#276).
[dcpomatic.git] / src / lib / config.cc
index 54b9168f2542a1bbd8ee49d0b933f4c95007ada2..93eec9bc0330fb4258f3f90d78de59759adc83b7 100644 (file)
@@ -64,6 +64,7 @@ Config::Config ()
        , _default_container (Ratio::from_id ("185"))
        , _default_dcp_content_type (DCPContentType::from_dci_name ("TST"))
        , _default_j2k_bandwidth (200000000)
+       , _default_audio_delay (0)
        , _kdm_email (
                "Dear Projectionist\n\nPlease find attached KDMs for $CPL_NAME.\n\nBest regards,\nDCP-o-matic"
                )
@@ -145,6 +146,7 @@ Config::read ()
        _default_dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
        _default_still_length = f.optional_number_child<int>("DefaultStillLength").get_value_or (10);
        _default_j2k_bandwidth = f.optional_number_child<int>("DefaultJ2KBandwidth").get_value_or (200000000);
+       _default_audio_delay = f.optional_number_child<int>("DefaultAudioDelay").get_value_or (0);
 
        list<cxml::NodePtr> cc = f.node_children ("ColourConversion");
 
@@ -334,6 +336,7 @@ Config::write () const
 
        root->add_child("DefaultStillLength")->add_child_text (lexical_cast<string> (_default_still_length));
        root->add_child("DefaultJ2KBandwidth")->add_child_text (lexical_cast<string> (_default_j2k_bandwidth));
+       root->add_child("DefaultAudioDelay")->add_child_text (lexical_cast<string> (_default_audio_delay));
 
        for (vector<PresetColourConversion>::const_iterator i = _colour_conversions.begin(); i != _colour_conversions.end(); ++i) {
                i->as_xml (root->add_child ("ColourConversion"));
@@ -353,7 +356,13 @@ Config::write () const
 boost::filesystem::path
 Config::default_directory_or (boost::filesystem::path a) const
 {
-       if (_default_directory.empty() || !boost::filesystem::exists (_default_directory)) {
+       if (_default_directory.empty()) {
+               return a;
+       }
+
+       boost::system::error_code ec;
+       bool const e = boost::filesystem::exists (_default_directory, ec);
+       if (ec || !e) {
                return a;
        }