Import Ardour's LocaleGuard to fix problems with saving decimals to metadata (#119).
authorCarl Hetherington <cth@carlh.net>
Sat, 20 Apr 2013 19:45:32 +0000 (20:45 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 20 Apr 2013 19:45:32 +0000 (20:45 +0100)
ChangeLog
src/lib/film.cc
src/lib/util.cc
src/lib/util.h

index 85cdb48a6ea9c342b7099988bb85c719c96cd1ce..0fbb73773170f5bef650e6888ba0e78f1fda6eb9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-04-20  Carl Hetherington  <cth@carlh.net>
+
+       * Fix bad saving of metadata in locales which use
+       commas to separate decimals (#119).
+
 2013-04-19  Carl Hetherington  <cth@carlh.net>
 
        * Add basic frame index and timecode to viewer, and previous/next
index 227f8557bcb1058ae5cd8a0a7f044e88aad7b150..b0785df34aeba5e1eb7b203dc124b6f031637068 100644 (file)
@@ -204,6 +204,7 @@ string
 Film::video_state_identifier () const
 {
        assert (format ());
+       LocaleGuard lg;
 
        pair<string, string> f = Filter::ffmpeg_strings (filters());
 
@@ -428,6 +429,7 @@ void
 Film::write_metadata () const
 {
        boost::mutex::scoped_lock lm (_state_mutex);
+       LocaleGuard lg;
 
        boost::filesystem::create_directories (directory());
 
@@ -515,6 +517,7 @@ void
 Film::read_metadata ()
 {
        boost::mutex::scoped_lock lm (_state_mutex);
+       LocaleGuard lg;
 
        _external_audio.clear ();
        _content_audio_streams.clear ();
index 557e9a34bd26563406292c7dce8cbfde55794426..e43b598ab3ef3e635baac415cce0ad7f511c47fd 100644 (file)
@@ -1018,3 +1018,22 @@ FrameRateConversion::FrameRateConversion (float source, int dcp)
                }
        }
 }
+
+LocaleGuard::LocaleGuard ()
+       : _old (0)
+{
+       char const * old = setlocale (LC_NUMERIC, 0);
+
+        if (old) {
+                _old = strdup (old);
+                if (strcmp (_old, "POSIX")) {
+                        setlocale (LC_NUMERIC, "POSIX");
+                }
+        }
+}
+
+LocaleGuard::~LocaleGuard ()
+{
+       setlocale (LC_NUMERIC, _old);
+       free (_old);
+}
index 3d251cf06ad0d1d9ca36816ea438fdd41d26a680..31d0fc96707fb976759fed42e69b51225a845389 100644 (file)
@@ -293,5 +293,16 @@ extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_r
 extern bool still_image_file (std::string);
 extern std::pair<std::string, int> cpu_info ();
 
+class LocaleGuard
+{
+public:
+       LocaleGuard ();
+       ~LocaleGuard ();
+       
+private:
+       char* _old;
+};
+
+
 #endif