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.

263 lines
7.7KB

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