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.

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