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.

205 lines
5.4KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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. #include "DistrhoUIPrivateData.hpp"
  17. #include "src/WindowPrivateData.hpp"
  18. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  19. # include "src/TopLevelWidgetPrivateData.hpp"
  20. #endif
  21. START_NAMESPACE_DISTRHO
  22. /* ------------------------------------------------------------------------------------------------------------
  23. * Static data, see DistrhoUIInternal.hpp */
  24. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  25. uintptr_t g_nextWindowId = 0;
  26. double g_nextScaleFactor = 1.0;
  27. const char* g_nextBundlePath = nullptr;
  28. #endif
  29. /* ------------------------------------------------------------------------------------------------------------
  30. * UI::PrivateData special handling */
  31. UI::PrivateData* UI::PrivateData::s_nextPrivateData = nullptr;
  32. PluginWindow& UI::PrivateData::createNextWindow(UI* const ui, const uint width, const uint height)
  33. {
  34. UI::PrivateData* const pData = s_nextPrivateData;
  35. pData->window = new PluginWindow(ui, pData->app, pData->winId, width, height, pData->scaleFactor);
  36. return pData->window.getObject();
  37. }
  38. /* ------------------------------------------------------------------------------------------------------------
  39. * UI */
  40. UI::UI(const uint width, const uint height, const bool automaticallyScale)
  41. : UIWidget(UI::PrivateData::createNextWindow(this, width, height)),
  42. uiData(UI::PrivateData::s_nextPrivateData)
  43. {
  44. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  45. if (width > 0 && height > 0)
  46. {
  47. Widget::setSize(width, height);
  48. if (automaticallyScale)
  49. setGeometryConstraints(width, height, true, true);
  50. }
  51. #endif
  52. }
  53. UI::~UI()
  54. {
  55. }
  56. /* ------------------------------------------------------------------------------------------------------------
  57. * Host state */
  58. bool UI::isResizable() const noexcept
  59. {
  60. #if DISTRHO_UI_USER_RESIZABLE
  61. return uiData->window->isResizable();
  62. #else
  63. return false;
  64. #endif
  65. }
  66. uint UI::getBackgroundColor() const noexcept
  67. {
  68. return uiData->bgColor;
  69. }
  70. uint UI::getForegroundColor() const noexcept
  71. {
  72. return uiData->fgColor;
  73. }
  74. double UI::getSampleRate() const noexcept
  75. {
  76. return uiData->sampleRate;
  77. }
  78. void UI::editParameter(uint32_t index, bool started)
  79. {
  80. uiData->editParamCallback(index + uiData->parameterOffset, started);
  81. }
  82. void UI::setParameterValue(uint32_t index, float value)
  83. {
  84. uiData->setParamCallback(index + uiData->parameterOffset, value);
  85. }
  86. #if DISTRHO_PLUGIN_WANT_STATE
  87. void UI::setState(const char* key, const char* value)
  88. {
  89. uiData->setStateCallback(key, value);
  90. }
  91. #endif
  92. #if DISTRHO_PLUGIN_WANT_STATEFILES
  93. bool UI::requestStateFile(const char* key)
  94. {
  95. return uiData->fileRequestCallback(key);
  96. }
  97. #endif
  98. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  99. void UI::sendNote(uint8_t channel, uint8_t note, uint8_t velocity)
  100. {
  101. uiData->sendNoteCallback(channel, note, velocity);
  102. }
  103. #endif
  104. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  105. /* ------------------------------------------------------------------------------------------------------------
  106. * Direct DSP access */
  107. void* UI::getPluginInstancePointer() const noexcept
  108. {
  109. return uiData->dspPtr;
  110. }
  111. #endif
  112. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  113. /* ------------------------------------------------------------------------------------------------------------
  114. * External UI helpers */
  115. const char* UI::getNextBundlePath() noexcept
  116. {
  117. return g_nextBundlePath;
  118. }
  119. double UI::getNextScaleFactor() noexcept
  120. {
  121. return g_nextScaleFactor;
  122. }
  123. # if DISTRHO_PLUGIN_HAS_EMBED_UI
  124. uintptr_t UI::getNextWindowId() noexcept
  125. {
  126. return g_nextWindowId;
  127. }
  128. # endif
  129. #endif
  130. /* ------------------------------------------------------------------------------------------------------------
  131. * DSP/Plugin Callbacks (optional) */
  132. void UI::sampleRateChanged(double)
  133. {
  134. }
  135. #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  136. /* ------------------------------------------------------------------------------------------------------------
  137. * UI Callbacks (optional) */
  138. void UI::uiFocus(bool, DGL_NAMESPACE::CrossingMode)
  139. {
  140. }
  141. void UI::uiReshape(uint, uint)
  142. {
  143. // NOTE this must be the same as Window::onReshape
  144. pData->fallbackOnResize();
  145. }
  146. void UI::uiScaleFactorChanged(double)
  147. {
  148. }
  149. # ifndef DGL_FILE_BROWSER_DISABLED
  150. void UI::uiFileBrowserSelected(const char*)
  151. {
  152. }
  153. # endif
  154. /* ------------------------------------------------------------------------------------------------------------
  155. * UI Resize Handling, internal */
  156. void UI::onResize(const ResizeEvent& ev)
  157. {
  158. UIWidget::onResize(ev);
  159. const uint width = ev.size.getWidth();
  160. const uint height = ev.size.getHeight();
  161. uiData->setSizeCallback(width, height);
  162. }
  163. #endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  164. // -----------------------------------------------------------------------------------------------------------
  165. END_NAMESPACE_DISTRHO