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.

151 lines
4.2KB

  1. /*
  2. * ZamEQ2 2 band parametric equaliser
  3. * Copyright (C) 2014 Damien Zammit <damien@zamaudio.com>
  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 ZAMEQ2UI_HPP_INCLUDED
  18. #define ZAMEQ2UI_HPP_INCLUDED
  19. #define EQPOINTS 1000
  20. #include <complex>
  21. #include "DistrhoUI.hpp"
  22. #include "ImageKnob.hpp"
  23. #include "ImageSlider.hpp"
  24. #include "ZamEQ2Artwork.hpp"
  25. #include "ZamEQ2Plugin.hpp"
  26. using DGL::Image;
  27. using DGL::ImageKnob;
  28. using DGL::ImageSlider;
  29. START_NAMESPACE_DISTRHO
  30. // -----------------------------------------------------------------------
  31. class ZamEQ2UI : public UI,
  32. public ImageKnob::Callback,
  33. public ImageSlider::Callback
  34. {
  35. public:
  36. ZamEQ2UI();
  37. ~ZamEQ2UI() override;
  38. protected:
  39. // -------------------------------------------------------------------
  40. // Information
  41. unsigned int d_getWidth() const noexcept override
  42. {
  43. return ZamEQ2Artwork::zameq2Width;
  44. }
  45. unsigned int d_getHeight() const noexcept override
  46. {
  47. return ZamEQ2Artwork::zameq2Height;
  48. }
  49. inline double
  50. to_dB(double g) {
  51. return (20.*log10(g));
  52. }
  53. inline double
  54. from_dB(double gdb) {
  55. return (exp(gdb/20.*log(10.)));
  56. }
  57. inline double
  58. sanitize_denormal(double value) {
  59. if (!std::isnormal(value)) {
  60. return (0.);
  61. }
  62. return value;
  63. }
  64. float toIEC(float db) {
  65. float def = 0.0f; /* Meter deflection %age */
  66. if (db < -70.0f) {
  67. def = 0.0f;
  68. } else if (db < -60.0f) {
  69. def = (db + 70.0f) * 0.25f;
  70. } else if (db < -50.0f) {
  71. def = (db + 60.0f) * 0.5f + 5.0f;
  72. } else if (db < -40.0f) {
  73. def = (db + 50.0f) * 0.75f + 7.5;
  74. } else if (db < -30.0f) {
  75. def = (db + 40.0f) * 1.5f + 15.0f;
  76. } else if (db < -20.0f) {
  77. def = (db + 30.0f) * 2.0f + 30.0f;
  78. } else if (db < 0.0f) {
  79. def = (db + 20.0f) * 2.5f + 50.0f;
  80. } else {
  81. def = 100.0f;
  82. }
  83. return (def * 2.0f);
  84. }
  85. void calceqcurve(float x[], float y[]);
  86. void peq(int i, int ch, float srate, float fc, float g, float bw);
  87. void lowshelf(int i, int ch, float srate, float fc, float g);
  88. void highshelf(int i, int ch, float srate, float fc, float g);
  89. // -------------------------------------------------------------------
  90. // DSP Callbacks
  91. void d_parameterChanged(uint32_t index, float value) override;
  92. void d_programChanged(uint32_t index) override;
  93. // -------------------------------------------------------------------
  94. // Widget Callbacks
  95. void imageKnobDragStarted(ImageKnob* knob) override;
  96. void imageKnobDragFinished(ImageKnob* knob) override;
  97. void imageKnobValueChanged(ImageKnob* knob, float value) override;
  98. void imageSliderDragStarted(ImageSlider* slider) override;
  99. void imageSliderDragFinished(ImageSlider* slider) override;
  100. void imageSliderValueChanged(ImageSlider* slider, float value) override;
  101. void onDisplay() override;
  102. private:
  103. Image fImgBackground;
  104. ImageKnob* fKnobGain1;
  105. ImageKnob* fKnobQ1;
  106. ImageKnob* fKnobFreq1;
  107. ImageKnob* fKnobGain2;
  108. ImageKnob* fKnobQ2;
  109. ImageKnob* fKnobFreq2;
  110. ImageKnob* fKnobGainL;
  111. ImageKnob* fKnobFreqL;
  112. ImageKnob* fKnobGainH;
  113. ImageKnob* fKnobFreqH;
  114. ImageSlider* fSliderMaster;
  115. float eqx[EQPOINTS];
  116. float eqy[EQPOINTS];
  117. DGL::Rectangle<int> fCanvasArea;
  118. double a1[1][MAX_FILT], a2[1][MAX_FILT], b0[1][MAX_FILT], b1[1][MAX_FILT], b2[1][MAX_FILT];
  119. };
  120. // -----------------------------------------------------------------------
  121. END_NAMESPACE_DISTRHO
  122. #endif // ZAMEQ2UI_HPP_INCLUDED