File: bodeplot.h

package info (click to toggle)
eq10q 2.2~repack0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,384 kB
  • sloc: cpp: 8,036; ansic: 1,776; makefile: 6
file content (211 lines) | stat: -rw-r--r-- 8,145 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/***************************************************************************
 *   Copyright (C) 2009 by Pere Ràfols Soler                               *
 *   sapista2@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef PLOT_BODE_CURVE_H
  #define PLOT_BODE_CURVE_H

#include <iostream>
#include <gtkmm/drawingarea.h>
#include "filter.h"
#include "../eq_defines.h"

#define MIN_FREQ 18.0 
#define MAX_FREQ 22000.0
#define MIN_SPAN_DEC 0.5
#define CURVE_NUM_OF_POINTS 1000
#define GRID_VERTICAL_LINES 28
#define CURVE_MARGIN 8
#define CURVE_BORDER 1.5
#define CURVE_TEXT_OFFSET_X 18
#define CURVE_TEXT_OFFSET_Y 38
#define ZOOM_WIDGET_BORDER_Y 22
#define PLOT_HIGHT 300
#define PLOT_WIDTH 500
#define SCROLL_EVENT_INCREMENT 0.3
#define AUTO_REFRESH_TIMEOUT_MS 20
#define SPECTROGRAM_LINE_THICKNESS 3.0 

typedef struct
{
  float Gain;
  float Freq;
  float Q;
  bool bIsOn;
  FilterType fType;
}FilterBandParams;

class PlotEQCurve : public Gtk::DrawingArea
{
  public:
    PlotEQCurve(int iNumOfBands, int channels);
    virtual ~PlotEQCurve();
    void resetCurve();
    virtual void setBandGain(int bd_ix, float newGain);
    virtual void setBandFreq(int bd_ix, float newFreq);
    virtual void setBandQ(int bd_ix, float newQ);
    virtual void setBandType(int bd_ix, int newType);
    virtual void setBandEnable(int bd_ix, bool bIsEnabled);
    virtual void setBypass(bool bypass);
    virtual void setSampleRate(double samplerate);
    virtual void setFftData(double *fft_data);
    virtual void setFftActive(bool active, bool isSpectrogram);
    virtual void setFftGain(double g);
    virtual void setFftRange(double r);
    virtual void setFftHold(bool hold);
    virtual void setPlotdBRange(double range);
    virtual void glowBand(int band);
    virtual void unglowBands();
        
    enum MSState { ML, DUAL, SR, MONO};
    void setStereoState(int band, MSState state);
    
    //signal accessor:
    //Slot prototype: void on_band_changed(int band_ix, float Gain, float Freq, float Q);
    typedef sigc::signal<void, int, float, float, float> signal_BandChanged;
    signal_BandChanged signal_changed();
    
    //Slot prototype: void on_band_enabled(int band_ix, bool enabled);
    typedef sigc::signal<void, int, bool> signal_BandEnabled;
    signal_BandEnabled signal_enabled();
    
    //Slot prototype: void on_band_selected(int band_ix, bool enabled);
    typedef sigc::signal<void, int> signal_BandSelected;
    signal_BandSelected signal_selected();
    
    //Slot prototype: void on_band_selected(int band_ix, bool enabled);
    typedef sigc::signal<void> signal_BandUnselected;
    signal_BandUnselected signal_unselected();
       
  protected:    
      //Mouse grab signal handlers
      virtual bool on_button_press_event(GdkEventButton* event);
      virtual bool on_button_release_event(GdkEventButton* event);
      virtual bool on_scrollwheel_event(GdkEventScroll* event);
      virtual bool on_mouse_motion_event(GdkEventMotion* event);
      virtual bool on_timeout_redraw();
      virtual bool on_mouse_leave_widget(GdkEventCrossing* event);
      virtual void cueBandRedraws(int band);
      virtual void redraw_background_widget();
      virtual void redraw_zoom_widget();
      virtual void redraw_curve_widgets(int band);
      virtual void redraw_main_curve();
      virtual void redraw_grid_widget();
      virtual void redraw_xAxis_widget();
      virtual void redraw_yAxis_widget();
      virtual void redraw_fft_widget();
      virtual void redraw_cursor(double x, double y);
        
      //Override default signal handler:
      virtual bool on_expose_event(GdkEventExpose* event);
    
  private:
    int width, height; 
    int m_TotalBandsCount;
    int m_NumChannels;
    bool m_Bypass;
    int m_iBandSel;
    bool bMotionIsConnected;
    bool bBandFocus;
    bool *m_Bands2Redraw;
    bool m_BandRedraw, m_fullRedraw, m_justRedraw;
    double SampleRate;
    bool m_FftActive;
    double m_minFreq, m_maxFreq;
    double m_dB_plot_range;
        
    //To hadle mouse mouve events
    sigc::connection m_motion_connection;
    
    //Store filters data
    FilterBandParams **m_filters;  //This pointer is initialized by construcor to an array of total num of bands
    
    //X axes LUT tables
    int xPixels_Grid[GRID_VERTICAL_LINES]; //Pixels used to draw the grind in logspace
    double *f; //This pointer is initialized by construcor to an array of total num of points acording min/max freq define
    int *xPixels; //This pointer is initialized by construcor to an array of total num of points, each item is the pixel space transaltion of corresponding freq
    
    //Curve vector for Y axes in dB units
    double **main_y; //This pointer is initialized by construcor to an array of total num of points acording the format main_y[channel][num_points]
    double **band_y;  //This pointer is initialized by construcor to an array acording the format band_y[bd_ix][num_points]
    MSState *band_state; //A vector containing the Stereo states for each band
    
    //FFT vectors
    double *xPixels_fft, *xPixels_fft_bins;
    double *fft_pink_noise;
    double *fft_plot;
    double *fft_ant_data;
    double fft_gain;
    double fft_range;
    float *fft_log_lut;
    bool m_bIsSpectrogram, m_bFftHold;
    double *fft_raw_data;
    
    //Zoom widget data
    struct zoom_widget
    {
      bool center_focus;
      bool f1_focus;
      bool f2_focus;
      double x1;
      double x2;
      double x_ant;
      bool center_press;
      bool f1_press;
      bool f2_press;
    } m_zoom_widget;
    
    
    //Cairo surfaces
    Cairo::RefPtr<Cairo::ImageSurface> m_background_surface_ptr, m_fft_surface_ptr, m_zoom_surface_ptr, *m_curve_surface_ptr, m_maincurve_surface_ptr, m_grid_surface_ptr, m_xAxis_surface_ptr, m_yAxis_surface_ptr, m_cursor_surface_ptr; 
    
    //Bode change signal
    signal_BandChanged m_BandChangedSignal;
    signal_BandEnabled m_BandEnabledSignal;
    signal_BandSelected m_BandSelectedSignal;
    signal_BandUnselected m_BandUnselectedSignal;
        
    //Function for dB to pixels convertion
    double dB2Pixels(double db);
    
    //Function for Hz to pixels convertion
    double freq2Pixels(double f);
    
    //Function for pixels to dB convertion
    double Pixels2dB(double pixels);
    
    //Function for pixels to Hz convertion
    double Pixels2freq(double pixels);
    
    //Compute a filter points
    void ComputeFilter(int bd_ix); 
    
    //Curve math functions   
    void CalcBand_DigitalFilter(int bd_ix);
    
    //Compute zoom bar
    virtual void setCenterSpan(double center, double span);
    virtual void resetCenterSpan();   
    virtual void setCenter(double center);
    virtual void setSpan(double span);
    void recomputeMinFreq_fromX1Pixel(double x1);
    void recomputeMaxFreq_fromX2Pixel(double x2);
    void recomputeCenterFreq(double xDiff);
};
#endif