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.

260 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. /**
  60. Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically.
  61. @see Window::setGeometryConstraints(uint,uint,bool)
  62. @see Window::setScaling(double)
  63. */
  64. void setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale = false);
  65. /* --------------------------------------------------------------------------------------------------------
  66. * Host state */
  67. /**
  68. Get the current sample rate used in plugin processing.
  69. @see sampleRateChanged(double)
  70. */
  71. double getSampleRate() const noexcept;
  72. /**
  73. editParameter.
  74. @TODO Document this.
  75. */
  76. void editParameter(uint32_t index, bool started);
  77. /**
  78. setParameterValue.
  79. @TODO Document this.
  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. #ifdef HAVE_DGL
  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. #ifdef HAVE_DGL
  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