From 9a443f07c8c896f052f2c4d50ebc85abe5154ec1 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 3 Feb 2018 10:58:15 -0500 Subject: [PATCH] Refactoring, remove "f" and "i" prefixes from math.hpp functions --- include/app.hpp | 13 +++- include/componentlibrary.hpp | 26 ++++---- include/dsp/filter.hpp | 2 +- include/dsp/ringbuffer.hpp | 2 +- include/dsp/vumeter.hpp | 2 +- include/util/common.hpp | 16 ++--- include/util/math.hpp | 105 +++++++++++++++++++-------------- src/app/LightWidget.cpp | 8 +-- src/app/ModuleLightWidget.cpp | 2 +- src/app/ParamWidget.cpp | 2 +- src/app/RackWidget.cpp | 4 +- src/app/SVGFader.cpp | 2 +- src/app/SVGKnob.cpp | 2 +- src/app/SVGPanel.cpp | 2 +- src/app/SVGSwitch.cpp | 4 +- src/app/SpriteKnob.cpp | 2 +- src/audio.cpp | 4 +- src/core/MidiClockToCV.cpp | 4 +- src/settings.cpp | 2 +- src/widgets/ProgressBar.cpp | 2 +- src/widgets/QuantityWidget.cpp | 2 +- src/widgets/Slider.cpp | 2 +- src/widgets/TextField.cpp | 4 +- 23 files changed, 122 insertions(+), 92 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index 6db43862..1ab3a233 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -4,7 +4,8 @@ #include "widgets.hpp" -#define SVG_DPI 75.0 +static const float SVG_DPI = 75.0; +static const float MM_PER_IN = 25.4; #define CHECKMARK_STRING "✔" #define CHECKMARK(_cond) ((_cond) ? CHECKMARK_STRING : "") @@ -12,12 +13,20 @@ namespace rack { +inline float in2px(float inches) { + return inches * SVG_DPI; +} + inline Vec in2px(Vec inches) { return inches.mult(SVG_DPI); } +inline float mm2px(float millimeters) { + return millimeters * (SVG_DPI / MM_PER_IN); +} + inline Vec mm2px(Vec millimeters) { - return millimeters.mult(SVG_DPI / 25.4); + return millimeters.mult(SVG_DPI / MM_PER_IN); } diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index 4bc68fe9..c5de23e7 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -10,16 +10,18 @@ namespace rack { // Colors //////////////////// -#define COLOR_BLACK_TRANSPARENT nvgRGBA(0x00, 0x00, 0x00, 0x00) -#define COLOR_BLACK nvgRGB(0x00, 0x00, 0x00) -#define COLOR_WHITE nvgRGB(0xff, 0xff, 0xff) -#define COLOR_RED nvgRGB(0xed, 0x2c, 0x24) -#define COLOR_ORANGE nvgRGB(0xf2, 0xb1, 0x20) -#define COLOR_YELLOW nvgRGB(0xf9, 0xdf, 0x1c) -#define COLOR_GREEN nvgRGB(0x90, 0xc7, 0x3e) -#define COLOR_CYAN nvgRGB(0x22, 0xe6, 0xef) -#define COLOR_BLUE nvgRGB(0x29, 0xb2, 0xef) -#define COLOR_PURPLE nvgRGB(0xd5, 0x2b, 0xed) +static const NVGcolor COLOR_BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00); +static const NVGcolor COLOR_BLACK = nvgRGB(0x00, 0x00, 0x00); +static const NVGcolor COLOR_WHITE = nvgRGB(0xff, 0xff, 0xff); +static const NVGcolor COLOR_RED = nvgRGB(0xed, 0x2c, 0x24); +static const NVGcolor COLOR_ORANGE = nvgRGB(0xf2, 0xb1, 0x20); +static const NVGcolor COLOR_YELLOW = nvgRGB(0xf9, 0xdf, 0x1c); +static const NVGcolor COLOR_GREEN = nvgRGB(0x90, 0xc7, 0x3e); +static const NVGcolor COLOR_CYAN = nvgRGB(0x22, 0xe6, 0xef); +static const NVGcolor COLOR_BLUE = nvgRGB(0x29, 0xb2, 0xef); +static const NVGcolor COLOR_PURPLE = nvgRGB(0xd5, 0x2b, 0xed); +static const NVGcolor COLOR_LIGHT_PANEL = nvgRGB(0xe6, 0xe6, 0xe6); +static const NVGcolor COLOR_DARK_PANEL = nvgRGB(0x17, 0x17, 0x17); //////////////////// // Knobs @@ -553,13 +555,13 @@ struct ScrewBlack : SVGScrew { struct LightPanel : Panel { LightPanel() { - backgroundColor = nvgRGB(0xe6, 0xe6, 0xe6); + backgroundColor = COLOR_LIGHT_PANEL; } }; struct DarkPanel : Panel { DarkPanel() { - backgroundColor = nvgRGB(0x17, 0x17, 0x17); + backgroundColor = COLOR_DARK_PANEL; } }; diff --git a/include/dsp/filter.hpp b/include/dsp/filter.hpp index f2e9eb2a..ad4d5aea 100644 --- a/include/dsp/filter.hpp +++ b/include/dsp/filter.hpp @@ -57,7 +57,7 @@ struct SlewLimiter { fall = _fall; } float process(float in) { - float delta = clampf(in - out, -fall, rise); + float delta = clamp(in - out, -fall, rise); out += delta; return out; } diff --git a/include/dsp/ringbuffer.hpp b/include/dsp/ringbuffer.hpp index 8ac80300..0a0d1ed6 100644 --- a/include/dsp/ringbuffer.hpp +++ b/include/dsp/ringbuffer.hpp @@ -89,7 +89,7 @@ struct DoubleRingBuffer { void endIncr(int n) { int e = mask(end); int e1 = e + n; - int e2 = mini(e1, S); + int e2 = min(e1, S); // Copy data forward memcpy(data + S + e, data + e, sizeof(T) * (e2 - e)); diff --git a/include/dsp/vumeter.hpp b/include/dsp/vumeter.hpp index e1278ad9..6cf12d32 100644 --- a/include/dsp/vumeter.hpp +++ b/include/dsp/vumeter.hpp @@ -23,7 +23,7 @@ struct VUMeter { return (dBScaled >= 0.0) ? 1.0 : 0.0; } else { - return clampf(dBScaled + i, 0.0, 1.0); + return clamp(dBScaled + i, 0.0, 1.0); } } }; diff --git a/include/util/common.hpp b/include/util/common.hpp index 76fa42d0..dbc3e462 100644 --- a/include/util/common.hpp +++ b/include/util/common.hpp @@ -7,13 +7,11 @@ #include #include +#include #include #include #include -// Include math utilities for convenience -#include "util/math.hpp" - /** Surrounds raw text with quotes Example: @@ -34,20 +32,24 @@ will expand to #define LENGTHOF(arr) (sizeof(arr) / sizeof((arr)[0])) -/** Reserve space for _count enums starting with _name. +/** Reserve space for `count` enums starting with `name`. Example: enum Foo { - ENUMS(BAR, 14) + ENUMS(BAR, 14), + BAZ }; - BAR + 0 to BAR + 11 is reserved + BAR + 0 to BAR + 13 is reserved. BAZ has a value of 14. */ -#define ENUMS(_name, _count) _name, _name ## _LAST = _name + (_count) - 1 +#define ENUMS(name, count) name, name ## _LAST = name + (count) - 1 /** Deprecation notice for GCC */ #define DEPRECATED __attribute__ ((deprecated)) +#include "util/math.hpp" + + namespace rack { diff --git a/include/util/math.hpp b/include/util/math.hpp index 70ec9dcc..133543ee 100644 --- a/include/util/math.hpp +++ b/include/util/math.hpp @@ -1,7 +1,5 @@ #pragma once -#include -#include -#include +#include "util/common.hpp" namespace rack { @@ -10,39 +8,38 @@ namespace rack { // basic integer functions (suffixed with "i") //////////////////// -inline int mini(int a, int b) { - return a < b ? a : b; +inline int min(int a, int b) { + return (a < b) ? a : b; } -inline int maxi(int a, int b) { - return a > b ? a : b; +inline int max(int a, int b) { + return (a > b) ? a : b; } /** Limits a value between a minimum and maximum Assumes min <= max */ -inline int clampi(int x, int min, int max) { - if (x < min) - return min; - if (x > max) - return max; - return x; +inline int clamp(int x, int minimum, int maximum) { + return min(max(x, minimum), maximum); } -inline int absi(int a) { +/** Absolute value of a +Undefined for a == INT_MIN +*/ +inline int abs(int a) { return (a >= 0) ? a : -a; } /** Euclidean modulus, always returns 0 <= mod < base for positive base. */ -inline int eucmodi(int a, int base) { +inline int eucmod(int a, int base) { int mod = a % base; return (mod >= 0) ? mod : mod + base; } /** Returns floor(log_2(n)), or 0 if n == 1. */ -inline int log2i(int n) { +inline int log2(int n) { int i = 0; while (n >>= 1) { i++; @@ -50,7 +47,7 @@ inline int log2i(int n) { return i; } -inline bool ispow2i(int n) { +inline bool ispow2(int n) { return n > 0 && (n & (n - 1)) == 0; } @@ -58,69 +55,65 @@ inline bool ispow2i(int n) { // basic float functions (suffixed with "f") //////////////////// -inline float absf(float x) { - return (x < 0.f) ? -x : x; +inline float abs(float x) { + return (x >= 0.f) ? x : -x; } /** Returns 1.f for positive numbers and -1.f for negative numbers (including positive/negative zero) */ -inline float sgnf(float x) { +inline float sgn(float x) { return copysignf(1.f, x); } -inline float eucmodf(float a, float base) { +inline float eucmod(float a, float base) { float mod = fmodf(a, base); return (mod >= 0.f) ? mod : mod + base; } -inline float nearf(float a, float b, float epsilon = 1e-6) { +inline float near(float a, float b, float epsilon = 1e-6) { return fabsf(a - b) <= epsilon; } /** Limits a value between a minimum and maximum Assumes min <= max */ -inline float clampf(float x, float min, float max) { - if (x < min) - return min; - if (x > max) - return max; - return x; +inline float clamp(float x, float minimum, float maximum) { + return fminf(fmaxf(x, minimum), maximum); } /** Limits a value between a minimum and maximum If min > max, switches the two values */ -inline float clamp2f(float x, float min, float max) { - return clampf(x, fminf(min, max), fmaxf(min, max)); +inline float clamp2(float x, float min, float max) { + return clamp(x, fminf(min, max), fmaxf(min, max)); } /** If the magnitude of x if less than eps, return 0 */ -inline float chopf(float x, float eps) { +inline float chop(float x, float eps) { return (-eps < x && x < eps) ? 0.f : x; } -inline float rescalef(float x, float xMin, float xMax, float yMin, float yMax) { +inline float rescale(float x, float xMin, float xMax, float yMin, float yMax) { return yMin + (x - xMin) / (xMax - xMin) * (yMax - yMin); } -inline float crossf(float a, float b, float frac) { +inline float crossfade(float a, float b, float frac) { return a + frac * (b - a); } /** Linearly interpolate an array `p` with index `x` Assumes that the array at `p` is of length at least floor(x)+1. */ -inline float interpf(const float *p, float x) { +inline float interp(const float *p, float x) { int xi = x; float xf = x - xi; - return crossf(p[xi], p[xi+1], xf); + return crossfade(p[xi], p[xi+1], xf); } /** Complex multiply c = a * b Arguments may be the same pointers i.e. cmultf(&ar, &ai, ar, ai, br, bi) */ -inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) { +inline void cmult(float *cr, float *ci, float ar, float ai, float br, float bi) { *cr = ar * br - ai * bi; *ci = ar * bi + ai * br; } @@ -235,18 +228,18 @@ struct Rect { /** Clamps the edges of the rectangle to fit within a bound */ Rect clamp(Rect bound) { Rect r; - r.pos.x = clamp2f(pos.x, bound.pos.x, bound.pos.x + bound.size.x); - r.pos.y = clamp2f(pos.y, bound.pos.y, bound.pos.y + bound.size.y); - r.size.x = clampf(pos.x + size.x, bound.pos.x, bound.pos.x + bound.size.x) - r.pos.x; - r.size.y = clampf(pos.y + size.y, bound.pos.y, bound.pos.y + bound.size.y) - r.pos.y; + r.pos.x = clamp2(pos.x, bound.pos.x, bound.pos.x + bound.size.x); + r.pos.y = clamp2(pos.y, bound.pos.y, bound.pos.y + bound.size.y); + r.size.x = rack::clamp(pos.x + size.x, bound.pos.x, bound.pos.x + bound.size.x) - r.pos.x; + r.size.y = rack::clamp(pos.y + size.y, bound.pos.y, bound.pos.y + bound.size.y) - r.pos.y; return r; } /** Nudges the position to fix inside a bounding box */ Rect nudge(Rect bound) { Rect r; r.size = size; - r.pos.x = clamp2f(pos.x, bound.pos.x, bound.pos.x + bound.size.x - size.x); - r.pos.y = clamp2f(pos.y, bound.pos.y, bound.pos.y + bound.size.y - size.y); + r.pos.x = clamp2(pos.x, bound.pos.x, bound.pos.x + bound.size.x - size.x); + r.pos.y = clamp2(pos.y, bound.pos.y, bound.pos.y + bound.size.y - size.y); return r; } /** Expands this Rect to contain `other` */ @@ -269,9 +262,33 @@ struct Rect { inline Vec Vec::clamp(Rect bound) { return Vec( - clamp2f(x, bound.pos.x, bound.pos.x + bound.size.x), - clamp2f(y, bound.pos.y, bound.pos.y + bound.size.y)); + clamp2(x, bound.pos.x, bound.pos.x + bound.size.x), + clamp2(y, bound.pos.y, bound.pos.y + bound.size.y)); } +//////////////////// +// Deprecated functions, will by removed in Rack 1.0 +//////////////////// + +inline int DEPRECATED mini(int a, int b) {return min(a, b);} +inline int DEPRECATED maxi(int a, int b) {return max(a, b);} +inline int DEPRECATED clampi(int x, int min, int max) {return clamp(x, min, max);} +inline int DEPRECATED absi(int a) {return abs(a);} +inline int DEPRECATED eucmodi(int a, int base) {return eucmod(a, base);} +inline int DEPRECATED log2i(int n) {return log2(n);} +inline bool DEPRECATED ispow2i(int n) {return ispow2(n);} +inline float DEPRECATED absf(float x) {return abs(x);} +inline float DEPRECATED sgnf(float x) {return sgn(x);} +inline float DEPRECATED eucmodf(float a, float base) {return eucmod(a, base);} +inline float DEPRECATED nearf(float a, float b, float epsilon = 1e-6) {return near(a, b, epsilon);} +inline float DEPRECATED clampf(float x, float min, float max) {return clamp(x, min, max);} +inline float DEPRECATED clamp2f(float x, float min, float max) {return clamp2(x, min, max);} +inline float DEPRECATED chopf(float x, float eps) {return chop(x, eps);} +inline float DEPRECATED rescalef(float x, float xMin, float xMax, float yMin, float yMax) {return rescale(x, xMin, xMax, yMin, yMax);} +inline float DEPRECATED crossf(float a, float b, float frac) {return crossfade(a, b, frac);} +inline float DEPRECATED interpf(const float *p, float x) {return interp(p, x);} +inline void DEPRECATED cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return cmult(cr, ci, ar, ai, br, bi);} + + } // namespace rack diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index 2ec2a3f5..7a78f8e1 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -5,10 +5,10 @@ namespace rack { void LightWidget::draw(NVGcontext *vg) { - color.r = clampf(color.r, 0.0, 1.0); - color.g = clampf(color.g, 0.0, 1.0); - color.b = clampf(color.b, 0.0, 1.0); - color.a = clampf(color.a, 0.0, 1.0); + color.r = clamp(color.r, 0.0, 1.0); + color.g = clamp(color.g, 0.0, 1.0); + color.b = clamp(color.b, 0.0, 1.0); + color.a = clamp(color.a, 0.0, 1.0); drawLight(vg); drawHalo(vg); diff --git a/src/app/ModuleLightWidget.cpp b/src/app/ModuleLightWidget.cpp index 02296a0d..1982ffd8 100644 --- a/src/app/ModuleLightWidget.cpp +++ b/src/app/ModuleLightWidget.cpp @@ -12,7 +12,7 @@ void ModuleLightWidget::step() { for (size_t i = 0; i < baseColors.size(); i++) { float value = module->lights[firstLightId + i].getBrightness(); - value = clampf(value, 0.0, 1.0); + value = clamp(value, 0.0, 1.0); values[i] = value; } setValues(values); diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index c3ee57d1..2386a2d2 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -20,7 +20,7 @@ void ParamWidget::fromJson(json_t *rootJ) { void ParamWidget::randomize() { if (randomizable) - setValue(rescalef(randomf(), 0.0, 1.0, minValue, maxValue)); + setValue(rescale(randomf(), 0.0, 1.0, minValue, maxValue)); } void ParamWidget::onMouseDown(EventMouseDown &e) { diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 9a75d62d..eb05c874 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -374,8 +374,8 @@ bool RackWidget::requestModuleBoxNearest(ModuleWidget *m, Rect box) { int x0 = roundf(box.pos.x / RACK_GRID_WIDTH); int y0 = roundf(box.pos.y / RACK_GRID_HEIGHT); std::vector positions; - for (int y = maxi(0, y0 - 8); y < y0 + 8; y++) { - for (int x = maxi(0, x0 - 400); x < x0 + 400; x++) { + for (int y = max(0, y0 - 8); y < y0 + 8; y++) { + for (int x = max(0, x0 - 400); x < x0 + 400; x++) { positions.push_back(Vec(x * RACK_GRID_WIDTH, y * RACK_GRID_HEIGHT)); } } diff --git a/src/app/SVGFader.cpp b/src/app/SVGFader.cpp index ee170ea1..088c401d 100644 --- a/src/app/SVGFader.cpp +++ b/src/app/SVGFader.cpp @@ -15,7 +15,7 @@ SVGFader::SVGFader() { void SVGFader::step() { if (dirty) { // Update handle position - Vec handlePos = Vec(rescalef(value, minValue, maxValue, minHandlePos.x, maxHandlePos.x), rescalef(value, minValue, maxValue, minHandlePos.y, maxHandlePos.y)); + Vec handlePos = Vec(rescale(value, minValue, maxValue, minHandlePos.x, maxHandlePos.x), rescale(value, minValue, maxValue, minHandlePos.y, maxHandlePos.y)); handle->box.pos = handlePos; } FramebufferWidget::step(); diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index fc96b131..0bc514d7 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -25,7 +25,7 @@ void SVGKnob::step() { tw->box.size = box.size; float angle = 0.0; if (std::isfinite(minValue) && std::isfinite(maxValue)) - angle = rescalef(value, minValue, maxValue, minAngle, maxAngle); + angle = rescale(value, minValue, maxValue, minAngle, maxAngle); tw->identity(); // Scale SVG to box tw->scale(box.size.div(sw->box.size)); diff --git a/src/app/SVGPanel.cpp b/src/app/SVGPanel.cpp index 26a3b86b..32a9b4ea 100644 --- a/src/app/SVGPanel.cpp +++ b/src/app/SVGPanel.cpp @@ -18,7 +18,7 @@ struct PanelBorder : TransparentWidget { void SVGPanel::step() { - if (nearf(gPixelRatio, 1.0)) { + if (near(gPixelRatio, 1.0)) { // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer oversample = 2.0; } diff --git a/src/app/SVGSwitch.cpp b/src/app/SVGSwitch.cpp index eecaeb1e..3d163604 100644 --- a/src/app/SVGSwitch.cpp +++ b/src/app/SVGSwitch.cpp @@ -20,8 +20,8 @@ void SVGSwitch::addFrame(std::shared_ptr svg) { void SVGSwitch::onChange(EventChange &e) { assert(frames.size() > 0); - float valueScaled = rescalef(value, minValue, maxValue, 0, frames.size() - 1); - int index = clampi((int) roundf(valueScaled), 0, frames.size() - 1); + float valueScaled = rescale(value, minValue, maxValue, 0, frames.size() - 1); + int index = clamp((int) roundf(valueScaled), 0, frames.size() - 1); sw->setSVG(frames[index]); dirty = true; Switch::onChange(e); diff --git a/src/app/SpriteKnob.cpp b/src/app/SpriteKnob.cpp index 0ab19025..59cdc26e 100644 --- a/src/app/SpriteKnob.cpp +++ b/src/app/SpriteKnob.cpp @@ -4,7 +4,7 @@ namespace rack { void SpriteKnob::step() { - index = eucmodi((int) roundf(rescalef(value, minValue, maxValue, minIndex, maxIndex)), spriteCount); + index = eucmod((int) roundf(rescale(value, minValue, maxValue, minIndex, maxIndex)), spriteCount); } } // namespace rack diff --git a/src/audio.cpp b/src/audio.cpp index c572cb09..06e5741c 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -132,8 +132,8 @@ void AudioIO::openStream() { return; } - numOutputs = mini(deviceInfo.outputChannels, maxOutputs); - numInputs = mini(deviceInfo.inputChannels, maxInputs); + numOutputs = min(deviceInfo.outputChannels, maxOutputs); + numInputs = min(deviceInfo.inputChannels, maxInputs); if (numOutputs == 0 && numInputs == 0) { warn("RtAudio device %d has 0 inputs and 0 outputs"); diff --git a/src/core/MidiClockToCV.cpp b/src/core/MidiClockToCV.cpp index eda9a413..fe6e8f2a 100644 --- a/src/core/MidiClockToCV.cpp +++ b/src/core/MidiClockToCV.cpp @@ -108,11 +108,11 @@ void MIDIClockToCVInterface::step() { } if (inputs[CLOCK1_RATIO].active) { - clock1ratio = int(clampf(inputs[CLOCK1_RATIO].value, 0.0, 10.0) * (numratios - 1) / 10); + clock1ratio = int(clamp(inputs[CLOCK1_RATIO].value, 0.0, 10.0) * (numratios - 1) / 10); } if (inputs[CLOCK2_RATIO].active) { - clock2ratio = int(clampf(inputs[CLOCK2_RATIO].value, 0.0, 10.0) * (numratios - 1) / 10); + clock2ratio = int(clamp(inputs[CLOCK2_RATIO].value, 0.0, 10.0) * (numratios - 1) / 10); } if (start) { diff --git a/src/settings.cpp b/src/settings.cpp index e593c92b..f0a6642d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -102,7 +102,7 @@ static void settingsFromJson(json_t *rootJ) { // zoom json_t *zoomJ = json_object_get(rootJ, "zoom"); if (zoomJ) { - gRackScene->zoomWidget->setZoom(clampf(json_number_value(zoomJ), 0.25, 4.0)); + gRackScene->zoomWidget->setZoom(clamp(json_number_value(zoomJ), 0.25f, 4.0f)); gToolbar->zoomSlider->setValue(json_number_value(zoomJ) * 100.0); } diff --git a/src/widgets/ProgressBar.cpp b/src/widgets/ProgressBar.cpp index 862343d1..c99b0246 100644 --- a/src/widgets/ProgressBar.cpp +++ b/src/widgets/ProgressBar.cpp @@ -4,7 +4,7 @@ namespace rack { void ProgressBar::draw(NVGcontext *vg) { - float progress = rescalef(value, minValue, maxValue, 0.0, 1.0); + float progress = rescale(value, minValue, maxValue, 0.0, 1.0); bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, getText().c_str(), NULL); } diff --git a/src/widgets/QuantityWidget.cpp b/src/widgets/QuantityWidget.cpp index 268e4e99..5746616b 100644 --- a/src/widgets/QuantityWidget.cpp +++ b/src/widgets/QuantityWidget.cpp @@ -9,7 +9,7 @@ QuantityWidget::QuantityWidget() { } void QuantityWidget::setValue(float value) { - this->value = clampf(value, fminf(minValue, maxValue), fmaxf(minValue, maxValue)); + this->value = clamp(value, fminf(minValue, maxValue), fmaxf(minValue, maxValue)); EventChange e; onChange(e); } diff --git a/src/widgets/Slider.cpp b/src/widgets/Slider.cpp index de3e22cb..16e46911 100644 --- a/src/widgets/Slider.cpp +++ b/src/widgets/Slider.cpp @@ -7,7 +7,7 @@ namespace rack { #define SLIDER_SENSITIVITY 0.001 void Slider::draw(NVGcontext *vg) { - float progress = rescalef(value, minValue, maxValue, 0.0, 1.0); + float progress = rescale(value, minValue, maxValue, 0.0, 1.0); bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL); } diff --git a/src/widgets/TextField.cpp b/src/widgets/TextField.cpp index 8bea1bf5..22a85455 100644 --- a/src/widgets/TextField.cpp +++ b/src/widgets/TextField.cpp @@ -117,8 +117,8 @@ void TextField::onKey(EventKey &e) { break; } - begin = mini(maxi(begin, 0), text.size()); - end = mini(maxi(end, 0), text.size()); + begin = clamp(begin, 0, text.size()); + end = clamp(end, 0, text.size()); e.consumed = true; }