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

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