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.

191 lines
5.7KB

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