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.

CarlaUtils.cpp 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaUtils.h"
  18. #include "CarlaPipeUtils.hpp"
  19. #include "CarlaThread.hpp"
  20. #include "juce_core.h"
  21. // -------------------------------------------------------------------------------------------------------------------
  22. const char* carla_get_library_filename()
  23. {
  24. carla_debug("carla_get_library_filename()");
  25. static CarlaString ret;
  26. if (ret.isEmpty())
  27. {
  28. using juce::File;
  29. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  30. }
  31. return ret;
  32. }
  33. const char* carla_get_library_folder()
  34. {
  35. carla_debug("carla_get_library_folder()");
  36. static CarlaString ret;
  37. if (ret.isEmpty())
  38. {
  39. using juce::File;
  40. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  41. }
  42. return ret;
  43. }
  44. // -------------------------------------------------------------------------------------------------------------------
  45. void carla_set_locale_C()
  46. {
  47. ::setlocale(LC_NUMERIC, "C");
  48. }
  49. // -------------------------------------------------------------------------------------------------------------------
  50. void carla_set_process_name(const char* name)
  51. {
  52. carla_debug("carla_set_process_name(\"%s\")", name);
  53. CarlaThread::setCurrentThreadName(name);
  54. juce::Thread::setCurrentThreadName(name);
  55. }
  56. // -------------------------------------------------------------------------------------------------------------------
  57. class CarlaPipeClientPlugin : public CarlaPipeClient
  58. {
  59. public:
  60. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  61. : CarlaPipeClient(),
  62. fCallbackFunc(callbackFunc),
  63. fCallbackPtr(callbackPtr),
  64. leakDetector_CarlaPipeClientPlugin()
  65. {
  66. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  67. }
  68. const char* readlineblock(const uint timeout) noexcept
  69. {
  70. return CarlaPipeClient::readlineblock(timeout);
  71. }
  72. bool msgReceived(const char* const msg) noexcept
  73. {
  74. if (fCallbackFunc != nullptr)
  75. {
  76. try {
  77. fCallbackFunc(fCallbackPtr, msg);
  78. } CARLA_SAFE_EXCEPTION("msgReceived");
  79. }
  80. return true;
  81. }
  82. private:
  83. const CarlaPipeCallbackFunc fCallbackFunc;
  84. void* const fCallbackPtr;
  85. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  86. };
  87. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  88. {
  89. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  90. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  91. if (! pipe->init(argv))
  92. {
  93. delete pipe;
  94. return nullptr;
  95. }
  96. return pipe;
  97. }
  98. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  99. {
  100. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  101. ((CarlaPipeClientPlugin*)handle)->idle();
  102. }
  103. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  104. {
  105. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  106. return ((CarlaPipeClientPlugin*)handle)->isRunning();
  107. }
  108. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  109. {
  110. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  111. return ((CarlaPipeClientPlugin*)handle)->lock();
  112. }
  113. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  114. {
  115. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  116. return ((CarlaPipeClientPlugin*)handle)->unlock();
  117. }
  118. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  119. {
  120. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  121. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  122. }
  123. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  124. {
  125. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  126. return ((CarlaPipeClientPlugin*)handle)->writeMsg(msg);
  127. }
  128. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  129. {
  130. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  131. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMsg(msg);
  132. }
  133. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  134. {
  135. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  136. return ((CarlaPipeClientPlugin*)handle)->flush();
  137. }
  138. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  139. {
  140. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  141. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  142. const bool ret(pipe->flush());
  143. pipe->unlock();
  144. return ret;
  145. }
  146. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  147. {
  148. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  149. carla_debug("carla_pipe_client_destroy(%p)", handle);
  150. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  151. pipe->close();
  152. delete pipe;
  153. }
  154. // -------------------------------------------------------------------------------------------------------------------
  155. #include "CarlaPipeUtils.cpp"
  156. // -------------------------------------------------------------------------------------------------------------------