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.

266 lines
6.8KB

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