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.

107 lines
3.2KB

  1. /*
  2. * Simple Gain audio effect based on DISTRHO Plugin Framework (DPF)
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to
  10. * deal in the Software without restriction, including without limitation the
  11. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  24. * IN THE SOFTWARE.
  25. */
  26. #include "UISimpleGain.hpp"
  27. START_NAMESPACE_DISTRHO
  28. // -----------------------------------------------------------------------
  29. // Init / Deinit
  30. UISimpleGain::UISimpleGain()
  31. : UI(600, 400),
  32. fGain(0.0f),
  33. fResizeHandle(this)
  34. {
  35. setGeometryConstraints(600, 400, true);
  36. // hide handle if UI is resizable
  37. if (isResizable())
  38. fResizeHandle.hide();
  39. }
  40. // -----------------------------------------------------------------------
  41. // DSP/Plugin callbacks
  42. /**
  43. A parameter has changed on the plugin side.
  44. This is called by the host to inform the UI about parameter changes.
  45. */
  46. void UISimpleGain::parameterChanged(uint32_t index, float value)
  47. {
  48. DISTRHO_SAFE_ASSERT_RETURN(index == 0,);
  49. fGain = value;
  50. repaint();
  51. }
  52. // -----------------------------------------------------------------------
  53. // Widget callbacks
  54. /**
  55. A function called to draw the view contents.
  56. */
  57. void UISimpleGain::onImGuiDisplay()
  58. {
  59. const float width = getWidth();
  60. const float height = getHeight();
  61. const float margin = 20.0f * getScaleFactor();
  62. ImGui::SetNextWindowPos(ImVec2(margin, margin));
  63. ImGui::SetNextWindowSize(ImVec2(width - 2 * margin, height - 2 * margin));
  64. if (ImGui::Begin("Simple gain", nullptr, ImGuiWindowFlags_NoResize))
  65. {
  66. static char aboutText[256] = "This is a demo plugin made with ImGui.\n";
  67. ImGui::InputTextMultiline("About", aboutText, sizeof(aboutText));
  68. if (ImGui::SliderFloat("Gain (dB)", &fGain, -90.0f, 30.0f))
  69. {
  70. if (ImGui::IsItemActivated())
  71. editParameter(0, true);
  72. setParameterValue(0, fGain);
  73. }
  74. if (ImGui::IsItemDeactivated())
  75. {
  76. editParameter(0, false);
  77. }
  78. }
  79. ImGui::End();
  80. }
  81. // -----------------------------------------------------------------------
  82. UI* createUI()
  83. {
  84. return new UISimpleGain();
  85. }
  86. // -----------------------------------------------------------------------
  87. END_NAMESPACE_DISTRHO