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