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 7.3KB

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
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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::oscWait() const
  110. {
  111. fOsc.idleWait();
  112. }
  113. void CarlaBridgeClient::oscClose()
  114. {
  115. carla_debug("CarlaBridgeClient::oscClose()");
  116. fOsc.close();
  117. }
  118. bool CarlaBridgeClient::isOscControlRegistered() const noexcept
  119. {
  120. return fOsc.isControlRegistered();
  121. }
  122. void CarlaBridgeClient::sendOscUpdate() const
  123. {
  124. carla_debug("CarlaBridgeClient::sendOscUpdate()");
  125. if (fOscData.target != nullptr)
  126. osc_send_update(fOscData, fOsc.getServerPath());
  127. }
  128. #ifdef BUILD_BRIDGE_PLUGIN
  129. void CarlaBridgeClient::sendOscBridgeUpdate() const
  130. {
  131. carla_debug("CarlaBridgeClient::sendOscBridgeUpdate()");
  132. if (fOscData.target != nullptr)
  133. osc_send_bridge_update(fOscData, fOscData.path);
  134. }
  135. void CarlaBridgeClient::sendOscBridgeError(const char* const error) const
  136. {
  137. carla_debug("CarlaBridgeClient::sendOscBridgeError(\"%s\")", error);
  138. if (fOscData.target != nullptr)
  139. osc_send_bridge_error(fOscData, error);
  140. }
  141. #endif
  142. // ---------------------------------------------------------------------
  143. void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* const value) const
  144. {
  145. carla_debug("CarlaBridgeClient::sendOscConfigure(\"%s\", \"%s\")", key, value);
  146. if (fOscData.target != nullptr)
  147. osc_send_configure(fOscData, key, value);
  148. }
  149. void CarlaBridgeClient::sendOscControl(const int32_t index, const float value) const
  150. {
  151. carla_debug("CarlaBridgeClient::sendOscControl(%i, %f)", index, value);
  152. if (fOscData.target != nullptr)
  153. osc_send_control(fOscData, index, value);
  154. }
  155. void CarlaBridgeClient::sendOscProgram(const uint32_t index) const
  156. {
  157. carla_debug("CarlaBridgeClient::sendOscProgram(%i)", index);
  158. if (fOscData.target != nullptr)
  159. osc_send_program(fOscData, index);
  160. }
  161. void CarlaBridgeClient::sendOscMidiProgram(const uint32_t index) const
  162. {
  163. carla_debug("CarlaBridgeClient::sendOscMidiProgram(%i)", index);
  164. if (fOscData.target != nullptr)
  165. osc_send_midi_program(fOscData, index);
  166. }
  167. void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4]) const
  168. {
  169. carla_debug("CarlaBridgeClient::sendOscMidi(%p)", midiBuf);
  170. if (fOscData.target != nullptr)
  171. osc_send_midi(fOscData, midiBuf);
  172. }
  173. void CarlaBridgeClient::sendOscExiting() const
  174. {
  175. carla_debug("CarlaBridgeClient::sendOscExiting()");
  176. if (fOscData.target != nullptr)
  177. osc_send_exiting(fOscData);
  178. }
  179. #ifdef BRIDGE_LV2
  180. void CarlaBridgeClient::sendOscLv2AtomTransfer(const int32_t portIndex, const char* const atomBuf) const
  181. {
  182. carla_debug("CarlaBridgeClient::sendOscLv2TransferAtom(%i, \"%s\")", portIndex, atomBuf);
  183. if (fOscData.target != nullptr)
  184. osc_send_lv2_atom_transfer(fOscData, portIndex, atomBuf);
  185. }
  186. void CarlaBridgeClient::sendOscLv2UridMap(const uint32_t urid, const char* const uri) const
  187. {
  188. carla_debug("CarlaBridgeClient::sendOscLv2UridMap(%i, \"%s\")", urid, uri);
  189. if (fOscData.target != nullptr)
  190. osc_send_lv2_urid_map(fOscData, urid, uri);
  191. }
  192. #endif
  193. // ---------------------------------------------------------------------
  194. #ifdef BUILD_BRIDGE_UI
  195. void* CarlaBridgeClient::getContainerId()
  196. {
  197. carla_debug("CarlaBridgeClient::getContainerId()");
  198. return fUI.toolkit->getContainerId();
  199. }
  200. bool CarlaBridgeClient::uiLibOpen(const char* const filename)
  201. {
  202. CARLA_ASSERT(fUI.lib == nullptr);
  203. CARLA_ASSERT(filename != nullptr);
  204. carla_debug("CarlaBridgeClient::uiLibOpen(\"%s\")", filename);
  205. fUI.lib = lib_open(filename);
  206. fUI.filename = filename;
  207. return (fUI.lib != nullptr);
  208. }
  209. bool CarlaBridgeClient::uiLibClose()
  210. {
  211. CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, false);
  212. carla_debug("CarlaBridgeClient::uiLibClose()");
  213. const bool closed = lib_close(fUI.lib);
  214. fUI.lib = nullptr;
  215. return closed;
  216. }
  217. void* CarlaBridgeClient::uiLibSymbol(const char* const symbol)
  218. {
  219. CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, nullptr);
  220. carla_debug("CarlaBridgeClient::uiLibSymbol(\"%s\")", symbol);
  221. return lib_symbol(fUI.lib, symbol);
  222. }
  223. const char* CarlaBridgeClient::uiLibError()
  224. {
  225. carla_debug("CarlaBridgeClient::uiLibError()");
  226. return lib_error(fUI.filename);
  227. }
  228. #endif
  229. CARLA_BRIDGE_END_NAMESPACE