Audio plugin host https://kx.studio/carla
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.

DistrhoUI.hpp 7.0KB

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