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
53 #define DISTRHO_MACRO_AS_STRING(MACRO) #MACRO
62 int64_t d_cconst(
const uint8_t a,
const uint8_t b,
const uint8_t c,
const uint8_t d) noexcept
64 return (a << 24) | (b << 16) | (c << 8) | (d << 0);
71 uint32_t d_version(
const uint8_t major,
const uint8_t minor,
const uint8_t micro) noexcept
73 return uint32_t(major << 16) | uint32_t(minor << 8) | (micro << 0);
80 void d_pass() noexcept {}
93 void d_debug(
const char*
const fmt, ...) noexcept
97 ::va_start(args, fmt);
98 std::fprintf(stdout,
"\x1b[30;1m");
99 std::vfprintf(stdout, fmt, args);
100 std::fprintf(stdout,
"\x1b[0m\n");
110 void d_stdout(
const char*
const fmt, ...) noexcept
114 ::va_start(args, fmt);
115 std::vfprintf(stdout, fmt, args);
116 std::fprintf(stdout,
"\n");
125 void d_stderr(
const char*
const fmt, ...) noexcept
129 ::va_start(args, fmt);
130 std::vfprintf(stderr, fmt, args);
131 std::fprintf(stderr,
"\n");
140 void d_stderr2(
const char*
const fmt, ...) noexcept
144 ::va_start(args, fmt);
145 std::fprintf(stderr,
"\x1b[31m");
146 std::vfprintf(stderr, fmt, args);
147 std::fprintf(stderr,
"\x1b[0m\n");
156 void d_safe_assert(
const char*
const assertion,
const char*
const file,
const int line) noexcept
158 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
165 void d_safe_assert_int(
const char*
const assertion,
const char*
const file,
166 const int line,
const int value) noexcept
168 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i, value %i", assertion, file, line, value);
175 void d_safe_assert_uint(
const char*
const assertion,
const char*
const file,
176 const int line,
const uint value) noexcept
178 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i, value %u", assertion, file, line, value);
185 void d_safe_assert_int2(
const char*
const assertion,
const char*
const file,
186 const int line,
const int v1,
const int v2) noexcept
188 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i, v1 %i, v2 %i", assertion, file, line, v1, v2);
195 void d_safe_assert_uint2(
const char*
const assertion,
const char*
const file,
196 const int line,
const uint v1,
const uint v2) noexcept
198 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i, v1 %u, v2 %u", assertion, file, line, v1, v2);
205 void d_safe_exception(
const char*
const exception,
const char*
const file,
const int line) noexcept
207 d_stderr2(
"exception caught: \"%s\" in file %s, line %i", exception, file, line);
219 bool d_isEqual(
const T& v1,
const T& v2)
221 return std::abs(v1-v2) < std::numeric_limits<T>::epsilon();
230 bool d_isNotEqual(
const T& v1,
const T& v2)
232 return std::abs(v1-v2) >= std::numeric_limits<T>::epsilon();
240 bool d_isZero(
const T& value)
242 return std::abs(value) < std::numeric_limits<T>::epsilon();
250 bool d_isNotZero(
const T& value)
252 return std::abs(value) >= std::numeric_limits<T>::epsilon();
259 uint32_t d_nextPowerOf2(uint32_t size) noexcept
261 DISTRHO_SAFE_ASSERT_RETURN(size > 0, 0);
275 #ifndef DONT_SET_USING_DISTRHO_NAMESPACE
278 namespace DISTRHO_NAMESPACE {}
279 using namespace DISTRHO_NAMESPACE;
284 #endif // DISTRHO_UTILS_HPP_INCLUDED