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.

261 lines
7.6KB

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