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.

310 lines
7.9KB

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