Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EqualizationPanel Class Referencefinal

EqualizationPanel is used with EqualizationDialog and controls a graph for EffectEqualization. We should look at amalgamating the various graphing code, such as provided by FreqWindow and FilterPanel. More...

#include <Equalization.h>

Inheritance diagram for EqualizationPanel:
wxPanelWrapper wxTabTraversalWrapper< wxPanel >

Public Member Functions

 EqualizationPanel (wxWindow *parent, wxWindowID winid, EffectEqualization *effect)
 
 ~EqualizationPanel ()
 
bool AcceptsFocus () const
 
bool AcceptsFocusFromKeyboard () const
 
void ForceRecalc ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&...args)
 

Private Member Functions

void Recalc ()
 
void OnMouseEvent (wxMouseEvent &event)
 
void OnCaptureLost (wxMouseCaptureLostEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnSize (wxSizeEvent &event)
 

Private Attributes

wxWindow * mParent
 
EffectEqualizationmEffect
 
std::unique_ptr< EnvelopeEditormLinEditor
 
std::unique_ptr< EnvelopeEditormLogEditor
 
bool mRecalcRequired
 
std::unique_ptr< wxBitmap > mBitmap
 
wxRect mEnvRect
 
int mWidth
 
int mHeight
 
Floats mOutr
 
Floats mOuti
 

Detailed Description

EqualizationPanel is used with EqualizationDialog and controls a graph for EffectEqualization. We should look at amalgamating the various graphing code, such as provided by FreqWindow and FilterPanel.

Definition at line 283 of file Equalization.h.

Constructor & Destructor Documentation

EqualizationPanel::EqualizationPanel ( wxWindow *  parent,
wxWindowID  winid,
EffectEqualization effect 
)

Definition at line 2840 of file Equalization.cpp.

2842 : wxPanelWrapper(parent, winid)
2843 {
2844  mParent = parent;
2845  mEffect = effect;
2846 
2847  mBitmap = NULL;
2848  mWidth = 0;
2849  mHeight = 0;
2850 
2851  mLinEditor = std::make_unique<EnvelopeEditor>(*mEffect->mLinEnvelope, false);
2852  mLogEditor = std::make_unique<EnvelopeEditor>(*mEffect->mLogEnvelope, false);
2853  mEffect->mEnvelope->Flatten(0.);
2854  mEffect->mEnvelope->SetTrackLen(1.0);
2855 
2856  ForceRecalc();
2857 }
void Flatten(double value)
Definition: Envelope.cpp:137
wxWindow * mParent
Definition: Equalization.h:312
Envelope * mEnvelope
Definition: Equalization.h:235
std::unique_ptr< wxBitmap > mBitmap
Definition: Equalization.h:318
void SetTrackLen(double trackLen, double sampleDur=0.0)
Definition: Envelope.cpp:1077
std::unique_ptr< Envelope > mLogEnvelope
Definition: Equalization.h:234
std::unique_ptr< EnvelopeEditor > mLinEditor
Definition: Equalization.h:314
std::unique_ptr< Envelope > mLinEnvelope
Definition: Equalization.h:234
EffectEqualization * mEffect
Definition: Equalization.h:313
std::unique_ptr< EnvelopeEditor > mLogEditor
Definition: Equalization.h:314
EqualizationPanel::~EqualizationPanel ( )

Definition at line 2859 of file Equalization.cpp.

2860 {
2861  if(HasCapture())
2862  ReleaseMouse();
2863 }

Member Function Documentation

bool EqualizationPanel::AcceptsFocus ( ) const
inline

Definition at line 291 of file Equalization.h.

291 { return false; }
bool EqualizationPanel::AcceptsFocusFromKeyboard ( ) const
inline

Definition at line 293 of file Equalization.h.

293 { return false; }
void EqualizationPanel::ForceRecalc ( )

Definition at line 2865 of file Equalization.cpp.

References mRecalcRequired.

Referenced by EffectEqualization::ForceRecalc(), and OnMouseEvent().

2866 {
2867  mRecalcRequired = true;
2868  Refresh(false);
2869 }
void EqualizationPanel::OnCaptureLost ( wxMouseCaptureLostEvent &  event)
private

Definition at line 3089 of file Equalization.cpp.

3090 {
3091  if (HasCapture())
3092  {
3093  ReleaseMouse();
3094  }
3095 }
void EqualizationPanel::OnMouseEvent ( wxMouseEvent &  event)
private

Definition at line 3062 of file Equalization.cpp.

References EffectEqualization::EnvelopeUpdated(), ForceRecalc(), EffectEqualization::mdBMax, EffectEqualization::mdBMin, EffectEqualization::mDrawMode, mEffect, mEnvRect, EffectEqualization::mLin, mLinEditor, and mLogEditor.

3063 {
3064  if (!mEffect->mDrawMode)
3065  {
3066  return;
3067  }
3068 
3069  if (event.ButtonDown() && !HasCapture())
3070  {
3071  CaptureMouse();
3072  }
3073 
3074  auto &pEditor = (mEffect->mLin ? mLinEditor : mLogEditor);
3075  if (pEditor->MouseEvent(event, mEnvRect, ZoomInfo(0.0, mEnvRect.width),
3076  false, 0.0,
3078  {
3080  ForceRecalc();
3081  }
3082 
3083  if (event.ButtonUp() && HasCapture())
3084  {
3085  ReleaseMouse();
3086  }
3087 }
std::unique_ptr< EnvelopeEditor > mLinEditor
Definition: Equalization.h:314
EffectEqualization * mEffect
Definition: Equalization.h:313
std::unique_ptr< EnvelopeEditor > mLogEditor
Definition: Equalization.h:314
void EqualizationPanel::OnPaint ( wxPaintEvent &  event)
private

Definition at line 2886 of file Equalization.cpp.

References ThemeBase::Colour(), Ruler::DrawGrid(), Envelope::DrawPoints(), Envelope::GetValues(), EffectEqualization::IsLinear(), AColor::Line(), LINEAR_TO_DB, lrint, M_PI, mBitmap, EffectEqualization::mdBMax, EffectEqualization::mdBMin, EffectEqualization::mdBRuler, EffectEqualization::mDraw, EffectEqualization::mDrawGrid, mEffect, EffectEqualization::mEnvelope, mEnvRect, EffectEqualization::mFilterFuncI, EffectEqualization::mFilterFuncR, EffectEqualization::mFreqRuler, mHeight, EffectEqualization::mHiFreq, EffectEqualization::mLoFreq, EffectEqualization::mM, mOutr, mRecalcRequired, mWidth, EffectEqualization::mWindowSize, PANELBORDER, Recalc(), RulerPanel::ruler, and theTheme.

2887 {
2888  wxPaintDC dc(this);
2889  if(mRecalcRequired) {
2890  Recalc();
2891  mRecalcRequired = false;
2892  }
2893  int width, height;
2894  GetSize(&width, &height);
2895 
2896  if (!mBitmap || mWidth!=width || mHeight!=height)
2897  {
2898  mWidth = width;
2899  mHeight = height;
2900  mBitmap = std::make_unique<wxBitmap>(mWidth, mHeight);
2901  }
2902 
2903  wxBrush bkgndBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
2904 
2905  wxMemoryDC memDC;
2906  memDC.SelectObject(*mBitmap);
2907 
2908  wxRect bkgndRect;
2909  bkgndRect.x = 0;
2910  bkgndRect.y = 0;
2911  bkgndRect.width = mWidth;
2912  bkgndRect.height = mHeight;
2913  memDC.SetBrush(bkgndBrush);
2914  memDC.SetPen(*wxTRANSPARENT_PEN);
2915  memDC.DrawRectangle(bkgndRect);
2916 
2917  bkgndRect.y = mHeight;
2918  memDC.DrawRectangle(bkgndRect);
2919 
2920  wxRect border;
2921  border.x = 0;
2922  border.y = 0;
2923  border.width = mWidth;
2924  border.height = mHeight;
2925 
2926  memDC.SetBrush(*wxWHITE_BRUSH);
2927  memDC.SetPen(*wxBLACK_PEN);
2928  memDC.DrawRectangle(border);
2929 
2930  mEnvRect = border;
2931  mEnvRect.Deflate(PANELBORDER, PANELBORDER);
2932 
2933  // Pure blue x-axis line
2934  memDC.SetPen(wxPen(theTheme.Colour( clrGraphLines ), 1, wxSOLID));
2935  int center = (int) (mEnvRect.height * mEffect->mdBMax/(mEffect->mdBMax-mEffect->mdBMin) + .5);
2936  AColor::Line(memDC,
2937  mEnvRect.GetLeft(), mEnvRect.y + center,
2938  mEnvRect.GetRight(), mEnvRect.y + center);
2939 
2940  // Draw the grid, if asked for. Do it now so it's underneath the main plots.
2941  if( mEffect->mDrawGrid )
2942  {
2943  mEffect->mFreqRuler->ruler.DrawGrid(memDC, mEnvRect.height, true, true, PANELBORDER, PANELBORDER);
2944  mEffect->mdBRuler->ruler.DrawGrid(memDC, mEnvRect.width, true, true, PANELBORDER, PANELBORDER);
2945  }
2946 
2947  // Med-blue envelope line
2948  memDC.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxSOLID));
2949 
2950  // Draw envelope
2951  int x, y, xlast = 0, ylast = 0;
2952  {
2953  Doubles values{ size_t(mEnvRect.width) };
2954  mEffect->mEnvelope->GetValues(values.get(), mEnvRect.width, 0.0, 1.0 / mEnvRect.width);
2955  bool off = false, off1 = false;
2956  for (int i = 0; i < mEnvRect.width; i++)
2957  {
2958  x = mEnvRect.x + i;
2959  y = lrint(mEnvRect.height*((mEffect->mdBMax - values[i]) / (mEffect->mdBMax - mEffect->mdBMin)) + .25); //needs more optimising, along with'what you get'?
2960  if (y >= mEnvRect.height)
2961  {
2962  y = mEnvRect.height - 1;
2963  off = true;
2964  }
2965  else
2966  {
2967  off = false;
2968  off1 = false;
2969  }
2970  if ((i != 0) & (!off1))
2971  {
2972  AColor::Line(memDC, xlast, ylast,
2973  x, mEnvRect.y + y);
2974  }
2975  off1 = off;
2976  xlast = x;
2977  ylast = mEnvRect.y + y;
2978  }
2979  }
2980 
2981  //Now draw the actual response that you will get.
2982  //mFilterFunc has a linear scale, window has a log one so we have to fiddle about
2983  memDC.SetPen(wxPen(theTheme.Colour( clrResponseLines ), 1, wxSOLID));
2984  double scale = (double)mEnvRect.height/(mEffect->mdBMax-mEffect->mdBMin); //pixels per dB
2985  double yF; //gain at this freq
2986  double delta = mEffect->mHiFreq / (((double)mEffect->mWindowSize / 2.)); //size of each freq bin
2987 
2988  bool lin = mEffect->IsLinear(); // log or lin scale?
2989 
2990  double loLog = log10(mEffect->mLoFreq);
2991  double step = lin ? mEffect->mHiFreq : (log10(mEffect->mHiFreq) - loLog);
2992  step /= ((double)mEnvRect.width-1.);
2993  double freq; //actual freq corresponding to x position
2994  int halfM = (mEffect->mM - 1) / 2;
2995  int n; //index to mFreqFunc
2996  for(int i=0; i<mEnvRect.width; i++)
2997  {
2998  x = mEnvRect.x + i;
2999  freq = lin ? step*i : pow(10., loLog + i*step); //Hz
3000  if( ( lin ? step : (pow(10., loLog + (i+1)*step)-freq) ) < delta)
3001  { //not enough resolution in FFT
3002  // set up for calculating cos using recurrance - faster than calculating it directly each time
3003  double theta = M_PI*freq/mEffect->mHiFreq; //radians, normalized
3004  double wtemp = sin(0.5 * theta);
3005  double wpr = -2.0 * wtemp * wtemp;
3006  double wpi = -1.0 * sin(theta);
3007  double wr = cos(theta*halfM);
3008  double wi = sin(theta*halfM);
3009 
3010  yF = 0.;
3011  for(int j=0;j<halfM;j++)
3012  {
3013  yF += 2. * mOutr[j] * wr; // This works for me, compared to the previous version. Compare wr to cos(theta*(halfM-j)). Works for me. Keep everything as doubles though.
3014  // do recurrance
3015  wr = (wtemp = wr) * wpr - wi * wpi + wr;
3016  wi = wi * wpr + wtemp * wpi + wi;
3017  }
3018  yF += mOutr[halfM];
3019  yF = fabs(yF);
3020  if(yF!=0.)
3021  yF = LINEAR_TO_DB(yF);
3022  else
3023  yF = mEffect->mdBMin;
3024  }
3025  else
3026  { //use FFT, it has enough resolution
3027  n = (int)(freq/delta + .5);
3028  if(pow(mEffect->mFilterFuncR[n],2)+pow(mEffect->mFilterFuncI[n],2)!=0.)
3029  yF = 10.0*log10(pow(mEffect->mFilterFuncR[n],2)+pow(mEffect->mFilterFuncI[n],2)); //10 here, a power
3030  else
3031  yF = mEffect->mdBMin;
3032  }
3033  if(yF < mEffect->mdBMin)
3034  yF = mEffect->mdBMin;
3035  yF = center-scale*yF;
3036  if(yF>mEnvRect.height)
3037  yF = mEnvRect.height - 1;
3038  if(yF<0.)
3039  yF=0.;
3040  y = (int)(yF+.5);
3041 
3042  if (i != 0)
3043  {
3044  AColor::Line(memDC, xlast, ylast, x, mEnvRect.y + y);
3045  }
3046  xlast = x;
3047  ylast = mEnvRect.y + y;
3048  }
3049 
3050  memDC.SetPen(*wxBLACK_PEN);
3051  if( mEffect->mDraw->GetValue() )
3052  {
3053  TrackPanelDrawingContext context{ memDC, {}, {} };
3055  context, mEnvRect, ZoomInfo(0.0, mEnvRect.width-1), false, 0.0,
3056  mEffect->mdBMin, mEffect->mdBMax, false);
3057  }
3058 
3059  dc.Blit(0, 0, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE);
3060 }
void DrawPoints(TrackPanelDrawingContext &context, const wxRect &r, const ZoomInfo &zoomInfo, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored) const
TODO: This should probably move to track artist.
Definition: Envelope.cpp:322
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
Envelope * mEnvelope
Definition: Equalization.h:235
wxRadioButton * mDraw
Definition: Equalization.h:259
std::unique_ptr< wxBitmap > mBitmap
Definition: Equalization.h:318
RulerPanel * mFreqRuler
Definition: Equalization.h:222
#define PANELBORDER
Definition: Equalization.h:16
#define lrint(dbl)
Definition: float_cast.h:136
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0)
Definition: Ruler.cpp:1465
#define LINEAR_TO_DB(x)
Definition: Audacity.h:217
#define M_PI
Definition: Distortion.cpp:28
RulerPanel * mdBRuler
Definition: Equalization.h:221
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void GetValues(double *buffer, int len, double t0, double tstep) const
Get many envelope points at once.
Definition: Envelope.cpp:1214
EffectEqualization * mEffect
Definition: Equalization.h:313
Ruler ruler
Definition: Ruler.h:306
void EqualizationPanel::OnSize ( wxSizeEvent &  event)
private

Definition at line 2880 of file Equalization.cpp.

2881 {
2882  Refresh( false );
2883 }
void EqualizationPanel::Recalc ( )
private

Definition at line 2871 of file Equalization.cpp.

References EffectEqualization::CalcFilter(), InverseRealFFT(), mEffect, EffectEqualization::mFilterFuncI, EffectEqualization::mFilterFuncR, mOuti, mOutr, and EffectEqualization::mWindowSize.

Referenced by OnPaint().

2872 {
2875 
2876  mEffect->CalcFilter(); //to calculate the actual response
2878 }
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn, float *RealOut)
Definition: FFT.cpp:269
EffectEqualization * mEffect
Definition: Equalization.h:313

Member Data Documentation

std::unique_ptr<wxBitmap> EqualizationPanel::mBitmap
private

Definition at line 318 of file Equalization.h.

Referenced by OnPaint().

EffectEqualization* EqualizationPanel::mEffect
private

Definition at line 313 of file Equalization.h.

Referenced by OnMouseEvent(), OnPaint(), and Recalc().

wxRect EqualizationPanel::mEnvRect
private

Definition at line 319 of file Equalization.h.

Referenced by OnMouseEvent(), and OnPaint().

int EqualizationPanel::mHeight
private

Definition at line 321 of file Equalization.h.

Referenced by OnPaint().

std::unique_ptr<EnvelopeEditor> EqualizationPanel::mLinEditor
private

Definition at line 314 of file Equalization.h.

Referenced by OnMouseEvent().

std::unique_ptr<EnvelopeEditor> EqualizationPanel::mLogEditor
private

Definition at line 314 of file Equalization.h.

Referenced by OnMouseEvent().

Floats EqualizationPanel::mOuti
private

Definition at line 325 of file Equalization.h.

Referenced by Recalc().

Floats EqualizationPanel::mOutr
private

Definition at line 325 of file Equalization.h.

Referenced by OnPaint(), and Recalc().

wxWindow* EqualizationPanel::mParent
private

Definition at line 312 of file Equalization.h.

bool EqualizationPanel::mRecalcRequired
private

Definition at line 316 of file Equalization.h.

Referenced by ForceRecalc(), and OnPaint().

int EqualizationPanel::mWidth
private

Definition at line 320 of file Equalization.h.

Referenced by OnPaint().


The documentation for this class was generated from the following files: