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.

271 lines
7.9KB

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