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

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
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
11 years ago
11 years ago
11 years ago
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
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 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.quit = true;
  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 bool onlyOnce) const
  87. {
  88. if (onlyOnce)
  89. fOsc.idleOnce();
  90. else
  91. fOsc.idle();
  92. return ! fUI.quit;
  93. }
  94. void CarlaBridgeClient::oscClose()
  95. {
  96. carla_debug("CarlaBridgeClient::oscClose()");
  97. fOsc.close();
  98. }
  99. bool CarlaBridgeClient::isOscControlRegistered() const noexcept
  100. {
  101. return fOsc.isControlRegistered();
  102. }
  103. void CarlaBridgeClient::sendOscUpdate() const
  104. {
  105. carla_debug("CarlaBridgeClient::sendOscUpdate()");
  106. if (fOscData.target != nullptr)
  107. osc_send_update(fOscData, fOsc.getServerPath());
  108. }
  109. // ---------------------------------------------------------------------
  110. void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* const value) const
  111. {
  112. carla_debug("CarlaBridgeClient::sendOscConfigure(\"%s\", \"%s\")", key, value);
  113. if (fOscData.target != nullptr)
  114. osc_send_configure(fOscData, key, value);
  115. }
  116. void CarlaBridgeClient::sendOscControl(const int32_t index, const float value) const
  117. {
  118. carla_debug("CarlaBridgeClient::sendOscControl(%i, %f)", index, value);
  119. if (fOscData.target != nullptr)
  120. osc_send_control(fOscData, index, value);
  121. }
  122. void CarlaBridgeClient::sendOscProgram(const uint32_t index) const
  123. {
  124. carla_debug("CarlaBridgeClient::sendOscProgram(%i)", index);
  125. if (fOscData.target != nullptr)
  126. osc_send_program(fOscData, index);
  127. }
  128. void CarlaBridgeClient::sendOscMidiProgram(const uint32_t index) const
  129. {
  130. carla_debug("CarlaBridgeClient::sendOscMidiProgram(%i)", index);
  131. if (fOscData.target != nullptr)
  132. osc_send_midi_program(fOscData, index);
  133. }
  134. void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4]) const
  135. {
  136. carla_debug("CarlaBridgeClient::sendOscMidi(%p)", midiBuf);
  137. if (fOscData.target != nullptr)
  138. osc_send_midi(fOscData, midiBuf);
  139. }
  140. void CarlaBridgeClient::sendOscExiting() const
  141. {
  142. carla_debug("CarlaBridgeClient::sendOscExiting()");
  143. if (fOscData.target != nullptr)
  144. osc_send_exiting(fOscData);
  145. }
  146. #ifdef BRIDGE_LV2
  147. void CarlaBridgeClient::sendOscLv2AtomTransfer(const uint32_t portIndex, const char* const atomBuf) const
  148. {
  149. carla_debug("CarlaBridgeClient::sendOscLv2TransferAtom(%i, \"%s\")", portIndex, atomBuf);
  150. if (fOscData.target != nullptr)
  151. osc_send_lv2_atom_transfer(fOscData, portIndex, atomBuf);
  152. }
  153. void CarlaBridgeClient::sendOscLv2UridMap(const uint32_t urid, const char* const uri) const
  154. {
  155. carla_debug("CarlaBridgeClient::sendOscLv2UridMap(%i, \"%s\")", urid, uri);
  156. if (fOscData.target != nullptr)
  157. osc_send_lv2_urid_map(fOscData, urid, uri);
  158. }
  159. #endif
  160. // ---------------------------------------------------------------------
  161. void* CarlaBridgeClient::getContainerId()
  162. {
  163. carla_debug("CarlaBridgeClient::getContainerId()");
  164. return fUI.toolkit->getContainerId();
  165. }
  166. void* CarlaBridgeClient::getContainerId2()
  167. {
  168. carla_debug("CarlaBridgeClient::getContainerId2()");
  169. return fUI.toolkit->getContainerId2();
  170. }
  171. bool CarlaBridgeClient::uiLibOpen(const char* const filename)
  172. {
  173. CARLA_ASSERT(fUI.lib == nullptr);
  174. CARLA_ASSERT(filename != nullptr);
  175. carla_debug("CarlaBridgeClient::uiLibOpen(\"%s\")", filename);
  176. fUI.lib = lib_open(filename);
  177. fUI.filename = filename;
  178. return (fUI.lib != nullptr);
  179. }
  180. bool CarlaBridgeClient::uiLibClose()
  181. {
  182. CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, false);
  183. carla_debug("CarlaBridgeClient::uiLibClose()");
  184. const bool closed = lib_close(fUI.lib);
  185. fUI.lib = nullptr;
  186. return closed;
  187. }
  188. void* CarlaBridgeClient::uiLibSymbol(const char* const symbol)
  189. {
  190. CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, nullptr);
  191. carla_debug("CarlaBridgeClient::uiLibSymbol(\"%s\")", symbol);
  192. return lib_symbol(fUI.lib, symbol);
  193. }
  194. const char* CarlaBridgeClient::uiLibError()
  195. {
  196. carla_debug("CarlaBridgeClient::uiLibError()");
  197. return lib_error(fUI.filename);
  198. }
  199. // ---------------------------------------------------------------------
  200. CARLA_BRIDGE_END_NAMESPACE