Signed-off-by: falkTX <falktx@gmail.com>tags/v2.1-alpha2
| @@ -842,7 +842,7 @@ protected: | |||
| carla_zeroChars(tmpBuf, STR_MAX); | |||
| { | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| std::sprintf(tmpBuf, "%f\n", newSampleRate); | |||
| } | |||
| @@ -943,7 +943,7 @@ protected: | |||
| carla_zeroChars(tmpBuf, STR_MAX); | |||
| const CarlaMutexLocker cml(fUiServer.getPipeLock()); | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| const uint pluginId(plugin->getId()); | |||
| @@ -1191,7 +1191,7 @@ protected: | |||
| if (! fUiServer.writeMessage(tmpBuf)) | |||
| return; | |||
| { | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| std::sprintf(tmpBuf, "%f\n", static_cast<double>(value3)); | |||
| } | |||
| if (! fUiServer.writeMessage(tmpBuf)) | |||
| @@ -1253,7 +1253,7 @@ protected: | |||
| if (! fUiServer.writeAndFixMessage("sample-rate")) | |||
| return; | |||
| { | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| std::sprintf(tmpBuf, "%f\n", pData->sampleRate); | |||
| } | |||
| if (! fUiServer.writeMessage(tmpBuf)) | |||
| @@ -1807,7 +1807,7 @@ protected: | |||
| carla_zeroChars(tmpBuf, STR_MAX); | |||
| const CarlaMutexLocker cml(fUiServer.getPipeLock()); | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| const EngineTimeInfo& timeInfo(pData->timeInfo); | |||
| // send transport | |||
| @@ -459,15 +459,18 @@ public: | |||
| bool startPipeServer(const int size) noexcept | |||
| { | |||
| char sampleRateStr[32]; | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| std::snprintf(sampleRateStr, 31, "%f", kEngine->getSampleRate()); | |||
| } | |||
| sampleRateStr[31] = '\0'; | |||
| const ScopedEngineEnvironmentLocker _seel(kEngine); | |||
| const ScopedEnvVar _sev1("LV2_PATH", kEngine->getOptions().pathLV2); | |||
| #ifdef CARLA_OS_LINUX | |||
| const ScopedEnvVar _sev2("LD_PRELOAD", nullptr); | |||
| #endif | |||
| char sampleRateStr[32]; | |||
| carla_zeroChars(sampleRateStr, 32); | |||
| std::snprintf(sampleRateStr, 31, "%f", kEngine->getSampleRate()); | |||
| carla_setenv("CARLA_SAMPLE_RATE", sampleRateStr); | |||
| return CarlaPipeServer::startPipeServer(fFilename, fPluginURI, fUiURI, size); | |||
| @@ -1346,7 +1349,7 @@ public: | |||
| tmpBuf[0xff] = '\0'; | |||
| const CarlaMutexLocker cml(fPipeServer.getPipeLock()); | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| // write URI mappings | |||
| uint32_t u = 0; | |||
| @@ -1213,7 +1213,10 @@ int main(int argc, const char* argv[]) | |||
| // try to get sampleRate value | |||
| if (const char* const sampleRateStr = std::getenv("CARLA_SAMPLE_RATE")) | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| gInitialSampleRate = std::atof(sampleRateStr); | |||
| } | |||
| // Init LV2 client | |||
| CarlaLv2Client client; | |||
| @@ -306,7 +306,6 @@ protected: | |||
| const uint32_t bar = static_cast<uint32_t>(std::floor(fullBeats/beatsPerBar)); | |||
| const CarlaMutexLocker cml(getPipeLock()); | |||
| const ScopedLocale csl; | |||
| if (! writeAndFixMessage("transport")) | |||
| return; | |||
| @@ -317,10 +316,13 @@ protected: | |||
| if (! writeMessage(strBuf)) | |||
| return; | |||
| std::sprintf(strBuf, "%f:%f:%f\n", | |||
| static_cast<double>(beatsPerMinute), | |||
| static_cast<double>(beatsPerBar), | |||
| static_cast<double>(beatType)); | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| std::sprintf(strBuf, "%f:%f:%f\n", | |||
| static_cast<double>(beatsPerMinute), | |||
| static_cast<double>(beatsPerBar), | |||
| static_cast<double>(beatType)); | |||
| } | |||
| if (! writeMessage(strBuf)) | |||
| return; | |||
| @@ -21,6 +21,7 @@ | |||
| #include "CarlaLv2Utils.hpp" | |||
| #include "CarlaPipeUtils.hpp" | |||
| #include "CarlaScopedLocale.hpp" | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| @@ -137,7 +138,7 @@ public: | |||
| const float* const valuePtr = (const float*)buffer; | |||
| { | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| std::snprintf(msg, 127, "control %u %f", portIndex, static_cast<double>(*valuePtr)); | |||
| } | |||
| @@ -419,7 +419,7 @@ public: | |||
| float value; | |||
| { | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| value = static_cast<float>(std::atof(msgSplit+1)); | |||
| } | |||
| @@ -31,7 +31,6 @@ | |||
| # include "lv2/lv2plug.in/ns/ext/atom/util.h" | |||
| #endif | |||
| #include <clocale> | |||
| #include <fcntl.h> | |||
| #include "water/misc/Time.h" | |||
| @@ -827,7 +826,10 @@ bool CarlaPipeCommon::readNextLineAsFloat(float& value) const noexcept | |||
| if (const char* const msg = _readlineblock()) | |||
| { | |||
| value = static_cast<float>(std::atof(msg)); | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| value = static_cast<float>(std::atof(msg)); | |||
| } | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| @@ -841,7 +843,10 @@ bool CarlaPipeCommon::readNextLineAsDouble(double& value) const noexcept | |||
| if (const char* const msg = _readlineblock()) | |||
| { | |||
| value = std::atof(msg); | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| value = std::atof(msg); | |||
| } | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| @@ -983,7 +988,7 @@ void CarlaPipeCommon::writeControlMessage(const uint32_t index, const float valu | |||
| return; | |||
| { | |||
| const ScopedLocale csl; | |||
| const CarlaScopedLocale csl; | |||
| std::snprintf(tmpBuf, 0xff, "%f\n", static_cast<double>(value)); | |||
| } | |||
| @@ -1890,22 +1895,6 @@ ScopedEnvVar::~ScopedEnvVar() noexcept | |||
| } | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| ScopedLocale::ScopedLocale() noexcept | |||
| : fLocale(carla_strdup_safe(::setlocale(LC_NUMERIC, nullptr))) | |||
| { | |||
| ::setlocale(LC_NUMERIC, "C"); | |||
| } | |||
| ScopedLocale::~ScopedLocale() noexcept | |||
| { | |||
| if (fLocale != nullptr) | |||
| { | |||
| ::setlocale(LC_NUMERIC, fLocale); | |||
| delete[] fLocale; | |||
| } | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| @@ -357,21 +357,6 @@ private: | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| // ScopedLocale class | |||
| class ScopedLocale { | |||
| public: | |||
| ScopedLocale() noexcept; | |||
| ~ScopedLocale() noexcept; | |||
| private: | |||
| const char* const fLocale; | |||
| CARLA_DECLARE_NON_COPY_CLASS(ScopedLocale) | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| #endif // CARLA_PIPE_UTILS_HPP_INCLUDED | |||
| @@ -0,0 +1,54 @@ | |||
| /* | |||
| * Carla Scoped Locale | |||
| * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * 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 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. | |||
| * | |||
| * For a full copy of the GNU General Public License see the doc/GPL.txt file. | |||
| */ | |||
| #ifndef CARLA_SCOPED_LOCALE_HPP_INCLUDED | |||
| #define CARLA_SCOPED_LOCALE_HPP_INCLUDED | |||
| #include "CarlaUtils.hpp" | |||
| #include <clocale> | |||
| // ----------------------------------------------------------------------- | |||
| // CarlaScopedLocale class | |||
| class CarlaScopedLocale { | |||
| public: | |||
| CarlaScopedLocale() noexcept | |||
| : fLocale(carla_strdup_safe(::setlocale(LC_NUMERIC, nullptr))) | |||
| { | |||
| ::setlocale(LC_NUMERIC, "C"); | |||
| } | |||
| ~CarlaScopedLocale() noexcept | |||
| { | |||
| if (fLocale != nullptr) | |||
| { | |||
| ::setlocale(LC_NUMERIC, fLocale); | |||
| delete[] fLocale; | |||
| } | |||
| } | |||
| private: | |||
| const char* const fLocale; | |||
| CARLA_DECLARE_NON_COPY_CLASS(CarlaScopedLocale) | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| #endif // CARLA_SCOPED_LOCALE_HPP_INCLUDED | |||
| @@ -20,6 +20,7 @@ | |||
| #include "CarlaMathUtils.hpp" | |||
| #include "CarlaJuceUtils.hpp" | |||
| #include "CarlaScopedLocale.hpp" | |||
| #include <algorithm> | |||
| @@ -176,7 +177,12 @@ public: | |||
| fBufferAlloc(false) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%f", static_cast<double>(value)); | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| std::snprintf(strBuf, 0xff, "%f", static_cast<double>(value)); | |||
| } | |||
| strBuf[0xff] = '\0'; | |||
| _dup(strBuf); | |||
| @@ -191,7 +197,12 @@ public: | |||
| fBufferAlloc(false) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%f", value); | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| std::snprintf(strBuf, 0xff, "%f", value); | |||
| } | |||
| strBuf[0xff] = '\0'; | |||
| _dup(strBuf); | |||