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.

270 lines
7.2KB

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