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.

295 lines
7.4KB

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