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.

283 lines
8.3KB

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