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.

275 lines
8.0KB

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