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.

262 lines
6.7KB

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