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.

CarlaBridgeClient.cpp 8.2KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Carla Bridge Client
  3. * Copyright (C) 2011-2013 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 GPL.txt file
  16. */
  17. #include "CarlaBridgeClient.hpp"
  18. #ifdef BUILD_BRIDGE_UI
  19. # include "CarlaBridgeToolkit.hpp"
  20. # include "CarlaLibUtils.hpp"
  21. #endif
  22. CARLA_BRIDGE_START_NAMESPACE
  23. // ---------------------------------------------------------------------
  24. CarlaBridgeClient::CarlaBridgeClient(const char* const uiTitle)
  25. : kOsc(this),
  26. #ifdef BUILD_BRIDGE_UI
  27. kUiToolkit(CarlaBridgeToolkit::createNew(this, uiTitle)),
  28. fUiFilename(nullptr),
  29. fUiLib(nullptr),
  30. fUiQuit(false),
  31. #endif
  32. fOscData(nullptr)
  33. {
  34. carla_debug("CarlaBridgeClient::CarlaBridgeClient(\"%s\")", uiTitle);
  35. }
  36. CarlaBridgeClient::~CarlaBridgeClient()
  37. {
  38. carla_debug("CarlaBridgeClient::~CarlaBridgeClient()");
  39. #ifdef BUILD_BRIDGE_UI
  40. if (fUiFilename != nullptr)
  41. delete[] fUiFilename;
  42. delete kUiToolkit;
  43. #endif
  44. }
  45. #ifdef BUILD_BRIDGE_UI
  46. // ---------------------------------------------------------------------
  47. // ui initialization
  48. bool CarlaBridgeClient::uiInit(const char* const, const char* const)
  49. {
  50. carla_debug("CarlaBridgeClient::uiInit()");
  51. // Test for single init
  52. {
  53. static bool initiated = false;
  54. CARLA_ASSERT(! initiated);
  55. initiated = true;
  56. }
  57. fUiQuit = false;
  58. kUiToolkit->init();
  59. return false;
  60. }
  61. void CarlaBridgeClient::uiClose()
  62. {
  63. carla_debug("CarlaBridgeClient::uiClose()");
  64. if (! fUiQuit)
  65. {
  66. fUiQuit = true;
  67. if (isOscControlRegistered())
  68. sendOscExiting();
  69. }
  70. kUiToolkit->quit();
  71. }
  72. #endif
  73. // ---------------------------------------------------------------------
  74. // osc stuff
  75. void CarlaBridgeClient::oscInit(const char* const url)
  76. {
  77. carla_debug("CarlaBridgeClient::oscInit(\"%s\")", url);
  78. kOsc.init(url);
  79. fOscData = kOsc.getControlData();
  80. }
  81. bool CarlaBridgeClient::oscIdle()
  82. {
  83. kOsc.idle();
  84. #ifdef BUILD_BRIDGE_UI
  85. return ! fUiQuit;
  86. #else
  87. return true;
  88. #endif
  89. }
  90. void CarlaBridgeClient::oscClose()
  91. {
  92. carla_debug("CarlaBridgeClient::oscClose()");
  93. CARLA_ASSERT(fOscData != nullptr);
  94. kOsc.close();
  95. fOscData = nullptr;
  96. }
  97. bool CarlaBridgeClient::isOscControlRegistered() const
  98. {
  99. return kOsc.isControlRegistered();
  100. }
  101. void CarlaBridgeClient::sendOscUpdate()
  102. {
  103. carla_debug("CarlaBridgeClient::sendOscUpdate()");
  104. CARLA_ASSERT(fOscData != nullptr);
  105. if (fOscData != nullptr && fOscData->target != nullptr)
  106. osc_send_update(fOscData, kOsc.getServerPath());
  107. }
  108. #ifdef BUILD_BRIDGE_PLUGIN
  109. void CarlaBridgeClient::sendOscBridgeUpdate()
  110. {
  111. carla_debug("CarlaBridgeClient::sendOscBridgeUpdate()");
  112. CARLA_ASSERT(fOscData != nullptr);
  113. CARLA_ASSERT(fOscData->target != nullptr && fOscData->path != nullptr);
  114. if (fOscData != nullptr && fOscData->target != nullptr && fOscData->path != nullptr)
  115. osc_send_bridge_update(fOscData, fOscData->path);
  116. }
  117. void CarlaBridgeClient::sendOscBridgeError(const char* const error)
  118. {
  119. carla_debug("CarlaBridgeClient::sendOscBridgeError(\"%s\")", error);
  120. CARLA_ASSERT(fOscData != nullptr);
  121. CARLA_ASSERT(error != nullptr);
  122. if (fOscData != nullptr && fOscData->target != nullptr && error != nullptr)
  123. osc_send_bridge_error(fOscData, error);
  124. }
  125. #endif
  126. #ifdef BUILD_BRIDGE_UI
  127. // ---------------------------------------------------------------------
  128. // toolkit
  129. void CarlaBridgeClient::toolkitShow()
  130. {
  131. carla_debug("CarlaBridgeClient::toolkitShow()");
  132. kUiToolkit->show();
  133. }
  134. void CarlaBridgeClient::toolkitHide()
  135. {
  136. carla_debug("CarlaBridgeClient::toolkitHide()");
  137. kUiToolkit->hide();
  138. }
  139. void CarlaBridgeClient::toolkitResize(const int width, const int height)
  140. {
  141. carla_debug("CarlaBridgeClient::toolkitResize(%i, %i)", width, height);
  142. kUiToolkit->resize(width, height);
  143. }
  144. void CarlaBridgeClient::toolkitExec(const bool showGui)
  145. {
  146. carla_debug("CarlaBridgeClient::toolkitExec(%s)", bool2str(showGui));
  147. kUiToolkit->exec(showGui);
  148. }
  149. void CarlaBridgeClient::toolkitQuit()
  150. {
  151. carla_debug("CarlaBridgeClient::toolkitQuit()");
  152. fUiQuit = true;
  153. kUiToolkit->quit();
  154. }
  155. #endif
  156. // ---------------------------------------------------------------------
  157. void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* const value)
  158. {
  159. carla_debug("CarlaBridgeClient::sendOscConfigure(\"%s\", \"%s\")", key, value);
  160. CARLA_ASSERT(fOscData != nullptr);
  161. if (fOscData != nullptr && fOscData->target != nullptr)
  162. osc_send_configure(fOscData, key, value);
  163. }
  164. void CarlaBridgeClient::sendOscControl(const int32_t index, const float value)
  165. {
  166. carla_debug("CarlaBridgeClient::sendOscControl(%i, %f)", index, value);
  167. CARLA_ASSERT(fOscData != nullptr);
  168. if (fOscData != nullptr && fOscData->target != nullptr)
  169. osc_send_control(fOscData, index, value);
  170. }
  171. void CarlaBridgeClient::sendOscProgram(const int32_t index)
  172. {
  173. carla_debug("CarlaBridgeClient::sendOscProgram(%i)", index);
  174. CARLA_ASSERT(fOscData != nullptr);
  175. if (fOscData != nullptr && fOscData->target != nullptr)
  176. osc_send_program(fOscData, index);
  177. }
  178. #ifdef BUILD_BRIDGE_PLUGIN
  179. void CarlaBridgeClient::sendOscMidiProgram(const int32_t index)
  180. {
  181. carla_debug("CarlaBridgeClient::sendOscMidiProgram(%i)", index);
  182. CARLA_ASSERT(fOscData != nullptr);
  183. if (fOscData != nullptr && fOscData->target != nullptr)
  184. osc_send_midi_program(fOscData, index);
  185. }
  186. #endif
  187. void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4])
  188. {
  189. carla_debug("CarlaBridgeClient::sendOscMidi(%p)", midiBuf);
  190. CARLA_ASSERT(fOscData != nullptr);
  191. if (fOscData != nullptr && fOscData->target != nullptr)
  192. osc_send_midi(fOscData, midiBuf);
  193. }
  194. void CarlaBridgeClient::sendOscExiting()
  195. {
  196. carla_debug("CarlaBridgeClient::sendOscExiting()");
  197. CARLA_ASSERT(fOscData != nullptr);
  198. if (fOscData != nullptr && fOscData->target != nullptr)
  199. osc_send_exiting(fOscData);
  200. }
  201. #ifdef BRIDGE_LV2
  202. void CarlaBridgeClient::sendOscLv2TransferAtom(const int32_t portIndex, const char* const typeStr, const char* const atomBuf)
  203. {
  204. carla_debug("CarlaBridgeClient::sendOscLv2TransferAtom(%i, \"%s\", \"%s\")", portIndex, typeStr, atomBuf);
  205. CARLA_ASSERT(fOscData != nullptr);
  206. if (fOscData != nullptr && fOscData->target != nullptr)
  207. osc_send_lv2_transfer_atom(fOscData, portIndex, typeStr, atomBuf);
  208. }
  209. void CarlaBridgeClient::sendOscLv2TransferEvent(const int32_t portIndex, const char* const typeStr, const char* const atomBuf)
  210. {
  211. carla_debug("CarlaBridgeClient::sendOscLv2TransferEvent(%i, \"%s\", \"%s\")", portIndex, typeStr, atomBuf);
  212. CARLA_ASSERT(fOscData != nullptr);
  213. if (fOscData != nullptr && fOscData->target != nullptr)
  214. osc_send_lv2_transfer_event(fOscData, portIndex, typeStr, atomBuf);
  215. }
  216. #endif
  217. // ---------------------------------------------------------------------
  218. #ifdef BUILD_BRIDGE_UI
  219. void* CarlaBridgeClient::getContainerId()
  220. {
  221. return kUiToolkit->getContainerId();
  222. }
  223. bool CarlaBridgeClient::uiLibOpen(const char* const filename)
  224. {
  225. CARLA_ASSERT(fUiLib == nullptr);
  226. CARLA_ASSERT(fUiFilename != nullptr);
  227. if (fUiFilename != nullptr)
  228. delete[] fUiFilename;
  229. fUiLib = lib_open(filename);
  230. fUiFilename = carla_strdup(filename ? filename : "");
  231. return (fUiLib != nullptr);
  232. }
  233. bool CarlaBridgeClient::uiLibClose()
  234. {
  235. CARLA_ASSERT(fUiLib != nullptr);
  236. if (fUiLib != nullptr)
  237. {
  238. const bool closed = lib_close(fUiLib);
  239. fUiLib = nullptr;
  240. return closed;
  241. }
  242. return false;
  243. }
  244. void* CarlaBridgeClient::uiLibSymbol(const char* const symbol)
  245. {
  246. CARLA_ASSERT(fUiLib != nullptr);
  247. if (fUiLib != nullptr)
  248. return lib_symbol(fUiLib, symbol);
  249. return nullptr;
  250. }
  251. const char* CarlaBridgeClient::uiLibError()
  252. {
  253. return lib_error(fUiFilename);
  254. }
  255. #endif
  256. CARLA_BRIDGE_END_NAMESPACE