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.3KB

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