17 #ifndef DISTRHO_UTILS_HPP_INCLUDED 18 #define DISTRHO_UTILS_HPP_INCLUDED 20 #include "src/DistrhoDefines.h" 30 #ifdef DISTRHO_PROPER_CPP11_SUPPORT 36 #if defined(DISTRHO_OS_MAC) && ! defined(CARLA_OS_MAC) && ! defined(DISTRHO_PROPER_CPP11_SUPPORT) 38 inline float fmin(
float __x,
float __y)
39 {
return __builtin_fminf(__x, __y); }
40 inline float fmax(
float __x,
float __y)
41 {
return __builtin_fmaxf(__x, __y); }
42 inline float rint(
float __x)
43 {
return __builtin_rintf(__x); }
44 inline float round(
float __x)
45 {
return __builtin_roundf(__x); }
50 # define M_PI 3.14159265358979323846 60 int64_t d_cconst(
const uint8_t a,
const uint8_t b,
const uint8_t c,
const uint8_t d) noexcept
62 return (a << 24) | (b << 16) | (c << 8) | (d << 0);
69 uint32_t d_version(
const uint8_t major,
const uint8_t minor,
const uint8_t micro) noexcept
71 return uint32_t(major << 16) | uint32_t(minor << 8) | (micro << 0);
78 void d_pass() noexcept {}
91 void d_debug(
const char*
const fmt, ...) noexcept
95 ::va_start(args, fmt);
96 std::fprintf(stdout,
"\x1b[30;1m");
97 std::vfprintf(stdout, fmt, args);
98 std::fprintf(stdout,
"\x1b[0m\n");
108 void d_stdout(
const char*
const fmt, ...) noexcept
112 ::va_start(args, fmt);
113 std::vfprintf(stdout, fmt, args);
114 std::fprintf(stdout,
"\n");
123 void d_stderr(
const char*
const fmt, ...) noexcept
127 ::va_start(args, fmt);
128 std::vfprintf(stderr, fmt, args);
129 std::fprintf(stderr,
"\n");
138 void d_stderr2(
const char*
const fmt, ...) noexcept
142 ::va_start(args, fmt);
143 std::fprintf(stderr,
"\x1b[31m");
144 std::vfprintf(stderr, fmt, args);
145 std::fprintf(stderr,
"\x1b[0m\n");
154 void d_safe_assert(
const char*
const assertion,
const char*
const file,
const int line) noexcept
156 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
163 void d_safe_exception(
const char*
const exception,
const char*
const file,
const int line) noexcept
165 d_stderr2(
"exception caught: \"%s\" in file %s, line %i", exception, file, line);
177 bool d_isEqual(
const T& v1,
const T& v2)
179 return std::abs(v1-v2) < std::numeric_limits<T>::epsilon();
188 bool d_isNotEqual(
const T& v1,
const T& v2)
190 return std::abs(v1-v2) >= std::numeric_limits<T>::epsilon();
198 bool d_isZero(
const T& value)
200 return std::abs(value) < std::numeric_limits<T>::epsilon();
208 bool d_isNotZero(
const T& value)
210 return std::abs(value) >= std::numeric_limits<T>::epsilon();
217 uint32_t d_nextPowerOf2(uint32_t size) noexcept
219 DISTRHO_SAFE_ASSERT_RETURN(size > 0, 0);
233 #ifndef DONT_SET_USING_DISTRHO_NAMESPACE 242 #endif // DISTRHO_UTILS_HPP_INCLUDED Definition: DistrhoUtils.hpp:236