Audacity  3.0.3
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 FrequencyPlotDialog and FilterPanel. More...

#include <Equalization.h>

Inheritance diagram for EqualizationPanel:
[legend]
Collaboration diagram for EqualizationPanel:
[legend]

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 TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

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 FrequencyPlotDialog and FilterPanel.

Definition at line 300 of file Equalization.h.

Constructor & Destructor Documentation

◆ EqualizationPanel()

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

Definition at line 3072 of file Equalization.cpp.

3074 : wxPanelWrapper(parent, winid)
3075 {
3076  mParent = parent;
3077  mEffect = effect;
3078 
3079  mBitmap = NULL;
3080  mWidth = 0;
3081  mHeight = 0;
3082 
3083  mLinEditor = std::make_unique<EnvelopeEditor>(*mEffect->mLinEnvelope, false);
3084  mLogEditor = std::make_unique<EnvelopeEditor>(*mEffect->mLogEnvelope, false);
3085  mEffect->mEnvelope->Flatten(0.);
3086  mEffect->mEnvelope->SetTrackLen(1.0);
3087 
3088  ForceRecalc();
3089 }

◆ ~EqualizationPanel()

EqualizationPanel::~EqualizationPanel ( )

Definition at line 3091 of file Equalization.cpp.

3092 {
3093  if(HasCapture())
3094  ReleaseMouse();
3095 }

Member Function Documentation

◆ AcceptsFocus()

bool EqualizationPanel::AcceptsFocus ( ) const
inline

Definition at line 308 of file Equalization.h.

308 { return false; }

◆ AcceptsFocusFromKeyboard()

bool EqualizationPanel::AcceptsFocusFromKeyboard ( ) const
inline

Definition at line 310 of file Equalization.h.

310 { return false; }

◆ ForceRecalc()

void EqualizationPanel::ForceRecalc ( )

Definition at line 3097 of file Equalization.cpp.

3098 {
3099  mRecalcRequired = true;
3100  Refresh(false);
3101 }

References mRecalcRequired.

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

Here is the caller graph for this function:

◆ OnCaptureLost()

void EqualizationPanel::OnCaptureLost ( wxMouseCaptureLostEvent &  event)
private

Definition at line 3328 of file Equalization.cpp.

3329 {
3330  if (HasCapture())
3331  {
3332  ReleaseMouse();
3333  }
3334 }

◆ OnMouseEvent()

void EqualizationPanel::OnMouseEvent ( wxMouseEvent &  event)
private

Definition at line 3301 of file Equalization.cpp.

3302 {
3303  if (!mEffect->mDrawMode)
3304  {
3305  return;
3306  }
3307 
3308  if (event.ButtonDown() && !HasCapture())
3309  {
3310  CaptureMouse();
3311  }
3312 
3313  auto &pEditor = (mEffect->mLin ? mLinEditor : mLogEditor);
3314  if (pEditor->MouseEvent(event, mEnvRect, ZoomInfo(0.0, mEnvRect.width),
3315  false, 0.0,
3317  {
3319  ForceRecalc();
3320  }
3321 
3322  if (event.ButtonUp() && HasCapture())
3323  {
3324  ReleaseMouse();
3325  }
3326 }

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

Here is the call graph for this function:

◆ OnPaint()

void EqualizationPanel::OnPaint ( wxPaintEvent &  event)
private

Definition at line 3118 of file Equalization.cpp.

3119 {
3120  wxPaintDC dc(this);
3121  if(mRecalcRequired) {
3122  Recalc();
3123  mRecalcRequired = false;
3124  }
3125  int width, height;
3126  GetSize(&width, &height);
3127 
3128  if (!mBitmap || mWidth!=width || mHeight!=height)
3129  {
3130  mWidth = width;
3131  mHeight = height;
3132  mBitmap = std::make_unique<wxBitmap>(mWidth, mHeight,24);
3133  }
3134 
3135  wxBrush bkgndBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
3136 
3137  wxMemoryDC memDC;
3138  memDC.SelectObject(*mBitmap);
3139 
3140  wxRect bkgndRect;
3141  bkgndRect.x = 0;
3142  bkgndRect.y = 0;
3143  bkgndRect.width = mWidth;
3144  bkgndRect.height = mHeight;
3145  memDC.SetBrush(bkgndBrush);
3146  memDC.SetPen(*wxTRANSPARENT_PEN);
3147  memDC.DrawRectangle(bkgndRect);
3148 
3149  bkgndRect.y = mHeight;
3150  memDC.DrawRectangle(bkgndRect);
3151 
3152  wxRect border;
3153  border.x = 0;
3154  border.y = 0;
3155  border.width = mWidth;
3156  border.height = mHeight;
3157 
3158  memDC.SetBrush(*wxWHITE_BRUSH);
3159  memDC.SetPen(*wxBLACK_PEN);
3160  memDC.DrawRectangle(border);
3161 
3162  mEnvRect = border;
3163  mEnvRect.Deflate(PANELBORDER, PANELBORDER);
3164 
3165  // Pure blue x-axis line
3166  memDC.SetPen(wxPen(theTheme.Colour( clrGraphLines ), 1, wxPENSTYLE_SOLID));
3167  int center = (int) (mEnvRect.height * mEffect->mdBMax/(mEffect->mdBMax-mEffect->mdBMin) + .5);
3168  AColor::Line(memDC,
3169  mEnvRect.GetLeft(), mEnvRect.y + center,
3170  mEnvRect.GetRight(), mEnvRect.y + center);
3171 
3172  // Draw the grid, if asked for. Do it now so it's underneath the main plots.
3173  if( mEffect->mDrawGrid )
3174  {
3175  mEffect->mFreqRuler->ruler.DrawGrid(memDC, mEnvRect.height, true, true, PANELBORDER, PANELBORDER);
3176  mEffect->mdBRuler->ruler.DrawGrid(memDC, mEnvRect.width, true, true, PANELBORDER, PANELBORDER);
3177  }
3178 
3179  // Med-blue envelope line
3180  memDC.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
3181 
3182  // Draw envelope
3183  int x, y, xlast = 0, ylast = 0;
3184  {
3185  Doubles values{ size_t(mEnvRect.width) };
3186  mEffect->mEnvelope->GetValues(values.get(), mEnvRect.width, 0.0, 1.0 / mEnvRect.width);
3187  bool off = false, off1 = false;
3188  for (int i = 0; i < mEnvRect.width; i++)
3189  {
3190  x = mEnvRect.x + i;
3191  y = lrint(mEnvRect.height*((mEffect->mdBMax - values[i]) / (mEffect->mdBMax - mEffect->mdBMin)) + .25); //needs more optimising, along with'what you get'?
3192  if (y >= mEnvRect.height)
3193  {
3194  y = mEnvRect.height - 1;
3195  off = true;
3196  }
3197  else
3198  {
3199  off = false;
3200  off1 = false;
3201  }
3202  if ((i != 0) & (!off1))
3203  {
3204  AColor::Line(memDC, xlast, ylast,
3205  x, mEnvRect.y + y);
3206  }
3207  off1 = off;
3208  xlast = x;
3209  ylast = mEnvRect.y + y;
3210  }
3211  }
3212 
3213  //Now draw the actual response that you will get.
3214  //mFilterFunc has a linear scale, window has a log one so we have to fiddle about
3215  memDC.SetPen(wxPen(theTheme.Colour( clrResponseLines ), 1, wxPENSTYLE_SOLID));
3216  double scale = (double)mEnvRect.height/(mEffect->mdBMax-mEffect->mdBMin); //pixels per dB
3217  double yF; //gain at this freq
3218  double delta = mEffect->mHiFreq / (((double)mEffect->mWindowSize / 2.)); //size of each freq bin
3219 
3220  bool lin = mEffect->IsLinear(); // log or lin scale?
3221 
3222  double loLog = log10(mEffect->mLoFreq);
3223  double step = lin ? mEffect->mHiFreq : (log10(mEffect->mHiFreq) - loLog);
3224  step /= ((double)mEnvRect.width-1.);
3225  double freq; //actual freq corresponding to x position
3226  int halfM = (mEffect->mM - 1) / 2;
3227  int n; //index to mFreqFunc
3228  for(int i=0; i<mEnvRect.width; i++)
3229  {
3230  x = mEnvRect.x + i;
3231  freq = lin ? step*i : pow(10., loLog + i*step); //Hz
3232  if( ( lin ? step : (pow(10., loLog + (i+1)*step)-freq) ) < delta)
3233  { //not enough resolution in FFT
3234  // set up for calculating cos using recurrence - faster than calculating it directly each time
3235  double theta = M_PI*freq/mEffect->mHiFreq; //radians, normalized
3236  double wtemp = sin(0.5 * theta);
3237  double wpr = -2.0 * wtemp * wtemp;
3238  double wpi = -1.0 * sin(theta);
3239  double wr = cos(theta*halfM);
3240  double wi = sin(theta*halfM);
3241 
3242  yF = 0.;
3243  for(int j=0;j<halfM;j++)
3244  {
3245  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.
3246  // do recurrence
3247  wr = (wtemp = wr) * wpr - wi * wpi + wr;
3248  wi = wi * wpr + wtemp * wpi + wi;
3249  }
3250  yF += mOutr[halfM];
3251  yF = fabs(yF);
3252  if(yF!=0.)
3253  yF = LINEAR_TO_DB(yF);
3254  else
3255  yF = mEffect->mdBMin;
3256  }
3257  else
3258  { //use FFT, it has enough resolution
3259  n = (int)(freq/delta + .5);
3260  if(pow(mEffect->mFilterFuncR[n],2)+pow(mEffect->mFilterFuncI[n],2)!=0.)
3261  yF = 10.0*log10(pow(mEffect->mFilterFuncR[n],2)+pow(mEffect->mFilterFuncI[n],2)); //10 here, a power
3262  else
3263  yF = mEffect->mdBMin;
3264  }
3265  if(yF < mEffect->mdBMin)
3266  yF = mEffect->mdBMin;
3267  yF = center-scale*yF;
3268  if(yF>mEnvRect.height)
3269  yF = mEnvRect.height - 1;
3270  if(yF<0.)
3271  yF=0.;
3272  y = (int)(yF+.5);
3273 
3274  if (i != 0)
3275  {
3276  AColor::Line(memDC, xlast, ylast, x, mEnvRect.y + y);
3277  }
3278  xlast = x;
3279  ylast = mEnvRect.y + y;
3280  }
3281 
3282  memDC.SetPen(*wxBLACK_PEN);
3283  if( mEffect->mDrawMode )
3284  {
3285  ZoomInfo zoomInfo( 0.0, mEnvRect.width-1 );
3286 
3287  // Back pointer to TrackPanel won't be needed in the one drawing
3288  // function we use here
3289  TrackArtist artist( nullptr );
3290 
3291  artist.pZoomInfo = &zoomInfo;
3292  TrackPanelDrawingContext context{ memDC, {}, {}, &artist };
3294  context, mEnvRect, false, 0.0,
3295  mEffect->mdBMin, mEffect->mdBMax, false);
3296  }
3297 
3298  dc.Blit(0, 0, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE);
3299 }

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

Here is the call graph for this function:

◆ OnSize()

void EqualizationPanel::OnSize ( wxSizeEvent &  event)
private

Definition at line 3112 of file Equalization.cpp.

3113 {
3114  Refresh( false );
3115 }

◆ Recalc()

void EqualizationPanel::Recalc ( )
private

Definition at line 3103 of file Equalization.cpp.

3104 {
3107 
3108  mEffect->CalcFilter(); //to calculate the actual response
3110 }

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

Referenced by OnPaint().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mBitmap

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

Definition at line 335 of file Equalization.h.

Referenced by OnPaint().

◆ mEffect

EffectEqualization* EqualizationPanel::mEffect
private

Definition at line 330 of file Equalization.h.

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

◆ mEnvRect

wxRect EqualizationPanel::mEnvRect
private

Definition at line 336 of file Equalization.h.

Referenced by OnMouseEvent(), and OnPaint().

◆ mHeight

int EqualizationPanel::mHeight
private

Definition at line 338 of file Equalization.h.

Referenced by OnPaint().

◆ mLinEditor

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

Definition at line 331 of file Equalization.h.

Referenced by OnMouseEvent().

◆ mLogEditor

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

Definition at line 331 of file Equalization.h.

Referenced by OnMouseEvent().

◆ mOuti

Floats EqualizationPanel::mOuti
private

Definition at line 342 of file Equalization.h.

Referenced by Recalc().

◆ mOutr

Floats EqualizationPanel::mOutr
private

Definition at line 342 of file Equalization.h.

Referenced by OnPaint(), and Recalc().

◆ mParent

wxWindow* EqualizationPanel::mParent
private

Definition at line 329 of file Equalization.h.

◆ mRecalcRequired

bool EqualizationPanel::mRecalcRequired
private

Definition at line 333 of file Equalization.h.

Referenced by ForceRecalc(), and OnPaint().

◆ mWidth

int EqualizationPanel::mWidth
private

Definition at line 337 of file Equalization.h.

Referenced by OnPaint().


The documentation for this class was generated from the following files:
EqualizationPanel::mRecalcRequired
bool mRecalcRequired
Definition: Equalization.h:333
EqualizationPanel::ForceRecalc
void ForceRecalc()
Definition: Equalization.cpp:3097
EffectEqualization::mLogEnvelope
std::unique_ptr< Envelope > mLogEnvelope
Definition: Equalization.h:235
EqualizationPanel::mBitmap
std::unique_ptr< wxBitmap > mBitmap
Definition: Equalization.h:335
EffectEqualization::mdBMin
float mdBMin
Definition: Equalization.h:214
ZoomInfo
Definition: ZoomInfo.h:47
EffectEqualization::mWindowSize
size_t mWindowSize
Definition: Equalization.h:228
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
EqualizationPanel::mLogEditor
std::unique_ptr< EnvelopeEditor > mLogEditor
Definition: Equalization.h:331
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
EffectEqualization::mLoFreq
double mLoFreq
Definition: Equalization.h:226
Envelope::SetTrackLen
void SetTrackLen(double trackLen, double sampleDur=0.0)
Definition: Envelope.cpp:791
EffectEqualization::mdBMax
float mdBMax
Definition: Equalization.h:213
EqualizationPanel::mLinEditor
std::unique_ptr< EnvelopeEditor > mLinEditor
Definition: Equalization.h:331
TrackArtist
This class handles the actual rendering of WaveTracks (both waveforms and spectra),...
Definition: TrackArtist.h:76
PANELBORDER
#define PANELBORDER
Definition: Equalization.h:16
EffectEqualization::mLin
bool mLin
Definition: Equalization.h:212
EffectEqualization::mFilterFuncR
Floats mFilterFuncR
Definition: Equalization.h:209
EffectEqualization::mLinEnvelope
std::unique_ptr< Envelope > mLinEnvelope
Definition: Equalization.h:235
EqualizationPanel::Recalc
void Recalc()
Definition: Equalization.cpp:3103
InverseRealFFT
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn, float *RealOut)
Definition: FFT.cpp:268
EffectEqualization::mM
size_t mM
Definition: Equalization.h:210
EqualizationPanel::mWidth
int mWidth
Definition: Equalization.h:337
EqualizationPanel::mEffect
EffectEqualization * mEffect
Definition: Equalization.h:330
EnvelopeEditor::DrawPoints
static void DrawPoints(const Envelope &env, TrackPanelDrawingContext &context, const wxRect &r, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored)
Definition: EnvelopeEditor.cpp:36
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:79
EqualizationPanel::mOuti
Floats mOuti
Definition: Equalization.h:342
EffectEqualization::IsLinear
bool IsLinear()
Definition: Equalization.cpp:2148
EffectEqualization::mDrawMode
bool mDrawMode
Definition: Equalization.h:215
EffectEqualization::EnvelopeUpdated
void EnvelopeUpdated()
Definition: Equalization.cpp:2086
wxPanelWrapper::wxPanelWrapper
wxPanelWrapper()
Definition: wxPanelWrapper.h:44
RulerPanel::ruler
Ruler ruler
Definition: Ruler.h:288
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1057
LINEAR_TO_DB
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:631
Envelope::Flatten
void Flatten(double value)
Definition: Envelope.cpp:134
EffectEqualization::mFreqRuler
RulerPanel * mFreqRuler
Definition: Equalization.h:223
M_PI
#define M_PI
Definition: Distortion.cpp:29
EqualizationPanel::mHeight
int mHeight
Definition: Equalization.h:338
EffectEqualization::mHiFreq
double mHiFreq
Definition: Equalization.h:227
EffectEqualization::mEnvelope
Envelope * mEnvelope
Definition: Equalization.h:236
EffectEqualization::CalcFilter
bool CalcFilter()
Definition: Equalization.cpp:1448
EffectEqualization::mdBRuler
RulerPanel * mdBRuler
Definition: Equalization.h:222
EffectEqualization::mFilterFuncI
Floats mFilterFuncI
Definition: Equalization.h:209
EqualizationPanel::mParent
wxWindow * mParent
Definition: Equalization.h:329
EffectEqualization::mDrawGrid
bool mDrawGrid
Definition: Equalization.h:217
lrint
#define lrint(dbl)
Definition: float_cast.h:169
values
const wxChar * values
Definition: Equalization.cpp:472
Ruler::DrawGrid
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
Definition: Ruler.cpp:1521
ArrayOf< double >
Envelope::GetValues
static void GetValues(const Envelope &env, double aligned_time, double sampleDur, double *buffer, int bufferLen, int leftOffset, const ZoomInfo &zoomInfo)
Get many envelope points for pixel columns at once, but don't assume uniform time per pixel.
Definition: Envelope.cpp:1472
EqualizationPanel::mEnvRect
wxRect mEnvRect
Definition: Equalization.h:336
EqualizationPanel::mOutr
Floats mOutr
Definition: Equalization.h:342