| @@ -8,9 +8,11 @@ OBJCOPY ?= objcopy | |||||
| # Generate dependency files alongside the object files | # Generate dependency files alongside the object files | ||||
| FLAGS += -MMD -MP | FLAGS += -MMD -MP | ||||
| # Debugger symbols. These are removed with `strip`. | |||||
| FLAGS += -g | FLAGS += -g | ||||
| # Optimization | # Optimization | ||||
| FLAGS += -O3 -march=nocona -ffast-math -fno-finite-math-only | |||||
| FLAGS += -O3 -march=nocona | |||||
| # Warnings | |||||
| FLAGS += -Wall -Wextra -Wno-unused-parameter | FLAGS += -Wall -Wextra -Wno-unused-parameter | ||||
| ifneq ($(ARCH), mac) | ifneq ($(ARCH), mac) | ||||
| @@ -103,6 +103,11 @@ inline float sgn(float x) { | |||||
| return x > 0.f ? 1.f : x < 0.f ? -1.f : 0.f; | 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) { | inline float eucMod(float a, float base) { | ||||
| float mod = std::fmod(a, base); | float mod = std::fmod(a, base); | ||||
| return (mod >= 0.0f) ? mod : mod + base; | return (mod >= 0.0f) ? mod : mod + base; | ||||
| @@ -1,7 +1,6 @@ | |||||
| #pragma once | #pragma once | ||||
| #include "ui/common.hpp" | #include "ui/common.hpp" | ||||
| #include "math.hpp" | #include "math.hpp" | ||||
| #include "string.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -46,16 +45,9 @@ struct Quantity { | |||||
| virtual int getDisplayPrecision() {return 2;} | virtual int getDisplayPrecision() {return 2;} | ||||
| /** Returns a string representation of the display value */ | /** 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 */ | /** The name of the quantity */ | ||||
| virtual std::string getLabel() {return "";} | virtual std::string getLabel() {return "";} | ||||
| @@ -66,14 +58,7 @@ struct Quantity { | |||||
| virtual std::string getUnit() {return "";} | virtual std::string getUnit() {return "";} | ||||
| /** Returns a string representation of the quantity */ | /** 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 | // Helper methods | ||||
| @@ -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 | |||||