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.

280 lines
7.7KB

  1. /*
  2. * Carla Bridge UI
  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. #ifndef CARLA_BRIDGE_UI_HPP_INCLUDED
  18. #define CARLA_BRIDGE_UI_HPP_INCLUDED
  19. #include "CarlaBridgeToolkit.hpp"
  20. #include "CarlaLibUtils.hpp"
  21. #include "CarlaPipeUtils.hpp"
  22. #ifdef BRIDGE_LV2
  23. # include "lv2/atom.h"
  24. # include "lv2/urid.h"
  25. #endif
  26. //#include "CarlaBridgeToolkit.hpp"
  27. //#include "CarlaLibUtils.hpp"
  28. CARLA_BRIDGE_START_NAMESPACE
  29. /*!
  30. * @defgroup CarlaBridgeUIAPI Carla UI Bridge API
  31. *
  32. * The Carla UI Bridge API.
  33. * @{
  34. */
  35. // -----------------------------------------------------------------------
  36. class CarlaBridgeUI : public CarlaPipeClient
  37. {
  38. protected:
  39. /*!
  40. * Constructor.
  41. */
  42. CarlaBridgeUI() noexcept;
  43. /*!
  44. * Destructor.
  45. */
  46. virtual ~CarlaBridgeUI() noexcept;
  47. // ---------------------------------------------------------------------
  48. // Host DSP State
  49. void sendControl(const uint32_t index, const float value) const noexcept;
  50. void sendProgram(const uint32_t index) const noexcept;
  51. void sendConfigure(const char* const key, const char* const value) const noexcept;
  52. void sendNote(const bool onOff, const uint8_t channel, const uint8_t note, const uint8_t velocity) const noexcept;
  53. #ifdef BRIDGE_LV2
  54. void sendAtom(const uint32_t index, const LV2_Atom* const atom) const noexcept;
  55. void sendURID(const LV2_URID urid, const char* const uri) const noexcept;
  56. #endif
  57. bool libOpen(const char* const filename) noexcept;
  58. void* libSymbol(const char* const symbol) const noexcept;
  59. const char* libError() const noexcept;
  60. // ---------------------------------------------------------------------
  61. // DSP Callbacks
  62. virtual void dspParameterChanged(const uint32_t index, const float value) = 0;
  63. virtual void dspProgramChanged(const uint32_t index) = 0;
  64. virtual void dspMidiProgramChanged(const uint32_t bank, const uint32_t program) = 0;
  65. virtual void dspStateChanged(const char* const key, const char* const value) = 0;
  66. virtual void dspNoteReceived(const bool onOff, const uint8_t channel, const uint8_t note, const uint8_t velocity) = 0;
  67. #ifdef BRIDGE_LV2
  68. virtual void dspAtomReceived(const uint32_t index, const LV2_Atom* const atom) = 0;
  69. virtual void dspURIDReceived(const LV2_URID urid, const char* const uri) = 0;
  70. #endif
  71. public:
  72. // ---------------------------------------------------------------------
  73. // UI initialization
  74. virtual bool init(const int argc, const char* argv[]);
  75. virtual void exec(const bool showUI);
  76. virtual void idleUI() {}
  77. // ---------------------------------------------------------------------
  78. // UI management
  79. /*!
  80. * Get the widget associated with this UI.
  81. * This can be a Gtk widget, Qt widget or a native Window handle depending on the compile target.
  82. */
  83. virtual void* getWidget() const noexcept = 0;
  84. /*!
  85. * Options.
  86. */
  87. struct Options {
  88. /*!
  89. * UI is resizable by the user.
  90. * The UI can still sometimes resize itself internally if this is false.
  91. */
  92. bool isResizable;
  93. /*!
  94. * Use the Carla PRO theme if possible.
  95. */
  96. bool useTheme;
  97. /*!
  98. * Use the Carla PRO theme colors if possible.
  99. * This implies useTheme to be true.
  100. */
  101. bool useThemeColors;
  102. /*!
  103. * Window title.
  104. */
  105. const char* windowTitle;
  106. /*!
  107. * Transient window id (parent), null if zero.
  108. */
  109. uintptr_t transientWindowId;
  110. /*!
  111. * Constructor for default options.
  112. */
  113. Options() noexcept
  114. : isResizable(true),
  115. useTheme(true),
  116. useThemeColors(true),
  117. windowTitle(nullptr),
  118. transientWindowId(0) {}
  119. };
  120. /*!
  121. * Get options associated with this UI.
  122. */
  123. virtual const Options& getOptions() const noexcept = 0;
  124. // ---------------------------------------------------------------------
  125. protected:
  126. bool fQuitReceived;
  127. #ifdef BRIDGE_LV2
  128. bool fUridMapComplete;
  129. #endif
  130. CarlaBridgeToolkit* fToolkit;
  131. lib_t fLib;
  132. CarlaString fLibFilename;
  133. /*! @internal */
  134. bool msgReceived(const char* const msg) noexcept override;
  135. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeUI)
  136. };
  137. /**@}*/
  138. // -----------------------------------------------------------------------
  139. CARLA_BRIDGE_END_NAMESPACE
  140. #endif // CARLA_BRIDGE_UI_HPP_INCLUDED
  141. // -----------------------------------------------------------------------
  142. #if 0
  143. // ---------------------------------------------------------------------
  144. // ui initialization
  145. virtual bool uiInit(const char*, const char* const, const char* const);
  146. virtual void uiIdle() {}
  147. virtual void uiClose();
  148. // ---------------------------------------------------------------------
  149. // ui toolkit
  150. void toolkitShow();
  151. void toolkitHide();
  152. void toolkitResize(const int width, const int height);
  153. void toolkitExec(const bool showGui);
  154. void toolkitQuit();
  155. // ---------------------------------------------------------------------
  156. // osc stuff
  157. void oscInit(const char* const url);
  158. bool oscIdle(const bool onlyOnce = false) const;
  159. void oscClose();
  160. bool isOscControlRegistered() const noexcept;
  161. void sendOscUpdate() const;
  162. // ---------------------------------------------------------------------
  163. protected:
  164. void sendOscConfigure(const char* const key, const char* const value) const;
  165. void sendOscControl(const int32_t index, const float value) const;
  166. void sendOscProgram(const uint32_t index) const;
  167. void sendOscMidiProgram(const uint32_t index) const;
  168. void sendOscMidi(const uint8_t midiBuf[4]) const;
  169. void sendOscExiting() const;
  170. #ifdef BRIDGE_LV2
  171. void sendOscLv2AtomTransfer(const uint32_t portIndex, const char* const atomBuf) const;
  172. void sendOscLv2UridMap(const uint32_t urid, const char* const uri) const;
  173. #endif
  174. // ---------------------------------------------------------------------
  175. void* getContainerId();
  176. void* getContainerId2();
  177. // ---------------------------------------------------------------------
  178. const char* uiLibError();
  179. template<typename Func>
  180. Func uiLibSymbol(const char* const symbol)
  181. {
  182. CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, nullptr);
  183. carla_debug("CarlaBridgeUI::uiLibSymbol(\"%s\")", symbol);
  184. return lib_symbol<Func>(fUI.lib, symbol);
  185. }
  186. #endif
  187. #if 0
  188. struct UI {
  189. CarlaBridgeToolkit* const toolkit;
  190. CarlaString filename;
  191. lib_t lib;
  192. bool quit;
  193. UI(CarlaBridgeToolkit* const toolkit_)
  194. : toolkit(toolkit_),
  195. filename(),
  196. lib(nullptr),
  197. quit(false)
  198. {
  199. CARLA_ASSERT(toolkit != nullptr);
  200. }
  201. ~UI()
  202. {
  203. delete toolkit;
  204. }
  205. void init()
  206. {
  207. toolkit->init();
  208. quit = false;
  209. }
  210. void close()
  211. {
  212. quit = true;
  213. toolkit->quit();
  214. }
  215. #ifdef CARLA_PROPER_CPP11_SUPPORT
  216. UI() = delete;
  217. CARLA_DECLARE_NON_COPY_STRUCT(UI)
  218. #endif
  219. } fUI;
  220. #endif