Audacity 3.2.0
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 338 of file Equalization.h.

Constructor & Destructor Documentation

◆ EqualizationPanel()

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

Definition at line 2972 of file Equalization.cpp.

2974: wxPanelWrapper(parent, winid)
2975{
2976 mParent = parent;
2977 mEffect = effect;
2978
2979 mBitmap = NULL;
2980 mWidth = 0;
2981 mHeight = 0;
2982
2983 mLinEditor = std::make_unique<EnvelopeEditor>(*mEffect->mLinEnvelope, false);
2984 mLogEditor = std::make_unique<EnvelopeEditor>(*mEffect->mLogEnvelope, false);
2987
2988 ForceRecalc();
2989}
std::unique_ptr< Envelope > mLinEnvelope
Definition: Equalization.h:244
std::unique_ptr< Envelope > mLogEnvelope
Definition: Equalization.h:244
Envelope * mEnvelope
Definition: Equalization.h:245
void SetTrackLen(double trackLen, double sampleDur=0.0)
Definition: Envelope.cpp:787
void Flatten(double value)
Definition: Envelope.cpp:132
EffectEqualization * mEffect
Definition: Equalization.h:368
std::unique_ptr< wxBitmap > mBitmap
Definition: Equalization.h:373
std::unique_ptr< EnvelopeEditor > mLinEditor
Definition: Equalization.h:369
wxWindow * mParent
Definition: Equalization.h:367
std::unique_ptr< EnvelopeEditor > mLogEditor
Definition: Equalization.h:369

◆ ~EqualizationPanel()

EqualizationPanel::~EqualizationPanel ( )

Definition at line 2991 of file Equalization.cpp.

2992{
2993 if(HasCapture())
2994 ReleaseMouse();
2995}

Member Function Documentation

◆ AcceptsFocus()

bool EqualizationPanel::AcceptsFocus ( ) const
inline

Definition at line 346 of file Equalization.h.

346{ return false; }

◆ AcceptsFocusFromKeyboard()

bool EqualizationPanel::AcceptsFocusFromKeyboard ( ) const
inline

Definition at line 348 of file Equalization.h.

348{ return false; }

◆ ForceRecalc()

void EqualizationPanel::ForceRecalc ( )

Definition at line 2997 of file Equalization.cpp.

2998{
2999 mRecalcRequired = true;
3000 Refresh(false);
3001}

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 3228 of file Equalization.cpp.

3229{
3230 if (HasCapture())
3231 {
3232 ReleaseMouse();
3233 }
3234}

◆ OnMouseEvent()

void EqualizationPanel::OnMouseEvent ( wxMouseEvent &  event)
private

Definition at line 3201 of file Equalization.cpp.

3202{
3203 if (!mEffect->mDrawMode)
3204 {
3205 return;
3206 }
3207
3208 if (event.ButtonDown() && !HasCapture())
3209 {
3210 CaptureMouse();
3211 }
3212
3213 auto &pEditor = (mEffect->mLin ? mLinEditor : mLogEditor);
3214 if (pEditor->MouseEvent(event, mEnvRect, ZoomInfo(0.0, mEnvRect.width),
3215 false, 0.0,
3217 {
3219 ForceRecalc();
3220 }
3221
3222 if (event.ButtonUp() && HasCapture())
3223 {
3224 ReleaseMouse();
3225 }
3226}

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 3018 of file Equalization.cpp.

3019{
3020 wxPaintDC dc(this);
3021 if(mRecalcRequired) {
3022 Recalc();
3023 mRecalcRequired = false;
3024 }
3025 int width, height;
3026 GetSize(&width, &height);
3027
3028 if (!mBitmap || mWidth!=width || mHeight!=height)
3029 {
3030 mWidth = width;
3031 mHeight = height;
3032 mBitmap = std::make_unique<wxBitmap>(mWidth, mHeight,24);
3033 }
3034
3035 wxBrush bkgndBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
3036
3037 wxMemoryDC memDC;
3038 memDC.SelectObject(*mBitmap);
3039
3040 wxRect bkgndRect;
3041 bkgndRect.x = 0;
3042 bkgndRect.y = 0;
3043 bkgndRect.width = mWidth;
3044 bkgndRect.height = mHeight;
3045 memDC.SetBrush(bkgndBrush);
3046 memDC.SetPen(*wxTRANSPARENT_PEN);
3047 memDC.DrawRectangle(bkgndRect);
3048
3049 bkgndRect.y = mHeight;
3050 memDC.DrawRectangle(bkgndRect);
3051
3052 wxRect border;
3053 border.x = 0;
3054 border.y = 0;
3055 border.width = mWidth;
3056 border.height = mHeight;
3057
3058 memDC.SetBrush(*wxWHITE_BRUSH);
3059 memDC.SetPen(*wxBLACK_PEN);
3060 memDC.DrawRectangle(border);
3061
3062 mEnvRect = border;
3064
3065 // Pure blue x-axis line
3066 memDC.SetPen(wxPen(theTheme.Colour( clrGraphLines ), 1, wxPENSTYLE_SOLID));
3067 int center = (int) (mEnvRect.height * mEffect->mdBMax/(mEffect->mdBMax-mEffect->mdBMin) + .5);
3068 AColor::Line(memDC,
3069 mEnvRect.GetLeft(), mEnvRect.y + center,
3070 mEnvRect.GetRight(), mEnvRect.y + center);
3071
3072 // Draw the grid, if asked for. Do it now so it's underneath the main plots.
3073 if( mEffect->mDrawGrid )
3074 {
3075 mEffect->mFreqRuler->ruler.DrawGrid(memDC, mEnvRect.height, true, true, PANELBORDER, PANELBORDER);
3076 mEffect->mdBRuler->ruler.DrawGrid(memDC, mEnvRect.width, true, true, PANELBORDER, PANELBORDER);
3077 }
3078
3079 // Med-blue envelope line
3080 memDC.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
3081
3082 // Draw envelope
3083 int x, y, xlast = 0, ylast = 0;
3084 {
3085 Doubles values{ size_t(mEnvRect.width) };
3086 mEffect->mEnvelope->GetValues(values.get(), mEnvRect.width, 0.0, 1.0 / mEnvRect.width);
3087 bool off = false, off1 = false;
3088 for (int i = 0; i < mEnvRect.width; i++)
3089 {
3090 x = mEnvRect.x + i;
3091 y = lrint(mEnvRect.height*((mEffect->mdBMax - values[i]) / (mEffect->mdBMax - mEffect->mdBMin)) + .25); //needs more optimising, along with'what you get'?
3092 if (y >= mEnvRect.height)
3093 {
3094 y = mEnvRect.height - 1;
3095 off = true;
3096 }
3097 else
3098 {
3099 off = false;
3100 off1 = false;
3101 }
3102 if ((i != 0) & (!off1))
3103 {
3104 AColor::Line(memDC, xlast, ylast,
3105 x, mEnvRect.y + y);
3106 }
3107 off1 = off;
3108 xlast = x;
3109 ylast = mEnvRect.y + y;
3110 }
3111 }
3112
3113 //Now draw the actual response that you will get.
3114 //mFilterFunc has a linear scale, window has a log one so we have to fiddle about
3115 memDC.SetPen(wxPen(theTheme.Colour( clrResponseLines ), 1, wxPENSTYLE_SOLID));
3116 double scale = (double)mEnvRect.height/(mEffect->mdBMax-mEffect->mdBMin); //pixels per dB
3117 double yF; //gain at this freq
3118 double delta = mEffect->mHiFreq / (((double)mEffect->mWindowSize / 2.)); //size of each freq bin
3119
3120 bool lin = mEffect->IsLinear(); // log or lin scale?
3121
3122 double loLog = log10(mEffect->mLoFreq);
3123 double step = lin ? mEffect->mHiFreq : (log10(mEffect->mHiFreq) - loLog);
3124 step /= ((double)mEnvRect.width-1.);
3125 double freq; //actual freq corresponding to x position
3126 int halfM = (mEffect->mM - 1) / 2;
3127 int n; //index to mFreqFunc
3128 for(int i=0; i<mEnvRect.width; i++)
3129 {
3130 x = mEnvRect.x + i;
3131 freq = lin ? step*i : pow(10., loLog + i*step); //Hz
3132 if( ( lin ? step : (pow(10., loLog + (i+1)*step)-freq) ) < delta)
3133 { //not enough resolution in FFT
3134 // set up for calculating cos using recurrence - faster than calculating it directly each time
3135 double theta = M_PI*freq/mEffect->mHiFreq; //radians, normalized
3136 double wtemp = sin(0.5 * theta);
3137 double wpr = -2.0 * wtemp * wtemp;
3138 double wpi = -1.0 * sin(theta);
3139 double wr = cos(theta*halfM);
3140 double wi = sin(theta*halfM);
3141
3142 yF = 0.;
3143 for(int j=0;j<halfM;j++)
3144 {
3145 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.
3146 // do recurrence
3147 wr = (wtemp = wr) * wpr - wi * wpi + wr;
3148 wi = wi * wpr + wtemp * wpi + wi;
3149 }
3150 yF += mOutr[halfM];
3151 yF = fabs(yF);
3152 if(yF!=0.)
3153 yF = LINEAR_TO_DB(yF);
3154 else
3155 yF = mEffect->mdBMin;
3156 }
3157 else
3158 { //use FFT, it has enough resolution
3159 n = (int)(freq/delta + .5);
3160 if(pow(mEffect->mFilterFuncR[n],2)+pow(mEffect->mFilterFuncI[n],2)!=0.)
3161 yF = 10.0*log10(pow(mEffect->mFilterFuncR[n],2)+pow(mEffect->mFilterFuncI[n],2)); //10 here, a power
3162 else
3163 yF = mEffect->mdBMin;
3164 }
3165 if(yF < mEffect->mdBMin)
3166 yF = mEffect->mdBMin;
3167 yF = center-scale*yF;
3168 if(yF>mEnvRect.height)
3169 yF = mEnvRect.height - 1;
3170 if(yF<0.)
3171 yF=0.;
3172 y = (int)(yF+.5);
3173
3174 if (i != 0)
3175 {
3176 AColor::Line(memDC, xlast, ylast, x, mEnvRect.y + y);
3177 }
3178 xlast = x;
3179 ylast = mEnvRect.y + y;
3180 }
3181
3182 memDC.SetPen(*wxBLACK_PEN);
3183 if( mEffect->mDrawMode )
3184 {
3185 ZoomInfo zoomInfo( 0.0, mEnvRect.width-1 );
3186
3187 // Back pointer to TrackPanel won't be needed in the one drawing
3188 // function we use here
3189 TrackArtist artist( nullptr );
3190
3191 artist.pZoomInfo = &zoomInfo;
3192 TrackPanelDrawingContext context{ memDC, {}, {}, &artist };
3194 context, mEnvRect, false, 0.0,
3195 mEffect->mdBMin, mEffect->mdBMax, false);
3196 }
3197
3198 dc.Blit(0, 0, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE);
3199}
#define M_PI
Definition: Distortion.cpp:29
const wxChar * values
#define PANELBORDER
Definition: Equalization.h:16
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:544
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
RulerPanel * mdBRuler
Definition: Equalization.h:231
RulerPanel * mFreqRuler
Definition: Equalization.h:232
static void DrawPoints(const Envelope &env, TrackPanelDrawingContext &context, const wxRect &r, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored, int origin=0)
void GetValues(double *buffer, int len, double t0, double tstep) const
Get many envelope points at once.
Definition: Envelope.cpp:923
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
Definition: Ruler.cpp:1521
Ruler ruler
Definition: Ruler.h:288
wxColour & Colour(int iIndex)
This class handles the actual rendering of WaveTracks (both waveforms and spectra),...
Definition: TrackArtist.h:39
#define lrint(dbl)
Definition: float_cast.h:169

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 3012 of file Equalization.cpp.

3013{
3014 Refresh( false );
3015}

◆ Recalc()

void EqualizationPanel::Recalc ( )
private

Definition at line 3003 of file Equalization.cpp.

3004{
3007
3008 mEffect->CalcFilter(); //to calculate the actual response
3010}
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn, float *RealOut)
Definition: FFT.cpp:268

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 373 of file Equalization.h.

Referenced by OnPaint().

◆ mEffect

EffectEqualization* EqualizationPanel::mEffect
private

Definition at line 368 of file Equalization.h.

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

◆ mEnvRect

wxRect EqualizationPanel::mEnvRect
private

Definition at line 374 of file Equalization.h.

Referenced by OnMouseEvent(), and OnPaint().

◆ mHeight

int EqualizationPanel::mHeight
private

Definition at line 376 of file Equalization.h.

Referenced by OnPaint().

◆ mLinEditor

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

Definition at line 369 of file Equalization.h.

Referenced by OnMouseEvent().

◆ mLogEditor

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

Definition at line 369 of file Equalization.h.

Referenced by OnMouseEvent().

◆ mOuti

Floats EqualizationPanel::mOuti
private

Definition at line 380 of file Equalization.h.

Referenced by Recalc().

◆ mOutr

Floats EqualizationPanel::mOutr
private

Definition at line 380 of file Equalization.h.

Referenced by OnPaint(), and Recalc().

◆ mParent

wxWindow* EqualizationPanel::mParent
private

Definition at line 367 of file Equalization.h.

◆ mRecalcRequired

bool EqualizationPanel::mRecalcRequired
private

Definition at line 371 of file Equalization.h.

Referenced by ForceRecalc(), and OnPaint().

◆ mWidth

int EqualizationPanel::mWidth
private

Definition at line 375 of file Equalization.h.

Referenced by OnPaint().


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