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.

carla_bridge_client.cpp 7.7KB

11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Carla Bridge Client
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_bridge_client.hpp"
  18. #include "carla_bridge_toolkit.hpp"
  19. #ifdef BUILD_BRIDGE_UI
  20. # include "carla_lib_utils.hpp"
  21. #endif
  22. #include <cstdlib>
  23. #include <cstring>
  24. CARLA_BRIDGE_START_NAMESPACE
  25. // ---------------------------------------------------------------------
  26. CarlaBridgeClient::CarlaBridgeClient(const char* const uiTitle)
  27. : m_osc(this),
  28. m_toolkit(CarlaBridgeToolkit::createNew(this, uiTitle))
  29. {
  30. qDebug("CarlaBridgeClient::CarlaBridgeClient(\"%s\")", uiTitle);
  31. m_oscData = nullptr;
  32. #ifdef BUILD_BRIDGE_UI
  33. m_uiFilename = nullptr;
  34. m_uiLib = nullptr;
  35. m_uiQuit = false;
  36. #endif
  37. }
  38. CarlaBridgeClient::~CarlaBridgeClient()
  39. {
  40. qDebug("CarlaBridgeClient::~CarlaBridgeClient()");
  41. #ifdef BUILD_BRIDGE_UI
  42. if (m_uiFilename)
  43. free(m_uiFilename);
  44. #endif
  45. delete m_toolkit;
  46. }
  47. #ifdef BUILD_BRIDGE_UI
  48. // ---------------------------------------------------------------------
  49. // ui initialization
  50. bool CarlaBridgeClient::init(const char* const, const char* const)
  51. {
  52. qDebug("CarlaBridgeClient::init()");
  53. // Test for single init
  54. {
  55. static bool initiated = false;
  56. CARLA_ASSERT(! initiated);
  57. initiated = true;
  58. }
  59. m_uiQuit = false;
  60. m_toolkit->init();
  61. return false;
  62. }
  63. void CarlaBridgeClient::close()
  64. {
  65. qDebug("CarlaBridgeClient::close()");
  66. if (! m_uiQuit)
  67. {
  68. m_uiQuit = true;
  69. if (isOscControlRegistered())
  70. sendOscExiting();
  71. }
  72. m_toolkit->quit();
  73. }
  74. #endif
  75. // ---------------------------------------------------------------------
  76. // osc stuff
  77. bool CarlaBridgeClient::oscInit(const char* const url)
  78. {
  79. qDebug("CarlaBridgeClient::oscInit(\"%s\")", url);
  80. const bool ret = m_osc.init(url);
  81. m_oscData = m_osc.getControlData();
  82. return ret;
  83. }
  84. bool CarlaBridgeClient::oscIdle()
  85. {
  86. m_osc.idle();
  87. #ifdef BUILD_BRIDGE_UI
  88. return ! m_uiQuit;
  89. #else
  90. return true;
  91. #endif
  92. }
  93. void CarlaBridgeClient::oscClose()
  94. {
  95. qDebug("CarlaBridgeClient::oscClose()");
  96. CARLA_ASSERT(m_oscData);
  97. m_osc.close();
  98. m_oscData = nullptr;
  99. }
  100. bool CarlaBridgeClient::isOscControlRegistered() const
  101. {
  102. return m_osc.isControlRegistered();
  103. }
  104. void CarlaBridgeClient::sendOscUpdate()
  105. {
  106. qDebug("CarlaBridgeClient::sendOscUpdate()");
  107. CARLA_ASSERT(m_oscData);
  108. if (m_oscData && m_oscData->target)
  109. osc_send_update(m_oscData, m_osc.getServerPath());
  110. }
  111. #ifdef BUILD_BRIDGE_PLUGIN
  112. void CarlaBridgeClient::sendOscBridgeUpdate()
  113. {
  114. qDebug("CarlaBridgeClient::sendOscBridgeUpdate()");
  115. CARLA_ASSERT(m_oscData);
  116. CARLA_ASSERT(m_oscData->target && m_oscData->path);
  117. if (m_oscData && m_oscData->target && m_oscData->path)
  118. osc_send_bridge_update(m_oscData, m_oscData->path);
  119. }
  120. void CarlaBridgeClient::sendOscBridgeError(const char* const error)
  121. {
  122. qDebug("CarlaBridgeClient::sendOscBridgeError(\"%s\")", error);
  123. CARLA_ASSERT(m_oscData);
  124. CARLA_ASSERT(error);
  125. if (m_oscData && m_oscData->target)
  126. osc_send_bridge_error(m_oscData, error);
  127. }
  128. #endif
  129. // ---------------------------------------------------------------------
  130. // toolkit
  131. void CarlaBridgeClient::toolkitShow()
  132. {
  133. qDebug("CarlaBridgeClient::toolkitShow()");
  134. m_toolkit->show();
  135. }
  136. void CarlaBridgeClient::toolkitHide()
  137. {
  138. qDebug("CarlaBridgeClient::toolkitHide()");
  139. m_toolkit->hide();
  140. }
  141. void CarlaBridgeClient::toolkitResize(const int width, const int height)
  142. {
  143. qDebug("CarlaBridgeClient::toolkitResize(%i, %i)", width, height);
  144. m_toolkit->resize(width, height);
  145. }
  146. void CarlaBridgeClient::toolkitExec(const bool showGui)
  147. {
  148. qDebug("CarlaBridgeClient::toolkitExec(%s)", bool2str(showGui));
  149. m_toolkit->exec(showGui);
  150. }
  151. void CarlaBridgeClient::toolkitQuit()
  152. {
  153. qDebug("CarlaBridgeClient::toolkitQuit()");
  154. #ifdef BUILD_BRIDGE_UI
  155. m_uiQuit = true;
  156. #endif
  157. m_toolkit->quit();
  158. }
  159. // ---------------------------------------------------------------------
  160. void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* const value)
  161. {
  162. qDebug("CarlaBridgeClient::sendOscConfigure(\"%s\", \"%s\")", key, value);
  163. CARLA_ASSERT(m_oscData);
  164. if (m_oscData && m_oscData->target)
  165. osc_send_configure(m_oscData, key, value);
  166. }
  167. void CarlaBridgeClient::sendOscControl(const int32_t index, const float value)
  168. {
  169. qDebug("CarlaBridgeClient::sendOscControl(%i, %f)", index, value);
  170. CARLA_ASSERT(m_oscData);
  171. if (m_oscData && m_oscData->target)
  172. osc_send_control(m_oscData, index, value);
  173. }
  174. void CarlaBridgeClient::sendOscProgram(const int32_t index)
  175. {
  176. qDebug("CarlaBridgeClient::sendOscProgram(%i)", index);
  177. CARLA_ASSERT(m_oscData);
  178. if (m_oscData && m_oscData->target)
  179. osc_send_program(m_oscData, index);
  180. }
  181. void CarlaBridgeClient::sendOscMidiProgram(const int32_t index)
  182. {
  183. qDebug("CarlaBridgeClient::sendOscMidiProgram(%i)", index);
  184. CARLA_ASSERT(m_oscData);
  185. if (m_oscData && m_oscData->target)
  186. osc_send_midi_program(m_oscData, index);
  187. }
  188. void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4])
  189. {
  190. qDebug("CarlaBridgeClient::sendOscMidi(%p)", midiBuf);
  191. CARLA_ASSERT(m_oscData);
  192. if (m_oscData && m_oscData->target)
  193. osc_send_midi(m_oscData, midiBuf);
  194. }
  195. void CarlaBridgeClient::sendOscExiting()
  196. {
  197. qDebug("CarlaBridgeClient::sendOscExiting()");
  198. CARLA_ASSERT(m_oscData);
  199. if (m_oscData && m_oscData->target)
  200. osc_send_exiting(m_oscData);
  201. }
  202. #ifdef BRIDGE_LV2
  203. void CarlaBridgeClient::sendOscLv2TransferAtom(const int32_t portIndex, const char* const typeStr, const char* const atomBuf)
  204. {
  205. qDebug("CarlaBridgeClient::sendOscLv2TransferAtom(%i, \"%s\", \"%s\")", portIndex, typeStr, atomBuf);
  206. CARLA_ASSERT(m_oscData);
  207. if (m_oscData && m_oscData->target)
  208. osc_send_lv2_transfer_atom(m_oscData, portIndex, typeStr, atomBuf);
  209. }
  210. void CarlaBridgeClient::sendOscLv2TransferEvent(const int32_t portIndex, const char* const typeStr, const char* const atomBuf)
  211. {
  212. qDebug("CarlaBridgeClient::sendOscLv2TransferEvent(%i, \"%s\", \"%s\")", portIndex, typeStr, atomBuf);
  213. CARLA_ASSERT(m_oscData);
  214. if (m_oscData && m_oscData->target)
  215. osc_send_lv2_transfer_event(m_oscData, portIndex, typeStr, atomBuf);
  216. }
  217. #endif
  218. // ---------------------------------------------------------------------
  219. void* CarlaBridgeClient::getContainerId()
  220. {
  221. return m_toolkit->getContainerId();
  222. }
  223. #ifdef BUILD_BRIDGE_UI
  224. bool CarlaBridgeClient::uiLibOpen(const char* const filename)
  225. {
  226. CARLA_ASSERT(! m_uiLib);
  227. CARLA_ASSERT(filename);
  228. if (m_uiFilename)
  229. free(m_uiFilename);
  230. m_uiLib = lib_open(filename);
  231. m_uiFilename = strdup(filename ? filename : "");
  232. return bool(m_uiLib);
  233. }
  234. bool CarlaBridgeClient::uiLibClose()
  235. {
  236. CARLA_ASSERT(m_uiLib);
  237. if (m_uiLib)
  238. {
  239. const bool closed = lib_close(m_uiLib);
  240. m_uiLib = nullptr;
  241. return closed;
  242. }
  243. return false;
  244. }
  245. void* CarlaBridgeClient::uiLibSymbol(const char* const symbol)
  246. {
  247. CARLA_ASSERT(m_uiLib);
  248. if (m_uiLib)
  249. return lib_symbol(m_uiLib, symbol);
  250. return nullptr;
  251. }
  252. const char* CarlaBridgeClient::uiLibError()
  253. {
  254. return lib_error(m_uiFilename);
  255. }
  256. #endif
  257. CARLA_BRIDGE_END_NAMESPACE