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.

150 lines
3.5KB

  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
  26. #ifdef QTCREATOR_TEST
  27. # undef Q_COMPILER_INITIALIZER_LISTS
  28. #endif
  29. #ifndef Q_COMPILER_LAMBDA
  30. # define nullptr (0)
  31. #endif
  32. #ifdef Q_OS_WIN
  33. # include <winsock2.h>
  34. # include <windows.h>
  35. # define uintptr_t size_t // FIXME
  36. # define carla_sleep(t) Sleep(t * 1000)
  37. # define carla_msleep(t) Sleep(t)
  38. # define carla_usleep(t) Sleep(t / 1000)
  39. # define carla_setenv(key, value) SetEnvironmentVariableA(key, value)
  40. #else
  41. # include <dlfcn.h>
  42. # include <unistd.h>
  43. # define carla_sleep(t) sleep(t)
  44. # define carla_msleep(t) usleep(t * 1000)
  45. # define carla_usleep(t) usleep(t)
  46. # define carla_setenv(key, value) setenv(key, value, 1)
  47. # ifndef __cdecl
  48. # define __cdecl
  49. # endif
  50. #endif
  51. // needed for qDebug/Warning/Critical sections
  52. #if defined(Q_OS_WIN64) && ! defined(__WINE__)
  53. # define P_INT64 "%I64i"
  54. # define P_INTPTR "%I64i"
  55. # define P_UINTPTR "%I64x"
  56. # define P_SIZE "%I64u"
  57. #elif __WORDSIZE == 64
  58. # define P_INT64 "%li"
  59. # define P_INTPTR "%li"
  60. # define P_UINTPTR "%lx"
  61. # define P_SIZE "%lu"
  62. #else
  63. # define P_INT64 "%lli"
  64. # define P_INTPTR "%i"
  65. # define P_UINTPTR "%x"
  66. # define P_SIZE "%u"
  67. #endif
  68. // set native binary type
  69. #if defined(Q_OS_HAIKU) || defined(Q_OS_UNIX)
  70. # ifdef __LP64__
  71. # define BINARY_NATIVE BINARY_POSIX64
  72. # else
  73. # define BINARY_NATIVE BINARY_POSIX32
  74. # endif
  75. #elif defined(Q_OS_WIN)
  76. # ifdef Q_OS_WIN64
  77. # define BINARY_NATIVE BINARY_WIN64
  78. # else
  79. # define BINARY_NATIVE BINARY_WIN32
  80. # endif
  81. #else
  82. # warning Unknown binary type
  83. # define BINARY_NATIVE BINARY_OTHER
  84. #endif
  85. // export symbols if needed
  86. #ifdef BUILD_BRIDGE
  87. # define CARLA_EXPORT extern "C"
  88. #else
  89. # if defined(Q_OS_WIN) && ! defined(__WINE__)
  90. # define CARLA_EXPORT extern "C" __declspec (dllexport)
  91. # else
  92. # define CARLA_EXPORT extern "C" __attribute__ ((visibility("default")))
  93. # endif
  94. #endif
  95. #ifdef NDEBUG
  96. # define CARLA_ASSERT(cond) ((!(cond)) ? carla_assert(#cond, __FILE__, __LINE__) : pass())
  97. #else
  98. # define CARLA_ASSERT Q_ASSERT
  99. #endif
  100. // carla_setprocname
  101. #ifdef Q_OS_LINUX
  102. # include <sys/prctl.h>
  103. # include <linux/prctl.h>
  104. static inline
  105. void carla_setprocname(const char* const name)
  106. {
  107. prctl(PR_SET_NAME, name);
  108. }
  109. #else
  110. static inline
  111. void carla_setprocname(const char* const /*name*/)
  112. {
  113. }
  114. #endif
  115. static inline
  116. void carla_assert(const char* const assertion, const char* const file, const int line)
  117. {
  118. qCritical("Carla assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
  119. }
  120. static inline
  121. const char* bool2str(const bool yesNo)
  122. {
  123. return yesNo ? "true" : "false";
  124. }
  125. static inline
  126. void pass() {}
  127. static inline
  128. void zeroF(float* data, const unsigned int size)
  129. {
  130. for (unsigned int i=0; i < size; i++)
  131. *data++ = 0.0f;
  132. }
  133. #endif // CARLA_INCLUDES_H