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.

262 lines
7.6KB

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