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.

146 lines
4.1KB

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