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.

207 lines
6.1KB

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