Audio plugin host https://kx.studio/carla
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.

136 lines
3.7KB

  1. /*
  2. * Power Juice Plugin
  3. * Copyright (C) 2014 Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef POWERJUICEUI_HPP_INCLUDED
  18. #define POWERJUICEUI_HPP_INCLUDED
  19. #include "DistrhoUI.hpp"
  20. #include "ImageAboutWindow.hpp"
  21. #include "ImageButton.hpp"
  22. #include "ImageKnob.hpp"
  23. #include "ImageSlider.hpp"
  24. #include "PowerJuiceArtwork.hpp"
  25. #include "PowerJuicePlugin.hpp"
  26. #include <cmath>
  27. using DGL::Image;
  28. using DGL::ImageAboutWindow;
  29. using DGL::ImageButton;
  30. using DGL::ImageKnob;
  31. START_NAMESPACE_DISTRHO
  32. // -----------------------------------------------------------------------
  33. class PowerJuiceUI : public UI,
  34. public ImageButton::Callback,
  35. public ImageKnob::Callback
  36. {
  37. public:
  38. PowerJuiceUI();
  39. ~PowerJuiceUI() override;
  40. protected:
  41. // -------------------------------------------------------------------
  42. // Information
  43. unsigned int d_getWidth() const noexcept override
  44. {
  45. return PowerJuiceArtwork::backgroundWidth;
  46. }
  47. unsigned int d_getHeight() const noexcept override
  48. {
  49. return PowerJuiceArtwork::backgroundHeight;
  50. }
  51. // -------------------------------------------------------------------
  52. // DSP Callbacks
  53. void d_parameterChanged(uint32_t index, float value) override;
  54. void d_programChanged(uint32_t index) override;
  55. // -------------------------------------------------------------------
  56. // UI Callbacks
  57. void d_uiIdle() override;
  58. // -------------------------------------------------------------------
  59. // Widget Callbacks
  60. void imageButtonClicked(ImageButton* button, int) override;
  61. void imageKnobDragStarted(ImageKnob* knob) override;
  62. void imageKnobDragFinished(ImageKnob* knob) override;
  63. void imageKnobValueChanged(ImageKnob* knob, float value) override;
  64. void onDisplay() override;
  65. private:
  66. Image fImgBackground;
  67. ImageAboutWindow fAboutWindow;
  68. ImageKnob* fKnobAttack;
  69. ImageKnob* fKnobRelease;
  70. ImageKnob* fKnobThreshold;
  71. ImageKnob* fKnobRatio;
  72. ImageKnob* fKnobMakeup;
  73. ImageKnob* fKnobMix;
  74. ImageButton* fButtonAbout;
  75. PowerJuicePlugin* dsp;
  76. float fromDB(float gdb) {
  77. return (std::exp(gdb/20.f*std::log(10.f)));
  78. };
  79. float toDB(float g) {
  80. return (20.f*std::log10(g));
  81. }
  82. float toIEC(float db) {
  83. float def = 0.0f; /* Meter deflection %age */
  84. if (db < -70.0f) {
  85. def = 0.0f;
  86. } else if (db < -60.0f) {
  87. def = (db + 70.0f) * 0.25f;
  88. } else if (db < -50.0f) {
  89. def = (db + 60.0f) * 0.5f + 5.0f;
  90. } else if (db < -40.0f) {
  91. def = (db + 50.0f) * 0.75f + 7.5;
  92. } else if (db < -30.0f) {
  93. def = (db + 40.0f) * 1.5f + 15.0f;
  94. } else if (db < -20.0f) {
  95. def = (db + 30.0f) * 2.0f + 30.0f;
  96. } else if (db < 0.0f) {
  97. def = (db + 20.0f) * 2.5f + 50.0f;
  98. } else {
  99. def = 100.0f;
  100. }
  101. return (def * 2.0f);
  102. }
  103. };
  104. // -----------------------------------------------------------------------
  105. END_NAMESPACE_DISTRHO
  106. #endif // POWERJUICEUI_HPP_INCLUDED