diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-01-30 18:10:50 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-01-30 18:10:50 +0000 |
commit | d7707af16b008129ba98e9bd2187fcd4c7a0b299 (patch) | |
tree | 4f2da4ad4881528eeaaa237781b03b66be79accb /libs | |
parent | 06c8a2baefdb909e40be3c3656ee845de46db310 (diff) |
move LocaleGuard "up" into libpbd; use LocaleGuard to replace utterly broken std::locale() in Gtkmm2ext::BarController handling of logarithmic values
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6598 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/ardour.h | 6 | ||||
-rw-r--r-- | libs/ardour/audio_diskstream.cc | 1 | ||||
-rw-r--r-- | libs/ardour/audio_track.cc | 1 | ||||
-rw-r--r-- | libs/ardour/audio_unit.cc | 1 | ||||
-rw-r--r-- | libs/ardour/audioregion.cc | 1 | ||||
-rw-r--r-- | libs/ardour/automation_event.cc | 1 | ||||
-rw-r--r-- | libs/ardour/configuration.cc | 1 | ||||
-rw-r--r-- | libs/ardour/crossfade.cc | 2 | ||||
-rw-r--r-- | libs/ardour/globals.cc | 15 | ||||
-rw-r--r-- | libs/ardour/io.cc | 1 | ||||
-rw-r--r-- | libs/ardour/ladspa_plugin.cc | 2 | ||||
-rw-r--r-- | libs/ardour/lv2_plugin.cc | 1 | ||||
-rw-r--r-- | libs/ardour/panner.cc | 1 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 1 | ||||
-rw-r--r-- | libs/ardour/tempo.cc | 3 | ||||
-rw-r--r-- | libs/ardour/vst_plugin.cc | 1 | ||||
-rw-r--r-- | libs/gtkmm2ext/barcontroller.cc | 42 | ||||
-rw-r--r-- | libs/pbd/SConscript | 1 | ||||
-rw-r--r-- | libs/pbd/localeguard.cc | 21 | ||||
-rw-r--r-- | libs/pbd/pbd/localeguard.h | 33 |
20 files changed, 88 insertions, 48 deletions
diff --git a/libs/ardour/ardour/ardour.h b/libs/ardour/ardour/ardour.h index e900577ea1..cdd66a0da1 100644 --- a/libs/ardour/ardour/ardour.h +++ b/libs/ardour/ardour/ardour.h @@ -79,12 +79,6 @@ namespace ARDOUR { extern Change NameChanged; extern Change BoundsChanged; - struct LocaleGuard { - LocaleGuard (const char*); - ~LocaleGuard (); - const char* old; - }; - static const double SHUTTLE_FRACT_SPEED1=0.48412291827; /* derived from A1,A2 */ void setup_fpu (); diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index fe0523b6fc..6d96fd1350 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -32,6 +32,7 @@ #include <pbd/error.h> #include <pbd/basename.h> +#include <pbd/localeguard.h> #include <glibmm/thread.h> #include <pbd/xml++.h> #include <pbd/memento_command.h> diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index beec3ee4de..433ac1d1de 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -23,6 +23,7 @@ #include <pbd/error.h> #include <pbd/enumwriter.h> +#include <pbd/localeguard.h> #include <ardour/audio_track.h> #include <ardour/audio_diskstream.h> diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index e9a7d8b702..70fe96c0d2 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -28,6 +28,7 @@ #include <pbd/xml++.h> #include <pbd/whitespace.h> #include <pbd/pathscanner.h> +#include <pbd/localeguard.h> #include <glibmm/thread.h> #include <glibmm/fileutils.h> diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index ad7a295907..373f9fced7 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -34,6 +34,7 @@ #include <pbd/stacktrace.h> #include <pbd/enumwriter.h> #include <pbd/convert.h> +#include <pbd/localeguard.h> #include <ardour/audioregion.h> #include <ardour/session.h> diff --git a/libs/ardour/automation_event.cc b/libs/ardour/automation_event.cc index d5a7d50bb1..4b666b178b 100644 --- a/libs/ardour/automation_event.cc +++ b/libs/ardour/automation_event.cc @@ -26,6 +26,7 @@ #include <sigc++/bind.h> #include <ardour/automation_event.h> #include <pbd/stacktrace.h> +#include <pbd/localeguard.h> #include "i18n.h" diff --git a/libs/ardour/configuration.cc b/libs/ardour/configuration.cc index 819b78fb88..c8237616f2 100644 --- a/libs/ardour/configuration.cc +++ b/libs/ardour/configuration.cc @@ -26,6 +26,7 @@ #include <pbd/failed_constructor.h> #include <pbd/xml++.h> +#include <pbd/localeguard.h> #include <midi++/manager.h> diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index 0c0889fb1b..890a86a9cc 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -19,7 +19,7 @@ #include <sigc++/bind.h> -#include <pbd/stacktrace.h> +#include <pbd/localeguard.h> #include <ardour/types.h> #include <ardour/crossfade.h> diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 65740d5a5d..c6db415a88 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -24,7 +24,6 @@ #include <sys/resource.h> #include <unistd.h> #include <fcntl.h> -#include <locale.h> #include <errno.h> #ifdef VST_SUPPORT @@ -606,20 +605,6 @@ ARDOUR::find_data_file (string name, string subdir) return find_file (name, envvar, subdir); } -ARDOUR::LocaleGuard::LocaleGuard (const char* str) -{ - old = strdup (setlocale (LC_NUMERIC, NULL)); - if (strcmp (old, str)) { - setlocale (LC_NUMERIC, str); - } -} - -ARDOUR::LocaleGuard::~LocaleGuard () -{ - setlocale (LC_NUMERIC, old); - free ((char*)old); -} - void ARDOUR::setup_fpu () { diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 395cabd4e9..4fef59fe01 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -30,6 +30,7 @@ #include <pbd/xml++.h> #include <pbd/replace_all.h> +#include <pbd/localeguard.h> #include <ardour/audioengine.h> #include <ardour/io.h> diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index f9c8fa836c..2ca726a510 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -33,6 +33,7 @@ #include <pbd/error.h> #include <pbd/pathscanner.h> #include <pbd/xml++.h> +#include <pbd/localeguard.h> #include <midi++/manager.h> @@ -44,7 +45,6 @@ #include <pbd/stl_delete.h> #include "i18n.h" -#include <locale.h> using namespace std; using namespace ARDOUR; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index f2fbefd7cc..38c0843842 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -29,6 +29,7 @@ #include <pbd/error.h> #include <pbd/pathscanner.h> #include <pbd/xml++.h> +#include <pbd/localeguard.h> #include <ardour/ardour.h> #include <ardour/session.h> diff --git a/libs/ardour/panner.cc b/libs/ardour/panner.cc index 473354d29e..737c2e052a 100644 --- a/libs/ardour/panner.cc +++ b/libs/ardour/panner.cc @@ -33,6 +33,7 @@ #include <pbd/failed_constructor.h> #include <pbd/xml++.h> #include <pbd/enumwriter.h> +#include <pbd/localeguard.h> #include <ardour/session.h> #include <ardour/panner.h> diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index efdac5eae3..a63e0b5085 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -55,6 +55,7 @@ #include <pbd/strsplit.h> #include <pbd/stacktrace.h> #include <pbd/copyfile.h> +#include <pbd/localeguard.h> #include <ardour/audioengine.h> #include <ardour/configuration.h> diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 8414242b43..6c914424fd 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -25,7 +25,10 @@ #include <sigc++/bind.h> #include <glibmm/thread.h> + #include <pbd/xml++.h> +#include <pbd/localeguard.h> + #include <ardour/tempo.h> #include <ardour/utils.h> diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc index 37ea68eed3..a945f5c13c 100644 --- a/libs/ardour/vst_plugin.cc +++ b/libs/ardour/vst_plugin.cc @@ -40,6 +40,7 @@ #include <pbd/error.h> #include <pbd/pathscanner.h> #include <pbd/xml++.h> +#include <pbd/localeguard.h> #include <ardour/ardour.h> #include <ardour/session.h> diff --git a/libs/gtkmm2ext/barcontroller.cc b/libs/gtkmm2ext/barcontroller.cc index 775e6b4a8d..01e67e4010 100644 --- a/libs/gtkmm2ext/barcontroller.cc +++ b/libs/gtkmm2ext/barcontroller.cc @@ -25,6 +25,7 @@ #include <algorithm> #include <pbd/controllable.h> +#include <pbd/localeguard.h> #include <gtkmm2ext/gtk_ui.h> #include <gtkmm2ext/utils.h> @@ -108,13 +109,14 @@ BarController::entry_input (double* new_value) // extract a double from the string and take its log Entry *entry = dynamic_cast<Entry *>(&spinner); - stringstream stream(entry->get_text()); - stream.imbue(std::locale("")); - double value; - stream >> value; - - *new_value = log(value); + { + PBD::LocaleGuard lg (X_("POSIX")); + double value; + sscanf (entry->get_text().c_str(), "%g", &value); + *new_value = log(value); + } + return true; } @@ -141,27 +143,17 @@ BarController::entry_output () string str; size_t found; - // Gtk.Entry does not like the thousands separator, so we have to - // remove it after conversion from float to string. + // Be sure to use POSIX or C locale here so that + // we don't end up with commas (as used by some locales) + // in the text entry. - stream.imbue(std::locale("")); - stream.precision(spinner.get_digits()); - - stream << fixed << exp(spinner.get_adjustment()->get_value()); - - str=stream.str(); - - // find thousands separators, remove them - found = str.find(use_facet<numpunct<char> >(std::locale("")).thousands_sep()); - while(found != str.npos) { - str.erase(found,1); - - //find next - found = str.find(use_facet<numpunct<char> >(std::locale("")).thousands_sep()); + { + PBD::LocaleGuard lg (X_("POSIX")); + char buf[128]; + snprintf (buf, sizeof (buf), "%g", spinner.get_adjustment()->get_value()); + Entry *entry = dynamic_cast<Entry *>(&spinner); + entry->set_text (buf); } - - Entry *entry = dynamic_cast<Entry *>(&spinner); - entry->set_text(str); return true; } diff --git a/libs/pbd/SConscript b/libs/pbd/SConscript index 96d1a772b5..b33ab58173 100644 --- a/libs/pbd/SConscript +++ b/libs/pbd/SConscript @@ -29,6 +29,7 @@ dmalloc.cc error.cc fpu.cc id.cc +localeguard.cc mountpoint.cc path.cc pathscanner.cc diff --git a/libs/pbd/localeguard.cc b/libs/pbd/localeguard.cc new file mode 100644 index 0000000000..a97a99bfd3 --- /dev/null +++ b/libs/pbd/localeguard.cc @@ -0,0 +1,21 @@ +#include <cstring> +#include <locale.h> +#include <stdlib.h> + +#include "pbd/localeguard.h" + +PBD::LocaleGuard::LocaleGuard (const char* str) +{ + old = strdup (setlocale (LC_NUMERIC, NULL)); + if (strcmp (old, str)) { + setlocale (LC_NUMERIC, str); + } +} + +PBD::LocaleGuard::~LocaleGuard () +{ + setlocale (LC_NUMERIC, old); + free ((char*)old); +} + + diff --git a/libs/pbd/pbd/localeguard.h b/libs/pbd/pbd/localeguard.h new file mode 100644 index 0000000000..e03e4ce4f2 --- /dev/null +++ b/libs/pbd/pbd/localeguard.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 1999-2010 Paul Davis + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __pbd_localeguard_h__ +#define __pbd_localeguard_h__ + +namespace PBD { + +struct LocaleGuard { + LocaleGuard (const char*); + ~LocaleGuard (); + const char* old; +}; + +}; // namespace + +#endif /* __pbd_localeguard_h__ */ |