From 1a1d4b22589d5832dd594a65054d9261f9f496cf Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 13 Mar 2016 01:37:44 +0000 Subject: [PATCH] Accept either , or . for a decimal separator in the gain calculator. --- src/lib/util.cc | 16 +++++++++++++++- src/lib/util.h | 1 + src/wx/gain_calculator_dialog.cc | 10 ++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/lib/util.cc b/src/lib/util.cc index f434f358e..61c9dac06 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2016 Carl Hetherington 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 asset) { return "pcm_" + asset->id() + ".mxf"; } + +float +relaxed_string_to_float (string s) +{ + try { + boost::algorithm::replace_all (s, ",", "."); + return lexical_cast (s); + } catch (bad_lexical_cast) { + boost::algorithm::replace_all (s, ".", ","); + return lexical_cast (s); + } +} diff --git a/src/lib/util.h b/src/lib/util.h index 5cfdae5f9..640933f00 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -74,5 +74,6 @@ extern void set_backtrace_file (boost::filesystem::path); extern std::map split_get_request (std::string url); extern std::string video_asset_filename (boost::shared_ptr asset); extern std::string audio_asset_filename (boost::shared_ptr asset); +extern float relaxed_string_to_float (std::string); #endif diff --git a/src/wx/gain_calculator_dialog.cc b/src/wx/gain_calculator_dialog.cc index a840aebef..418ec2e77 100644 --- a/src/wx/gain_calculator_dialog.cc +++ b/src/wx/gain_calculator_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2016 Carl Hetherington 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 @@ -17,11 +17,9 @@ */ -#include #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 (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 (wx_to_std (_actual->GetValue ())); + return relaxed_string_to_float (wx_to_std (_actual->GetValue ())); } -- 2.30.2