DISTRHO Plugin Framework
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.

306 lines
9.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DISTRHO_UI_HPP_INCLUDED
  17. #define DISTRHO_UI_HPP_INCLUDED
  18. #include "extra/LeakDetector.hpp"
  19. #include "src/DistrhoPluginChecks.h"
  20. #ifdef DGL_CAIRO
  21. # include "Cairo.hpp"
  22. #endif
  23. #ifdef DGL_OPENGL
  24. # include "OpenGL.hpp"
  25. #endif
  26. #ifdef DGL_VULKAN
  27. # include "Vulkan.hpp"
  28. #endif
  29. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  30. # include "../dgl/Base.hpp"
  31. # include "extra/ExternalWindow.hpp"
  32. typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget;
  33. #elif DISTRHO_UI_USE_CUSTOM
  34. # include DISTRHO_UI_CUSTOM_INCLUDE_PATH
  35. typedef DISTRHO_UI_CUSTOM_WIDGET_TYPE UIWidget;
  36. #elif DISTRHO_UI_USE_CAIRO
  37. # include "../dgl/Cairo.hpp"
  38. typedef DGL_NAMESPACE::CairoTopLevelWidget UIWidget;
  39. #elif DISTRHO_UI_USE_NANOVG
  40. # include "../dgl/NanoVG.hpp"
  41. typedef DGL_NAMESPACE::NanoTopLevelWidget UIWidget;
  42. #else
  43. # include "../dgl/TopLevelWidget.hpp"
  44. typedef DGL_NAMESPACE::TopLevelWidget UIWidget;
  45. #endif
  46. START_NAMESPACE_DISTRHO
  47. /* ------------------------------------------------------------------------------------------------------------
  48. * DPF UI */
  49. /**
  50. @addtogroup MainClasses
  51. @{
  52. */
  53. /**
  54. DPF UI class from where UI instances are created.
  55. @note You must call setSize during construction,
  56. @TODO Detailed information about this class.
  57. */
  58. class UI : public UIWidget
  59. {
  60. public:
  61. /**
  62. UI class constructor.
  63. The UI should be initialized to a default state that matches the plugin side.
  64. */
  65. UI(uint width = 0, uint height = 0);
  66. /**
  67. Destructor.
  68. */
  69. virtual ~UI();
  70. /* --------------------------------------------------------------------------------------------------------
  71. * Host state */
  72. /**
  73. Get the color used for UI background (i.e. window color) in RGBA format.
  74. Returns 0 by default, in case of error or lack of host support.
  75. The following example code can be use to extract individual colors:
  76. ```
  77. const int red = (bgColor >> 24) & 0xff;
  78. const int green = (bgColor >> 16) & 0xff;
  79. const int blue = (bgColor >> 8) & 0xff;
  80. ```
  81. */
  82. uint getBackgroundColor() const noexcept;
  83. /**
  84. Get the color used for UI foreground (i.e. text color) in RGBA format.
  85. Returns 0xffffffff by default, in case of error or lack of host support.
  86. The following example code can be use to extract individual colors:
  87. ```
  88. const int red = (fgColor >> 24) & 0xff;
  89. const int green = (fgColor >> 16) & 0xff;
  90. const int blue = (fgColor >> 8) & 0xff;
  91. ```
  92. */
  93. uint getForegroundColor() const noexcept;
  94. /**
  95. Get the current sample rate used in plugin processing.
  96. @see sampleRateChanged(double)
  97. */
  98. double getSampleRate() const noexcept;
  99. /**
  100. editParameter.
  101. Touch/pressed-down event.
  102. Lets the host know the user is tweaking a parameter.
  103. Required in some hosts to record automation.
  104. */
  105. void editParameter(uint32_t index, bool started);
  106. /**
  107. setParameterValue.
  108. Change a parameter value in the Plugin.
  109. */
  110. void setParameterValue(uint32_t index, float value);
  111. #if DISTRHO_PLUGIN_WANT_STATE
  112. /**
  113. setState.
  114. @TODO Document this.
  115. */
  116. void setState(const char* key, const char* value);
  117. #endif
  118. #if DISTRHO_PLUGIN_WANT_STATEFILES
  119. /**
  120. Request a new file from the host, matching the properties of a state key.@n
  121. This will use the native host file browser if available, otherwise a DPF built-in file browser is used.@n
  122. Response will be sent asynchronously to stateChanged, with the matching key and the new file as the value.@n
  123. It is not possible to know if the action was cancelled by the user.
  124. @return Success if a file-browser was opened, otherwise false.
  125. @note You cannot request more than one file at a time.
  126. */
  127. bool requestStateFile(const char* key);
  128. #endif
  129. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  130. /**
  131. sendNote.
  132. @TODO Document this.
  133. @note Work in progress. Implemented for DSSI and LV2 formats.
  134. */
  135. void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
  136. #endif
  137. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  138. /* --------------------------------------------------------------------------------------------------------
  139. * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
  140. /**
  141. getPluginInstancePointer.
  142. @TODO Document this.
  143. */
  144. void* getPluginInstancePointer() const noexcept;
  145. #endif
  146. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  147. /* --------------------------------------------------------------------------------------------------------
  148. * External UI helpers */
  149. /**
  150. Get the bundle path that will be used for the next UI.
  151. @note: This function is only valid during createUI(),
  152. it will return null when called from anywhere else.
  153. */
  154. static const char* getNextBundlePath() noexcept;
  155. /**
  156. Get the scale factor that will be used for the next UI.
  157. @note: This function is only valid during createUI(),
  158. it will return 1.0 when called from anywhere else.
  159. */
  160. static double getNextScaleFactor() noexcept;
  161. # if DISTRHO_PLUGIN_HAS_EMBED_UI
  162. /**
  163. Get the Window Id that will be used for the next created window.
  164. @note: This function is only valid during createUI(),
  165. it will return 0 when called from anywhere else.
  166. */
  167. static uintptr_t getNextWindowId() noexcept;
  168. # endif
  169. #endif
  170. protected:
  171. /* --------------------------------------------------------------------------------------------------------
  172. * DSP/Plugin Callbacks */
  173. /**
  174. A parameter has changed on the plugin side.@n
  175. This is called by the host to inform the UI about parameter changes.
  176. */
  177. virtual void parameterChanged(uint32_t index, float value) = 0;
  178. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  179. /**
  180. A program has been loaded on the plugin side.@n
  181. This is called by the host to inform the UI about program changes.
  182. */
  183. virtual void programLoaded(uint32_t index) = 0;
  184. #endif
  185. #if DISTRHO_PLUGIN_WANT_STATE
  186. /**
  187. A state has changed on the plugin side.@n
  188. This is called by the host to inform the UI about state changes.
  189. */
  190. virtual void stateChanged(const char* key, const char* value) = 0;
  191. #endif
  192. /* --------------------------------------------------------------------------------------------------------
  193. * DSP/Plugin Callbacks (optional) */
  194. /**
  195. Optional callback to inform the UI about a sample rate change on the plugin side.
  196. @see getSampleRate()
  197. */
  198. virtual void sampleRateChanged(double newSampleRate);
  199. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  200. /* --------------------------------------------------------------------------------------------------------
  201. * UI Callbacks (optional) */
  202. /**
  203. uiIdle.
  204. @TODO Document this.
  205. */
  206. virtual void uiIdle() {}
  207. # ifndef DGL_FILE_BROWSER_DISABLED
  208. /**
  209. File browser selected function.
  210. @see Window::onFileSelected(const char*)
  211. */
  212. virtual void uiFileBrowserSelected(const char* filename);
  213. # endif
  214. /**
  215. OpenGL window reshape function, called when parent window is resized.
  216. You can reimplement this function for a custom OpenGL state.
  217. @see Window::onReshape(uint,uint)
  218. */
  219. virtual void uiReshape(uint width, uint height);
  220. /* --------------------------------------------------------------------------------------------------------
  221. * UI Resize Handling, internal */
  222. /**
  223. OpenGL widget resize function, called when the widget is resized.
  224. This is overriden here so the host knows when the UI is resized by you.
  225. @see Widget::onResize(const ResizeEvent&)
  226. */
  227. void onResize(const ResizeEvent& ev) override;
  228. #endif
  229. // -------------------------------------------------------------------------------------------------------
  230. private:
  231. struct PrivateData;
  232. PrivateData* const uiData;
  233. friend class UIExporter;
  234. friend class UIExporterWindow;
  235. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
  236. };
  237. /** @} */
  238. /* ------------------------------------------------------------------------------------------------------------
  239. * Create UI, entry point */
  240. /**
  241. @addtogroup EntryPoints
  242. @{
  243. */
  244. /**
  245. createUI.
  246. @TODO Document this.
  247. */
  248. extern UI* createUI();
  249. /** @} */
  250. // -----------------------------------------------------------------------------------------------------------
  251. END_NAMESPACE_DISTRHO
  252. #endif // DISTRHO_UI_HPP_INCLUDED