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.

311 lines
7.8KB

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