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.

270 lines
7.8KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 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, bool userResizable = false);
  57. /**
  58. Destructor.
  59. */
  60. virtual ~UI();
  61. /**
  62. Wherever this UI is resizable by the user.
  63. This simply returns the value passed in the constructor.
  64. */
  65. bool isUserResizable() const noexcept;
  66. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  67. /**
  68. Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically.
  69. @see Window::setGeometryConstraints(uint,uint,bool)
  70. @see Window::setScaling(double)
  71. */
  72. void setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale = false);
  73. #endif
  74. /* --------------------------------------------------------------------------------------------------------
  75. * Host state */
  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. @TODO Document this.
  84. */
  85. void editParameter(uint32_t index, bool started);
  86. /**
  87. setParameterValue.
  88. @TODO Document this.
  89. */
  90. void setParameterValue(uint32_t index, float value);
  91. #if DISTRHO_PLUGIN_WANT_STATE
  92. /**
  93. setState.
  94. @TODO Document this.
  95. */
  96. void setState(const char* key, const char* value);
  97. #endif
  98. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  99. /**
  100. sendNote.
  101. @TODO Document this.
  102. @note Work in progress. Implemented for DSSI and LV2 formats.
  103. */
  104. void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
  105. #endif
  106. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  107. /* --------------------------------------------------------------------------------------------------------
  108. * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
  109. /**
  110. getPluginInstancePointer.
  111. @TODO Document this.
  112. */
  113. void* getPluginInstancePointer() const noexcept;
  114. #endif
  115. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  116. /* --------------------------------------------------------------------------------------------------------
  117. * External UI helpers */
  118. /**
  119. Get the bundle path that will be used for the next UI.
  120. @note: This function is only valid during createUI(),
  121. it will return null when called from anywhere else.
  122. */
  123. static const char* getNextBundlePath() noexcept;
  124. # if DISTRHO_PLUGIN_HAS_EMBED_UI
  125. /**
  126. Get the Window Id that will be used for the next created window.
  127. @note: This function is only valid during createUI(),
  128. it will return 0 when called from anywhere else.
  129. */
  130. static uintptr_t getNextWindowId() noexcept;
  131. # endif
  132. #endif
  133. protected:
  134. /* --------------------------------------------------------------------------------------------------------
  135. * DSP/Plugin Callbacks */
  136. /**
  137. A parameter has changed on the plugin side.@n
  138. This is called by the host to inform the UI about parameter changes.
  139. */
  140. virtual void parameterChanged(uint32_t index, float value) = 0;
  141. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  142. /**
  143. A program has been loaded on the plugin side.@n
  144. This is called by the host to inform the UI about program changes.
  145. */
  146. virtual void programLoaded(uint32_t index) = 0;
  147. #endif
  148. #if DISTRHO_PLUGIN_WANT_STATE
  149. /**
  150. A state has changed on the plugin side.@n
  151. This is called by the host to inform the UI about state changes.
  152. */
  153. virtual void stateChanged(const char* key, const char* value) = 0;
  154. #endif
  155. /* --------------------------------------------------------------------------------------------------------
  156. * DSP/Plugin Callbacks (optional) */
  157. /**
  158. Optional callback to inform the UI about a sample rate change on the plugin side.
  159. @see getSampleRate()
  160. */
  161. virtual void sampleRateChanged(double newSampleRate);
  162. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  163. /* --------------------------------------------------------------------------------------------------------
  164. * UI Callbacks (optional) */
  165. /**
  166. uiIdle.
  167. @TODO Document this.
  168. */
  169. virtual void uiIdle() {}
  170. # ifndef DGL_FILE_BROWSER_DISABLED
  171. /**
  172. File browser selected function.
  173. @see Window::fileBrowserSelected(const char*)
  174. */
  175. virtual void uiFileBrowserSelected(const char* filename);
  176. # endif
  177. /**
  178. OpenGL window reshape function, called when parent window is resized.
  179. You can reimplement this function for a custom OpenGL state.
  180. @see Window::onReshape(uint,uint)
  181. */
  182. virtual void uiReshape(uint width, uint height);
  183. /* --------------------------------------------------------------------------------------------------------
  184. * UI Resize Handling, internal */
  185. /**
  186. OpenGL widget resize function, called when the widget is resized.
  187. This is overriden here so the host knows when the UI is resized by you.
  188. @see Widget::onResize(const ResizeEvent&)
  189. */
  190. void onResize(const ResizeEvent& ev) override;
  191. #endif
  192. // -------------------------------------------------------------------------------------------------------
  193. private:
  194. struct PrivateData;
  195. PrivateData* const pData;
  196. friend class UIExporter;
  197. friend class UIExporterWindow;
  198. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  199. // these should not be used
  200. void setAbsoluteX(int) const noexcept {}
  201. void setAbsoluteY(int) const noexcept {}
  202. void setAbsolutePos(int, int) const noexcept {}
  203. void setAbsolutePos(const DGL_NAMESPACE::Point<int>&) const noexcept {}
  204. #endif
  205. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
  206. };
  207. /** @} */
  208. /* ------------------------------------------------------------------------------------------------------------
  209. * Create UI, entry point */
  210. /**
  211. @addtogroup EntryPoints
  212. @{
  213. */
  214. /**
  215. createUI.
  216. @TODO Document this.
  217. */
  218. extern UI* createUI();
  219. /** @} */
  220. // -----------------------------------------------------------------------------------------------------------
  221. END_NAMESPACE_DISTRHO
  222. #endif // DISTRHO_UI_HPP_INCLUDED