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.

204 lines
6.0KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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/d_leakdetector.hpp"
  19. #include "src/DistrhoPluginChecks.h"
  20. #if DISTRHO_UI_USE_NTK
  21. # include "../dgl/ntk/NtkWidget.hpp"
  22. typedef DGL::NtkWidget UIWidget;
  23. #elif DISTRHO_UI_USE_NANOVG
  24. # include "../dgl/NanoVG.hpp"
  25. typedef DGL::NanoWidget UIWidget;
  26. # else
  27. # include "../dgl/Widget.hpp"
  28. typedef DGL::Widget UIWidget;
  29. #endif
  30. START_NAMESPACE_DISTRHO
  31. /* ------------------------------------------------------------------------------------------------------------
  32. * DPF UI */
  33. /**
  34. DPF UI class from where UI instances are created.
  35. TODO.
  36. must call setSize during construction,
  37. */
  38. class UI : public UIWidget
  39. {
  40. public:
  41. /**
  42. UI class constructor.
  43. */
  44. UI();
  45. /**
  46. Destructor.
  47. */
  48. virtual ~UI();
  49. /* --------------------------------------------------------------------------------------------------------
  50. * Host state */
  51. /**
  52. Get the current sample rate used in plugin processing.
  53. @see d_sampleRateChanged(double)
  54. */
  55. double d_getSampleRate() const noexcept;
  56. /**
  57. TODO: Document this.
  58. */
  59. void d_editParameter(const uint32_t index, const bool started);
  60. /**
  61. TODO: Document this.
  62. */
  63. void d_setParameterValue(const uint32_t index, const float value);
  64. #if DISTRHO_PLUGIN_WANT_STATE
  65. /**
  66. TODO: Document this.
  67. */
  68. void d_setState(const char* const key, const char* const value);
  69. #endif
  70. #if DISTRHO_PLUGIN_IS_SYNTH
  71. /**
  72. TODO: Document this.
  73. */
  74. void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity);
  75. #endif
  76. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  77. /* --------------------------------------------------------------------------------------------------------
  78. * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
  79. /**
  80. TODO: Document this.
  81. */
  82. void* d_getPluginInstancePointer() const noexcept;
  83. #endif
  84. protected:
  85. /* --------------------------------------------------------------------------------------------------------
  86. * DSP/Plugin Callbacks */
  87. /**
  88. A parameter has changed on the plugin side.
  89. This is called by the host to inform the UI about parameter changes.
  90. */
  91. virtual void d_parameterChanged(uint32_t index, float value) = 0;
  92. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  93. /**
  94. The current program has changed on the plugin side.
  95. This is called by the host to inform the UI about program changes.
  96. */
  97. virtual void d_programChanged(uint32_t index) = 0;
  98. #endif
  99. #if DISTRHO_PLUGIN_WANT_STATE
  100. /**
  101. A state has changed on the plugin side.
  102. This is called by the host to inform the UI about state changes.
  103. */
  104. virtual void d_stateChanged(const char* key, const char* value) = 0;
  105. #endif
  106. /* --------------------------------------------------------------------------------------------------------
  107. * DSP/Plugin Callbacks (optional) */
  108. /**
  109. Optional callback to inform the UI about a sample rate change on the plugin side.
  110. @see d_getSampleRate()
  111. */
  112. virtual void d_sampleRateChanged(double newSampleRate);
  113. /* --------------------------------------------------------------------------------------------------------
  114. * UI Callbacks (optional) */
  115. /**
  116. TODO: Document this.
  117. */
  118. virtual void d_uiIdle() {}
  119. #if ! DISTRHO_UI_USE_NTK
  120. /**
  121. OpenGL window reshape function, called when parent window is resized.
  122. You can reimplement this function for a custom OpenGL state.
  123. @see Window::onReshape(uint,uint)
  124. */
  125. virtual void d_uiReshape(uint width, uint height);
  126. #endif
  127. /* --------------------------------------------------------------------------------------------------------
  128. * UI Resize Handling, internal */
  129. #if DISTRHO_UI_USE_NTK
  130. /**
  131. NTK widget resize function, called when the widget is resized.
  132. This is overriden here so the host knows when the UI is resized by you.
  133. */
  134. void resize(int x, int y, int w, int h) override;
  135. #else
  136. /**
  137. OpenGL widget resize function, called when the widget is resized.
  138. This is overriden here so the host knows when the UI is resized by you.
  139. @see Widget::onResize(const ResizeEvent&)
  140. */
  141. void onResize(const ResizeEvent& ev) override;
  142. #endif
  143. // -------------------------------------------------------------------------------------------------------
  144. private:
  145. struct PrivateData;
  146. PrivateData* const pData;
  147. friend class UIExporter;
  148. friend class UIExporterWindow;
  149. // these should not be used
  150. void position(int, int) noexcept {}
  151. void setAbsoluteX(int) const noexcept {}
  152. void setAbsoluteY(int) const noexcept {}
  153. void setAbsolutePos(int, int) const noexcept {}
  154. void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
  155. void setNeedsFullViewport(bool) const noexcept {}
  156. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
  157. };
  158. /* ------------------------------------------------------------------------------------------------------------
  159. * Create UI, entry point */
  160. /**
  161. TODO.
  162. */
  163. extern UI* createUI();
  164. // -----------------------------------------------------------------------------------------------------------
  165. END_NAMESPACE_DISTRHO
  166. #endif // DISTRHO_UI_HPP_INCLUDED