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.

158 lines
4.4KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2016 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 "DistrhoUIInternal.hpp"
  17. #ifdef HAVE_DGL
  18. # include "src/WidgetPrivateData.hpp"
  19. #endif
  20. START_NAMESPACE_DISTRHO
  21. /* ------------------------------------------------------------------------------------------------------------
  22. * Static data, see DistrhoUIInternal.hpp */
  23. double d_lastUiSampleRate = 0.0;
  24. void* d_lastUiDspPtr = nullptr;
  25. #ifdef HAVE_DGL
  26. Window* d_lastUiWindow = nullptr;
  27. #endif
  28. uintptr_t g_nextWindowId = 0;
  29. const char* g_nextBundlePath = nullptr;
  30. /* ------------------------------------------------------------------------------------------------------------
  31. * UI */
  32. #ifdef HAVE_DGL
  33. UI::UI(uint width, uint height)
  34. : UIWidget(*d_lastUiWindow),
  35. pData(new PrivateData())
  36. {
  37. ((UIWidget*)this)->pData->needsFullViewport = false;
  38. if (width > 0 && height > 0)
  39. setSize(width, height);
  40. }
  41. #else
  42. UI::UI(uint width, uint height)
  43. : UIWidget(width, height),
  44. pData(new PrivateData()) {}
  45. #endif
  46. UI::~UI()
  47. {
  48. delete pData;
  49. }
  50. /* ------------------------------------------------------------------------------------------------------------
  51. * Host state */
  52. double UI::getSampleRate() const noexcept
  53. {
  54. return pData->sampleRate;
  55. }
  56. void UI::editParameter(uint32_t index, bool started)
  57. {
  58. pData->editParamCallback(index + pData->parameterOffset, started);
  59. }
  60. void UI::setParameterValue(uint32_t index, float value)
  61. {
  62. pData->setParamCallback(index + pData->parameterOffset, value);
  63. }
  64. #if DISTRHO_PLUGIN_WANT_STATE
  65. void UI::setState(const char* key, const char* value)
  66. {
  67. pData->setStateCallback(key, value);
  68. }
  69. #endif
  70. #if DISTRHO_PLUGIN_IS_SYNTH
  71. void UI::sendNote(uint8_t channel, uint8_t note, uint8_t velocity)
  72. {
  73. pData->sendNoteCallback(channel, note, velocity);
  74. }
  75. #endif
  76. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  77. /* ------------------------------------------------------------------------------------------------------------
  78. * Direct DSP access */
  79. void* UI::getPluginInstancePointer() const noexcept
  80. {
  81. return pData->dspPtr;
  82. }
  83. #endif
  84. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  85. /* ------------------------------------------------------------------------------------------------------------
  86. * External UI helpers */
  87. const char* UI::getNextBundlePath() noexcept
  88. {
  89. return g_nextBundlePath;
  90. }
  91. # if DISTRHO_PLUGIN_HAS_EMBED_UI
  92. uintptr_t UI::getNextWindowId() noexcept
  93. {
  94. return g_nextWindowId;
  95. }
  96. # endif
  97. #endif
  98. /* ------------------------------------------------------------------------------------------------------------
  99. * DSP/Plugin Callbacks (optional) */
  100. void UI::sampleRateChanged(double) {}
  101. #ifdef HAVE_DGL
  102. /* ------------------------------------------------------------------------------------------------------------
  103. * UI Callbacks (optional) */
  104. #ifndef DGL_FILE_BROWSER_DISABLED
  105. void UI::uiFileBrowserSelected(const char*)
  106. {
  107. }
  108. #endif
  109. void UI::uiReshape(uint width, uint height)
  110. {
  111. glEnable(GL_BLEND);
  112. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  113. glMatrixMode(GL_PROJECTION);
  114. glLoadIdentity();
  115. glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0);
  116. glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
  117. glMatrixMode(GL_MODELVIEW);
  118. glLoadIdentity();
  119. }
  120. /* ------------------------------------------------------------------------------------------------------------
  121. * UI Resize Handling, internal */
  122. void UI::onResize(const ResizeEvent& ev)
  123. {
  124. pData->setSizeCallback(ev.size.getWidth(), ev.size.getHeight());
  125. }
  126. #endif
  127. // -----------------------------------------------------------------------------------------------------------
  128. END_NAMESPACE_DISTRHO