1 /*
2  * ZamDynamicEQ
3  * Copyright (C) 2016  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 (at your option) 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 
16 #ifndef ZAMDYNAMICEQUI_HPP_INCLUDED
17 #define ZAMDYNAMICEQUI_HPP_INCLUDED
18 
19 #include "DistrhoUI.hpp"
20 #include "ImageWidgets.hpp"
21 #include "../../widgets/ZamWidgets.hpp"
22 
23 #include "ZamDynamicEQArtwork.hpp"
24 
25 #define EQPOINTS 575
26 #include <complex>
27 
28 using DGL::Image;
29 using DGL::ZamKnob;
30 using DGL::ZamSwitch;
31 using DGL::ImageSwitch;
32 using DGL::ImageSlider;
33 
34 START_NAMESPACE_DISTRHO
35 
36 // -----------------------------------------------------------------------
37 
38 class ZamDynamicEQUI : public UI,
39                         public ZamKnob::Callback,
40                         public ZamSwitch::Callback,
41                         public ImageSwitch::Callback
42 {
43 public:
44     ZamDynamicEQUI();
45 
46 protected:
47     // -------------------------------------------------------------------
48     // DSP Callbacks
49 
50     void parameterChanged(uint32_t index, float value) override;
51     void programLoaded(uint32_t index) override;
52 
53     // -------------------------------------------------------------------
54     // Widget Callbacks
55 
56     void imageKnobDragStarted(ZamKnob* knob) override;
57     void imageKnobDragFinished(ZamKnob* knob) override;
58     void imageKnobValueChanged(ZamKnob* knob, float value) override;
59     void imageSwitchClicked(ImageSwitch* toggle, bool down) override;
60     void imageSwitchClicked(ZamSwitch* toggle, bool down) override;
61 
62     void onDisplay() override;
63 
64 inline double
to_dB(double g)65 to_dB(double g) {
66         return (20.*log10(g));
67 }
68 
69 inline double
from_dB(double gdb)70 from_dB(double gdb) {
71         return (exp(gdb/20.*log(10.)));
72 }
73 
74 inline double
sanitize_denormal(double value)75 sanitize_denormal(double value) {
76         if (!std::isnormal(value)) {
77                 return (0.);
78         }
79         return value;
80 }
81 
82 	void calceqcurve(float x[], float y[]);
83 	void peq(double G0, double G, double GB, double w0, double Dw, double *a0, double *a1, double *a2, double *b0, double *b1, double *b2, double *gn);
84 	void highshelfeq(double, double G, double, double w0, double, double q, double B[], double A[]);
85 	void lowshelfeq(double, double G, double, double w0, double, double q, double B[], double A[]);
86 
87 
88 private:
89     Image fImgBackground, fHighOnImg, fHighOffImg, fLowOnImg, fLowOffImg;
90     Image fPeakOnImg, fPeakOffImg, fTogOffImg, fTogOnImg, fSliderEq;
91 
92     ScopedPointer<ZamSwitch> fToggleLow, fTogglePeak, fToggleHigh;
93     ScopedPointer<ImageSwitch> fToggleSidechain, fToggleBoostCut;
94     ScopedPointer<ZamKnob> fKnobAttack, fKnobRelease;
95     ScopedPointer<ZamKnob> fKnobThresh, fKnobRatio, fKnobKnee, fKnobTargetWidth;
96     ScopedPointer<ZamKnob> fKnobMax, fKnobSlew, fKnobTargetFreq, fKnobDetectFreq;
97 
98     DGL::Rectangle<int> fCanvasArea;
99     float eqx[EQPOINTS], eqy[EQPOINTS];
100     double a0x,a1x,a2x,b0x,b1x,b2x,gainx;
101     double a0y,a1y,a2y,b0y,b1y,b2y,gainy;
102     double Bl[3];
103     double Al[3];
104     double Bh[3];
105     double Ah[3];
106     float fControlGain;
107 };
108 
109 // -----------------------------------------------------------------------
110 
111 END_NAMESPACE_DISTRHO
112 
113 #endif
114