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.

PowerJuiceUI.hpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. protected:
  40. // -------------------------------------------------------------------
  41. // Information
  42. uint d_getWidth() const noexcept override
  43. {
  44. return PowerJuiceArtwork::backgroundWidth;
  45. }
  46. uint d_getHeight() const noexcept override
  47. {
  48. return PowerJuiceArtwork::backgroundHeight;
  49. }
  50. // -------------------------------------------------------------------
  51. // DSP Callbacks
  52. void d_parameterChanged(uint32_t index, float value) override;
  53. void d_programChanged(uint32_t index) override;
  54. // -------------------------------------------------------------------
  55. // UI Callbacks
  56. void d_uiIdle() override;
  57. // -------------------------------------------------------------------
  58. // Widget Callbacks
  59. void imageButtonClicked(ImageButton* button, int) override;
  60. void imageKnobDragStarted(ImageKnob* knob) override;
  61. void imageKnobDragFinished(ImageKnob* knob) override;
  62. void imageKnobValueChanged(ImageKnob* knob, float value) override;
  63. void onDisplay() override;
  64. private:
  65. Image fImgBackground;
  66. ImageAboutWindow fAboutWindow;
  67. ScopedPointer<ImageKnob> fKnobAttack, fKnobRelease, fKnobThreshold;
  68. ScopedPointer<ImageKnob> fKnobRatio, fKnobMakeup, fKnobMix;
  69. ScopedPointer<ImageButton> fButtonAbout;
  70. PowerJuicePlugin* const dsp;
  71. float fromDB(float gdb) {
  72. return (std::exp(gdb/20.f*std::log(10.f)));
  73. };
  74. float toDB(float g) {
  75. return (20.f*std::log10(g));
  76. }
  77. float toIEC(float db) {
  78. float def = 0.0f; /* Meter deflection %age */
  79. if (db < -70.0f) {
  80. def = 0.0f;
  81. } else if (db < -60.0f) {
  82. def = (db + 70.0f) * 0.25f;
  83. } else if (db < -50.0f) {
  84. def = (db + 60.0f) * 0.5f + 5.0f;
  85. } else if (db < -40.0f) {
  86. def = (db + 50.0f) * 0.75f + 7.5;
  87. } else if (db < -30.0f) {
  88. def = (db + 40.0f) * 1.5f + 15.0f;
  89. } else if (db < -20.0f) {
  90. def = (db + 30.0f) * 2.0f + 30.0f;
  91. } else if (db < 0.0f) {
  92. def = (db + 20.0f) * 2.5f + 50.0f;
  93. } else {
  94. def = 100.0f;
  95. }
  96. return (def * 2.0f);
  97. }
  98. };
  99. // -----------------------------------------------------------------------
  100. END_NAMESPACE_DISTRHO
  101. #endif // POWERJUICEUI_HPP_INCLUDED