Accept either , or . for a decimal separator in the gain calculator.
authorCarl Hetherington <cth@carlh.net>
Sun, 13 Mar 2016 01:37:44 +0000 (01:37 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 13 Mar 2016 01:37:44 +0000 (01:37 +0000)
src/lib/util.cc
src/lib/util.h
src/wx/gain_calculator_dialog.cc

index f434f358e38982c1ee7f6c3afe9b830d070c81a3..61c9dac068479ca179f6d2935609e77a6e2bfc19 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -85,6 +85,8 @@ using std::set_terminate;
 using boost::shared_ptr;
 using boost::thread;
 using boost::optional;
+using boost::lexical_cast;
+using boost::bad_lexical_cast;
 using dcp::Size;
 
 /** Path to our executable, required by the stacktrace stuff and filled
@@ -622,3 +624,15 @@ audio_asset_filename (shared_ptr<dcp::SoundAsset> asset)
 {
        return "pcm_" + asset->id() + ".mxf";
 }
+
+float
+relaxed_string_to_float (string s)
+{
+       try {
+               boost::algorithm::replace_all (s, ",", ".");
+               return lexical_cast<float> (s);
+       } catch (bad_lexical_cast) {
+               boost::algorithm::replace_all (s, ".", ",");
+               return lexical_cast<float> (s);
+       }
+}
index 5cfdae5f9b0b2b7fb09046cf79c029f2d6dd05ba..640933f00e573c9e08ccfa155fdf933de721b069 100644 (file)
@@ -74,5 +74,6 @@ extern void set_backtrace_file (boost::filesystem::path);
 extern std::map<std::string, std::string> split_get_request (std::string url);
 extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset);
 extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset);
+extern float relaxed_string_to_float (std::string);
 
 #endif
index a840aebef4ad7a64f94691f3ed6461fe7bc45f1d..418ec2e7719b3eefba026e3b65e3780583552c76 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#include <boost/lexical_cast.hpp>
 #include "gain_calculator_dialog.h"
 #include "wx_util.h"
-
-using namespace boost;
+#include "lib/util.h"
 
 GainCalculatorDialog::GainCalculatorDialog (wxWindow* parent)
        : TableDialog (parent, _("Gain Calculator"), 2, 1, true)
@@ -42,7 +40,7 @@ GainCalculatorDialog::wanted_fader () const
                return 0;
        }
 
-       return lexical_cast<float> (wx_to_std (_wanted->GetValue ()));
+       return relaxed_string_to_float (wx_to_std (_wanted->GetValue ()));
 }
 
 float
@@ -52,5 +50,5 @@ GainCalculatorDialog::actual_fader () const
                return 0;
        }
 
-       return lexical_cast<float> (wx_to_std (_actual->GetValue ()));
+       return relaxed_string_to_float (wx_to_std (_actual->GetValue ()));
 }