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
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2015 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. #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. @addtogroup MainClasses
  32. @{
  33. */
  34. /**
  35. DPF UI class from where UI instances are created.
  36. TODO.
  37. must call setSize during construction,
  38. */
  39. class UI : public UIWidget
  40. {
  41. public:
  42. /**
  43. UI class constructor.
  44. The UI should be initialized to a default state that matches the plugin side.
  45. */
  46. UI(uint width = 0, uint height = 0);
  47. /**
  48. Destructor.
  49. */
  50. virtual ~UI();
  51. /* --------------------------------------------------------------------------------------------------------
  52. * Host state */
  53. /**
  54. Get the current sample rate used in plugin processing.
  55. @see sampleRateChanged(double)
  56. */
  57. double getSampleRate() const noexcept;
  58. /**
  59. TODO: Document this.
  60. */
  61. void editParameter(uint32_t index, bool started);
  62. /**
  63. TODO: Document this.
  64. */
  65. void setParameterValue(uint32_t index, float value);
  66. #if DISTRHO_PLUGIN_WANT_STATE
  67. /**
  68. TODO: Document this.
  69. */
  70. void setState(const char* key, const char* value);
  71. #endif
  72. #if DISTRHO_PLUGIN_IS_SYNTH
  73. /**
  74. TODO: Document this.
  75. */
  76. void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
  77. #endif
  78. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  79. /* --------------------------------------------------------------------------------------------------------
  80. * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
  81. /**
  82. TODO: Document this.
  83. */
  84. void* getPluginInstancePointer() const noexcept;
  85. #endif
  86. protected:
  87. /* --------------------------------------------------------------------------------------------------------
  88. * DSP/Plugin Callbacks */
  89. /**
  90. A parameter has changed on the plugin side.@n
  91. This is called by the host to inform the UI about parameter changes.
  92. */
  93. virtual void parameterChanged(uint32_t index, float value) = 0;
  94. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  95. /**
  96. A program has been loaded on the plugin side.@n
  97. This is called by the host to inform the UI about program changes.
  98. */
  99. virtual void programLoaded(uint32_t index) = 0;
  100. #endif
  101. #if DISTRHO_PLUGIN_WANT_STATE
  102. /**
  103. A state has changed on the plugin side.@n
  104. This is called by the host to inform the UI about state changes.
  105. */
  106. virtual void stateChanged(const char* key, const char* value) = 0;
  107. #endif
  108. /* --------------------------------------------------------------------------------------------------------
  109. * DSP/Plugin Callbacks (optional) */
  110. /**
  111. Optional callback to inform the UI about a sample rate change on the plugin side.
  112. @see getSampleRate()
  113. */
  114. virtual void sampleRateChanged(double newSampleRate);
  115. /* --------------------------------------------------------------------------------------------------------
  116. * UI Callbacks (optional) */
  117. /**
  118. TODO: Document this.
  119. */
  120. virtual void uiIdle() {}
  121. /**
  122. File browser selected function.
  123. @see Window::fileBrowserSelected(const char*)
  124. */
  125. virtual void uiFileBrowserSelected(const char* filename);
  126. /**
  127. OpenGL window reshape function, called when parent window is resized.
  128. You can reimplement this function for a custom OpenGL state.
  129. @see Window::onReshape(uint,uint)
  130. */
  131. virtual void uiReshape(uint width, uint height);
  132. /* --------------------------------------------------------------------------------------------------------
  133. * UI Resize Handling, internal */
  134. /**
  135. OpenGL widget resize function, called when the widget is resized.
  136. This is overriden here so the host knows when the UI is resized by you.
  137. @see Widget::onResize(const ResizeEvent&)
  138. */
  139. void onResize(const ResizeEvent& ev) override;
  140. // -------------------------------------------------------------------------------------------------------
  141. private:
  142. struct PrivateData;
  143. PrivateData* const pData;
  144. friend class UIExporter;
  145. friend class UIExporterWindow;
  146. // these should not be used
  147. void setAbsoluteX(int) const noexcept {}
  148. void setAbsoluteY(int) const noexcept {}
  149. void setAbsolutePos(int, int) const noexcept {}
  150. void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
  151. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
  152. };
  153. /** @} */
  154. /* ------------------------------------------------------------------------------------------------------------
  155. * Create UI, entry point */
  156. /**
  157. @addtogroup EntryPoints
  158. @{
  159. */
  160. /**
  161. TODO.
  162. */
  163. extern UI* createUI();
  164. /** @} */
  165. // -----------------------------------------------------------------------------------------------------------
  166. END_NAMESPACE_DISTRHO
  167. #endif // DISTRHO_UI_HPP_INCLUDED