Browse Source

Switch to C++ headers

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
13107b8577
21 changed files with 106 additions and 199 deletions
  1. +0
    -6
      include/app.hpp
  2. +0
    -63
      include/dsp/fft.hpp
  3. +1
    -1
      include/dsp/fir.hpp
  4. +5
    -5
      include/dsp/functions.hpp
  5. +1
    -1
      include/dsp/resampler.hpp
  6. +1
    -1
      include/dsp/vumeter.hpp
  7. +5
    -5
      include/util/common.hpp
  8. +62
    -76
      include/util/math.hpp
  9. +1
    -1
      src/app/AudioWidget.cpp
  10. +3
    -3
      src/app/Knob.cpp
  11. +2
    -2
      src/app/LedDisplay.cpp
  12. +2
    -2
      src/app/ModuleBrowser.cpp
  13. +3
    -3
      src/app/ParamWidget.cpp
  14. +2
    -2
      src/app/RackWidget.cpp
  15. +2
    -2
      src/app/SVGKnob.cpp
  16. +0
    -10
      src/app/SpriteKnob.cpp
  17. +5
    -5
      src/audio.cpp
  18. +1
    -1
      src/ui/ScrollWidget.cpp
  19. +7
    -7
      src/ui/TextField.cpp
  20. +2
    -2
      src/widgets/FramebufferWidget.cpp
  21. +1
    -1
      src/widgets/SVGWidget.cpp

+ 0
- 6
include/app.hpp View File

@@ -273,12 +273,6 @@ struct Knob : ParamWidget {
void onDragEnd(EventDragEnd &e) override;
};

/** Deprecated */
struct SpriteKnob : Knob, SpriteWidget {
int minIndex, maxIndex, spriteCount;
void step() override;
};

/** A knob which rotates an SVG and caches it in a framebuffer */
struct SVGKnob : Knob, FramebufferWidget {
TransformWidget *tw;


+ 0
- 63
include/dsp/fft.hpp View File

@@ -1,63 +0,0 @@
#pragma once

#include <complex>


namespace rack {

/** Simple FFT implementation
If you need something fast, use pffft, KissFFT, etc instead.
The size N must be a power of 2
*/
struct SimpleFFT {
int N;
/** Twiddle factors e^(2pi k/N), interleaved complex numbers */
std::complex<float> *tw;
SimpleFFT(int N, bool inverse) : N(N) {
tw = new std::complex<float>[N];
for (int i = 0; i < N; i++) {
float phase = 2*M_PI * (float)i / N;
if (inverse)
phase *= -1.0;
tw[i] = std::exp(std::complex<float>(0.0, phase));
}
}
~SimpleFFT() {
delete[] tw;
}
/** Reference naive implementation
x and y are arrays of interleaved complex numbers
y must be size N/s
s is the stride factor for the x array which divides the size N
*/
void dft(const std::complex<float> *x, std::complex<float> *y, int s=1) {
for (int k = 0; k < N/s; k++) {
std::complex<float> yk = 0.0;
for (int n = 0; n < N; n += s) {
int m = (n*k) % N;
yk += x[n] * tw[m];
}
y[k] = yk;
}
}
void fft(const std::complex<float> *x, std::complex<float> *y, int s=1) {
if (N/s <= 2) {
// Naive DFT is faster than further FFT recursions at this point
dft(x, y, s);
return;
}
std::complex<float> *e = new std::complex<float>[N/(2*s)]; // Even inputs
std::complex<float> *o = new std::complex<float>[N/(2*s)]; // Odd inputs
fft(x, e, 2*s);
fft(x + s, o, 2*s);
for (int k = 0; k < N/(2*s); k++) {
int m = (k*s) % N;
y[k] = e[k] + tw[m] * o[k];
y[k + N/(2*s)] = e[k] - tw[m] * o[k];
}
delete[] e;
delete[] o;
}
};

} // namespace rack

+ 1
- 1
include/dsp/fir.hpp View File

@@ -93,7 +93,7 @@ struct RealTimeConvolver {
for (size_t i = 0; i < kernelBlocks; i++) {
// Pad each block with zeros
memset(tmpBlock, 0, sizeof(float) * blockSize*2);
size_t len = min((int) blockSize, (int) (length - i*blockSize));
size_t len = std::min((int) blockSize, (int) (length - i*blockSize));
memcpy(tmpBlock, &kernel[i*blockSize], sizeof(float)*len);
// Compute fft
pffft_transform(pffft, tmpBlock, &kernelFfts[blockSize*2 * i], NULL, PFFFT_FORWARD);


+ 5
- 5
include/dsp/functions.hpp View File

@@ -11,7 +11,7 @@ inline float sinc(float x) {
if (x == 0.f)
return 1.f;
x *= M_PI;
return sinf(x) / x;
return std::sin(x) / x;
}

inline float quadraticBipolar(float x) {
@@ -34,21 +34,21 @@ inline float quintic(float x) {
}

inline float sqrtBipolar(float x) {
return (x >= 0.f) ? sqrtf(x) : -sqrtf(-x);
return (x >= 0.f) ? std::sqrt(x) : -std::sqrt(-x);
}

/** This is pretty much a scaled sinh */
inline float exponentialBipolar(float b, float x) {
const float a = b - 1.f / b;
return (powf(b, x) - powf(b, -x)) / a;
return (std::pow(b, x) - std::pow(b, -x)) / a;
}

inline float gainToDb(float gain) {
return log10f(gain) * 20.f;
return std::log10(gain) * 20.f;
}

inline float dbToGain(float db) {
return powf(10.f, db / 20.f);
return std::pow(10.f, db / 20.f);
}




+ 1
- 1
include/dsp/resampler.hpp View File

@@ -90,7 +90,7 @@ struct SampleRateConverter {
}
else {
// Simply copy the buffer without conversion
int frames = min(*inFrames, *outFrames);
int frames = std::min(*inFrames, *outFrames);
memcpy(out, in, frames * sizeof(Frame<CHANNELS>));
*inFrames = frames;
*outFrames = frames;


+ 1
- 1
include/dsp/vumeter.hpp View File

@@ -12,7 +12,7 @@ struct VUMeter {
float dBScaled;
/** Value should be scaled so that 1.0 is clipping */
void setValue(float v) {
dBScaled = log10f(fabsf(v)) * 20.0 / dBInterval;
dBScaled = std::log10(std::abs(v)) * 20.0 / dBInterval;
}
/** Returns the brightness of the light indexed by i
Light 0 is a clip light (red) which is either on or off.


+ 5
- 5
include/util/common.hpp View File

@@ -1,11 +1,11 @@
#pragma once

// Include most of the C standard library for convenience
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <cassert>

#include <string>
#include <vector>


+ 62
- 76
include/util/math.hpp View File

@@ -1,15 +1,8 @@
#pragma once
#include "util/common.hpp"
#include <math.h> // for global namespace functions
#include <cmath> // for std::isfinite, etc
#include <cstdlib> // for std::abs, etc


// Use a few standard math functions without std::
using std::isfinite;
using std::isinf;
using std::isnan;
using std::isnormal;
#include <cmath>
#include <cstdlib>
#include <algorithm> // for std::min, max


namespace rack {
@@ -18,43 +11,33 @@ namespace rack {
// basic integer functions
////////////////////

/** Returns true if x is odd */
inline bool isOdd(int x) {
return x % 2 != 0;
}

/** Returns true if x is odd */
inline bool isEven(int x) {
return x % 2 == 0;
}

/** Returns the minimum of `a` and `b` */
inline int min(int a, int b) {
return (a < b) ? a : b;
}

/** Returns the maximum of `a` and `b` */
inline int max(int a, int b) {
return (a > b) ? a : b;
/** Returns true if x is odd */
inline bool isOdd(int x) {
return x % 2 != 0;
}

/** Limits `x` between `a` and `b`
Assumes a <= b
*/
inline int clamp(int x, int a, int b) {
return min(max(x, a), b);
return std::min(std::max(x, a), b);
}

/** Limits `x` between `a` and `b`
If a > b, switches the two values
*/
inline int clamp2(int x, int a, int b) {
return clamp(x, min(a, b), max(a, b));
inline int clampBetween(int x, int a, int b) {
return clamp(x, std::min(a, b), std::max(a, b));
}

/** Euclidean modulus, always returns 0 <= mod < base for positive base.
*/
inline int eucmod(int a, int base) {
inline int eucMod(int a, int base) {
int mod = a % base;
return (mod >= 0) ? mod : mod + base;
}
@@ -69,7 +52,7 @@ inline int log2(int n) {
return i;
}

inline bool ispow2(int n) {
inline bool isPow2(int n) {
return n > 0 && (n & (n - 1)) == 0;
}

@@ -77,47 +60,37 @@ inline bool ispow2(int n) {
// basic float functions
////////////////////

/** Returns the minimum of `a` and `b` */
inline float min(float a, float b) {
return (a < b) ? a : b;
}

/** Returns the maximum of `a` and `b` */
inline float max(float a, float b) {
return (a > b) ? a : b;
}

/** Limits `x` between `a` and `b`
Assumes a <= b
*/
inline float clamp(float x, float a, float b) {
return min(max(x, a), b);
return std::min(std::max(x, a), b);
}

/** Limits `x` between `a` and `b`
If a > b, switches the two values
*/
inline float clamp2(float x, float a, float b) {
return clamp(x, min(a, b), max(a, b));
inline float clampBetween(float x, float a, float b) {
return clamp(x, std::min(a, b), std::max(a, b));
}

/** Returns 1.f for positive numbers and -1.f for negative numbers (including positive/negative zero) */
/** Returns 1 for positive numbers, -1 for negative numbers, and 0 for zero */
inline float sgn(float x) {
return copysignf(1.0f, x);
return x > 0.f ? 1.f : x < 0.f ? -1.f : 0.f;
}

inline float eucmod(float a, float base) {
float mod = fmodf(a, base);
inline float eucMod(float a, float base) {
float mod = std::fmod(a, base);
return (mod >= 0.0f) ? mod : mod + base;
}

inline bool isNear(float a, float b, float epsilon = 1.0e-6f) {
return fabsf(a - b) <= epsilon;
return std::abs(a - b) <= epsilon;
}

/** If the magnitude of x if less than eps, return 0 */
inline float chop(float x, float eps) {
return (-eps < x && x < eps) ? 0.0f : x;
/** If the magnitude of x if less than epsilon, return 0 */
inline float chop(float x, float epsilon = 1.0e-6f) {
return isNear(x, 0.f, epsilon) ? 0.f : x;
}

inline float rescale(float x, float a, float b, float yMin, float yMax) {
@@ -184,25 +157,25 @@ struct Vec {
return x * b.x + y * b.y;
}
float norm() {
return hypotf(x, y);
return std::hypotf(x, y);
}
Vec flip() {
return Vec(y, x);
}
Vec min(Vec b) {
return Vec(rack::min(x, b.x), rack::min(y, b.y));
return Vec(std::min(x, b.x), std::min(y, b.y));
}
Vec max(Vec b) {
return Vec(rack::max(x, b.x), rack::max(y, b.y));
return Vec(std::max(x, b.x), std::max(y, b.y));
}
Vec round() {
return Vec(roundf(x), roundf(y));
return Vec(std::round(x), std::round(y));
}
Vec floor() {
return Vec(floorf(x), floorf(y));
return Vec(std::floor(x), std::floor(y));
}
Vec ceil() {
return Vec(ceilf(x), ceilf(y));
return Vec(std::ceil(x), std::ceil(y));
}
bool isEqual(Vec b) {
return x == b.x && y == b.y;
@@ -211,10 +184,11 @@ struct Vec {
return x == 0.0f && y == 0.0f;
}
bool isFinite() {
return isfinite(x) && isfinite(y);
return std::isfinite(x) && std::isfinite(y);
}
Vec clamp(Rect bound);
Vec clamp2(Rect bound);
Vec clampBetween(Rect bound);
DEPRECATED Vec clamp2(Rect bound);
};


@@ -262,8 +236,8 @@ struct Rect {
/** Clamps the edges of the rectangle to fit within a bound */
Rect clamp(Rect bound) {
Rect r;
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.pos.x = clampBetween(pos.x, bound.pos.x, bound.pos.x + bound.size.x);
r.pos.y = clampBetween(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;
@@ -272,17 +246,17 @@ struct Rect {
Rect nudge(Rect bound) {
Rect r;
r.size = size;
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);
r.pos.x = clampBetween(pos.x, bound.pos.x, bound.pos.x + bound.size.x - size.x);
r.pos.y = clampBetween(pos.y, bound.pos.y, bound.pos.y + bound.size.y - size.y);
return r;
}
/** Expands this Rect to contain `other` */
Rect expand(Rect other) {
Rect r;
r.pos.x = min(pos.x, other.pos.x);
r.pos.y = min(pos.y, other.pos.y);
r.size.x = max(pos.x + size.x, other.pos.x + other.size.x) - r.pos.x;
r.size.y = max(pos.y + size.y, other.pos.y + other.size.y) - r.pos.y;
r.pos.x = std::min(pos.x, other.pos.x);
r.pos.y = std::min(pos.y, other.pos.y);
r.size.x = std::max(pos.x + size.x, other.pos.x + other.size.x) - r.pos.x;
r.size.y = std::max(pos.y + size.y, other.pos.y + other.size.y) - r.pos.y;
return r;
}
/** Returns a Rect with its position set to zero */
@@ -312,30 +286,42 @@ inline Vec Vec::clamp(Rect bound) {
rack::clamp(y, bound.pos.y, bound.pos.y + bound.size.y));
}

inline Vec Vec::clamp2(Rect bound) {
inline Vec Vec::clampBetween(Rect bound) {
return Vec(
rack::clamp2(x, bound.pos.x, bound.pos.x + bound.size.x),
rack::clamp2(y, bound.pos.y, bound.pos.y + bound.size.y));
rack::clampBetween(x, bound.pos.x, bound.pos.x + bound.size.x),
rack::clampBetween(y, bound.pos.y, bound.pos.y + bound.size.y));
}

inline Vec Vec::clamp2(Rect bound) {return clampBetween(bound);}


////////////////////
// Deprecated functions
////////////////////

DEPRECATED inline int mini(int a, int b) {return min(a, b);}
DEPRECATED inline int maxi(int a, int b) {return max(a, b);}
DEPRECATED inline int min(int a, int b) {return std::min(a, b);}
DEPRECATED inline int max(int a, int b) {return std::max(a, b);}
DEPRECATED inline int eucmod(int a, int base) {return eucMod(a, base);}
DEPRECATED inline bool ispow2(int n) {return isPow2(n);}
DEPRECATED inline int clamp2(int x, int a, int b) {return clampBetween(x, a, b);}
DEPRECATED inline float min(float a, float b) {return std::min(a, b);}
DEPRECATED inline float max(float a, float b) {return std::max(a, b);}
DEPRECATED inline float eucmod(float a, float base) {return eucMod(a, base);}
DEPRECATED inline float clamp2(float x, float a, float b) {return clampBetween(x, a, b);}

DEPRECATED inline int mini(int a, int b) {return std::min(a, b);}
DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);}
DEPRECATED inline int clampi(int x, int min, int max) {return clamp(x, min, max);}
DEPRECATED inline int absi(int a) {return abs(a);}
DEPRECATED inline int eucmodi(int a, int base) {return eucmod(a, base);}
DEPRECATED inline int absi(int a) {return std::abs(a);}
DEPRECATED inline int eucmodi(int a, int base) {return eucMod(a, base);}
DEPRECATED inline int log2i(int n) {return log2(n);}
DEPRECATED inline bool ispow2i(int n) {return ispow2(n);}
DEPRECATED inline float absf(float x) {return fabsf(x);}
DEPRECATED inline bool ispow2i(int n) {return isPow2(n);}
DEPRECATED inline float absf(float x) {return std::abs(x);}
DEPRECATED inline float sgnf(float x) {return sgn(x);}
DEPRECATED inline float eucmodf(float a, float base) {return eucmod(a, base);}
DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);}
DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return isNear(a, b, epsilon);}
DEPRECATED inline float clampf(float x, float min, float max) {return clamp(x, min, max);}
DEPRECATED inline float clamp2f(float x, float min, float max) {return clamp2(x, min, max);}
DEPRECATED inline float clamp2f(float x, float min, float max) {return clampBetween(x, min, max);}
DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);}
DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return rescale(x, a, b, yMin, yMax);}
DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);}


+ 1
- 1
src/app/AudioWidget.cpp View File

@@ -60,7 +60,7 @@ struct AudioDeviceChoice : LedDisplayChoice {
menu->addChild(item);
}
for (int device = 0; device < deviceCount; device++) {
int channels = min(maxTotalChannels, audioWidget->audioIO->getDeviceChannels(device));
int channels = std::min(maxTotalChannels, audioWidget->audioIO->getDeviceChannels(device));
for (int offset = 0; offset < channels; offset += audioWidget->audioIO->maxChannels) {
AudioDeviceItem *item = new AudioDeviceItem();
item->audioIO = audioWidget->audioIO;


+ 3
- 3
src/app/Knob.cpp View File

@@ -23,7 +23,7 @@ void Knob::onDragStart(EventDragStart &e) {

void Knob::onDragMove(EventDragMove &e) {
float range;
if (isfinite(minValue) && isfinite(maxValue)) {
if (std::isfinite(minValue) && std::isfinite(maxValue)) {
range = maxValue - minValue;
}
else {
@@ -36,9 +36,9 @@ void Knob::onDragMove(EventDragMove &e) {
if (windowIsModPressed())
delta /= 16.f;
dragValue += delta;
dragValue = clamp2(dragValue, minValue, maxValue);
dragValue = clampBetween(dragValue, minValue, maxValue);
if (snap)
setValue(roundf(dragValue));
setValue(std::round(dragValue));
else
setValue(dragValue);
}


+ 2
- 2
src/app/LedDisplay.cpp View File

@@ -84,8 +84,8 @@ void LedDisplayTextField::draw(NVGcontext *vg) {

NVGcolor highlightColor = color;
highlightColor.a = 0.5;
int begin = min(cursor, selection);
int end = (this == gFocusedWidget) ? max(cursor, selection) : -1;
int begin = std::min(cursor, selection);
int end = (this == gFocusedWidget) ? std::max(cursor, selection) : -1;
bndIconLabelCaret(vg, textOffset.x, textOffset.y,
box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y,
-1, color, 12, text.c_str(), highlightColor, begin, end);


+ 2
- 2
src/app/ModuleBrowser.cpp View File

@@ -425,8 +425,8 @@ struct ModuleBrowser : OpaqueWidget {
box.pos = parent->box.size.minus(box.size).div(2).round();
box.pos.y = 60;
box.size.y = parent->box.size.y - 2 * box.pos.y;
moduleScroll->box.size.y = min(box.size.y - moduleScroll->box.pos.y, moduleList->box.size.y);
box.size.y = min(box.size.y, moduleScroll->box.getBottomRight().y);
moduleScroll->box.size.y = std::min(box.size.y - moduleScroll->box.pos.y, moduleList->box.size.y);
box.size.y = std::min(box.size.y, moduleScroll->box.getBottomRight().y);

gFocusedWidget = searchField;
Widget::step();


+ 3
- 3
src/app/ParamWidget.cpp View File

@@ -10,7 +10,7 @@ json_t *ParamWidget::toJson() {
json_object_set_new(rootJ, "paramId", json_integer(paramId));

// Infinite params should serialize to 0
float v = (isfinite(minValue) && isfinite(maxValue)) ? value : 0.f;
float v = (std::isfinite(minValue) && std::isfinite(maxValue)) ? value : 0.f;
json_object_set_new(rootJ, "value", json_real(v));
return rootJ;
}
@@ -23,14 +23,14 @@ void ParamWidget::fromJson(json_t *rootJ) {

void ParamWidget::reset() {
// Infinite params should not be reset
if (isfinite(minValue) && isfinite(maxValue)) {
if (std::isfinite(minValue) && std::isfinite(maxValue)) {
setValue(defaultValue);
}
}

void ParamWidget::randomize() {
// Infinite params should not be randomized
if (randomizable && isfinite(minValue) && isfinite(maxValue)) {
if (randomizable && std::isfinite(minValue) && std::isfinite(maxValue)) {
setValue(rescale(randomUniform(), 0.f, 1.f, minValue, maxValue));
}
}


+ 2
- 2
src/app/RackWidget.cpp View File

@@ -449,8 +449,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<Vec> positions;
for (int y = max(0, y0 - 8); y < y0 + 8; y++) {
for (int x = max(0, x0 - 400); x < x0 + 400; x++) {
for (int y = std::max(0, y0 - 8); y < y0 + 8; y++) {
for (int x = std::max(0, x0 - 400); x < x0 + 400; x++) {
positions.push_back(Vec(x * RACK_GRID_WIDTH, y * RACK_GRID_HEIGHT));
}
}


+ 2
- 2
src/app/SVGKnob.cpp View File

@@ -29,12 +29,12 @@ void SVGKnob::step() {
// Re-transform TransformWidget if dirty
if (dirty) {
float angle;
if (isfinite(minValue) && isfinite(maxValue)) {
if (std::isfinite(minValue) && std::isfinite(maxValue)) {
angle = rescale(value, minValue, maxValue, minAngle, maxAngle);
}
else {
angle = rescale(value, -1.0, 1.0, minAngle, maxAngle);
angle = fmodf(angle, 2*M_PI);
angle = std::fmod(angle, 2*M_PI);
}
tw->identity();
// Rotate SVG


+ 0
- 10
src/app/SpriteKnob.cpp View File

@@ -1,10 +0,0 @@
#include "app.hpp"


namespace rack {

void SpriteKnob::step() {
index = eucmod((int) roundf(rescale(value, minValue, maxValue, minIndex, maxIndex)), spriteCount);
}

} // namespace rack

+ 5
- 5
src/audio.cpp View File

@@ -103,10 +103,10 @@ int AudioIO::getDeviceChannels(int device) {
if (rtAudio) {
RtAudio::DeviceInfo deviceInfo;
if (getDeviceInfo(device, &deviceInfo))
return max((int) deviceInfo.inputChannels, (int) deviceInfo.outputChannels);
return std::max((int) deviceInfo.inputChannels, (int) deviceInfo.outputChannels);
}
else if (driver == BRIDGE_DRIVER) {
return max(BRIDGE_OUTPUTS, BRIDGE_INPUTS);
return std::max(BRIDGE_OUTPUTS, BRIDGE_INPUTS);
}
return 0;
}
@@ -135,11 +135,11 @@ std::string AudioIO::getDeviceDetail(int device, int offset) {
if (getDeviceInfo(device, &deviceInfo)) {
std::string deviceDetail = stringf("%s (", deviceInfo.name.c_str());
if (offset < (int) deviceInfo.inputChannels)
deviceDetail += stringf("%d-%d in", offset + 1, min(offset + maxChannels, (int) deviceInfo.inputChannels));
deviceDetail += stringf("%d-%d in", offset + 1, std::min(offset + maxChannels, (int) deviceInfo.inputChannels));
if (offset < (int) deviceInfo.inputChannels && offset < (int) deviceInfo.outputChannels)
deviceDetail += ", ";
if (offset < (int) deviceInfo.outputChannels)
deviceDetail += stringf("%d-%d out", offset + 1, min(offset + maxChannels, (int) deviceInfo.outputChannels));
deviceDetail += stringf("%d-%d out", offset + 1, std::min(offset + maxChannels, (int) deviceInfo.outputChannels));
deviceDetail += ")";
return deviceDetail;
}
@@ -248,7 +248,7 @@ void AudioIO::openStream() {

int closestSampleRate = deviceInfo.preferredSampleRate;
for (int sr : deviceInfo.sampleRates) {
if (abs(sr - sampleRate) < abs(closestSampleRate - sampleRate)) {
if (std::abs(sr - sampleRate) < std::abs(closestSampleRate - sampleRate)) {
closestSampleRate = sr;
}
}


+ 1
- 1
src/ui/ScrollWidget.cpp View File

@@ -62,7 +62,7 @@ ScrollWidget::ScrollWidget() {

void ScrollWidget::scrollTo(Rect r) {
Rect bound = Rect::fromMinMax(r.getBottomRight().minus(box.size), r.pos);
offset = offset.clamp2(bound);
offset = offset.clampBetween(bound);
}

void ScrollWidget::draw(NVGcontext *vg) {


+ 7
- 7
src/ui/TextField.cpp View File

@@ -19,8 +19,8 @@ void TextField::draw(NVGcontext *vg) {
else
state = BND_DEFAULT;

int begin = min(cursor, selection);
int end = max(cursor, selection);
int begin = std::min(cursor, selection);
int end = std::max(cursor, selection);
bndTextField(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str(), begin, end);
// Draw placeholder text
if (text.empty() && state != BND_ACTIVE) {
@@ -71,7 +71,7 @@ void TextField::onKey(EventKey &e) {
selection = cursor;
}
else {
int begin = min(cursor, selection);
int begin = std::min(cursor, selection);
text.erase(begin, std::abs(selection - cursor));
onTextChange();
cursor = selection = begin;
@@ -83,7 +83,7 @@ void TextField::onKey(EventKey &e) {
onTextChange();
}
else {
int begin = min(cursor, selection);
int begin = std::min(cursor, selection);
text.erase(begin, std::abs(selection - cursor));
onTextChange();
cursor = selection = begin;
@@ -133,7 +133,7 @@ void TextField::onKey(EventKey &e) {
case GLFW_KEY_X: {
if (windowIsModPressed()) {
if (cursor != selection) {
int begin = min(cursor, selection);
int begin = std::min(cursor, selection);
std::string selectedText = text.substr(begin, std::abs(selection - cursor));
glfwSetClipboardString(gWindow, selectedText.c_str());
insertText("");
@@ -143,7 +143,7 @@ void TextField::onKey(EventKey &e) {
case GLFW_KEY_C: {
if (windowIsModPressed()) {
if (cursor != selection) {
int begin = min(cursor, selection);
int begin = std::min(cursor, selection);
std::string selectedText = text.substr(begin, std::abs(selection - cursor));
glfwSetClipboardString(gWindow, selectedText.c_str());
}
@@ -173,7 +173,7 @@ void TextField::onKey(EventKey &e) {

void TextField::insertText(std::string text) {
if (cursor != selection) {
int begin = min(cursor, selection);
int begin = std::min(cursor, selection);
this->text.erase(begin, std::abs(selection - cursor));
cursor = selection = begin;
}


+ 2
- 2
src/widgets/FramebufferWidget.cpp View File

@@ -40,8 +40,8 @@ void FramebufferWidget::draw(NVGcontext *vg) {
float xform[6];
nvgCurrentTransform(vg, xform);
// Skew and rotate is not supported
assert(fabsf(xform[1]) < 1e-6);
assert(fabsf(xform[2]) < 1e-6);
assert(std::abs(xform[1]) < 1e-6);
assert(std::abs(xform[2]) < 1e-6);
Vec s = Vec(xform[0], xform[3]);
Vec b = Vec(xform[4], xform[5]);
Vec bi = b.floor();


+ 1
- 1
src/widgets/SVGWidget.cpp View File

@@ -47,7 +47,7 @@ static float getLineCrossing(Vec p0, Vec p1, Vec p2, Vec p3) {
Vec e = p3.minus(p2);
float m = d.x * e.y - d.y * e.x;
// Check if lines are parallel, or if either pair of points are equal
if (fabsf(m) < 1e-6)
if (std::abs(m) < 1e-6)
return NAN;
return -(d.x * b.y - d.y * b.x) / m;
}


Loading…
Cancel
Save