diff --git a/include/lmms_math.h b/include/lmms_math.h index a0f43c3e6f9..c68af071942 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -323,31 +323,6 @@ inline float safeDbfsToAmp(float dbfs) } -// TODO C++20: use std::formatted_size -// @brief Calculate number of digits which LcdSpinBox would show for a given number -inline int numDigitsAsInt(float f) -{ - // use rounding: - // LcdSpinBox sometimes uses std::round(), sometimes cast rounding - // we use rounding to be on the "safe side" - int asInt = static_cast(std::round(f)); - int digits = 1; // always at least 1 - if(asInt < 0) - { - ++digits; - asInt = -asInt; - } - // "asInt" is positive from now - int power = 1; - for (int i = 1; i < 10; ++i) - { - power *= 10; - if (asInt >= power) { ++digits; } // 2 digits for >=10, 3 for >=100 - else { break; } - } - return digits; -} - template class LinearMap { diff --git a/src/gui/Lv2ViewBase.cpp b/src/gui/Lv2ViewBase.cpp index 0cd6a0ee4b7..44ea4c08d10 100644 --- a/src/gui/Lv2ViewBase.cpp +++ b/src/gui/Lv2ViewBase.cpp @@ -26,6 +26,7 @@ #ifdef LMMS_HAVE_LV2 +#include #include #include #include @@ -74,10 +75,11 @@ Lv2ViewProc::Lv2ViewProc(QWidget* parent, Lv2Proc* proc, int colNum) : break; case PortVis::Integer: { - sample_rate_t sr = Engine::audioEngine()->outputSampleRate(); - auto pMin = port.min(sr); - auto pMax = port.max(sr); - int numDigits = std::max(numDigitsAsInt(pMin), numDigitsAsInt(pMax)); + const sample_rate_t sr = Engine::audioEngine()->outputSampleRate(); + const auto numDigits = std::max( + std::formatted_size("{}", static_cast(std::round(port.min(sr)))), + std::formatted_size("{}", static_cast(std::round(port.max(sr)))) + ); m_control = new LcdControl(numDigits, m_parent); break; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b70d9fde9eb..1193acd6cf3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,7 +7,6 @@ set(LMMS_TESTS src/core/ArrayVectorTest.cpp src/core/AudioBufferTest.cpp src/core/AutomatableModelTest.cpp - src/core/MathTest.cpp src/core/ProjectVersionTest.cpp src/core/RelativePathsTest.cpp src/core/TimelineTest.cpp diff --git a/tests/src/core/MathTest.cpp b/tests/src/core/MathTest.cpp deleted file mode 100644 index 544f04f4da5..00000000000 --- a/tests/src/core/MathTest.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MathTest.cpp - * - * Copyright (c) 2023 Johannes Lorenz - * - * This file is part of LMMS - https://lmms.io - * - * 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 (see COPYING); if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - */ - -#include -#include - -#include "lmms_math.h" - -class MathTest : public QObject -{ - Q_OBJECT -private slots: - void NumDigitsTest() - { - using namespace lmms; - QCOMPARE(numDigitsAsInt(1.f), 1); - QCOMPARE(numDigitsAsInt(9.9f), 2); - QCOMPARE(numDigitsAsInt(10.f), 2); - QCOMPARE(numDigitsAsInt(0.f), 1); - QCOMPARE(numDigitsAsInt(-100.f), 4); - QCOMPARE(numDigitsAsInt(-99.f), 3); - QCOMPARE(numDigitsAsInt(-0.4f), 1); // there is no "-0" for LED spinbox - QCOMPARE(numDigitsAsInt(-0.99f), 2); - QCOMPARE(numDigitsAsInt(1000000000), 10); - QCOMPARE(numDigitsAsInt(-1000000000), 11); - QCOMPARE(numDigitsAsInt(900000000), 9); - QCOMPARE(numDigitsAsInt(-900000000), 10); - } -}; - -QTEST_GUILESS_MAIN(MathTest) -#include "MathTest.moc"