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 5.8KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. File browser selected function.
  119. @see Window::fileBrowserSelected(const char*)
  120. */
  121. virtual void d_uiFileBrowserSelected(const char* filename);
  122. /**
  123. OpenGL window reshape function, called when parent window is resized.
  124. You can reimplement this function for a custom OpenGL state.
  125. @see Window::onReshape(uint,uint)
  126. */
  127. virtual void d_uiReshape(uint width, uint height);
  128. /* --------------------------------------------------------------------------------------------------------
  129. * UI Resize Handling, internal */
  130. /**
  131. OpenGL 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. @see Widget::onResize(const ResizeEvent&)
  134. */
  135. void onResize(const ResizeEvent& ev) override;
  136. // -------------------------------------------------------------------------------------------------------
  137. private:
  138. struct PrivateData;
  139. PrivateData* const pData;
  140. friend class UIExporter;
  141. friend class UIExporterWindow;
  142. // these should not be used
  143. void setAbsoluteX(int) const noexcept {}
  144. void setAbsoluteY(int) const noexcept {}
  145. void setAbsolutePos(int, int) const noexcept {}
  146. void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
  147. void setNeedsFullViewport(bool) const noexcept {}
  148. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
  149. };
  150. /* ------------------------------------------------------------------------------------------------------------
  151. * Create UI, entry point */
  152. /**
  153. TODO.
  154. */
  155. extern UI* createUI();
  156. // -----------------------------------------------------------------------------------------------------------
  157. END_NAMESPACE_DISTRHO
  158. #endif // DISTRHO_UI_HPP_INCLUDED