Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.5KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DISTRHO_UTILS_HPP_INCLUDED
  17. #define DISTRHO_UTILS_HPP_INCLUDED
  18. #include "src/DistrhoDefines.h"
  19. #include <cstdarg>
  20. #include <cstdio>
  21. #include <cstdlib>
  22. #include <cstring>
  23. #ifdef PROPER_CPP11_SUPPORT
  24. # include <cstdint>
  25. #else
  26. # include <stdint.h>
  27. #endif
  28. #if defined(DISTRHO_OS_MAC) && ! defined(CARLA_OS_MAC)
  29. namespace std {
  30. inline float
  31. fmin(float __x, float __y)
  32. { return __builtin_fminf(__x, __y); }
  33. inline float
  34. fmax(float __x, float __y)
  35. { return __builtin_fmaxf(__x, __y); }
  36. inline float
  37. rint(float __x)
  38. { return __builtin_rintf(__x); }
  39. inline float
  40. round(float __x)
  41. { return __builtin_roundf(__x); }
  42. }
  43. #endif
  44. // -----------------------------------------------------------------------
  45. // misc functions
  46. static inline
  47. long d_cconst(const int a, const int b, const int c, const int d) noexcept
  48. {
  49. return (a << 24) | (b << 16) | (c << 8) | (d << 0);
  50. }
  51. static inline
  52. void d_pass() noexcept {}
  53. // -----------------------------------------------------------------------
  54. // string print functions
  55. #ifndef DEBUG
  56. # define d_debug(...)
  57. #else
  58. static inline
  59. void d_debug(const char* const fmt, ...) noexcept
  60. {
  61. try {
  62. ::va_list args;
  63. ::va_start(args, fmt);
  64. std::fprintf(stdout, "\x1b[30;1m");
  65. std::vfprintf(stdout, fmt, args);
  66. std::fprintf(stdout, "\x1b[0m\n");
  67. ::va_end(args);
  68. } catch (...) {}
  69. }
  70. #endif
  71. static inline
  72. void d_stdout(const char* const fmt, ...) noexcept
  73. {
  74. try {
  75. ::va_list args;
  76. ::va_start(args, fmt);
  77. std::vfprintf(stdout, fmt, args);
  78. std::fprintf(stdout, "\n");
  79. ::va_end(args);
  80. } catch (...) {}
  81. }
  82. static inline
  83. void d_stderr(const char* const fmt, ...) noexcept
  84. {
  85. try {
  86. ::va_list args;
  87. ::va_start(args, fmt);
  88. std::vfprintf(stderr, fmt, args);
  89. std::fprintf(stderr, "\n");
  90. ::va_end(args);
  91. } catch (...) {}
  92. }
  93. static inline
  94. void d_stderr2(const char* const fmt, ...) noexcept
  95. {
  96. try {
  97. ::va_list args;
  98. ::va_start(args, fmt);
  99. std::fprintf(stderr, "\x1b[31m");
  100. std::vfprintf(stderr, fmt, args);
  101. std::fprintf(stderr, "\x1b[0m\n");
  102. ::va_end(args);
  103. } catch (...) {}
  104. }
  105. static inline
  106. void d_safe_assert(const char* const assertion, const char* const file, const int line) noexcept
  107. {
  108. d_stderr2("assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
  109. }
  110. static inline
  111. void d_safe_exception(const char* const exception, const char* const file, const int line) noexcept
  112. {
  113. d_stderr2("exception caught: \"%s\" in file %s, line %i", exception, file, line);
  114. }
  115. // -----------------------------------------------------------------------
  116. #endif // DISTRHO_UTILS_HPP_INCLUDED