Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
FrequencyPlotDialog Class Referencefinal

Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot. More...

#include <FreqWindow.h>

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

Public Member Functions

 FrequencyPlotDialog (wxWindow *parent, wxWindowID id, AudacityProject &project, const TranslatableString &title, const wxPoint &pos)
 
virtual ~FrequencyPlotDialog ()
 
bool Show (bool show=true) override
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 
- Public Member Functions inherited from PrefsListener
 PrefsListener ()
 
virtual ~PrefsListener ()
 
virtual void UpdatePrefs ()=0
 

Private Member Functions

void Populate ()
 
void GetAudio ()
 
void PlotMouseEvent (wxMouseEvent &event)
 
void PlotPaint (wxPaintEvent &event)
 
void OnCloseWindow (wxCloseEvent &event)
 
void OnCloseButton (wxCommandEvent &event)
 
void OnGetURL (wxCommandEvent &event)
 
void OnSize (wxSizeEvent &event)
 
void OnPanScroller (wxScrollEvent &event)
 
void OnZoomSlider (wxCommandEvent &event)
 
void OnAlgChoice (wxCommandEvent &event)
 
void OnSizeChoice (wxCommandEvent &event)
 
void OnFuncChoice (wxCommandEvent &event)
 
void OnAxisChoice (wxCommandEvent &event)
 
void OnExport (wxCommandEvent &event)
 
void OnReplot (wxCommandEvent &event)
 
void OnGridOnOff (wxCommandEvent &event)
 
void OnRecalc (wxCommandEvent &event)
 
void SendRecalcEvent ()
 
void Recalc ()
 
void DrawPlot ()
 
void DrawBackground (wxMemoryDC &dc)
 
void UpdatePrefs () override
 

Private Attributes

bool mDrawGrid
 
int mSize
 
SpectrumAnalyst::Algorithm mAlg
 
int mFunc
 
int mAxis
 
int dBRange
 
AudacityProjectmProject
 
RulerPanelvRuler
 
RulerPanelhRuler
 
FreqPlotmFreqPlot
 
FreqGaugemProgress
 
wxRect mPlotRect
 
wxFont mFreqFont
 
std::unique_ptr< wxCursor > mArrowCursor
 
std::unique_ptr< wxCursor > mCrossCursor
 
wxButton * mCloseButton
 
wxButton * mExportButton
 
wxButton * mReplotButton
 
wxCheckBox * mGridOnOff
 
wxChoice * mAlgChoice
 
wxChoice * mSizeChoice
 
wxChoice * mFuncChoice
 
wxChoice * mAxisChoice
 
wxScrollBar * mPanScroller
 
wxSlider * mZoomSlider
 
wxTextCtrl * mCursorText
 
wxTextCtrl * mPeakText
 
double mRate
 
size_t mDataLen
 
Floats mData
 
size_t mWindowSize
 
bool mLogAxis
 
float mYMin
 
float mYMax
 
float mYStep
 
std::unique_ptr< wxBitmap > mBitmap
 
int mMouseX
 
int mMouseY
 
std::unique_ptr< SpectrumAnalystmAnalyst
 

Static Private Attributes

static const int fontSize = 8
 

Friends

class FreqPlot
 

Additional Inherited Members

- Static Public Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 
- Protected Member Functions inherited from PrefsListener
virtual void UpdateSelectedPrefs (int id)
 

Detailed Description

Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot.

Has a feature that finds peaks and reports their value as you move the mouse around.

Definition at line 56 of file FreqWindow.h.

Constructor & Destructor Documentation

◆ FrequencyPlotDialog()

FrequencyPlotDialog::FrequencyPlotDialog ( wxWindow *  parent,
wxWindowID  id,
AudacityProject project,
const TranslatableString title,
const wxPoint &  pos 
)

Definition at line 184 of file FreqWindow.cpp.

188: wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
189 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
190 mProject{ &project }
191, mAnalyst(std::make_unique<SpectrumAnalyst>())
192{
193 SetName();
194
195 mMouseX = 0;
196 mMouseY = 0;
197 mRate = 0;
198 mDataLen = 0;
199
200 gPrefs->Read(wxT("/FrequencyPlotDialog/DrawGrid"), &mDrawGrid, true);
201 gPrefs->Read(wxT("/FrequencyPlotDialog/SizeChoice"), &mSize, 3);
202
203 int alg;
204 gPrefs->Read(wxT("/FrequencyPlotDialog/AlgChoice"), &alg, 0);
205 mAlg = static_cast<SpectrumAnalyst::Algorithm>(alg);
206
207 gPrefs->Read(wxT("/FrequencyPlotDialog/FuncChoice"), &mFunc, 3);
208 gPrefs->Read(wxT("/FrequencyPlotDialog/AxisChoice"), &mAxis, 1);
209
210 Populate();
211}
wxT("CloseDown"))
static const auto title
FileConfig * gPrefs
Definition: Prefs.cpp:71
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:101
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:154
AudacityProject * mProject
Definition: FreqWindow.h:105

◆ ~FrequencyPlotDialog()

FrequencyPlotDialog::~FrequencyPlotDialog ( )
virtual

Definition at line 213 of file FreqWindow.cpp.

214{
215}

Member Function Documentation

◆ DrawBackground()

void FrequencyPlotDialog::DrawBackground ( wxMemoryDC &  dc)
private

Definition at line 650 of file FreqWindow.cpp.

651{
652 Layout();
653
654 mBitmap.reset();
655
656 mPlotRect = mFreqPlot->GetClientRect();
657
658 mBitmap = std::make_unique<wxBitmap>(mPlotRect.width, mPlotRect.height,24);
659
660 dc.SelectObject(*mBitmap);
661
662 dc.SetBackground(wxBrush(wxColour(254, 254, 254)));// DONT-THEME Mask colour.
663 dc.Clear();
664
665 dc.SetPen(*wxBLACK_PEN);
666 dc.SetBrush(*wxWHITE_BRUSH);
667 dc.DrawRectangle(mPlotRect);
668
669 dc.SetFont(mFreqFont);
670}
std::unique_ptr< wxBitmap > mBitmap
Definition: FreqWindow.h:149
FreqPlot * mFreqPlot
Definition: FreqWindow.h:115

References mBitmap, mFreqFont, mFreqPlot, and mPlotRect.

Referenced by DrawPlot().

Here is the caller graph for this function:

◆ DrawPlot()

void FrequencyPlotDialog::DrawPlot ( )
private

Definition at line 672 of file FreqWindow.cpp.

673{
674 if (!mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
675 wxMemoryDC memDC;
676
677 vRuler->ruler.SetLog(false);
679
680 hRuler->ruler.SetLog(false);
681 hRuler->ruler.SetRange(0, 1);
682
683 DrawBackground(memDC);
684
685 if (mDataLen < mWindowSize) {
686 wxString msg = _("Not enough data selected.");
687 wxSize sz = memDC.GetTextExtent(msg);
688 memDC.DrawText(msg,
689 (mPlotRect.GetWidth() - sz.GetWidth()) / 2,
690 (mPlotRect.GetHeight() - sz.GetHeight()) / 2);
691 }
692
693 memDC.SelectObject(wxNullBitmap);
694
695 mFreqPlot->Refresh();
696
697 Refresh();
698
699 return;
700 }
701
702 float yRange = mYMax - mYMin;
703 float yTotal = yRange * ((float) mZoomSlider->GetValue() / 100.0f);
704
705 int sTotal = yTotal * 100;
706 int sRange = yRange * 100;
707 int sPos = mPanScroller->GetThumbPosition() + ((mPanScroller->GetThumbSize() - sTotal) / 2);
708 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
709
710 float yMax = mYMax - ((float)sPos / 100);
711 float yMin = yMax - yTotal;
712
713 // Set up y axis ruler
714
716 vRuler->ruler.SetUnits(XO("dB"));
718 } else {
719 vRuler->ruler.SetUnits({});
721 }
722 int w1, w2, h;
723 vRuler->ruler.GetMaxSize(&w1, &h);
724 vRuler->ruler.SetRange(yMax, yMin); // Note inversion for vertical.
725 vRuler->ruler.GetMaxSize(&w2, &h);
726 if( w1 != w2 ) // Reduces flicker
727 {
728 vRuler->SetMinSize(wxSize(w2,h));
729 Layout();
730 }
731 vRuler->Refresh(false);
732
733 wxMemoryDC memDC;
734 DrawBackground(memDC);
735
736 // Get the plot dimensions
737 //
738 // Must be done after setting the vertical ruler above since the
739 // the width could change.
740 wxRect r = mPlotRect;
741
742 // Set up x axis ruler
743
744 int width = r.width - 2;
745
746 float xMin, xMax, xRatio, xStep;
747
749 xMin = mRate / mWindowSize;
750 xMax = mRate / 2;
751 xRatio = xMax / xMin;
752 if (mLogAxis)
753 {
754 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
755 hRuler->ruler.SetLog(true);
756 }
757 else
758 {
759 xStep = (xMax - xMin) / width;
760 hRuler->ruler.SetLog(false);
761 }
762 hRuler->ruler.SetUnits(XO("Hz"));
763 } else {
764 xMin = 0;
765 xMax = mAnalyst->GetProcessedSize() / mRate;
766 xStep = (xMax - xMin) / width;
767 hRuler->ruler.SetLog(false);
768 /* i18n-hint: short form of 'seconds'.*/
769 hRuler->ruler.SetUnits(XO("s"));
770 }
771 hRuler->ruler.SetRange(xMin, xMax-xStep);
772 hRuler->Refresh(false);
773
774 // Draw the plot
776 memDC.SetPen(wxPen(theTheme.Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
777 else
778 memDC.SetPen(wxPen(theTheme.Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
779
780 float xPos = xMin;
781
782 for (int i = 0; i < width; i++) {
783 float y;
784
785 if (mLogAxis)
786 y = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
787 else
788 y = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
789
790 float ynorm = (y - yMin) / yTotal;
791
792 int lineheight = (int)(ynorm * (r.height - 1));
793
794 if (lineheight > r.height - 2)
795 lineheight = r.height - 2;
796
797 if (ynorm > 0.0)
798 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
799 r.x + 1 + i, r.y + r.height - 1);
800
801 if (mLogAxis)
802 xPos *= xStep;
803 else
804 xPos += xStep;
805 }
806
807 // Outline the graph
808 memDC.SetPen(*wxBLACK_PEN);
809 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
810 memDC.DrawRectangle(r);
811
812 if(mDrawGrid)
813 {
814 hRuler->ruler.DrawGrid(memDC, r.height, true, true, 1, 1);
815 vRuler->ruler.DrawGrid(memDC, r.width, true, true, 1, 1);
816 }
817
818 memDC.SelectObject( wxNullBitmap );
819
820 mFreqPlot->Refresh();
821}
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
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 * hRuler
Definition: FreqWindow.h:114
wxSlider * mZoomSlider
Definition: FreqWindow.h:134
RulerPanel * vRuler
Definition: FreqWindow.h:113
void DrawBackground(wxMemoryDC &dc)
Definition: FreqWindow.cpp:650
wxScrollBar * mPanScroller
Definition: FreqWindow.h:133
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
Definition: Ruler.cpp:1521
void SetLog(bool log)
Definition: Ruler.cpp:142
void GetMaxSize(wxCoord *width, wxCoord *height)
Definition: Ruler.cpp:1603
void SetUnits(const TranslatableString &units)
Definition: Ruler.cpp:153
void SetRange(double min, double max)
Definition: Ruler.cpp:188
void SetFormat(RulerFormat format)
Definition: Ruler.cpp:131
@ LinearDBFormat
Definition: Ruler.h:34
@ RealFormat
Definition: Ruler.h:31
Ruler ruler
Definition: Ruler.h:288
wxColour & Colour(int iIndex)

References _, ThemeBase::Colour(), dBRange, DrawBackground(), Ruler::DrawGrid(), Ruler::GetMaxSize(), hRuler, AColor::Line(), Ruler::LinearDBFormat, mAlg, mAnalyst, mData, mDataLen, mDrawGrid, mFreqPlot, mLogAxis, mPanScroller, mPlotRect, mRate, mWindowSize, mYMax, mYMin, mZoomSlider, Ruler::RealFormat, RulerPanel::ruler, Ruler::SetFormat(), Ruler::SetLog(), Ruler::SetRange(), Ruler::SetUnits(), SpectrumAnalyst::Spectrum, theTheme, vRuler, and XO.

Referenced by OnAxisChoice(), OnGridOnOff(), OnPanScroller(), OnSize(), OnZoomSlider(), and Recalc().

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

◆ GetAudio()

void FrequencyPlotDialog::GetAudio ( )
private

Definition at line 581 of file FreqWindow.cpp.

582{
583 mData.reset();
584 mDataLen = 0;
585
586 int selcount = 0;
587 bool warning = false;
588 for (auto track : TrackList::Get( *mProject ).Selected< const WaveTrack >()) {
589 auto &selectedRegion = ViewInfo::Get( *mProject ).selectedRegion;
590 if (selcount==0) {
591 mRate = track->GetRate();
592 auto start = track->TimeToLongSamples(selectedRegion.t0());
593 auto end = track->TimeToLongSamples(selectedRegion.t1());
594 auto dataLen = end - start;
595 // Permit approximately 46.60 minutes of selected samples at
596 // a sampling frequency of 48 kHz (11.65 minutes at 192 kHz).
597 auto maxDataLen = size_t(2) << 26;
598 if (dataLen > maxDataLen) {
599 warning = true;
600 mDataLen = maxDataLen;
601 }
602 else {
603 mDataLen = dataLen.as_size_t();
604 }
605 mData = Floats{ mDataLen };
606 // Don't allow throw for bad reads
607 track->GetFloats(mData.get(), start, mDataLen,
608 fillZero, false);
609 }
610 else {
611 if (track->GetRate() != mRate) {
613 XO(
614"To plot the spectrum, all selected tracks must be the same sample rate.") );
615 mData.reset();
616 mDataLen = 0;
617 return;
618 }
619 auto start = track->TimeToLongSamples(selectedRegion.t0());
620 Floats buffer2{ mDataLen };
621 // Again, stop exceptions
622 track->GetFloats(buffer2.get(), start, mDataLen,
623 fillZero, false);
624 for (size_t i = 0; i < mDataLen; i++)
625 mData[i] += buffer2[i];
626 }
627 selcount++;
628 }
629
630 if (selcount == 0)
631 return;
632
633 if (warning) {
634 auto msg = XO(
635"Too much audio was selected. Only the first %.1f seconds of audio will be analyzed.")
636 .Format(mDataLen / mRate);
637 AudacityMessageBox( msg );
638 }
639}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
@ fillZero
Definition: SampleFormat.h:54
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1454
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References AudacityMessageBox(), PackedArray::end(), fillZero, ViewInfo::Get(), TrackList::Get(), mData, mDataLen, mRate, TrackList::Selected(), ViewInfo::selectedRegion, and XO.

Referenced by OnReplot(), and Show().

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

◆ OnAlgChoice()

void FrequencyPlotDialog::OnAlgChoice ( wxCommandEvent &  event)
private

Definition at line 849 of file FreqWindow.cpp.

850{
851 mAlg = SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
852
853 // Log-frequency axis works for spectrum plots only.
855 mAxisChoice->Enable(true);
856 mLogAxis = mAxisChoice->GetSelection() ? true : false;
857 }
858 else {
859 mAxisChoice->Disable();
860 mLogAxis = false;
861 }
862
864}
wxChoice * mAlgChoice
Definition: FreqWindow.h:129
wxChoice * mAxisChoice
Definition: FreqWindow.h:132

References mAlg, mAlgChoice, mAxisChoice, mLogAxis, SendRecalcEvent(), and SpectrumAnalyst::Spectrum.

Here is the call graph for this function:

◆ OnAxisChoice()

void FrequencyPlotDialog::OnAxisChoice ( wxCommandEvent &  event)
private

Definition at line 880 of file FreqWindow.cpp.

881{
882 mLogAxis = mAxisChoice->GetSelection() ? true : false;
883 DrawPlot();
884}

References DrawPlot(), mAxisChoice, and mLogAxis.

Here is the call graph for this function:

◆ OnCloseButton()

void FrequencyPlotDialog::OnCloseButton ( wxCommandEvent &  event)
private

Definition at line 994 of file FreqWindow.cpp.

995{
996 gPrefs->Write(wxT("/FrequencyPlotDialog/DrawGrid"), mDrawGrid);
997 gPrefs->Write(wxT("/FrequencyPlotDialog/SizeChoice"), mSizeChoice->GetSelection());
998 gPrefs->Write(wxT("/FrequencyPlotDialog/AlgChoice"), mAlgChoice->GetSelection());
999 gPrefs->Write(wxT("/FrequencyPlotDialog/FuncChoice"), mFuncChoice->GetSelection());
1000 gPrefs->Write(wxT("/FrequencyPlotDialog/AxisChoice"), mAxisChoice->GetSelection());
1001 gPrefs->Flush();
1002 mData.reset();
1003 Show(false);
1004}
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
wxChoice * mSizeChoice
Definition: FreqWindow.h:130
wxChoice * mFuncChoice
Definition: FreqWindow.h:131
bool Show(bool show=true) override
Definition: FreqWindow.cpp:555

References FileConfig::Flush(), gPrefs, mAlgChoice, mAxisChoice, mData, mDrawGrid, mFuncChoice, mSizeChoice, Show(), and wxT().

Here is the call graph for this function:

◆ OnCloseWindow()

void FrequencyPlotDialog::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 989 of file FreqWindow.cpp.

990{
991 Show(false);
992}

References Show().

Here is the call graph for this function:

◆ OnExport()

void FrequencyPlotDialog::OnExport ( wxCommandEvent &  event)
private

Definition at line 1057 of file FreqWindow.cpp.

1058{
1059 wxString fName = _("spectrum.txt");
1060
1061 fName = SelectFile(FileNames::Operation::Export,
1062 XO("Export Spectral Data As:"),
1063 wxEmptyString,
1064 fName,
1065 wxT("txt"),
1067 wxFD_SAVE | wxRESIZE_BORDER,
1068 this);
1069
1070 if (fName.empty())
1071 return;
1072
1073 wxFFileOutputStream ffStream{ fName };
1074 if (!ffStream.IsOk()) {
1075 AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
1076 return;
1077 }
1078
1079 wxTextOutputStream ss(ffStream);
1080
1081 const int processedSize = mAnalyst->GetProcessedSize();
1082 const float *const processed = mAnalyst->GetProcessed();
1083 if (mAlgChoice->GetSelection() == 0) {
1084 ss
1085 << XO("Frequency (Hz)\tLevel (dB)") << '\n';
1086 for (int i = 1; i < processedSize; i++)
1087 ss
1088 << wxString::Format(wxT("%f\t%f\n"),
1089 i * mRate / mWindowSize, processed[i] );
1090 }
1091 else {
1092 ss
1093 << XO("Lag (seconds)\tFrequency (Hz)\tLevel") << '\n';
1094 for (int i = 1; i < processedSize; i++)
1095 ss
1096 << wxString::Format(wxT("%f\t%f\t%f\n"),
1097 i / mRate, mRate / i, processed[i] );
1098 }
1099}
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
FILES_API const FileType AllFiles
Definition: FileNames.h:71
FILES_API const FileType TextFiles
Definition: FileNames.h:74
Abstract base class used in importing a file.

References _, FileNames::AllFiles, AudacityMessageBox(), mAlgChoice, mAnalyst, mRate, mWindowSize, SelectFile(), FileNames::TextFiles, wxT(), and XO.

Here is the call graph for this function:

◆ OnFuncChoice()

void FrequencyPlotDialog::OnFuncChoice ( wxCommandEvent &  event)
private

Definition at line 875 of file FreqWindow.cpp.

876{
878}

References SendRecalcEvent().

Here is the call graph for this function:

◆ OnGetURL()

void FrequencyPlotDialog::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 548 of file FreqWindow.cpp.

549{
550 // Original help page is back on-line (March 2016), but the manual should be more reliable.
551 // http://www.eramp.com/WCAG_2_audio_contrast_tool_help.htm
552 HelpSystem::ShowHelp(this, L"Plot_Spectrum");
553}
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:239

References HelpSystem::ShowHelp().

Here is the call graph for this function:

◆ OnGridOnOff()

void FrequencyPlotDialog::OnGridOnOff ( wxCommandEvent &  event)
private

Definition at line 1110 of file FreqWindow.cpp.

1111{
1112 mDrawGrid = mGridOnOff->IsChecked();
1113
1114 DrawPlot();
1115}
wxCheckBox * mGridOnOff
Definition: FreqWindow.h:128

References DrawPlot(), mDrawGrid, and mGridOnOff.

Here is the call graph for this function:

◆ OnPanScroller()

void FrequencyPlotDialog::OnPanScroller ( wxScrollEvent &  event)
private

Definition at line 839 of file FreqWindow.cpp.

840{
841 DrawPlot();
842}

References DrawPlot().

Here is the call graph for this function:

◆ OnRecalc()

void FrequencyPlotDialog::OnRecalc ( wxCommandEvent &  event)
private

Definition at line 1117 of file FreqWindow.cpp.

1118{
1119 Recalc();
1120}

References Recalc().

Here is the call graph for this function:

◆ OnReplot()

void FrequencyPlotDialog::OnReplot ( wxCommandEvent &  event)
private

Definition at line 1101 of file FreqWindow.cpp.

1102{
1104 if(dBRange < 90.)
1105 dBRange = 90.;
1106 GetAudio();
1108}
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
Definition: Decibels.cpp:12
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200

References dBRange, DecibelScaleCutoff, GetAudio(), Setting< T >::Read(), and SendRecalcEvent().

Here is the call graph for this function:

◆ OnSize()

void FrequencyPlotDialog::OnSize ( wxSizeEvent &  event)
private

Definition at line 641 of file FreqWindow.cpp.

642{
643 Layout();
644
645 DrawPlot();
646
647 Refresh(true);
648}

References DrawPlot().

Here is the call graph for this function:

◆ OnSizeChoice()

void FrequencyPlotDialog::OnSizeChoice ( wxCommandEvent &  event)
private

Definition at line 866 of file FreqWindow.cpp.

867{
868 long windowSize = 0;
869 mSizeChoice->GetStringSelection().ToLong(&windowSize);
870 mWindowSize = windowSize;
871
873}

References mSizeChoice, mWindowSize, and SendRecalcEvent().

Here is the call graph for this function:

◆ OnZoomSlider()

void FrequencyPlotDialog::OnZoomSlider ( wxCommandEvent &  event)
private

Definition at line 844 of file FreqWindow.cpp.

845{
846 DrawPlot();
847}

References DrawPlot().

Here is the call graph for this function:

◆ PlotMouseEvent()

void FrequencyPlotDialog::PlotMouseEvent ( wxMouseEvent &  event)
private

Definition at line 824 of file FreqWindow.cpp.

825{
826 if (event.Moving() && (event.m_x != mMouseX || event.m_y != mMouseY)) {
827 mMouseX = event.m_x;
828 mMouseY = event.m_y;
829
830 if (mPlotRect.Contains(mMouseX, mMouseY))
831 mFreqPlot->SetCursor(*mCrossCursor);
832 else
833 mFreqPlot->SetCursor(*mArrowCursor);
834
835 mFreqPlot->Refresh(false);
836 }
837}
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:122
std::unique_ptr< wxCursor > mCrossCursor
Definition: FreqWindow.h:123

References mArrowCursor, mCrossCursor, mFreqPlot, mMouseX, mMouseY, and mPlotRect.

Referenced by FreqPlot::OnMouseEvent().

Here is the caller graph for this function:

◆ PlotPaint()

void FrequencyPlotDialog::PlotPaint ( wxPaintEvent &  event)
private

Definition at line 886 of file FreqWindow.cpp.

887{
888 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
889
890 dc.DrawBitmap( *mBitmap, 0, 0, true );
891 // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected"
892 if (!mData || mDataLen < mWindowSize)
893 return;
894
895 dc.SetFont(mFreqFont);
896
897 wxRect r = mPlotRect;
898
899 int width = r.width - 2;
900
901 float xMin, xMax, xRatio, xStep;
902
904 xMin = mRate / mWindowSize;
905 xMax = mRate / 2;
906 xRatio = xMax / xMin;
907 if (mLogAxis)
908 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
909 else
910 xStep = (xMax - xMin) / width;
911 } else {
912 xMin = 0;
913 xMax = mAnalyst->GetProcessedSize() / mRate;
914 xStep = (xMax - xMin) / width;
915 }
916
917 float xPos = xMin;
918
919 // Find the peak nearest the cursor and plot it
920 if ( r.Contains(mMouseX, mMouseY) && (mMouseX!=0) && (mMouseX!=r.width-1) ) {
921 if (mLogAxis)
922 xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
923 else
924 xPos = xMin + xStep * (mMouseX - (r.x + 1));
925
926 float bestValue = 0;
927 float bestpeak = mAnalyst->FindPeak(xPos, &bestValue);
928
929 int px;
930 if (mLogAxis)
931 px = (int)(log(bestpeak / xMin) / log(xStep));
932 else
933 px = (int)((bestpeak - xMin) * width / (xMax - xMin));
934
935 dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID));
936 AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
937
938 // print out info about the cursor location
939
940 float value;
941
942 if (mLogAxis) {
943 xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
944 value = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
945 } else {
946 xPos = xMin + xStep * (mMouseX - (r.x + 1));
947 value = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
948 }
949
950 TranslatableString cursor;
952
954 auto xp = PitchName_Absolute(FreqToMIDInote(xPos));
955 auto pp = PitchName_Absolute(FreqToMIDInote(bestpeak));
956 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
957 cursor = XO("%d Hz (%s) = %d dB")
958 .Format( (int)(xPos + 0.5), xp, (int)(value + 0.5));
959 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
960 peak = XO("%d Hz (%s) = %.1f dB")
961 .Format( (int)(bestpeak + 0.5), pp, bestValue );
962 } else if (xPos > 0.0 && bestpeak > 0.0) {
963 auto xp = PitchName_Absolute(FreqToMIDInote(1.0 / xPos));
964 auto pp = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak));
965 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
966 * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
967 cursor = XO("%.4f sec (%d Hz) (%s) = %f")
968 .Format( xPos, (int)(1.0 / xPos + 0.5), xp, value );
969 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
970 * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
971 peak = XO("%.4f sec (%d Hz) (%s) = %.3f")
972 .Format( bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue );
973 }
974 mCursorText->SetValue( cursor.Translation() );
975 mPeakText->SetValue( peak.Translation() );
976 }
977 else {
978 mCursorText->SetValue(wxT(""));
979 mPeakText->SetValue(wxT(""));
980 }
981
982
983 // Outline the graph
984 dc.SetPen(*wxBLACK_PEN);
985 dc.SetBrush(*wxTRANSPARENT_BRUSH);
986 dc.DrawRectangle(r);
987}
TranslatableString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice)
Definition: PitchName.cpp:154
double FreqToMIDInote(const double freq)
Definition: PitchName.cpp:29
wxTextCtrl * mCursorText
Definition: FreqWindow.h:135
wxTextCtrl * mPeakText
Definition: FreqWindow.h:136
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const

References FreqToMIDInote(), AColor::Line(), mAlg, mAnalyst, mBitmap, mCursorText, mData, mDataLen, mFreqFont, mLogAxis, mMouseX, mMouseY, mPeakText, mPlotRect, mRate, mWindowSize, PitchName_Absolute(), SpectrumAnalyst::Spectrum, TranslatableString::Translation(), wxT(), and XO.

Referenced by FreqPlot::OnPaint().

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

◆ Populate()

void FrequencyPlotDialog::Populate ( )
private

Definition at line 217 of file FreqWindow.cpp.

218{
220
221 TranslatableStrings algChoices{
222 XO("Spectrum") ,
223 XO("Standard Autocorrelation") ,
224 XO("Cuberoot Autocorrelation") ,
225 XO("Enhanced Autocorrelation") ,
226 /* i18n-hint: This is a technical term, derived from the word
227 * "spectrum". Do not translate it unless you are sure you
228 * know the correct technical word in your language. */
229 XO("Cepstrum") ,
230 };
231
232 TranslatableStrings sizeChoices{
233 Verbatim( "128" ) ,
234 Verbatim( "256" ) ,
235 Verbatim( "512" ) ,
236 Verbatim( "1024" ) ,
237 Verbatim( "2048" ) ,
238 Verbatim( "4096" ) ,
239 Verbatim( "8192" ) ,
240 Verbatim( "16384" ) ,
241 Verbatim( "32768" ) ,
242 Verbatim( "65536" ) ,
243 Verbatim( "131072" ) ,
244 };
245
246 TranslatableStrings funcChoices;
247 for (int i = 0, cnt = NumWindowFuncs(); i < cnt; i++)
248 {
249 funcChoices.push_back(
250 /* i18n-hint: This refers to a "window function",
251 * such as Hann or Rectangular, used in the
252 * Frequency analyze dialog box. */
253 XO("%s window").Format( WindowFuncName(i) ) );
254 }
255
256 TranslatableStrings axisChoices{
257 XO("Linear frequency") ,
258 XO("Log frequency") ,
259 };
260
261 mFreqFont = wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
262 mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
263 mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
264
265 long size;
266 // reinterpret one of the verbatim strings above as a number
267 sizeChoices[mSize].MSGID().GET().ToLong(&size);
269
271 if(dBRange < 90.)
272 dBRange = 90.;
273
274 ShuttleGui S(this, eIsCreating);
275
276 S.SetBorder(0);
277
278 S.AddSpace(5);
279
280 S.SetSizerProportion(1);
281 S.StartMultiColumn(3, wxEXPAND);
282 {
283 S.SetStretchyCol(1);
284 S.SetStretchyRow(0);
285
286 // -------------------------------------------------------------------
287 // ROW 1: Freq response panel and sliders for vertical scale
288 // -------------------------------------------------------------------
289
290 S.StartVerticalLay(2);
291 {
293 S.GetParent(), wxID_ANY, wxVERTICAL,
294 wxSize{ 100, 100 }, // Ruler can't handle small sizes
295 RulerPanel::Range{ 0.0, -dBRange },
297 XO("dB"),
299 .LabelEdges(true)
300 .TickColour( theTheme.Colour( clrGraphLabels ) )
301 );
302
303 S.AddSpace(wxDefaultCoord, 1);
304 S.Prop(1)
305 .Position(wxALIGN_RIGHT | wxALIGN_TOP)
306 .AddWindow(vRuler);
307 S.AddSpace(wxDefaultCoord, 1);
308 }
309 S.EndVerticalLay();
310
311 mFreqPlot = safenew FreqPlot(S.GetParent(), wxID_ANY);
312 S.Prop(1)
313 .Position(wxEXPAND)
314 .MinSize( { wxDefaultCoord, FREQ_WINDOW_HEIGHT } )
315 .AddWindow(mFreqPlot);
316
317 S.StartHorizontalLay(wxEXPAND, 0);
318 {
319 S.StartVerticalLay();
320 {
321 mPanScroller = safenew wxScrollBar(S.GetParent(), FreqPanScrollerID,
322 wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
323#if wxUSE_ACCESSIBILITY
324 // so that name can be set on a standard control
326#endif
327 S.Prop(1);
328 S
329 .Name(XO("Scroll"))
330 .Position( wxALIGN_LEFT | wxTOP)
331 .AddWindow(mPanScroller);
332 }
333 S.EndVerticalLay();
334
335 S.StartVerticalLay();
336 {
337 wxStaticBitmap *zi = safenew wxStaticBitmap(S.GetParent(), wxID_ANY, wxBitmap(ZoomIn));
338 S.Position(wxALIGN_CENTER)
339 .AddWindow(zi);
340
341 S.AddSpace(5);
342
343 mZoomSlider = safenew wxSliderWrapper(S.GetParent(), FreqZoomSliderID, 100, 1, 100,
344 wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL);
345 S.Prop(1);
346 S
347 .Name(XO("Zoom"))
348 .Position(wxALIGN_CENTER_HORIZONTAL)
349 .AddWindow(mZoomSlider);
350#if wxUSE_ACCESSIBILITY
351 // so that name can be set on a standard control
353#endif
354
355 S.AddSpace(5);
356
357 wxStaticBitmap *zo = safenew wxStaticBitmap(S.GetParent(), wxID_ANY, wxBitmap(ZoomOut));
358 S.Position(wxALIGN_CENTER)
359 .AddWindow(zo);
360 }
361 S.EndVerticalLay();
362
363 S.AddSpace(5, wxDefaultCoord);
364 }
365 S.EndHorizontalLay();
366
367 // -------------------------------------------------------------------
368 // ROW 2: Frequency ruler
369 // -------------------------------------------------------------------
370
371 S.AddSpace(1);
372
373 S.StartHorizontalLay(wxEXPAND, 0);
374 {
376 S.GetParent(), wxID_ANY, wxHORIZONTAL,
377 wxSize{ 100, 100 }, // Ruler can't handle small sizes
378 RulerPanel::Range{ 10, 20000 },
380 XO("Hz"),
382 .Log(true)
383 .Flip(true)
384 .LabelEdges(true)
385 .TickColour( theTheme.Colour( clrGraphLabels ) )
386 );
387
388 S.AddSpace(1, wxDefaultCoord);
389 S.Prop(1)
390 .Position(wxALIGN_LEFT | wxALIGN_TOP)
391 .AddWindow(hRuler);
392 S.AddSpace(1, wxDefaultCoord);
393 }
394 S.EndHorizontalLay();
395
396 S.AddSpace(1);
397
398 // -------------------------------------------------------------------
399 // ROW 3: Spacer
400 // -------------------------------------------------------------------
401
402 S.AddSpace(5);
403 S.AddSpace(5);
404 S.AddSpace(5);
405
406 // -------------------------------------------------------------------
407 // ROW 4: Info
408 // -------------------------------------------------------------------
409
410 S.AddSpace(1);
411
412 S.StartHorizontalLay(wxEXPAND);
413 {
414 S.SetSizerProportion(1);
415 S.StartMultiColumn(6);
416 S.SetStretchyCol(1);
417 S.SetStretchyCol(3);
418 {
419 S.AddPrompt(XXO("Cursor:"));
420
421 mCursorText = S.Style(wxTE_READONLY)
422 .AddTextBox( {}, wxT(""), 10);
423
424 S.AddPrompt(XXO("Peak:"));
425
426 mPeakText = S.Style(wxTE_READONLY)
427 .AddTextBox( {}, wxT(""), 10);
428 S.AddSpace(5);
429
430 mGridOnOff = S.Id(GridOnOffID).AddCheckBox(XXO("&Grids"), mDrawGrid);
431 }
432 S.EndMultiColumn();
433 }
434 S.EndHorizontalLay();
435
436 S.AddSpace(1);
437 }
438 S.EndMultiColumn();
439
440 // -------------------------------------------------------------------
441 // ROW 5: Spacer
442 // -------------------------------------------------------------------
443
444 S.AddSpace(5);
445
446 S.SetBorder(2);
447 S.SetSizerProportion(0);
448 S.StartMultiColumn(9, wxALIGN_CENTER);
449 {
450 // ----------------------------------------------------------------
451 // ROW 6: Algorithm, Size, Export, Replot
452 // ----------------------------------------------------------------
453
454 S.AddSpace(5);
455
456 mAlgChoice = S.Id(FreqAlgChoiceID).Focus()
457 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
458 .AddChoice(XXO("&Algorithm:"), algChoices, mAlg);
459
460 S.AddSpace(5);
461
463 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
464 .AddChoice(XXO("&Size:"), sizeChoices, mSize);
465
466 S.AddSpace(5);
467
468 mExportButton = S.Id(FreqExportButtonID).AddButton(XXO("&Export..."));
469
470 S.AddSpace(5);
471
472 // ----------------------------------------------------------------
473 // ROW 7: Function, Axis, Grids, Close
474 // ----------------------------------------------------------------
475
476 S.AddSpace(5);
477
479 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
480 .AddChoice(XXO("&Function:"), funcChoices, mFunc);
481 mFuncChoice->MoveAfterInTabOrder(mSizeChoice);
482
483 S.AddSpace(5);
484
486 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
487 .AddChoice(XXO("&Axis:"), axisChoices, mAxis);
488 mAxisChoice->MoveAfterInTabOrder(mFuncChoice);
489
490 S.AddSpace(5);
491
492 mReplotButton = S.Id(ReplotButtonID).AddButton(XXO("&Replot..."));
493
494 S.AddSpace(5);
495
496 //mCloseButton = S.Id(wxID_CANCEL).AddButton(XO("&Close"));
497
498 //S.AddSpace(5);
499 }
500 S.EndMultiColumn();
501 S.AddStandardButtons( eHelpButton | eCloseButton );
502
503 // -------------------------------------------------------------------
504 // ROW 8: Spacer
505 // -------------------------------------------------------------------
506
507 S.AddSpace(5);
508
509 mProgress = safenew FreqGauge(S.GetParent(), wxID_ANY); //, wxST_SIZEGRIP);
510 S.Position(wxEXPAND)
511 .AddWindow(mProgress);
512
513 // Log-frequency axis works for spectrum plots only.
515 {
516 mAxis = 0;
517 mAxisChoice->Disable();
518 }
519 mLogAxis = mAxis != 0;
520
521 mCloseButton = static_cast<wxButton*>(FindWindowById( wxID_CANCEL ));
522 mCloseButton->SetDefault();
523
524 Layout();
525 Fit();
526 // Bug 1607:
527 Center();
528
529 SetMinSize(GetSize());
530
531#if defined(__WXGTK__)
532 // This should be rechecked with wx3.
533 //
534 // The scrollbar (focus some reason) doesn't allow tabbing past it
535 // because it can't receive focus. So, convince it otherwise.
536 //
537 // Unfortunately, this still doesn't let you adjust the scrollbar
538 // from the keyboard. Near as I can tell, wxWGTK is capturing the
539 // keyboard input, so the GTK widget doesn't see it, preventing
540 // the normal scroll events from being generated.
541 //
542 // I guess the only way round it would be to handle key actions
543 // ourselves, but we'll leave that for a future date.
544// gtk_widget_set_can_focus(mPanScroller->m_widget, true);
545#endif
546}
int NumWindowFuncs()
Definition: FFT.cpp:329
const TranslatableString WindowFuncName(int whichFunction)
Definition: FFT.cpp:334
#define FrequencyAnalysisTitle
Definition: FreqWindow.cpp:92
static const char * ZoomOut[]
Definition: FreqWindow.cpp:140
#define FREQ_WINDOW_HEIGHT
Definition: FreqWindow.cpp:113
static const char * ZoomIn[]
Definition: FreqWindow.cpp:115
@ FreqAxisChoiceID
Definition: FreqWindow.cpp:105
@ FreqFuncChoiceID
Definition: FreqWindow.cpp:104
@ FreqPanScrollerID
Definition: FreqWindow.cpp:100
@ FreqExportButtonID
Definition: FreqWindow.cpp:101
@ ReplotButtonID
Definition: FreqWindow.cpp:106
@ FreqAlgChoiceID
Definition: FreqWindow.cpp:102
@ FreqSizeChoiceID
Definition: FreqWindow.cpp:103
@ FreqZoomSliderID
Definition: FreqWindow.cpp:99
@ GridOnOffID
Definition: FreqWindow.cpp:107
#define XXO(s)
Definition: Internat.h:44
#define safenew
Definition: MemoryX.h:10
@ eIsCreating
Definition: ShuttleGui.h:39
@ eCloseButton
Definition: ShuttleGui.h:607
@ eHelpButton
Definition: ShuttleGui.h:601
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
friend class FreqPlot
Definition: FreqWindow.h:158
wxButton * mExportButton
Definition: FreqWindow.h:126
wxButton * mReplotButton
Definition: FreqWindow.h:127
static const int fontSize
Definition: FreqWindow.h:108
FreqGauge * mProgress
Definition: FreqWindow.h:116
wxButton * mCloseButton
Definition: FreqWindow.h:125
RulerPanel class allows you to work with a Ruler like any other wxWindow.
Definition: Ruler.h:228
std::pair< double, double > Range
Definition: Ruler.h:232
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
void SetTitle(const TranslatableString &title)
Options & LabelEdges(bool l)
Definition: Ruler.h:250
Options & Log(bool l)
Definition: Ruler.h:244

References ThemeBase::Colour(), dBRange, DecibelScaleCutoff, eCloseButton, eHelpButton, eIsCreating, fontSize, FREQ_WINDOW_HEIGHT, FreqAlgChoiceID, FreqAxisChoiceID, FreqExportButtonID, FreqFuncChoiceID, FreqPanScrollerID, FreqPlot, FreqSizeChoiceID, FrequencyAnalysisTitle, FreqZoomSliderID, GridOnOffID, hRuler, RulerPanel::Options::LabelEdges(), Ruler::LinearDBFormat, RulerPanel::Options::Log(), mAlg, mAlgChoice, mArrowCursor, mAxis, mAxisChoice, mCloseButton, mCrossCursor, mCursorText, mDrawGrid, mExportButton, mFreqFont, mFreqPlot, mFunc, mFuncChoice, mGridOnOff, mLogAxis, mPanScroller, mPeakText, mProgress, mReplotButton, mSize, mSizeChoice, mWindowSize, mZoomSlider, NumWindowFuncs(), Setting< T >::Read(), Ruler::RealFormat, ReplotButtonID, S, safenew, wxDialogWrapper::SetTitle(), size, SpectrumAnalyst::Spectrum, theTheme, Verbatim(), vRuler, WindowFuncName(), wxT(), XO, XXO, ZoomIn, and ZoomOut.

Referenced by UpdatePrefs().

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

◆ Recalc()

void FrequencyPlotDialog::Recalc ( )
private

Definition at line 1012 of file FreqWindow.cpp.

1013{
1014 if (!mData || mDataLen < mWindowSize) {
1015 DrawPlot();
1016 return;
1017 }
1018
1020 SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
1021 int windowFunc = mFuncChoice->GetSelection();
1022
1023 wxWindow *hadFocus = FindFocus();
1024 // In wxMac, the skipped window MUST be a top level window. I'd originally made it
1025 // just the mProgress window with the idea of preventing user interaction with the
1026 // controls while the plot was being recalculated. This doesn't appear to be necessary
1027 // so just use the top level window instead.
1028 {
1029 std::optional<wxWindowDisabler> blocker;
1030 if (IsShown())
1031 blocker.emplace(this);
1032 wxYieldIfNeeded();
1033
1034 mAnalyst->Calculate(alg, windowFunc, mWindowSize, mRate,
1035 mData.get(), mDataLen,
1036 &mYMin, &mYMax, mProgress);
1037 }
1038 if (hadFocus) {
1039 hadFocus->SetFocus();
1040 }
1041
1042 if (alg == SpectrumAnalyst::Spectrum) {
1043 if(mYMin < -dBRange)
1044 mYMin = -dBRange;
1045 if(mYMax <= -dBRange)
1046 mYMax = -dBRange + 10.; // it's all out of range, but show a scale.
1047 else
1048 mYMax += .5;
1049 }
1050
1051 // Prime the scrollbar
1052 mPanScroller->SetScrollbar(0, (mYMax - mYMin) * 100, (mYMax - mYMin) * 100, 1);
1053
1054 DrawPlot();
1055}

References dBRange, DrawPlot(), mAlgChoice, mAnalyst, mData, mDataLen, mFuncChoice, mPanScroller, mProgress, mRate, mWindowSize, mYMax, mYMin, and SpectrumAnalyst::Spectrum.

Referenced by OnRecalc(), and Show().

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

◆ SendRecalcEvent()

void FrequencyPlotDialog::SendRecalcEvent ( )
private

Definition at line 1006 of file FreqWindow.cpp.

1007{
1008 wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
1009 GetEventHandler()->AddPendingEvent(e);
1010}

Referenced by OnAlgChoice(), OnFuncChoice(), OnReplot(), and OnSizeChoice().

Here is the caller graph for this function:

◆ Show()

bool FrequencyPlotDialog::Show ( bool  show = true)
override

Definition at line 555 of file FreqWindow.cpp.

556{
557 if (!show)
558 {
559 mFreqPlot->SetCursor(*mArrowCursor);
560 }
561
562 bool shown = IsShown();
563
564 if (show && !shown)
565 {
567 if(dBRange < 90.)
568 dBRange = 90.;
569 GetAudio();
570 // Don't send an event. We need the recalc right away.
571 // so that mAnalyst is valid when we paint.
572 //SendRecalcEvent();
573 Recalc();
574 }
575
576 bool res = wxDialogWrapper::Show(show);
577
578 return res;
579}

References dBRange, DecibelScaleCutoff, GetAudio(), mArrowCursor, mFreqPlot, Setting< T >::Read(), and Recalc().

Referenced by OnCloseButton(), OnCloseWindow(), anonymous_namespace{FreqWindow.cpp}::Handler::OnPlotSpectrum(), and UpdatePrefs().

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

◆ UpdatePrefs()

void FrequencyPlotDialog::UpdatePrefs ( )
overrideprivatevirtual

Implements PrefsListener.

Definition at line 1122 of file FreqWindow.cpp.

1123{
1124 bool shown = IsShown();
1125 if (shown) {
1126 Show(false);
1127 }
1128
1129 auto zoomSlider = mZoomSlider->GetValue();
1130 auto drawGrid = mGridOnOff->GetValue();
1131 auto sizeChoice = mSizeChoice->GetStringSelection();
1132 auto algChoice = mAlgChoice->GetSelection();
1133 auto funcChoice = mFuncChoice->GetSelection();
1134 auto axisChoice = mAxisChoice->GetSelection();
1135
1136 SetSizer(nullptr);
1137 DestroyChildren();
1138
1139 Populate();
1140
1141 mZoomSlider->SetValue(zoomSlider);
1142
1143 mDrawGrid = drawGrid;
1144 mGridOnOff->SetValue(drawGrid);
1145
1146 long windowSize = 0;
1147 sizeChoice.ToLong(&windowSize);
1148 mWindowSize = windowSize;
1149 mSizeChoice->SetStringSelection(sizeChoice);
1150
1151 mAlg = static_cast<SpectrumAnalyst::Algorithm>(algChoice);
1152 mAlgChoice->SetSelection(algChoice);
1153
1154 mFunc = funcChoice;
1155 mFuncChoice->SetSelection(funcChoice);
1156
1157 mAxis = axisChoice;
1158 mAxisChoice->SetSelection(axisChoice);
1159
1160 if (shown) {
1161 Show(true);
1162 }
1163}

References mAlg, mAlgChoice, mAxis, mAxisChoice, mDrawGrid, mFunc, mFuncChoice, mGridOnOff, mSizeChoice, mWindowSize, mZoomSlider, Populate(), and Show().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ FreqPlot

friend class FreqPlot
friend

Definition at line 158 of file FreqWindow.h.

Referenced by Populate().

Member Data Documentation

◆ dBRange

int FrequencyPlotDialog::dBRange
private

Definition at line 104 of file FreqWindow.h.

Referenced by DrawPlot(), OnReplot(), Populate(), Recalc(), and Show().

◆ fontSize

const int FrequencyPlotDialog::fontSize = 8
staticprivate

Definition at line 108 of file FreqWindow.h.

Referenced by Populate().

◆ hRuler

RulerPanel* FrequencyPlotDialog::hRuler
private

Definition at line 114 of file FreqWindow.h.

Referenced by DrawPlot(), and Populate().

◆ mAlg

SpectrumAnalyst::Algorithm FrequencyPlotDialog::mAlg
private

Definition at line 101 of file FreqWindow.h.

Referenced by DrawPlot(), OnAlgChoice(), PlotPaint(), Populate(), and UpdatePrefs().

◆ mAlgChoice

wxChoice* FrequencyPlotDialog::mAlgChoice
private

Definition at line 129 of file FreqWindow.h.

Referenced by OnAlgChoice(), OnCloseButton(), OnExport(), Populate(), Recalc(), and UpdatePrefs().

◆ mAnalyst

std::unique_ptr<SpectrumAnalyst> FrequencyPlotDialog::mAnalyst
private

Definition at line 154 of file FreqWindow.h.

Referenced by DrawPlot(), OnExport(), PlotPaint(), and Recalc().

◆ mArrowCursor

std::unique_ptr<wxCursor> FrequencyPlotDialog::mArrowCursor
private

Definition at line 122 of file FreqWindow.h.

Referenced by PlotMouseEvent(), Populate(), and Show().

◆ mAxis

int FrequencyPlotDialog::mAxis
private

Definition at line 103 of file FreqWindow.h.

Referenced by Populate(), and UpdatePrefs().

◆ mAxisChoice

wxChoice* FrequencyPlotDialog::mAxisChoice
private

Definition at line 132 of file FreqWindow.h.

Referenced by OnAlgChoice(), OnAxisChoice(), OnCloseButton(), Populate(), and UpdatePrefs().

◆ mBitmap

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

Definition at line 149 of file FreqWindow.h.

Referenced by DrawBackground(), and PlotPaint().

◆ mCloseButton

wxButton* FrequencyPlotDialog::mCloseButton
private

Definition at line 125 of file FreqWindow.h.

Referenced by Populate().

◆ mCrossCursor

std::unique_ptr<wxCursor> FrequencyPlotDialog::mCrossCursor
private

Definition at line 123 of file FreqWindow.h.

Referenced by PlotMouseEvent(), and Populate().

◆ mCursorText

wxTextCtrl* FrequencyPlotDialog::mCursorText
private

Definition at line 135 of file FreqWindow.h.

Referenced by PlotPaint(), and Populate().

◆ mData

Floats FrequencyPlotDialog::mData
private

Definition at line 141 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), OnCloseButton(), PlotPaint(), and Recalc().

◆ mDataLen

size_t FrequencyPlotDialog::mDataLen
private

Definition at line 140 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), PlotPaint(), and Recalc().

◆ mDrawGrid

bool FrequencyPlotDialog::mDrawGrid
private

Definition at line 99 of file FreqWindow.h.

Referenced by DrawPlot(), OnCloseButton(), OnGridOnOff(), Populate(), and UpdatePrefs().

◆ mExportButton

wxButton* FrequencyPlotDialog::mExportButton
private

Definition at line 126 of file FreqWindow.h.

Referenced by Populate().

◆ mFreqFont

wxFont FrequencyPlotDialog::mFreqFont
private

Definition at line 120 of file FreqWindow.h.

Referenced by DrawBackground(), PlotPaint(), and Populate().

◆ mFreqPlot

FreqPlot* FrequencyPlotDialog::mFreqPlot
private

Definition at line 115 of file FreqWindow.h.

Referenced by DrawBackground(), DrawPlot(), PlotMouseEvent(), Populate(), and Show().

◆ mFunc

int FrequencyPlotDialog::mFunc
private

Definition at line 102 of file FreqWindow.h.

Referenced by Populate(), and UpdatePrefs().

◆ mFuncChoice

wxChoice* FrequencyPlotDialog::mFuncChoice
private

Definition at line 131 of file FreqWindow.h.

Referenced by OnCloseButton(), Populate(), Recalc(), and UpdatePrefs().

◆ mGridOnOff

wxCheckBox* FrequencyPlotDialog::mGridOnOff
private

Definition at line 128 of file FreqWindow.h.

Referenced by OnGridOnOff(), Populate(), and UpdatePrefs().

◆ mLogAxis

bool FrequencyPlotDialog::mLogAxis
private

Definition at line 144 of file FreqWindow.h.

Referenced by DrawPlot(), OnAlgChoice(), OnAxisChoice(), PlotPaint(), and Populate().

◆ mMouseX

int FrequencyPlotDialog::mMouseX
private

Definition at line 151 of file FreqWindow.h.

Referenced by PlotMouseEvent(), and PlotPaint().

◆ mMouseY

int FrequencyPlotDialog::mMouseY
private

Definition at line 152 of file FreqWindow.h.

Referenced by PlotMouseEvent(), and PlotPaint().

◆ mPanScroller

wxScrollBar* FrequencyPlotDialog::mPanScroller
private

Definition at line 133 of file FreqWindow.h.

Referenced by DrawPlot(), Populate(), and Recalc().

◆ mPeakText

wxTextCtrl* FrequencyPlotDialog::mPeakText
private

Definition at line 136 of file FreqWindow.h.

Referenced by PlotPaint(), and Populate().

◆ mPlotRect

wxRect FrequencyPlotDialog::mPlotRect
private

Definition at line 118 of file FreqWindow.h.

Referenced by DrawBackground(), DrawPlot(), PlotMouseEvent(), and PlotPaint().

◆ mProgress

FreqGauge* FrequencyPlotDialog::mProgress
private

Definition at line 116 of file FreqWindow.h.

Referenced by Populate(), and Recalc().

◆ mProject

AudacityProject* FrequencyPlotDialog::mProject
private

Definition at line 105 of file FreqWindow.h.

◆ mRate

double FrequencyPlotDialog::mRate
private

Definition at line 139 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), OnExport(), PlotPaint(), and Recalc().

◆ mReplotButton

wxButton* FrequencyPlotDialog::mReplotButton
private

Definition at line 127 of file FreqWindow.h.

Referenced by Populate().

◆ mSize

int FrequencyPlotDialog::mSize
private

Definition at line 100 of file FreqWindow.h.

Referenced by Populate().

◆ mSizeChoice

wxChoice* FrequencyPlotDialog::mSizeChoice
private

Definition at line 130 of file FreqWindow.h.

Referenced by OnCloseButton(), OnSizeChoice(), Populate(), and UpdatePrefs().

◆ mWindowSize

size_t FrequencyPlotDialog::mWindowSize
private

Definition at line 142 of file FreqWindow.h.

Referenced by DrawPlot(), OnExport(), OnSizeChoice(), PlotPaint(), Populate(), Recalc(), and UpdatePrefs().

◆ mYMax

float FrequencyPlotDialog::mYMax
private

Definition at line 146 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

◆ mYMin

float FrequencyPlotDialog::mYMin
private

Definition at line 145 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

◆ mYStep

float FrequencyPlotDialog::mYStep
private

Definition at line 147 of file FreqWindow.h.

◆ mZoomSlider

wxSlider* FrequencyPlotDialog::mZoomSlider
private

Definition at line 134 of file FreqWindow.h.

Referenced by DrawPlot(), Populate(), and UpdatePrefs().

◆ vRuler

RulerPanel* FrequencyPlotDialog::vRuler
private

Definition at line 113 of file FreqWindow.h.

Referenced by DrawPlot(), and Populate().


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