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.

269 lines
7.1KB

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