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.

286 lines
8.5KB

  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. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  21. # include "../dgl/Base.hpp"
  22. # include "extra/ExternalWindow.hpp"
  23. typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget;
  24. #elif DISTRHO_UI_USE_CUSTOM
  25. # include DISTRHO_UI_CUSTOM_INCLUDE_PATH
  26. typedef DISTRHO_UI_CUSTOM_WIDGET_TYPE UIWidget;
  27. #elif DISTRHO_UI_USE_NANOVG
  28. # include "../dgl/NanoVG.hpp"
  29. typedef DGL_NAMESPACE::NanoTopLevelWidget UIWidget;
  30. #else
  31. # include "../dgl/TopLevelWidget.hpp"
  32. typedef DGL_NAMESPACE::TopLevelWidget UIWidget;
  33. #endif
  34. #ifdef DGL_CAIRO
  35. # include "Cairo.hpp"
  36. #endif
  37. #ifdef DGL_OPENGL
  38. # include "OpenGL.hpp"
  39. #endif
  40. START_NAMESPACE_DISTRHO
  41. /* ------------------------------------------------------------------------------------------------------------
  42. * DPF UI */
  43. /**
  44. @addtogroup MainClasses
  45. @{
  46. */
  47. /**
  48. DPF UI class from where UI instances are created.
  49. @note You must call setSize during construction,
  50. @TODO Detailed information about this class.
  51. */
  52. class UI : public UIWidget
  53. {
  54. public:
  55. /**
  56. UI class constructor.
  57. The UI should be initialized to a default state that matches the plugin side.
  58. */
  59. UI(uint width = 0, uint height = 0);
  60. /**
  61. Destructor.
  62. */
  63. virtual ~UI();
  64. /* --------------------------------------------------------------------------------------------------------
  65. * Host state */
  66. /**
  67. Get the color used for UI background (i.e. window color) in RGBA format.
  68. Returns 0 by default, in case of error or lack of host support.
  69. */
  70. uint getBackgroundColor() const noexcept;
  71. /**
  72. Get the color used for UI foreground (i.e. text color) in RGBA format.
  73. Returns 0xffffffff by default, in case of error or lack of host support.
  74. */
  75. uint getForegroundColor() const noexcept;
  76. /**
  77. Get the current sample rate used in plugin processing.
  78. @see sampleRateChanged(double)
  79. */
  80. double getSampleRate() const noexcept;
  81. /**
  82. editParameter.
  83. Touch/pressed-down event.
  84. Lets the host know the user is tweaking a parameter.
  85. Required in some hosts to record automation.
  86. */
  87. void editParameter(uint32_t index, bool started);
  88. /**
  89. setParameterValue.
  90. Change a parameter value in the Plugin.
  91. */
  92. void setParameterValue(uint32_t index, float value);
  93. #if DISTRHO_PLUGIN_WANT_STATE
  94. /**
  95. setState.
  96. @TODO Document this.
  97. */
  98. void setState(const char* key, const char* value);
  99. #endif
  100. #if DISTRHO_PLUGIN_WANT_STATEFILES
  101. /**
  102. Request a new file from the host, matching the properties of a state key.@n
  103. This will use the native host file browser if available, otherwise a DPF built-in file browser is used.@n
  104. Response will be sent asynchronously to stateChanged, with the matching key and the new file as the value.@n
  105. It is not possible to know if the action was cancelled by the user.
  106. @return Success if a file-browser was opened, otherwise false.
  107. @note You cannot request more than one file at a time.
  108. */
  109. bool requestStateFile(const char* key);
  110. #endif
  111. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  112. /**
  113. sendNote.
  114. @TODO Document this.
  115. @note Work in progress. Implemented for DSSI and LV2 formats.
  116. */
  117. void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
  118. #endif
  119. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  120. /* --------------------------------------------------------------------------------------------------------
  121. * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
  122. /**
  123. getPluginInstancePointer.
  124. @TODO Document this.
  125. */
  126. void* getPluginInstancePointer() const noexcept;
  127. #endif
  128. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  129. /* --------------------------------------------------------------------------------------------------------
  130. * External UI helpers */
  131. /**
  132. Get the bundle path that will be used for the next UI.
  133. @note: This function is only valid during createUI(),
  134. it will return null when called from anywhere else.
  135. */
  136. static const char* getNextBundlePath() noexcept;
  137. /**
  138. Get the scale factor that will be used for the next UI.
  139. @note: This function is only valid during createUI(),
  140. it will return 1.0 when called from anywhere else.
  141. */
  142. static double getNextScaleFactor() noexcept;
  143. # if DISTRHO_PLUGIN_HAS_EMBED_UI
  144. /**
  145. Get the Window Id that will be used for the next created window.
  146. @note: This function is only valid during createUI(),
  147. it will return 0 when called from anywhere else.
  148. */
  149. static uintptr_t getNextWindowId() noexcept;
  150. # endif
  151. #endif
  152. protected:
  153. /* --------------------------------------------------------------------------------------------------------
  154. * DSP/Plugin Callbacks */
  155. /**
  156. A parameter has changed on the plugin side.@n
  157. This is called by the host to inform the UI about parameter changes.
  158. */
  159. virtual void parameterChanged(uint32_t index, float value) = 0;
  160. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  161. /**
  162. A program has been loaded on the plugin side.@n
  163. This is called by the host to inform the UI about program changes.
  164. */
  165. virtual void programLoaded(uint32_t index) = 0;
  166. #endif
  167. #if DISTRHO_PLUGIN_WANT_STATE
  168. /**
  169. A state has changed on the plugin side.@n
  170. This is called by the host to inform the UI about state changes.
  171. */
  172. virtual void stateChanged(const char* key, const char* value) = 0;
  173. #endif
  174. /* --------------------------------------------------------------------------------------------------------
  175. * DSP/Plugin Callbacks (optional) */
  176. /**
  177. Optional callback to inform the UI about a sample rate change on the plugin side.
  178. @see getSampleRate()
  179. */
  180. virtual void sampleRateChanged(double newSampleRate);
  181. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  182. /* --------------------------------------------------------------------------------------------------------
  183. * UI Callbacks (optional) */
  184. /**
  185. uiIdle.
  186. @TODO Document this.
  187. */
  188. virtual void uiIdle() {}
  189. # ifndef DGL_FILE_BROWSER_DISABLED
  190. /**
  191. File browser selected function.
  192. @see Window::fileBrowserSelected(const char*)
  193. */
  194. virtual void uiFileBrowserSelected(const char* filename);
  195. # endif
  196. /**
  197. OpenGL window reshape function, called when parent window is resized.
  198. You can reimplement this function for a custom OpenGL state.
  199. @see Window::onReshape(uint,uint)
  200. */
  201. virtual void uiReshape(uint width, uint height);
  202. /* --------------------------------------------------------------------------------------------------------
  203. * UI Resize Handling, internal */
  204. /**
  205. OpenGL widget resize function, called when the widget is resized.
  206. This is overriden here so the host knows when the UI is resized by you.
  207. @see Widget::onResize(const ResizeEvent&)
  208. */
  209. void onResize(const ResizeEvent& ev) override;
  210. #endif
  211. // -------------------------------------------------------------------------------------------------------
  212. private:
  213. struct PrivateData;
  214. PrivateData* const uiData;
  215. friend class UIExporter;
  216. friend class UIExporterWindow;
  217. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
  218. };
  219. /** @} */
  220. /* ------------------------------------------------------------------------------------------------------------
  221. * Create UI, entry point */
  222. /**
  223. @addtogroup EntryPoints
  224. @{
  225. */
  226. /**
  227. createUI.
  228. @TODO Document this.
  229. */
  230. extern UI* createUI();
  231. /** @} */
  232. // -----------------------------------------------------------------------------------------------------------
  233. END_NAMESPACE_DISTRHO
  234. #endif // DISTRHO_UI_HPP_INCLUDED