Collection of tools useful for audio production
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.

161 lines
4.0KB

  1. /*
  2. * Carla common includes
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #ifndef CARLA_INCLUDES_H
  18. #define CARLA_INCLUDES_H
  19. #ifdef __WINE__
  20. # define Q_CORE_EXPORT
  21. # define Q_GUI_EXPORT
  22. # define QT_NO_STL
  23. #endif
  24. #include <QtCore/Qt>
  25. // TESTING - remove later (QtCreator doesn't fully support this)
  26. #ifdef QTCREATOR_TEST
  27. # undef Q_COMPILER_INITIALIZER_LISTS
  28. #endif
  29. // If the compiler can't do C++11 lambdas, it most likely doesn't know about nullptr either
  30. #ifndef Q_COMPILER_LAMBDA
  31. # define nullptr (0)
  32. #endif
  33. // Common includes and macros
  34. #ifdef Q_OS_WIN
  35. # include <winsock2.h>
  36. # include <windows.h>
  37. //# define uintptr_t size_t // FIXME
  38. # define carla_sleep(t) Sleep(t * 1000)
  39. # define carla_msleep(t) Sleep(t)
  40. # define carla_usleep(t) Sleep(t / 1000)
  41. # define carla_setenv(key, value) SetEnvironmentVariableA(key, value)
  42. #else
  43. # include <dlfcn.h>
  44. # include <unistd.h>
  45. # define carla_sleep(t) sleep(t)
  46. # define carla_msleep(t) usleep(t * 1000)
  47. # define carla_usleep(t) usleep(t)
  48. # define carla_setenv(key, value) setenv(key, value, 1)
  49. # ifndef __cdecl
  50. # define __cdecl
  51. # endif
  52. #endif
  53. // ..., needed for qDebug/Warning/Critical sections
  54. #if defined(Q_OS_WIN64) && ! defined(__WINE__)
  55. # define P_INT64 "%I64i"
  56. # define P_INTPTR "%I64i"
  57. # define P_UINTPTR "%I64x"
  58. # define P_SIZE "%I64u"
  59. #elif __WORDSIZE == 64
  60. # define P_INT64 "%li"
  61. # define P_INTPTR "%li"
  62. # define P_UINTPTR "%lx"
  63. # define P_SIZE "%lu"
  64. #else
  65. # define P_INT64 "%lli"
  66. # define P_INTPTR "%i"
  67. # define P_UINTPTR "%x"
  68. # define P_SIZE "%u"
  69. #endif
  70. // Define BINARY_NATIVE
  71. #if defined(Q_OS_HAIKU) || defined(Q_OS_UNIX)
  72. # ifdef __LP64__
  73. # define BINARY_NATIVE BINARY_POSIX64
  74. # else
  75. # define BINARY_NATIVE BINARY_POSIX32
  76. # endif
  77. #elif defined(Q_OS_WIN)
  78. # ifdef Q_OS_WIN64
  79. # define BINARY_NATIVE BINARY_WIN64
  80. # else
  81. # define BINARY_NATIVE BINARY_WIN32
  82. # endif
  83. #else
  84. # warning Unknown binary type
  85. # define BINARY_NATIVE BINARY_OTHER
  86. #endif
  87. // Define CARLA_ASSERT*
  88. #ifdef NDEBUG
  89. # define CARLA_ASSERT(cond) ((!(cond)) ? carla_assert(#cond, __FILE__, __LINE__) : pass())
  90. # define CARLA_ASSERT_INT(cond, value) ((!(cond)) ? carla_assert_int(#cond, __FILE__, __LINE__, value) : pass())
  91. #else
  92. # define CARLA_ASSERT Q_ASSERT
  93. # define CARLA_ASSERT_INT(cond, value) Q_ASSERT(cond)
  94. #endif
  95. // Export symbols if needed
  96. #ifdef BUILD_BRIDGE
  97. # define CARLA_EXPORT extern "C"
  98. #else
  99. # if defined(Q_OS_WIN) && ! defined(__WINE__)
  100. # define CARLA_EXPORT extern "C" __declspec (dllexport)
  101. # else
  102. # define CARLA_EXPORT extern "C" __attribute__ ((visibility("default")))
  103. # endif
  104. #endif
  105. // Inline functions
  106. #ifdef Q_OS_LINUX
  107. # include <sys/prctl.h>
  108. # include <linux/prctl.h>
  109. static inline
  110. void carla_setprocname(const char* const name)
  111. {
  112. prctl(PR_SET_NAME, name);
  113. }
  114. #else
  115. static inline
  116. void carla_setprocname(const char* const)
  117. {
  118. }
  119. #endif
  120. static inline
  121. void carla_assert(const char* const assertion, const char* const file, const int line)
  122. {
  123. qCritical("Carla assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
  124. }
  125. static inline
  126. void carla_assert_int(const char* const assertion, const char* const file, const int line, const int value)
  127. {
  128. qCritical("Carla assertion failure: \"%s\" in file %s, line %i, value %i", assertion, file, line, value);
  129. }
  130. static inline
  131. const char* bool2str(const bool yesNo)
  132. {
  133. return yesNo ? "true" : "false";
  134. }
  135. static inline
  136. void pass() {}
  137. static inline
  138. void zeroF(float* data, const unsigned int size)
  139. {
  140. for (unsigned int i=0; i < size; i++)
  141. *data++ = 0.0f;
  142. }
  143. #endif // CARLA_INCLUDES_H