Audacity  2.2.0
FreqWindow.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  FreqWindow.h
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_FREQ_WINDOW__
12 #define __AUDACITY_FREQ_WINDOW__
13 
14 #include "MemoryX.h"
15 #include <vector>
16 #include <wx/brush.h>
17 #include <wx/dcmemory.h>
18 #include <wx/frame.h>
19 #include <wx/panel.h>
20 #include <wx/checkbox.h>
21 #include <wx/dialog.h>
22 #include <wx/gdicmn.h>
23 #include <wx/pen.h>
24 #include <wx/font.h>
25 #include <wx/scrolbar.h>
26 #include <wx/sizer.h>
27 #include <wx/slider.h>
28 #include <wx/stattext.h>
29 #include <wx/statusbr.h>
30 #include <wx/textctrl.h>
31 #include <wx/utils.h>
32 #include "widgets/Ruler.h"
33 #include "SampleFormat.h"
34 
35 class wxStatusBar;
36 class wxButton;
37 class wxChoice;
38 
39 class FreqWindow;
40 class FreqGauge;
41 
42 DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_FREQWINDOW_RECALC, -1);
43 
45 {
46 public:
47 
48  enum Algorithm {
54 
56  };
57 
60 
61  // Return true iff successful
62  bool Calculate(Algorithm alg,
63  int windowFunc, // see FFT.h for values
64  size_t windowSize, double rate,
65  const float *data, size_t dataLen,
66  float *pYMin = NULL, float *pYMax = NULL, // outputs
67  FreqGauge *progress = NULL);
68 
69  const float *GetProcessed() const;
70  int GetProcessedSize() const;
71 
72  float GetProcessedValue(float freq0, float freq1) const;
73  float FindPeak(float xPos, float *pY) const;
74 
75 private:
76  float CubicInterpolate(float y0, float y1, float y2, float y3, float x) const;
77  float CubicMaximize(float y0, float y1, float y2, float y3, float * max) const;
78 
79 private:
81  double mRate;
82  size_t mWindowSize;
83  std::vector<float> mProcessed;
84 };
85 
86 class FreqGauge final : public wxStatusBar
87 {
88 public:
89  FreqGauge(wxWindow * parent);
90 
91  void SetRange(int range, int bar = 12, int gap = 3);
92  void SetValue(int value);
93  void Reset();
94 
95 private:
96  wxRect mRect;
97  int mRange;
98  int mCur;
99  int mLast;
101  int mBar;
102  int mGap;
103  int mMargin;
104 };
105 
106 class FreqPlot final : public wxWindow
107 {
108 public:
109  FreqPlot(wxWindow *parent);
110 
111  // We don't need or want to accept focus.
112  bool AcceptsFocus() const;
113 
114 private:
115  void OnPaint(wxPaintEvent & event);
116  void OnErase(wxEraseEvent & event);
117  void OnMouseEvent(wxMouseEvent & event);
118 
119 private:
121 
122  DECLARE_EVENT_TABLE()
123 };
124 
125 class FreqWindow final : public wxDialogWrapper
126 {
127 public:
128  FreqWindow(wxWindow *parent, wxWindowID id,
129  const wxString & title, const wxPoint & pos);
130  virtual ~ FreqWindow();
131 
132  bool Show( bool show = true ) override;
133 
134 private:
135  void GetAudio();
136 
137  void PlotMouseEvent(wxMouseEvent & event);
138  void PlotPaint(wxPaintEvent & event);
139 
140  void OnCloseWindow(wxCloseEvent & event);
141  void OnCloseButton(wxCommandEvent & event);
142  void OnGetURL(wxCommandEvent & event);
143  void OnSize(wxSizeEvent & event);
144  void OnPanScroller(wxScrollEvent & event);
145  void OnZoomSlider(wxCommandEvent & event);
146  void OnAlgChoice(wxCommandEvent & event);
147  void OnSizeChoice(wxCommandEvent & event);
148  void OnFuncChoice(wxCommandEvent & event);
149  void OnAxisChoice(wxCommandEvent & event);
150  void OnExport(wxCommandEvent & event);
151  void OnReplot(wxCommandEvent & event);
152  void OnGridOnOff(wxCommandEvent & event);
153  void OnRecalc(wxCommandEvent & event);
154 
155  void SendRecalcEvent();
156  void Recalc();
157  void DrawPlot();
158  void DrawBackground(wxMemoryDC & dc);
159 
160  private:
161  bool mDrawGrid;
162  int mSize;
164  int mFunc;
165  int mAxis;
166  int dBRange;
168 
169 #ifdef __WXMSW__
170  static const int fontSize = 8;
171 #else
172  static const int fontSize = 10;
173 #endif
174 
179 
180  wxRect mPlotRect;
181 
182  wxFont mFreqFont;
183 
184  std::unique_ptr<wxCursor> mArrowCursor;
185  std::unique_ptr<wxCursor> mCrossCursor;
186 
187  wxButton *mCloseButton;
188  wxButton *mExportButton;
189  wxButton *mReplotButton;
190  wxCheckBox *mGridOnOff;
191  wxChoice *mAlgChoice;
192  wxChoice *mSizeChoice;
193  wxChoice *mFuncChoice;
194  wxChoice *mAxisChoice;
195  wxScrollBar *mPanScroller;
196  wxSlider *mZoomSlider;
197  wxTextCtrl *mCursorText;
198  wxTextCtrl *mPeakText;
199 
200 
201  double mRate;
202  size_t mDataLen;
204  size_t mWindowSize;
205 
206  bool mLogAxis;
207  float mYMin;
208  float mYMax;
209  float mYStep;
210 
211  std::unique_ptr<wxBitmap> mBitmap;
212 
213  int mMouseX;
214  int mMouseY;
215 
216  std::unique_ptr<SpectrumAnalyst> mAnalyst;
217 
218  DECLARE_EVENT_TABLE()
219 
220  friend class FreqPlot;
221 };
222 
223 #endif
const float * GetProcessed() const
Definition: FreqWindow.cpp:1434
wxCheckBox * mGridOnOff
Definition: FreqWindow.h:190
float mYMin
Definition: FreqWindow.h:207
void OnPaint(wxPaintEvent &event)
Definition: FreqWindow.cpp:1128
Definition: FreqWindow.h:49
void OnAlgChoice(wxCommandEvent &event)
Definition: FreqWindow.cpp:829
float mYStep
Definition: FreqWindow.h:209
double mRate
Definition: FreqWindow.h:201
wxButton * mExportButton
Definition: FreqWindow.h:188
wxRect mPlotRect
Definition: FreqWindow.h:180
void OnErase(wxEraseEvent &event)
Definition: FreqWindow.cpp:1123
Definition: FreqWindow.h:55
void OnAxisChoice(wxCommandEvent &event)
Definition: FreqWindow.cpp:860
float FindPeak(float xPos, float *pY) const
Definition: FreqWindow.cpp:1493
void OnRecalc(wxCommandEvent &event)
Definition: FreqWindow.cpp:1101
wxButton * mCloseButton
Definition: FreqWindow.h:187
int mRange
Definition: FreqWindow.h:97
void OnGridOnOff(wxCommandEvent &event)
Definition: FreqWindow.cpp:1094
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:216
void OnFuncChoice(wxCommandEvent &event)
Definition: FreqWindow.cpp:855
void OnSizeChoice(wxCommandEvent &event)
Definition: FreqWindow.cpp:846
int mMargin
Definition: FreqWindow.h:103
int mInterval
Definition: FreqWindow.h:100
int mFunc
Definition: FreqWindow.h:164
bool mDrawGrid
Definition: FreqWindow.h:161
wxRect mRect
Definition: FreqWindow.h:96
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:184
FreqPlot(wxWindow *parent)
Definition: FreqWindow.cpp:1112
void OnSize(wxSizeEvent &event)
Definition: FreqWindow.cpp:622
wxChoice * mAlgChoice
Definition: FreqWindow.h:191
int mAxis
Definition: FreqWindow.h:165
Works with FreqWindow to dsplay a spectrum plot of the waveform. This class actually does the graph d...
Definition: FreqWindow.h:106
int mGap
Definition: FreqWindow.h:102
std::unique_ptr< wxBitmap > mBitmap
Definition: FreqWindow.h:211
Definition: wxPanelWrapper.h:19
RulerPanel class allows you to work with a Ruler like any other wxWindow.
Definition: Ruler.h:244
Floats mData
Definition: FreqWindow.h:203
Definition: FreqWindow.h:52
size_t mWindowSize
Definition: FreqWindow.h:82
RulerPanel * hRuler
Definition: FreqWindow.h:176
void Reset()
Definition: FreqWindow.cpp:1181
void OnCloseButton(wxCommandEvent &event)
Definition: FreqWindow.cpp:977
void Recalc()
Definition: FreqWindow.cpp:994
FreqWindow * freqWindow
Definition: FreqWindow.h:120
int dBRange
Definition: FreqWindow.h:166
bool mLogAxis
Definition: FreqWindow.h:206
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
int GetProcessedSize() const
Definition: FreqWindow.cpp:1439
int mSize
Definition: FreqWindow.h:162
wxTextCtrl * mCursorText
Definition: FreqWindow.h:197
void SetValue(int value)
Definition: FreqWindow.cpp:1161
void SetRange(int range, int bar=12, int gap=3)
Definition: FreqWindow.cpp:1144
float CubicMaximize(float y0, float y1, float y2, float y3, float *max) const
Definition: FreqWindow.cpp:1560
wxButton * mReplotButton
Definition: FreqWindow.h:189
size_t mWindowSize
Definition: FreqWindow.h:204
wxScrollBar * mPanScroller
Definition: FreqWindow.h:195
bool Calculate(Algorithm alg, int windowFunc, size_t windowSize, double rate, const float *data, size_t dataLen, float *pYMin=NULL, float *pYMax=NULL, FreqGauge *progress=NULL)
Definition: FreqWindow.cpp:1187
void OnMouseEvent(wxMouseEvent &event)
Definition: FreqWindow.cpp:1133
void DrawBackground(wxMemoryDC &dc)
Definition: FreqWindow.cpp:631
void OnReplot(wxCommandEvent &event)
Definition: FreqWindow.cpp:1085
int mCur
Definition: FreqWindow.h:98
Definition: FreqWindow.h:51
static const int gap
Definition: Meter.cpp:175
void OnCloseWindow(wxCloseEvent &event)
Definition: FreqWindow.cpp:972
float mYMax
Definition: FreqWindow.h:208
void GetAudio()
Definition: FreqWindow.cpp:562
FreqWindow(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos)
Definition: FreqWindow.cpp:191
static const int fontSize
Definition: FreqWindow.h:172
std::vector< float > mProcessed
Definition: FreqWindow.h:83
int mMouseX
Definition: FreqWindow.h:213
FreqPlot * mFreqPlot
Definition: FreqWindow.h:177
int mMouseY
Definition: FreqWindow.h:214
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:163
~SpectrumAnalyst()
Definition: FreqWindow.cpp:187
void PlotMouseEvent(wxMouseEvent &event)
Definition: FreqWindow.cpp:804
void OnPanScroller(wxScrollEvent &event)
Definition: FreqWindow.cpp:819
void SendRecalcEvent()
Definition: FreqWindow.cpp:988
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_FREQWINDOW_RECALC,-1)
virtual ~FreqWindow()
Definition: FreqWindow.cpp:525
Used for finding the peaks, for snapping to peaks.
Definition: FreqWindow.h:44
wxSlider * mZoomSlider
Definition: FreqWindow.h:196
bool AcceptsFocus() const
Definition: FreqWindow.cpp:1118
float GetProcessedValue(float freq0, float freq1) const
Definition: FreqWindow.cpp:1444
wxFont mFreqFont
Definition: FreqWindow.h:182
Definition: FreqWindow.h:86
double mRate
Definition: FreqWindow.h:81
AudacityProject * p
Definition: FreqWindow.h:167
wxChoice * mAxisChoice
Definition: FreqWindow.h:194
Algorithm
Definition: FreqWindow.h:48
wxChoice * mSizeChoice
Definition: FreqWindow.h:192
SpectrumAnalyst()
Definition: FreqWindow.cpp:180
bool Show(bool show=true) override
Definition: FreqWindow.cpp:536
int mLast
Definition: FreqWindow.h:99
Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot...
Definition: FreqWindow.h:125
void PlotPaint(wxPaintEvent &event)
Definition: FreqWindow.cpp:866
int mBar
Definition: FreqWindow.h:101
wxTextCtrl * mPeakText
Definition: FreqWindow.h:198
Definition: FreqWindow.h:53
FreqGauge * mProgress
Definition: FreqWindow.h:178
size_t mDataLen
Definition: FreqWindow.h:202
Definition: FreqWindow.h:50
void OnGetURL(wxCommandEvent &event)
Definition: FreqWindow.cpp:529
void OnZoomSlider(wxCommandEvent &event)
Definition: FreqWindow.cpp:824
void DrawPlot()
Definition: FreqWindow.cpp:653
std::unique_ptr< wxCursor > mCrossCursor
Definition: FreqWindow.h:185
wxChoice * mFuncChoice
Definition: FreqWindow.h:193
Algorithm mAlg
Definition: FreqWindow.h:80
RulerPanel * vRuler
Definition: FreqWindow.h:175
void OnExport(wxCommandEvent &event)
Definition: FreqWindow.cpp:1039
float CubicInterpolate(float y0, float y1, float y2, float y3, float x) const
Definition: FreqWindow.cpp:1545
FreqGauge(wxWindow *parent)
Definition: FreqWindow.cpp:1138