diff --git a/compile.mk b/compile.mk index 42c45335..d3063d41 100644 --- a/compile.mk +++ b/compile.mk @@ -8,9 +8,11 @@ OBJCOPY ?= objcopy # Generate dependency files alongside the object files FLAGS += -MMD -MP +# Debugger symbols. These are removed with `strip`. FLAGS += -g # Optimization -FLAGS += -O3 -march=nocona -ffast-math -fno-finite-math-only +FLAGS += -O3 -march=nocona +# Warnings FLAGS += -Wall -Wextra -Wno-unused-parameter ifneq ($(ARCH), mac) diff --git a/include/math.hpp b/include/math.hpp index 70c89197..a379d2b4 100644 --- a/include/math.hpp +++ b/include/math.hpp @@ -103,6 +103,11 @@ inline float sgn(float x) { return x > 0.f ? 1.f : x < 0.f ? -1.f : 0.f; } +/** Converts -0.f to 0.f. Leaves all other values unchanged. */ +inline float normalizeZero(float x) { + return x + 0.f; +} + inline float eucMod(float a, float base) { float mod = std::fmod(a, base); return (mod >= 0.0f) ? mod : mod + base; diff --git a/include/ui/Quantity.hpp b/include/ui/Quantity.hpp index cd3f81f3..182a05e2 100644 --- a/include/ui/Quantity.hpp +++ b/include/ui/Quantity.hpp @@ -1,7 +1,6 @@ #pragma once #include "ui/common.hpp" #include "math.hpp" -#include "string.hpp" namespace rack { @@ -46,16 +45,9 @@ struct Quantity { virtual int getDisplayPrecision() {return 2;} /** Returns a string representation of the display value */ - virtual std::string getDisplayValueString() { - return string::f("%.*f", getDisplayPrecision(), getDisplayValue()); - } + virtual std::string getDisplayValueString(); - virtual void setDisplayValueString(std::string s) { - float displayValue = 0.f; - int n = std::sscanf(s.c_str(), "%f", &displayValue); - if (n == 1) - setDisplayValue(displayValue); - } + virtual void setDisplayValueString(std::string s); /** The name of the quantity */ virtual std::string getLabel() {return "";} @@ -66,14 +58,7 @@ struct Quantity { virtual std::string getUnit() {return "";} /** Returns a string representation of the quantity */ - virtual std::string getString() { - std::string s; - std::string label = getLabel(); - if (!label.empty()) - s += label + ": "; - s += getDisplayValueString() + getUnit(); - return s; - } + virtual std::string getString(); // Helper methods diff --git a/src/ui/Quantity.cpp b/src/ui/Quantity.cpp new file mode 100644 index 00000000..f2302f5d --- /dev/null +++ b/src/ui/Quantity.cpp @@ -0,0 +1,29 @@ +#include "ui/Quantity.hpp" +#include "string.hpp" + + +namespace rack { + + +std::string Quantity::getDisplayValueString() { + return string::f("%.*f", getDisplayPrecision(), math::normalizeZero(getDisplayValue())); +} + +void Quantity::setDisplayValueString(std::string s) { + float displayValue = 0.f; + int n = std::sscanf(s.c_str(), "%f", &displayValue); + if (n == 1) + setDisplayValue(displayValue); +} + +std::string Quantity::getString() { + std::string s; + std::string label = getLabel(); + if (!label.empty()) + s += label + ": "; + s += getDisplayValueString() + getUnit(); + return s; +} + + +} // namespace rack