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.

126 lines
3.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. #include "DistrhoUIInternal.hpp"
  17. START_NAMESPACE_DISTRHO
  18. /* ------------------------------------------------------------------------------------------------------------
  19. * Static data, see DistrhoUIInternal.hpp */
  20. double d_lastUiSampleRate = 0.0;
  21. void* d_lastUiDspPtr = nullptr;
  22. UIWindow* d_lastUiWindow = nullptr;
  23. /* ------------------------------------------------------------------------------------------------------------
  24. * UI */
  25. UI::UI()
  26. : UIWidget(*d_lastUiWindow),
  27. pData(new PrivateData())
  28. {
  29. UIWidget::setNeedsFullViewport(true);
  30. }
  31. UI::~UI()
  32. {
  33. delete pData;
  34. }
  35. /* ------------------------------------------------------------------------------------------------------------
  36. * Host state */
  37. double UI::d_getSampleRate() const noexcept
  38. {
  39. return pData->sampleRate;
  40. }
  41. void UI::d_editParameter(const uint32_t index, const bool started)
  42. {
  43. pData->editParamCallback(index + pData->parameterOffset, started);
  44. }
  45. void UI::d_setParameterValue(const uint32_t index, const float value)
  46. {
  47. pData->setParamCallback(index + pData->parameterOffset, value);
  48. }
  49. #if DISTRHO_PLUGIN_WANT_STATE
  50. void UI::d_setState(const char* const key, const char* const value)
  51. {
  52. pData->setStateCallback(key, value);
  53. }
  54. #endif
  55. #if DISTRHO_PLUGIN_IS_SYNTH
  56. void UI::d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity)
  57. {
  58. pData->sendNoteCallback(channel, note, velocity);
  59. }
  60. #endif
  61. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  62. /* ------------------------------------------------------------------------------------------------------------
  63. * Direct DSP access */
  64. void* UI::d_getPluginInstancePointer() const noexcept
  65. {
  66. return pData->dspPtr;
  67. }
  68. #endif
  69. /* ------------------------------------------------------------------------------------------------------------
  70. * DSP/Plugin Callbacks (optional) */
  71. void UI::d_sampleRateChanged(double) {}
  72. /* ------------------------------------------------------------------------------------------------------------
  73. * UI Callbacks (optional) */
  74. #if ! DISTRHO_UI_USE_NTK
  75. void UI::d_uiReshape(uint width, uint height)
  76. {
  77. glEnable(GL_BLEND);
  78. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  79. glMatrixMode(GL_PROJECTION);
  80. glLoadIdentity();
  81. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  82. glViewport(0, 0, width, height);
  83. glMatrixMode(GL_MODELVIEW);
  84. glLoadIdentity();
  85. }
  86. #endif
  87. /* ------------------------------------------------------------------------------------------------------------
  88. * UI Resize Handling, internal */
  89. #if DISTRHO_UI_USE_NTK
  90. void UI::resize(int x, int y, int w, int h)
  91. {
  92. UIWidget::resize(x, y w, h);
  93. pData->setSizeCallback(w, h);
  94. }
  95. #else
  96. void UI::onResize(const ResizeEvent& ev)
  97. {
  98. pData->setSizeCallback(ev.size.getWidth(), ev.size.getHeight());
  99. }
  100. #endif
  101. // -----------------------------------------------------------------------------------------------------------
  102. END_NAMESPACE_DISTRHO