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.

300 lines
9.0KB

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