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.

257 lines
7.5KB

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