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.

131 lines
3.9KB

  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. #include <imgui.h>
  28. // #include "Window.hpp"
  29. START_NAMESPACE_DISTRHO
  30. // -----------------------------------------------------------------------
  31. // Init / Deinit
  32. UISimpleGain::UISimpleGain()
  33. : UI(600, 400)
  34. {
  35. setGeometryConstraints(600, 400, true);
  36. }
  37. UISimpleGain::~UISimpleGain() {
  38. }
  39. // -----------------------------------------------------------------------
  40. // DSP/Plugin callbacks
  41. /**
  42. A parameter has changed on the plugin side.
  43. This is called by the host to inform the UI about parameter changes.
  44. */
  45. void UISimpleGain::parameterChanged(uint32_t index, float value) {
  46. params[index] = value;
  47. switch (index) {
  48. case PluginSimpleGain::paramGain:
  49. // do something when Gain param is set, such as update a widget
  50. break;
  51. }
  52. (void)value;
  53. }
  54. /**
  55. A program has been loaded on the plugin side.
  56. This is called by the host to inform the UI about program changes.
  57. */
  58. void UISimpleGain::programLoaded(uint32_t index) {
  59. if (index < presetCount) {
  60. for (int i=0; i < PluginSimpleGain::paramCount; i++) {
  61. // set values for each parameter and update their widgets
  62. parameterChanged(i, factoryPresets[index].params[i]);
  63. }
  64. }
  65. }
  66. /**
  67. Optional callback to inform the UI about a sample rate change on the plugin side.
  68. */
  69. void UISimpleGain::sampleRateChanged(double newSampleRate) {
  70. (void)newSampleRate;
  71. }
  72. // -----------------------------------------------------------------------
  73. // Widget callbacks
  74. /**
  75. A function called to draw the view contents.
  76. */
  77. void UISimpleGain::onImGuiDisplay() {
  78. float width = getWidth();
  79. float height = getHeight();
  80. float margin = 20.0f;
  81. ImGui::SetNextWindowPos(ImVec2(margin, margin));
  82. ImGui::SetNextWindowSize(ImVec2(width - 2 * margin, height - 2 * margin));
  83. if (ImGui::Begin("Simple gain")) {
  84. static char aboutText[256] =
  85. "This is a demo plugin made with ImGui.\n";
  86. ImGui::InputTextMultiline("About", aboutText, sizeof(aboutText));
  87. float& gain = params[PluginSimpleGain::paramGain];
  88. if (ImGui::SliderFloat("Gain (dB)", &gain, -90.0f, 30.0f))
  89. {
  90. if (ImGui::IsItemActivated())
  91. {
  92. editParameter(PluginSimpleGain::paramGain, true);
  93. }
  94. setParameterValue(PluginSimpleGain::paramGain, gain);
  95. }
  96. if (ImGui::IsItemDeactivated())
  97. {
  98. editParameter(PluginSimpleGain::paramGain, false);
  99. }
  100. }
  101. ImGui::End();
  102. }
  103. // -----------------------------------------------------------------------
  104. UI* createUI() {
  105. return new UISimpleGain();
  106. }
  107. // -----------------------------------------------------------------------
  108. END_NAMESPACE_DISTRHO